[pypy-svn] r26450 - pypy/dist/pypy/module/_weakref
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Apr 27 17:07:48 CEST 2006
Author: cfbolz
Date: Thu Apr 27 17:07:45 2006
New Revision: 26450
Modified:
pypy/dist/pypy/module/_weakref/interp__weakref.py
Log:
code reordering
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 Apr 27 17:07:45 2006
@@ -9,32 +9,6 @@
W_Weakrefable = W_Root
W_Weakrefable.__lifeline__ = None
-class W_Weakref(Wrappable):
- def __init__(w_self, space, lifeline, index, w_obj, w_callable):
- w_self.space = space
- w_self.address = cast_object_to_address(w_obj)
- w_self.w_callable = w_callable
- w_self.addr_lifeline = cast_object_to_address(lifeline)
- w_self.index = index
-
- def descr__call__(self):
- return cast_address_to_object(self.address, W_Weakrefable)
-
- def invalidate(w_self):
- w_self.address = NULL
-
- def activate_callback(w_self):
- if not w_self.space.is_w(w_self.w_callable, w_self.space.w_None):
- try:
- w_self.space.call_function(w_self.w_callable, w_self)
- except OperationError, e:
- e.write_unraisable(w_self.space, 'function', w_self.w_callable)
-
- def __del__(w_self):
- if w_self.address != NULL:
- lifeline = cast_address_to_object(w_self.addr_lifeline,
- WeakrefLifeline)
- lifeline.ref_is_dead(w_self.index)
class WeakrefLifeline(object):
def __init__(self):
@@ -71,6 +45,48 @@
def ref_is_dead(self, index):
self.addr_refs[index] = NULL
+
+class W_Weakref(Wrappable):
+ def __init__(w_self, space, lifeline, index, w_obj, w_callable):
+ w_self.space = space
+ w_self.address = cast_object_to_address(w_obj)
+ w_self.w_callable = w_callable
+ w_self.addr_lifeline = cast_object_to_address(lifeline)
+ w_self.index = index
+
+ def descr__call__(self):
+ return cast_address_to_object(self.address, W_Weakrefable)
+
+ def invalidate(w_self):
+ w_self.address = NULL
+
+ def activate_callback(w_self):
+ if not w_self.space.is_w(w_self.w_callable, w_self.space.w_None):
+ try:
+ w_self.space.call_function(w_self.w_callable, w_self)
+ except OperationError, e:
+ e.write_unraisable(w_self.space, 'function', w_self.w_callable)
+
+ def __del__(w_self):
+ if w_self.address != NULL:
+ lifeline = cast_address_to_object(w_self.addr_lifeline,
+ WeakrefLifeline)
+ lifeline.ref_is_dead(w_self.index)
+
+
+def descr__new__(space, w_subtype, w_obj, w_callable=None):
+ assert isinstance(w_obj, W_Weakrefable)
+ if w_obj.__lifeline__ is None:
+ w_obj.__lifeline__ = WeakrefLifeline()
+ return w_obj.__lifeline__.get_weakref(space, w_subtype, w_obj, w_callable)
+
+
+W_Weakref.typedef = TypeDef("weakref",
+ __new__ = interp2app(descr__new__),
+ __call__ = interp2app(W_Weakref.descr__call__, unwrap_spec=['self'])
+)
+
+
def getweakrefcount(space, w_obj):
if not isinstance(w_obj, W_Weakrefable):
return space.wrap(0)
@@ -98,14 +114,4 @@
result.append(cast_address_to_object(addr, W_Weakref))
return space.newlist(result)
-def descr__new__(space, w_subtype, w_obj, w_callable=None):
- assert isinstance(w_obj, W_Weakrefable)
- if w_obj.__lifeline__ is None:
- w_obj.__lifeline__ = WeakrefLifeline()
- return w_obj.__lifeline__.get_weakref(space, w_subtype, w_obj, w_callable)
-
-W_Weakref.typedef = TypeDef("weakref",
- __new__ = interp2app(descr__new__),
- __call__ = interp2app(W_Weakref.descr__call__, unwrap_spec=['self'])
-)
More information about the Pypy-commit
mailing list