[pypy-commit] pypy gc-del: Fix cpyext.

arigo noreply at buildbot.pypy.org
Fri Apr 26 20:37:12 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: gc-del
Changeset: r63661:f1553ff74b5e
Date: 2013-04-26 20:35 +0200
http://bitbucket.org/pypy/pypy/changeset/f1553ff74b5e/

Log:	Fix cpyext.

diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -2,7 +2,7 @@
     cpython_api, generic_cpy_call, CANNOT_FAIL, CConfig, cpython_struct)
 from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, make_ref, from_ref
 from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib import rthread
+from rpython.rlib import rthread, rgc
 from pypy.module.thread import os_thread
 
 PyInterpreterStateStruct = lltype.ForwardReference()
@@ -60,7 +60,8 @@
                 self.memory = lltype.malloc(T, flavor=flavor)
             else:
                 self.memory = lltype.nullptr(T)
-        def __del__(self):
+            rgc.register_finalizer(self.finalizer)
+        def finalizer(self):
             if self.memory:
                 if dealloc and self.space:
                     dealloc(self.memory, self.space)
diff --git a/pypy/module/cpyext/test/test_getargs.py b/pypy/module/cpyext/test/test_getargs.py
--- a/pypy/module/cpyext/test/test_getargs.py
+++ b/pypy/module/cpyext/test/test_getargs.py
@@ -156,11 +156,12 @@
         freed = []
         class freestring(str):
             def __del__(self):
-                freed.append('x')
+                freed.append(str(self))
         raises(TypeError, pybuffer,
                freestring("string"), freestring("other string"), 42)
         import gc; gc.collect()
-        assert freed == ['x', 'x']
+        assert len(freed) == 2
+        assert set(freed) == set(['string', 'other string'])
 
 
     def test_pyarg_parse_charbuf_and_length(self):
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -22,7 +22,7 @@
 from pypy.objspace.std.formatting import mod_format
 
 class W_AbstractStringObject(W_Object):
-    __slots__ = ()
+    _attrs_ = ()
 
     def is_w(self, space, w_other):
         if not isinstance(w_other, W_AbstractStringObject):


More information about the pypy-commit mailing list