[pypy-svn] r49987 - in pypy/dist/pypy/translator: c llvm llvm/test
arigo at codespeak.net
arigo at codespeak.net
Fri Dec 21 16:50:59 CET 2007
Author: arigo
Date: Fri Dec 21 16:50:58 2007
New Revision: 49987
Modified:
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/llvm/database.py
pypy/dist/pypy/translator/llvm/test/test_new_gc.py
Log:
Support for prebuilt weakrefs.
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Fri Dec 21 16:50:58 2007
@@ -908,6 +908,7 @@
ptarget = obj._dereference()
wrapper = db.gcpolicy.convert_weakref_to(ptarget)
container = wrapper._obj
+ obj._converted_weakref = container # hack for genllvm :-/
return db.getcontainernode(container, _dont_write_c_code=False)
Modified: pypy/dist/pypy/translator/llvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/database.py (original)
+++ pypy/dist/pypy/translator/llvm/database.py Fri Dec 21 16:50:58 2007
@@ -114,6 +114,14 @@
else:
node = OpaqueNode(self, value)
+ elif type_ is llmemory.WeakRef:
+ # XXX this uses a hack in translator.c.node.weakrefnode_factory()
+ # because we need to obtain not just *a* conversion of the weakref
+ # by the gcpolicy, but *the same* one as was already registered
+ # in the genc database and seen by the gctransformer
+ value = value._converted_weakref
+ return self.create_constant_node(lltype.typeOf(value), value)
+
assert node is not None, "%s not supported" % (type_)
return node
@@ -161,8 +169,6 @@
ptrvalue = fakedaddress.ptr
ct = lltype.typeOf(ptrvalue)
self.prepare_constant(ct, ptrvalue)
- ##elif ct is llmemory.WeakGcAddress:
- ## return # XXX sometime soon
else:
if isinstance(value, llmemory.AddressOffset):
@@ -389,7 +395,6 @@
lltype.UnsignedLongLong: "i64",
lltype.SignedLongLong: "i64",
llmemory.Address: "i8*",
- #XXX llmemory.WeakGcAddress: "i8*",
}
# 32 bit platform
@@ -418,7 +423,6 @@
lltype.Bool : self.repr_bool,
lltype.Void : self.repr_void,
llmemory.Address : self.repr_address,
- #llmemory.WeakGcAddress : self.repr_weakgcaddress,
}
try:
@@ -536,11 +540,6 @@
res = "bitcast(%s to i8*)" % (ref,)
return res
- def repr_weakgcaddress(self, type_, value):
- assert isinstance(value, llmemory.fakeweakaddress)
- log.WARNING("XXX weakgcaddress completely ignored...")
- return 'null'
-
def repr_signed(self, type_, value):
if isinstance(value, Symbolic):
return self.repr_symbolic(type_, value)
Modified: pypy/dist/pypy/translator/llvm/test/test_new_gc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_new_gc.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_new_gc.py Fri Dec 21 16:50:58 2007
@@ -78,3 +78,27 @@
res = f()
# more than half of them should have been freed, ideally up to 6000
assert 3500 <= res <= 6000
+
+def test_prebuilt_weakref():
+ import weakref
+ from pypy.rlib import rgc
+ class A:
+ pass
+ a = A()
+ a.hello = 42
+ refs = [weakref.ref(a), weakref.ref(A())]
+ rgc.collect()
+ def fn():
+ result = 0
+ for i in range(2):
+ a = refs[i]()
+ rgc.collect()
+ if a is None:
+ result += (i+1)
+ else:
+ result += a.hello * (i+1)
+ return result
+
+ mod, f = compile_test(fn, [], gcpolicy="semispace")
+ res = f()
+ assert res == fn()
More information about the Pypy-commit
mailing list