summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-07-30 06:55:48 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-07-30 06:55:48 (GMT)
commit07aadb14f39c585a463f19ec0496860a100051ad (patch)
tree633fcc0bb9fa8edbdae49bf761c3c3ec822319c6 /Python
parent0d62a062066a4cbc8aabab9c305d60ebf7922c8c (diff)
downloadcpython-07aadb14f39c585a463f19ec0496860a100051ad.zip
cpython-07aadb14f39c585a463f19ec0496860a100051ad.tar.gz
cpython-07aadb14f39c585a463f19ec0496860a100051ad.tar.bz2
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')
-rw-r--r--Python/errors.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 56463a3..43d89bd 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