Author: Matti Picus <[email protected]>
Branch: missing-tp_new
Changeset: r88607:83a4988743eb
Date: 2016-11-24 11:23 +0200
http://bitbucket.org/pypy/pypy/changeset/83a4988743eb/

Log:    next set of hacks, still not good enough to pass cython datetime
        tests

diff --git a/pypy/module/cpyext/test/foo3.c b/pypy/module/cpyext/test/foo3.c
--- a/pypy/module/cpyext/test/foo3.c
+++ b/pypy/module/cpyext/test/foo3.c
@@ -21,6 +21,11 @@
     return newType;
 }
 
+void datetimetype_tp_dealloc(PyObject* self)
+{
+    return ((PyTypeObject*)typ)->tp_dealloc(self);
+}
+
 #define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
Py_TPFLAGS_CHECKTYPES
 
 PyTypeObject footype = {
@@ -76,7 +81,7 @@
     /*tp_name*/             "foo3.datetimetype",
     /*tp_basicsize*/        sizeof(PyTypeObject),
     /*tp_itemsize*/         0,
-    /*tp_dealloc*/          0,
+    /*tp_dealloc*/          datetimetype_tp_dealloc,
     /*tp_print*/            0,
     /*tp_getattr*/          0,
     /*tp_setattr*/          0,
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
@@ -1211,6 +1211,5 @@
             self._check_type_object(FooType)
         class X(object):
             __metaclass__ = FooType
-        print repr(X)
         X()
 
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
@@ -504,9 +504,15 @@
     this_func_ptr = llhelper(subtype_dealloc.api_func.functype,
             subtype_dealloc.api_func.get_wrapper(space))
     w_obj = from_ref(space, rffi.cast(PyObject, base))
-    # see comment in userslot.slot_tp_new, this call can also infinitely 
recurse if
-    # called with a c-extension type that inherits from a non-c-extension type
-    while base.c_tp_dealloc == this_func_ptr or w_obj.is_cpytype():
+    obj_not_cpytype = not w_obj.is_cpytype()
+    # see comment in userslot.slot_tp_new, this call can infinitely recurse
+    # We can only get into this function if tp_dealloc is being called on 
+    # a non-cpytype, which could or could not inherit from a cpytype
+    # So if the original obj is non-cpytype, climb the mro to the first 
non-cpytype,
+    # otherwise just make sure we are not calling ourselves again
+    #
+    # This logic might fail for complicated inheritance schemes.
+    while base.c_tp_dealloc == this_func_ptr or (obj_not_cpytype and 
w_obj.is_cpytype()):
         base = base.c_tp_base
         assert base
         w_obj = from_ref(space, rffi.cast(PyObject, base))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to