summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-07-16 09:55:00 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-07-16 09:55:00 +0200
commit13a88f9558886b91cde838d29e226d76bac1b099 (patch)
treefb94636dbf68a13d2f39e3c574956a0969a087dd
parentf7f9ae4c63930d089cebd169665695f8e729beeb (diff)
downloadcython-13a88f9558886b91cde838d29e226d76bac1b099.tar.gz
extract C-line handling from AddTraceback() into separate function to keep AddTraceback() available as a shared header file
-rw-r--r--Cython/Utility/Exceptions.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c
index de24c9cf8..5cc57ed8f 100644
--- a/Cython/Utility/Exceptions.c
+++ b/Cython/Utility/Exceptions.c
@@ -529,6 +529,32 @@ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
#endif
}
+/////////////// CLineInTraceback.proto ///////////////
+
+static int __Pyx_CLineForTraceback(int c_line);
+
+/////////////// CLineInTraceback ///////////////
+//@requires: ObjectHandling.c::PyObjectGetAttrStr
+//@substitute: naming
+
+static int __Pyx_CLineForTraceback(int c_line) {
+ PyObject *ptype, *pvalue, *ptraceback;
+ PyObject *use_cline;
+
+ PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ use_cline = __Pyx_PyObject_GetAttrStr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"));
+ if (!use_cline) {
+ c_line = 0;
+ PyObject_SetAttr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"), Py_False);
+ }
+ else if (PyObject_Not(use_cline) != 0) {
+ c_line = 0;
+ }
+ Py_XDECREF(use_cline);
+ PyErr_Restore(ptype, pvalue, ptraceback);
+ return c_line;
+}
+
/////////////// AddTraceback.proto ///////////////
static void __Pyx_AddTraceback(const char *funcname, int c_line,
@@ -536,7 +562,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
/////////////// AddTraceback ///////////////
//@requires: ModuleSetupCode.c::CodeObjectCache
-//@requires: ObjectHandling.c::PyObjectGetAttrStr
+//@requires: CLineInTraceback
//@substitute: naming
#include "compile.h"
@@ -601,20 +627,9 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
int py_line, const char *filename) {
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
- PyObject *use_cline = 0;
- PyObject *ptype, *pvalue, *ptraceback;
if (c_line) {
- PyErr_Fetch(&ptype, &pvalue, &ptraceback);
- use_cline = __Pyx_PyObject_GetAttrStr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"));
- if (use_cline == NULL) {
- c_line = 0;
- PyObject_SetAttr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"), Py_False);
- }
- else if (PyObject_Not(use_cline) != 0) {
- c_line = 0;
- }
- PyErr_Restore(ptype, pvalue, ptraceback);
+ c_line = __Pyx_CLineForTraceback(c_line);
}
// Negate to avoid collisions between py and c lines.
@@ -637,5 +652,4 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
bad:
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
- Py_XDECREF(use_cline);
}