[pypy-svn] r74241 - pypy/branch/cpyext-remove-pyolifeline/pypy/module/cpyext

fijal at codespeak.net fijal at codespeak.net
Thu Apr 29 21:01:22 CEST 2010


Author: fijal
Date: Thu Apr 29 21:01:18 2010
New Revision: 74241

Modified:
   pypy/branch/cpyext-remove-pyolifeline/pypy/module/cpyext/typeobject.py
Log:
use RWeakKeyDictionary instead of pyolifeline, works so far


Modified: pypy/branch/cpyext-remove-pyolifeline/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpyext-remove-pyolifeline/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/cpyext-remove-pyolifeline/pypy/module/cpyext/typeobject.py	Thu Apr 29 21:01:18 2010
@@ -2,8 +2,8 @@
 import sys
 
 from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.tool.pairtype import extendabletype
 from pypy.rpython.annlowlevel import llhelper
+from pypy.rlib.rweakref import RWeakKeyDictionary
 from pypy.interpreter.gateway import ObjSpace, W_Root, Arguments
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.baseobjspace import Wrappable, DescrMismatch
@@ -199,15 +199,6 @@
         if not pto.c_tp_new:
             pto.c_tp_new = base_pto.c_tp_new
 
-class __extend__(W_Root):
-    __metaclass__ = extendabletype
-    __slots__ = ("_pyolifeline", ) # hint for the annotator
-    _pyolifeline = None
-    def set_pyolifeline(self, lifeline):
-        self._pyolifeline = lifeline
-    def get_pyolifeline(self):
-        return self._pyolifeline
-
 class PyOLifeline(object):
     def __init__(self, space, pyo):
         self.pyo = pyo
@@ -220,6 +211,8 @@
             self.pyo = lltype.nullptr(PyObject.TO)
         # XXX handle borrowed objects here
 
+lifeline_dict = RWeakKeyDictionary(W_Root, PyOLifeline)
+
 def check_descr(space, w_self, pto):
     w_type = from_ref(space, (rffi.cast(PyObject, pto)))
     if not space.is_true(space.isinstance(w_self, w_type)):
@@ -392,7 +385,7 @@
     # extension modules
 
 def pyctype_make_ref(space, w_type, w_obj, itemcount=0):
-    lifeline = w_obj.get_pyolifeline()
+    lifeline = lifeline_dict.get(w_obj)
     if lifeline is not None: # make old PyObject ready for use in C code
         py_obj = lifeline.pyo
         assert py_obj.c_ob_refcnt == 0
@@ -400,7 +393,7 @@
     else:
         typedescr = get_typedescr(w_obj.typedef)
         py_obj = typedescr.allocate(space, w_type, itemcount=itemcount)
-        w_obj.set_pyolifeline(PyOLifeline(space, py_obj))
+        lifeline_dict.set(w_obj, PyOLifeline(space, py_obj))
     return py_obj
 
 @cpython_api([PyObject, rffi.INTP], lltype.Signed, external=False,



More information about the Pypy-commit mailing list