Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 39301:7dc5f3ede4cd legacy-trunk
Add PyErr_WarnEx() so C code can pass the stacklevel to warnings.warn().
This provides the proper warning for struct.pack().
PyErr_Warn() is now deprecated in favor of PyErr_WarnEx().
As mentioned by Tim Peters on python-dev.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sun, 30 Jul 2006 06:55:48 +0000 |
| parents | 5531955993ed |
| children | 40585fb387bb |
line wrap: on
line diff
--- a/Python/errors.c Sun Jul 30 06:53:31 2006 +0000 +++ b/Python/errors.c Sun Jul 30 06:55:48 2006 +0000 @@ -632,7 +632,7 @@ /* Function to issue a warning message; may raise an exception. */ int -PyErr_Warn(PyObject *category, char *message) +PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) { PyObject *dict, *func = NULL; PyObject *warnings_module = PyModule_GetWarningsModule(); @@ -650,7 +650,8 @@ if (category == NULL) category = PyExc_RuntimeWarning; - res = PyObject_CallFunction(func, "sO", message, category); + res = PyObject_CallFunction(func, "sOn", + message, category, stack_level); if (res == NULL) return -1; Py_DECREF(res); @@ -658,6 +659,16 @@ } } +/* PyErr_Warn is only for backwards compatability and will be removed. + Use PyErr_WarnEx instead. */ + +#undef PyErr_Warn + +int +PyErr_Warn(PyObject *category, char *message) +{ + return PyErr_WarnEx(category, message, 1); +} /* Warning with explicit origin */ int
