Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84322:979d7c8fcf6b
Date: 2016-05-09 10:04 +0200
http://bitbucket.org/pypy/pypy/changeset/979d7c8fcf6b/
Log: Fix for 4e12001044f0
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
@@ -922,7 +922,6 @@
else:
raise AssertionError("did not get TypeError!")
- @pytest.mark.xfail
def test_call_tp_dealloc_when_created_from_python(self):
module = self.import_extension('foo', [
("fetchFooType", "METH_VARARGS",
@@ -942,15 +941,16 @@
"""),
("getCounter", "METH_VARARGS",
"""
- return PyInt_FromLong(foo_dealloc_counter);
+ return PyInt_FromLong(foo_counter);
""")], prologue=
"""
- static int foo_dealloc_counter = -1;
+ static int foo_counter = 1000;
static void dealloc_foo(PyObject *foo) {
- foo_dealloc_counter++;
+ foo_counter += 10;
}
static PyObject *new_foo(PyTypeObject *t, PyObject *a, PyObject *k)
{
+ foo_counter += 1000;
return t->tp_alloc(t, 0);
}
static PyTypeObject Foo_Type = {
@@ -959,21 +959,21 @@
};
""")
Foo = module.fetchFooType()
- assert module.getCounter() == 0
+ assert module.getCounter() == 1010
Foo(); Foo()
for i in range(10):
- if module.getCounter() >= 2:
+ if module.getCounter() >= 3030:
break
# NB. use self.debug_collect() instead of gc.collect(),
# otherwise rawrefcount's dealloc callback doesn't trigger
self.debug_collect()
- assert module.getCounter() == 2
+ assert module.getCounter() == 3030
#
class Bar(Foo):
pass
Bar(); Bar()
for i in range(10):
- if module.getCounter() >= 4:
+ if module.getCounter() >= 5050:
break
self.debug_collect()
- assert module.getCounter() == 4
+ assert module.getCounter() == 5050
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
@@ -556,7 +556,14 @@
typedescr = get_typedescr(w_type.layout.typedef)
# dealloc
- pto.c_tp_dealloc = typedescr.get_dealloc(space)
+ if space.gettypeobject(w_type.layout.typedef) is w_type:
+ # only for the exact type, like 'space.w_tuple' or 'space.w_list'
+ pto.c_tp_dealloc = typedescr.get_dealloc(space)
+ else:
+ # for all subtypes, use subtype_dealloc()
+ pto.c_tp_dealloc = llhelper(
+ subtype_dealloc.api_func.functype,
+ subtype_dealloc.api_func.get_wrapper(space))
# buffer protocol
if space.is_w(w_type, space.w_str):
setup_string_buffer_procs(space, pto)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit