[pypy-svn] r28524 - pypy/dist/pypy/module/_weakref

mwh at codespeak.net mwh at codespeak.net
Thu Jun 8 15:48:54 CEST 2006


Author: mwh
Date: Thu Jun  8 15:48:53 2006
New Revision: 28524

Modified:
   pypy/dist/pypy/module/_weakref/interp__weakref.py
Log:
this was supposed to be part of r28518


Modified: pypy/dist/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/interp__weakref.py	(original)
+++ pypy/dist/pypy/module/_weakref/interp__weakref.py	Thu Jun  8 15:48:53 2006
@@ -248,3 +248,20 @@
     **callable_proxy_typedef_dict)
 W_CallableProxy.typedef.acceptable_as_base_class = False
 
+def basic_weakref(space, w_obj):
+    """this is a bit like the app-level weakref.ref(), but with no
+    fancy options like supporting subclasses of _weakref.ref and
+    callbacks."""
+    lifeline = w_obj.getweakref()
+    if lifeline is None:
+        lifeline = WeakrefLifeline()
+        w_obj.setweakref(space, lifeline)
+    if lifeline.cached_weakref_index >= 0:
+        cached_weakref_address = lifeline.addr_refs[lifeline.cached_weakref_index]
+        return cast_weakgcaddress_to_object(cached_weakref_address, W_Weakref)
+    index = len(lifeline.addr_refs)
+    w_ref = W_Weakref(space, lifeline, index, w_obj, space.w_None)
+    lifeline.addr_refs.append(cast_object_to_weakgcaddress(w_ref))
+    lifeline.cached_weakref_index = index
+    return w_ref
+    



More information about the Pypy-commit mailing list