summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2017-07-15 16:12:45 -0700
committerRobert Bradshaw <robertwb@gmail.com>2017-07-15 16:12:45 -0700
commit5e2dc4f78e2c9b560b07f73e664f3e70f7a8cfc8 (patch)
treec1b07ca71bcd67565a04a18b6a9140cf8f7cf701
parent85a2dfe76a2bc28d4c8c1a760ef04e614f61be73 (diff)
downloadcython-5e2dc4f78e2c9b560b07f73e664f3e70f7a8cfc8.tar.gz
Fix performance regression in exception tracebacks.
See #1719.
-rw-r--r--Cython/Utility/Exceptions.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c
index 910cbfcb2..7211953f9 100644
--- a/Cython/Utility/Exceptions.c
+++ b/Cython/Utility/Exceptions.c
@@ -603,10 +603,19 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
PyObject *use_cline = 0;
PyObject *ptype, *pvalue, *ptraceback;
+ static PyObject* cline_in_traceback = NULL;
+ if (cline_in_traceback == NULL) {
+ cline_in_traceback = PyString_InternFromString("cline_in_traceback");
+ }
+
if (c_line) {
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
- use_cline = PyObject_GetAttrString(${cython_runtime_cname}, "cline_in_traceback");
- if (use_cline == NULL || PyObject_Not(use_cline) != 0) {
+ use_cline = PyObject_GetAttr(${cython_runtime_cname}, cline_in_traceback);
+ if (use_cline == NULL) {
+ c_line = 0;
+ PyObject_SetAttr(${cython_runtime_cname}, cline_in_traceback, Py_False);
+ }
+ else if (PyObject_Not(use_cline) != 0) {
c_line = 0;
}
PyErr_Restore(ptype, pvalue, ptraceback);