Author: Devin Jeanpierre <[email protected]>
Branch: 
Changeset: r80202:0c4b1779bcfc
Date: 2015-10-12 02:42 -0700
http://bitbucket.org/pypy/pypy/changeset/0c4b1779bcfc/

Log:    Handle None explicitly, after failing to handle it twice!

diff --git a/pypy/module/cpyext/pytraceback.py 
b/pypy/module/cpyext/pytraceback.py
--- a/pypy/module/cpyext/pytraceback.py
+++ b/pypy/module/cpyext/pytraceback.py
@@ -32,7 +32,11 @@
 def traceback_attach(space, py_obj, w_obj):
     py_traceback = rffi.cast(PyTracebackObject, py_obj)
     traceback = space.interp_w(PyTraceback, w_obj)
-    py_traceback.c_tb_next = rffi.cast(PyTracebackObject, make_ref(space, 
space.wrap(traceback.next)))
+    if traceback.next is None:
+        w_next_traceback = None
+    else:
+        w_next_traceback = space.wrap(traceback.next)
+    py_traceback.c_tb_next = rffi.cast(PyTracebackObject, make_ref(space, 
w_next_traceback))
     py_traceback.c_tb_frame = rffi.cast(PyFrameObject, make_ref(space, 
space.wrap(traceback.frame)))
     rffi.setintfield(py_traceback, 'c_tb_lasti', traceback.lasti)
     rffi.setintfield(py_traceback, 'c_tb_lineno',traceback.get_lineno())
diff --git a/pypy/module/cpyext/test/test_traceback.py 
b/pypy/module/cpyext/test/test_traceback.py
--- a/pypy/module/cpyext/test/test_traceback.py
+++ b/pypy/module/cpyext/test/test_traceback.py
@@ -1,4 +1,4 @@
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import lltype, rffi
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.pyobject import PyObject, make_ref, from_ref
 from pypy.module.cpyext.pytraceback import PyTracebackObject
@@ -29,12 +29,12 @@
                                                     py_traceback.c_tb_frame)))
 
         while not space.is_w(w_traceback, space.w_None):
-            next_w_traceback = space.getattr(w_traceback, 
space.wrap("tb_next"))
-            next_py_traceback = py_traceback.c_tb_next
             assert space.is_w(
-                next_w_traceback,
-                from_ref(space, rffi.cast(PyObject, next_py_traceback)))
-            w_traceback = next_w_traceback
-            py_traceback = next_py_traceback
+                w_traceback,
+                from_ref(space, rffi.cast(PyObject, py_traceback)))
+            w_traceback = space.getattr(w_traceback, space.wrap("tb_next"))
+            py_traceback = py_traceback.c_tb_next
+
+        assert lltype.normalizeptr(py_traceback) is None
 
         api.Py_DecRef(py_obj)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to