Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r90662:1c56df677261
Date: 2017-03-13 17:34 +0100
http://bitbucket.org/pypy/pypy/changeset/1c56df677261/

Log:    Issue #2480: Test and fix for 'tp_bases'

diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1200,4 +1200,21 @@
         assert type(obj).__doc__ == "The Base12 type or object"
         assert obj.__doc__ == "The Base12 type or object"
 
-
+    def test_multiple_inheritance_fetch_tp_bases(self):
+        module = self.import_extension('foo', [
+           ("foo", "METH_O",
+            '''
+                PyTypeObject *tp;
+                tp = (PyTypeObject*)args;
+                Py_INCREF(tp->tp_bases);
+                return tp->tp_bases;
+            '''
+            )])
+        class A(object):
+            pass
+        class B(object):
+            pass
+        class C(A, B):
+            pass
+        bases = module.foo(C)
+        assert bases == (A, B)
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -760,7 +760,7 @@
     if builder.cpyext_type_init is not None:
         builder.cpyext_type_init.append((pto, w_type))
     else:
-        finish_type_1(space, pto)
+        finish_type_1(space, pto, w_type.bases_w)
         finish_type_2(space, pto, w_type)
 
     pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
@@ -903,7 +903,7 @@
 
     return w_obj
 
-def finish_type_1(space, pto):
+def finish_type_1(space, pto, bases_w=None):
     """
     Sets up tp_bases, necessary before creating the interpreter type.
     """
@@ -915,11 +915,12 @@
     if base and not pto.c_ob_type: # will be filled later
         pto.c_ob_type = base.c_ob_type
     if not pto.c_tp_bases:
-        if not base:
-            bases = space.newtuple([])
-        else:
-            bases = space.newtuple([from_ref(space, base_pyo)])
-        pto.c_tp_bases = make_ref(space, bases)
+        if bases_w is None:
+            if not base:
+                bases_w = []
+            else:
+                bases_w = [from_ref(space, base_pyo)]
+        pto.c_tp_bases = make_ref(space, space.newtuple(bases_w))
 
 def finish_type_2(space, pto, w_obj):
     """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to