diff options
author | Guido van Rossum <guido@python.org> | 2001-10-05 20:51:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-05 20:51:39 (GMT) |
commit | 9475a2310d9cdec4b4c36dee8bf30c72605ae928 (patch) | |
tree | 54b58a165e7b91118dafaa54a00db24162abdff7 /Lib/test/test_gc.py | |
parent | be63884d5069901effb9c045bde43e732c969f71 (diff) | |
download | cpython-9475a2310d9cdec4b4c36dee8bf30c72605ae928.zip cpython-9475a2310d9cdec4b4c36dee8bf30c72605ae928.tar.gz cpython-9475a2310d9cdec4b4c36dee8bf30c72605ae928.tar.bz2 |
Enable GC for new-style instances. This touches lots of files, since
many types were subclassable but had a xxx_dealloc function that
called PyObject_DEL(self) directly instead of deferring to
self->ob_type->tp_free(self). It is permissible to set tp_free in the
type object directly to _PyObject_Del, for non-GC types, or to
_PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster,
so I'm fearing that our pystone rating is going down again. I'm not
sure if doing something like
void xxx_dealloc(PyObject *self)
{
if (PyXxxCheckExact(self))
PyObject_DEL(self);
else
self->ob_type->tp_free(self);
}
is any faster than always calling the else branch, so I haven't
attempted that -- however those types whose own dealloc is fancier
(int, float, unicode) do use this pattern.
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 125521a..4d12e53 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -73,6 +73,24 @@ def test_instance(): del a expect_nonzero(gc.collect(), "instance") +def test_newinstance(): + class A(object): + pass + a = A() + a.a = a + gc.collect() + del a + expect_nonzero(gc.collect(), "newinstance") + class B(list): + pass + class C(B, A): + pass + a = C() + a.a = a + gc.collect() + del a + expect_nonzero(gc.collect(), "newinstance(2)") + def test_method(): # Tricky: self.__init__ is a bound method, it references the instance. class A: @@ -170,6 +188,7 @@ def test_all(): run_test("static classes", test_staticclass) run_test("dynamic classes", test_dynamicclass) run_test("instances", test_instance) + run_test("new instances", test_newinstance) run_test("methods", test_method) run_test("functions", test_function) run_test("frames", test_frame) |