[pypy-svn] r46569 - in pypy/dist/pypy: annotation rpython rpython/test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Sep 14 11:53:28 CEST 2007
Author: antocuni
Date: Fri Sep 14 11:53:28 2007
New Revision: 46569
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/rpython/rweakref.py
pypy/dist/pypy/rpython/test/test_rweakref.py
Log:
allow null weakref in both lltype and ootype
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Fri Sep 14 11:53:28 2007
@@ -765,6 +765,8 @@
_make_none_union('SomeList', 'obj.listdef')
_make_none_union('SomeDict', 'obj.dictdef')
_make_none_union('SomeExternalObject', 'obj.knowntype')
+_make_none_union('SomeWeakRef', 'obj.classdef')
+_make_none_union('SomeDeadWeakRef', '')
# getitem on SomePBCs, in particular None fails
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Fri Sep 14 11:53:28 2007
@@ -500,16 +500,10 @@
def __init__(self, classdef):
self.classdef = classdef
- def can_be_none(self):
- return False
-
class SomeDeadWeakRef(SomeObject):
knowntype = weakref.ReferenceType
immutable = True
- def can_be_none(self):
- return False
-
# ____________________________________________________________
# memory addresses
Modified: pypy/dist/pypy/rpython/rweakref.py
==============================================================================
--- pypy/dist/pypy/rpython/rweakref.py (original)
+++ pypy/dist/pypy/rpython/rweakref.py Fri Sep 14 11:53:28 2007
@@ -29,6 +29,9 @@
"this backend or GC policy")
def convert_const(self, value):
+ if value is None:
+ return self.null_wref
+
assert isinstance(value, weakref.ReferenceType)
instance = value()
bk = self.rtyper.annotator.bookkeeper
@@ -47,6 +50,7 @@
class LLWeakRefRepr(BaseWeakRefRepr):
lowleveltype = llmemory.WeakRefPtr
dead_wref = llmemory.dead_wref
+ null_wref = lltype.nullptr(llmemory.WeakRef)
def rtype_simple_call(self, hop):
v_wref, = hop.inputargs(self)
@@ -59,6 +63,7 @@
class OOWeakRefRepr(BaseWeakRefRepr):
lowleveltype = ootype.WeakReference
dead_wref = ootype.dead_wref
+ null_wref = ootype.null(ootype.WeakReference)
def rtype_simple_call(self, hop):
v_wref, = hop.inputargs(self)
Modified: pypy/dist/pypy/rpython/test/test_rweakref.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rweakref.py (original)
+++ pypy/dist/pypy/rpython/test/test_rweakref.py Fri Sep 14 11:53:28 2007
@@ -72,6 +72,16 @@
res = self.interpret(f, [0])
assert res == True
+ def test_pbc_null_weakref(self):
+ class A:
+ pass
+ a1 = A()
+ mylist = [weakref.ref(a1), None]
+ def fn(i):
+ item = mylist[i]
+ return item is None
+ assert self.interpret(fn, [0]) is False
+ assert self.interpret(fn, [1]) is True
class TestLLtype(BaseTestRweakref, LLRtypeMixin):
def test_ll_weakref(self):
More information about the Pypy-commit
mailing list