aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/_warnings.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 912468d2a59..39bf1b225cc 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -1479,6 +1479,28 @@ PyErr_WarnExplicitObject(PyObject *category, PyObject *message,
return 0;
}
+/* Like PyErr_WarnExplicitObject, but automatically sets up context */
+int
+_PyErr_WarnExplicitObjectWithContext(PyObject *category, PyObject *message,
+ PyObject *filename, int lineno)
+{
+ PyObject *unused_filename, *module, *registry;
+ int unused_lineno;
+ int stack_level = 1;
+
+ if (!setup_context(stack_level, NULL, &unused_filename, &unused_lineno,
+ &module, &registry)) {
+ return -1;
+ }
+
+ int rc = PyErr_WarnExplicitObject(category, message, filename, lineno,
+ module, registry);
+ Py_DECREF(unused_filename);
+ Py_DECREF(registry);
+ Py_DECREF(module);
+ return rc;
+}
+
int
PyErr_WarnExplicit(PyObject *category, const char *text,
const char *filename_str, int lineno,