[pypy-svn] r74248 - in pypy/trunk: . pypy/module/cpyext pypy/module/cpyext/test/zfec

fijal at codespeak.net fijal at codespeak.net
Thu Apr 29 22:52:00 CEST 2010


Author: fijal
Date: Thu Apr 29 22:51:58 2010
New Revision: 74248

Removed:
   pypy/trunk/pypy/module/cpyext/test/zfec/
Modified:
   pypy/trunk/   (props changed)
   pypy/trunk/pypy/module/cpyext/typeobject.py
Log:
Merge the cpyext-remove-pyolifeline branch.

This branch removes _pyolifeline on all W_Root objects and instead
uses RWeakKeyDictionary


Modified: pypy/trunk/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/typeobject.py	Thu Apr 29 22:51:58 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