mirror of
https://github.com/python/cpython.git
synced 2025-10-03 13:45:29 +00:00
while adding the traceback, because it may call indirectly a Python function and Python functions must not be called with an exception set. In the case of the issue #18609, _ctypes_add_traceback() called the iso8859-1 decoder which is implemented in Python. Python has a ISO-8859-1 codec implemented in C. It is not used because PyUnicode_Decode() only uses the C codec for other names (aliases) of this codec ("latin-1", "latin1" and "iso-8859-1").
This commit is contained in:
parent
362532bc48
commit
044c516854
1 changed files with 20 additions and 3 deletions
|
@ -98,20 +98,37 @@ void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
|
||||||
PyObject *py_globals = 0;
|
PyObject *py_globals = 0;
|
||||||
PyCodeObject *py_code = 0;
|
PyCodeObject *py_code = 0;
|
||||||
PyFrameObject *py_frame = 0;
|
PyFrameObject *py_frame = 0;
|
||||||
|
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);
|
||||||
|
|
||||||
py_globals = PyDict_New();
|
py_globals = PyDict_New();
|
||||||
if (!py_globals) goto bad;
|
if (!py_globals)
|
||||||
|
goto bad;
|
||||||
py_code = PyCode_NewEmpty(filename, funcname, lineno);
|
py_code = PyCode_NewEmpty(filename, funcname, lineno);
|
||||||
if (!py_code) goto bad;
|
if (!py_code)
|
||||||
|
goto bad;
|
||||||
py_frame = PyFrame_New(
|
py_frame = PyFrame_New(
|
||||||
PyThreadState_Get(), /*PyThreadState *tstate,*/
|
PyThreadState_Get(), /*PyThreadState *tstate,*/
|
||||||
py_code, /*PyCodeObject *code,*/
|
py_code, /*PyCodeObject *code,*/
|
||||||
py_globals, /*PyObject *globals,*/
|
py_globals, /*PyObject *globals,*/
|
||||||
0 /*PyObject *locals*/
|
0 /*PyObject *locals*/
|
||||||
);
|
);
|
||||||
if (!py_frame) goto bad;
|
if (!py_frame)
|
||||||
|
goto bad;
|
||||||
py_frame->f_lineno = lineno;
|
py_frame->f_lineno = lineno;
|
||||||
|
|
||||||
|
PyErr_Restore(exception, value, tb);
|
||||||
PyTraceBack_Here(py_frame);
|
PyTraceBack_Here(py_frame);
|
||||||
|
|
||||||
|
Py_DECREF(py_globals);
|
||||||
|
Py_DECREF(py_code);
|
||||||
|
Py_DECREF(py_frame);
|
||||||
|
return;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
Py_XDECREF(py_globals);
|
Py_XDECREF(py_globals);
|
||||||
Py_XDECREF(py_code);
|
Py_XDECREF(py_code);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue