From 07aadb14f39c585a463f19ec0496860a100051ad Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 30 Jul 2006 06:55:48 +0000 Subject: 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. --- Python/errors.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Python/errors.c') 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 -- cgit v1.2.1