summaryrefslogtreecommitdiff
path: root/Cython/Runtime
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@math.washington.edu>2009-02-25 12:25:16 -0800
committerRobert Bradshaw <robertwb@math.washington.edu>2009-02-25 12:25:16 -0800
commita74288bc92f185c294ad8ad26a2e25be4cc45d48 (patch)
treed9c5b55c7db960b9793c7a8c5a022f2a48f09afb /Cython/Runtime
parent55df14e80ddcfb122eadeb60cb642f2d0a9bf419 (diff)
downloadcython-a74288bc92f185c294ad8ad26a2e25be4cc45d48.tar.gz
Avoid crashes in refnanny when PyFinalize gets messy, Sage now exits cleanly.
Diffstat (limited to 'Cython/Runtime')
-rw-r--r--Cython/Runtime/refnanny.pyx15
1 files changed, 10 insertions, 5 deletions
diff --git a/Cython/Runtime/refnanny.pyx b/Cython/Runtime/refnanny.pyx
index 267cbf5a1..a6be7c635 100644
--- a/Cython/Runtime/refnanny.pyx
+++ b/Cython/Runtime/refnanny.pyx
@@ -62,7 +62,7 @@ class Context(object):
else:
return None
-def report_unraisable(e):
+cpdef report_unraisable(e):
try:
print "refnanny raised an exception: %s" % e
except:
@@ -73,6 +73,11 @@ def report_unraisable(e):
# exception-handling code.
cdef PyObject* NewContext(char* funcname, int lineno, char* filename) except NULL:
+ if Context is None:
+ # Context may be None during finalize phase.
+ # In that case, we don't want to be doing anything fancy
+ # like caching and resetting exceptions.
+ return NULL
cdef PyObject* type = NULL, *value = NULL, *tb = NULL
cdef PyObject* result = NULL
PyErr_Fetch(&type, &value, &tb)
@@ -125,18 +130,18 @@ cdef void DECREF(PyObject* ctx, PyObject* obj, int lineno):
if obj is not NULL: Py_DECREF(<object>obj)
cdef void FinishContext(PyObject** ctx):
+ if ctx == NULL or ctx[0] == NULL:
+ # We should have reported an error earlier.
+ return
cdef PyObject* type = NULL, *value = NULL, *tb = NULL
cdef object errors = None
PyErr_Fetch(&type, &value, &tb)
try:
- if ctx == NULL: assert False, "ctx is NULL"
- if ctx[0] == NULL: assert False, "ctx[0] is NULL"
-
errors = (<object>ctx[0]).end()
pos = (<object>ctx[0]).filename, (<object>ctx[0]).name
if errors:
print u"%s: %s()" % pos
- print errors # raise Error(errors)
+ print errors
except Exception, e:
report_unraisable(e)
Py_XDECREF(<object>ctx[0])