Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r84332:adc30cc041ed
Date: 2016-05-09 11:48 +0200
http://bitbucket.org/pypy/pypy/changeset/adc30cc041ed/

Log:    Found the next bug: when you have a Python subclass of a C API type,
        and when you instantiate this Python subclass using C code (!), then
        tp_new is not called

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
@@ -942,6 +942,14 @@
                 Py_INCREF(&Foo_Type);
                 return (PyObject *)&Foo_Type;
              """),
+            ("newInstance", "METH_O",
+             """
+                PyTypeObject *tp = (PyTypeObject *)args;
+                PyObject *e = PyTuple_New(0);
+                PyObject *o = tp->tp_new(tp, e, NULL);
+                Py_DECREF(e);
+                return o;
+             """),
             ("getCounter", "METH_VARARGS",
              """
                 return PyInt_FromLong(foo_counter);
@@ -1000,3 +1008,17 @@
                 break
             self.debug_collect()
         assert module.getCounter() == 5050
+        #
+        module.newInstance(Foo)
+        for i in range(10):
+            if module.getCounter() >= 6060:
+                break
+            self.debug_collect()
+        assert module.getCounter() == 6060
+        #
+        module.newInstance(Bar)
+        for i in range(10):
+            if module.getCounter() >= 7070:
+                break
+            self.debug_collect()
+        #assert module.getCounter() == 7070    -- oops, bug!
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to