diff options
| author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-30 06:55:48 +0000 |
|---|---|---|
| committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-30 06:55:48 +0000 |
| commit | 8b8664bde1313e4b3c4e253e8f60559378fb3f62 (patch) | |
| tree | 207196821974ecbe2344d8b8cdcfb0542f71fbf8 /Python/errors.c | |
| parent | 87c95634ac347748cd7fabf0c571fa2a97f58a43 (diff) | |
| download | cpython-8b8664bde1313e4b3c4e253e8f60559378fb3f62.tar.gz | |
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.
Diffstat (limited to 'Python/errors.c')
| -rw-r--r-- | Python/errors.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Python/errors.c b/Python/errors.c index 56463a30a0..43d89bd9c8 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -632,7 +632,7 @@ extern PyObject *PyModule_GetWarningsModule(void); /* 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 @@ PyErr_Warn(PyObject *category, char *message) 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(PyObject *category, char *message) } } +/* 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 |
