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.
This commit is contained in:
Neal Norwitz 2006-07-30 06:55:48 +00:00
parent 0d62a06206
commit 07aadb14f3
4 changed files with 28 additions and 7 deletions

View file

@ -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