[pypy-svn] r26451 - in pypy/dist/pypy/module/_weakref: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Apr 27 17:35:07 CEST 2006
Author: cfbolz
Date: Thu Apr 27 17:35:05 2006
New Revision: 26451
Modified:
pypy/dist/pypy/module/_weakref/interp__weakref.py
pypy/dist/pypy/module/_weakref/test/test_weakref.py
Log:
add equality of weak references
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:35:05 2006
@@ -2,7 +2,7 @@
from pypy.interpreter.argument import Arguments
from pypy.interpreter.error import OperationError
from pypy.interpreter.typedef import GetSetProperty, TypeDef
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import interp2app, ObjSpace
from pypy.rpython.objectmodel import cast_address_to_object, cast_object_to_address
from pypy.rpython.lltypesystem.llmemory import NULL
@@ -80,9 +80,20 @@
w_obj.__lifeline__ = WeakrefLifeline()
return w_obj.__lifeline__.get_weakref(space, w_subtype, w_obj, w_callable)
+def descr__eq__(space, ref1, ref2):
+ if ref1.address == NULL or ref2.address == NULL:
+ return space.is_(ref1, ref2)
+ return space.eq(ref1.descr__call__(), ref2.descr__call__())
+
+def descr__ne__(space, ref1, ref2):
+ return space.not_(space.eq(ref1, ref2))
W_Weakref.typedef = TypeDef("weakref",
__new__ = interp2app(descr__new__),
+ __eq__ = interp2app(descr__eq__,
+ unwrap_spec=[ObjSpace, W_Weakref, W_Weakref]),
+ __ne__ = interp2app(descr__ne__,
+ unwrap_spec=[ObjSpace, W_Weakref, W_Weakref]),
__call__ = interp2app(W_Weakref.descr__call__, unwrap_spec=['self'])
)
Modified: pypy/dist/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/test/test_weakref.py (original)
+++ pypy/dist/pypy/module/_weakref/test/test_weakref.py Thu Apr 27 17:35:05 2006
@@ -91,6 +91,23 @@
wref1 = wref(a)
assert isinstance(wref1, wref)
+ def test_weakref_equality(self):
+ import _weakref
+ class A:
+ def __eq__(self, other):
+ return True
+ a1 = A()
+ a2 = A()
+ ref1 = _weakref.ref(a1)
+ ref2 = _weakref.ref(a2)
+ assert ref1 == ref2
+ del a1
+ assert not ref1 == ref2
+ assert ref1 != ref2
+ del a2
+ assert not ref1 == ref2
+ assert ref1 != ref2
+
def test_getweakrefs(self):
import _weakref
class A:
More information about the Pypy-commit
mailing list