work-around to fix ticket #228 at least work in Py2.x, while still preventing crashes...
authorStefan Behnel <scoder@users.berlios.de>
Tue, 3 Mar 2009 19:44:15 +0000 (20:44 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 3 Mar 2009 19:44:15 +0000 (20:44 +0100)
Cython/Compiler/Nodes.py

index 1a2a6d758b10b2ec548c8106aeecfa5a4398a5d0..eacc97f01a3c6d1d5c17860bfcbf3c41223c4143 100644 (file)
@@ -5425,15 +5425,22 @@ static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *t
     PyObject *tmp_type, *tmp_value, *tmp_tb;
     PyThreadState *tstate = PyThreadState_GET();
 
-    tmp_type = tstate->exc_type;
-    tmp_value = tstate->exc_value;
-    tmp_tb = tstate->exc_traceback;
-    tstate->exc_type = 0;
-    tstate->exc_value = 0;
-    tstate->exc_traceback = 0;
-    Py_XDECREF(tmp_type);
-    Py_XDECREF(tmp_value);
-    Py_XDECREF(tmp_tb);
+#if PY_MAJOR_VERSION >= 3
+    /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */
+    if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) {
+        tmp_type = tstate->exc_type;
+        tmp_value = tstate->exc_value;
+        tmp_tb = tstate->exc_traceback;
+        PyErr_NormalizeException(&type, &value, &tb);
+        PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb);
+        tstate->exc_type = 0;
+        tstate->exc_value = 0;
+        tstate->exc_traceback = 0;
+        PyException_SetContext(value, tmp_value);
+        Py_DECREF(tmp_type);
+        Py_XDECREF(tmp_tb);
+    }
+#endif
 
     tmp_type = tstate->curexc_type;
     tmp_value = tstate->curexc_value;