/* Insert a frame into the traceback for (funcname, filename, lineno). */ void _PyTraceback_Add(const char *funcname, const char *filename, int lineno) { PyObject *globals; PyCodeObject *code; PyFrameObject *frame; PyObject *exc, *val, *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(&exc, &val, &tb); globals = PyDict_New(); if (!globals) goto error; code = PyCode_NewEmpty(filename, funcname, lineno); if (!code) { Py_DECREF(globals); goto error; } frame = PyFrame_New(PyThreadState_Get(), code, globals, NULL); Py_DECREF(globals); Py_DECREF(code); if (!frame) goto error; frame->f_lineno = lineno; PyErr_Restore(exc, val, tb); PyTraceBack_Here(frame); Py_DECREF(frame); return; error: _PyErr_ChainExceptions(exc, val, tb); }
/* after code that pyrex generates */ void _ctypes_add_traceback(char *funcname, char *filename, int lineno) { // TODO: Pyston change: // Supporting this will require frameobject.h #if 0 PyObject *py_globals = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; py_globals = PyDict_New(); if (!py_globals) goto bad; py_code = PyCode_NewEmpty(filename, funcname, lineno); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = lineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_globals); Py_XDECREF(py_code); Py_XDECREF(py_frame); #else assert(false); #endif }
static void _add_TB(PyObject *module,char *funcname) { int moduleLineno = GETSTATE(module)->moduleLineno; PyObject *py_globals = NULL; PyCodeObject *py_code = NULL; PyFrameObject *py_frame = NULL; #ifdef isPy3 py_globals = PyModule_GetDict(module); #else py_globals = PyModule_GetDict(GETSTATE(module)->module); #endif if(!py_globals) goto bad; py_code = PyCode_NewEmpty( __FILE__, /*PyObject *filename,*/ funcname, /*PyObject *name,*/ moduleLineno /*int firstlineno,*/ ); if(!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if(!py_frame) goto bad; py_frame->f_lineno = moduleLineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); }
/* after code that pyrex generates */ void _ctypes_add_traceback(char *funcname, char *filename, int lineno) { PyObject *py_globals = 0; PyCodeObject *py_code = 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(); if (!py_globals) goto bad; py_code = PyCode_NewEmpty(filename, funcname, lineno); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = lineno; PyErr_Restore(exception, value, tb); PyTraceBack_Here(py_frame); Py_DECREF(py_globals); Py_DECREF(py_code); Py_DECREF(py_frame); return; bad: Py_XDECREF(py_globals); Py_XDECREF(py_code); Py_XDECREF(py_frame); }
/* after code that pyrex generates */ void _ctypes_add_traceback(char *funcname, char *filename, int lineno) { PyObject *py_globals = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; py_globals = PyDict_New(); if (!py_globals) goto bad; py_code = PyCode_NewEmpty(filename, funcname, lineno); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = lineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_globals); Py_XDECREF(py_code); Py_XDECREF(py_frame); }