Commits

Armin Rigo committed bd4b609

Python 3 confusionness and jumping though hoops.

  • Participants
  • Parent commits b8678b7

Comments (0)

Files changed (2)

File c/_cffi_backend.c

     /* like PyErr_WriteUnraisable(), but write a full traceback */
     PyObject *f, *t, *v, *tb;
     PyErr_Fetch(&t, &v, &tb);
+#if PY_MAJOR_VERSION >= 3
+    /* jump through hoops to ensure the tb is attached to v, on Python 3 */
+    PyErr_NormalizeException(&t, &v, &tb);
+    if (tb == NULL) {
+        tb = Py_None;
+        Py_INCREF(tb);
+    }
+    PyException_SetTraceback(v, tb);
+#endif
     f = PySys_GetObject("stderr");
     if (f != NULL) {
         PyFile_WriteString("From callback ", f);
     except ImportError:
         import io as cStringIO    # Python 3
     import linecache
-    def matches(str, pattern):
+    def matches(istr, ipattern):
+        str, pattern = istr, ipattern
         while '$' in pattern:
             i = pattern.index('$')
             assert str[:i] == pattern[:i]