[pypy-commit] pypy cpyext-leakchecking: A failing test that explains why test_subclass() leaks the class Sub
rlamy
pypy.commits at gmail.com
Tue Jul 25 14:20:49 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: cpyext-leakchecking
Changeset: r91971:82d95ae3d2c8
Date: 2017-07-25 20:19 +0200
http://bitbucket.org/pypy/pypy/changeset/82d95ae3d2c8/
Log: A failing test that explains why test_subclass() leaks the class Sub
diff --git a/pypy/module/cpyext/test/array.c b/pypy/module/cpyext/test/array.c
--- a/pypy/module/cpyext/test/array.c
+++ b/pypy/module/cpyext/test/array.c
@@ -2468,6 +2468,15 @@
Py_RETURN_NONE;
}
+static PyObject *
+same_dealloc(PyObject *self, PyObject *args)
+{
+ PyObject *obj1, *obj2;
+ if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) {
+ return NULL;
+ }
+ return PyLong_FromLong(obj1->ob_type->tp_dealloc == obj2->ob_type->tp_dealloc);
+}
/*********************** Install Module **************************/
@@ -2477,6 +2486,7 @@
{"readbuffer_as_string", (PyCFunction)readbuffer_as_string, METH_VARARGS, NULL},
{"get_releasebuffer_cnt", (PyCFunction)get_releasebuffer_cnt, METH_NOARGS, NULL},
{"create_and_release_buffer", (PyCFunction)create_and_release_buffer, METH_O, NULL},
+ {"same_dealloc", (PyCFunction)same_dealloc, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL} /* Sentinel */
};
diff --git a/pypy/module/cpyext/test/test_arraymodule.py b/pypy/module/cpyext/test/test_arraymodule.py
--- a/pypy/module/cpyext/test/test_arraymodule.py
+++ b/pypy/module/cpyext/test/test_arraymodule.py
@@ -111,6 +111,18 @@
res = [1, 2, 3] * arr
assert res == [2, 4, 6]
+ def test_subclass_dealloc(self):
+ module = self.import_module(name='array')
+ class Sub(module.array):
+ pass
+
+ arr = Sub('i', [2])
+ module.readbuffer_as_string(arr)
+ class A(object):
+ pass
+ assert not module.same_dealloc(arr, module.array('i', [2]))
+ assert module.same_dealloc(arr, A())
+
def test_subclass(self):
import struct
module = self.import_module(name='array')
More information about the pypy-commit
mailing list