summaryrefslogtreecommitdiffstats
path: root/Python/traceback.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-10-08 18:02:40 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-10-08 18:02:40 (GMT)
commit94262ebc9c1249c1fdec771a48e9f666c37cfcde (patch)
tree5a2e32677494a1950edfa66ab67a186da867b5d6 /Python/traceback.c
parent3a43dbfabf73c8b74ccbb5255fdd3a2842a045e2 (diff)
parent0ddbf4795f40d2d3386dc56ffa264b50a015f6c9 (diff)
downloadcpython-94262ebc9c1249c1fdec771a48e9f666c37cfcde.zip
cpython-94262ebc9c1249c1fdec771a48e9f666c37cfcde.tar.gz
cpython-94262ebc9c1249c1fdec771a48e9f666c37cfcde.tar.bz2
Issue #22462: Fix pyexpat's creation of a dummy frame to make it appear in exception tracebacks.
Initial patch by Mark Shannon.
Diffstat (limited to 'Python/traceback.c')
-rw-r--r--Python/traceback.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 5d60dad..4316f66 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -142,6 +142,39 @@ PyTraceBack_Here(PyFrameObject *frame)
return 0;
}
+/* Insert a frame into the traceback for (funcname, filename, lineno). */
+void _PyTraceback_Add(char *funcname, char *filename, int lineno)
+{
+ PyObject *globals = NULL;
+ PyCodeObject *code = NULL;
+ PyFrameObject *frame = NULL;
+ PyObject *exception, *value, *tb;
+
+ /* Save and clear the current exception. Python functions must not be
+ called with an exception set. Calling Python functions happens when
+ the codec of the filesystem encoding is implemented in pure Python. */
+ PyErr_Fetch(&exception, &value, &tb);
+
+ globals = PyDict_New();
+ if (!globals)
+ goto done;
+ code = PyCode_NewEmpty(filename, funcname, lineno);
+ if (!code)
+ goto done;
+ frame = PyFrame_New(PyThreadState_Get(), code, globals, NULL);
+ if (!frame)
+ goto done;
+ frame->f_lineno = lineno;
+
+ PyErr_Restore(exception, value, tb);
+ PyTraceBack_Here(frame);
+
+done:
+ Py_XDECREF(globals);
+ Py_XDECREF(code);
+ Py_XDECREF(frame);
+}
+
static PyObject *
_Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *io)
{