[pypy-svn] r46482 - in pypy/branch/cleanup-weakref/pypy: annotation rpython rpython/lltypesystem rpython/memory/gctransform translator translator/c translator/c/test translator/stackless
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 11 21:13:40 CEST 2007
Author: arigo
Date: Tue Sep 11 21:13:38 2007
New Revision: 46482
Modified:
pypy/branch/cleanup-weakref/pypy/annotation/builtin.py
pypy/branch/cleanup-weakref/pypy/annotation/model.py
pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/llmemory.py
pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lltype.py
pypy/branch/cleanup-weakref/pypy/rpython/memory/gctransform/boehm.py
pypy/branch/cleanup-weakref/pypy/rpython/rbuiltin.py
pypy/branch/cleanup-weakref/pypy/rpython/rweakref.py
pypy/branch/cleanup-weakref/pypy/translator/c/database.py
pypy/branch/cleanup-weakref/pypy/translator/c/gc.py
pypy/branch/cleanup-weakref/pypy/translator/c/node.py
pypy/branch/cleanup-weakref/pypy/translator/c/primitive.py
pypy/branch/cleanup-weakref/pypy/translator/c/test/test_boehm.py
pypy/branch/cleanup-weakref/pypy/translator/exceptiontransform.py
pypy/branch/cleanup-weakref/pypy/translator/stackless/code.py
pypy/branch/cleanup-weakref/pypy/translator/stackless/frame.py
pypy/branch/cleanup-weakref/pypy/translator/stackless/transform.py
Log:
Turn WeakRef into a container type. This allows a number of
simplifications at various places. Thanks pedronis.
Modified: pypy/branch/cleanup-weakref/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/annotation/builtin.py (original)
+++ pypy/branch/cleanup-weakref/pypy/annotation/builtin.py Tue Sep 11 21:13:38 2007
@@ -9,7 +9,7 @@
from pypy.annotation.model import SomeFloat, unionof
from pypy.annotation.model import SomePBC, SomeInstance, SomeDict
from pypy.annotation.model import SomeExternalObject
-from pypy.annotation.model import SomeWeakRef, SomeLLWeakRef
+from pypy.annotation.model import SomeWeakRef
from pypy.annotation.model import annotation_to_lltype, lltype_to_annotation, ll_to_annotation
from pypy.annotation.model import add_knowntypedata
from pypy.annotation.model import s_ImpossibleValue
@@ -577,7 +577,7 @@
s_obj.ll_ptrtype.TO._gckind != 'gc'):
raise Exception("bad type for argument to weakref_create(): %r" % (
s_obj,))
- return SomeLLWeakRef()
+ return SomePtr(llmemory.WeakRefPtr)
def llweakref_deref(s_ptrtype, s_wref):
if not (s_ptrtype.is_constant() and
@@ -585,8 +585,9 @@
s_ptrtype.const.TO._gckind == 'gc'):
raise Exception("weakref_deref() arg 1 must be a constant "
"ptr type, got %s" % (s_ptrtype,))
- if not isinstance(s_wref, SomeLLWeakRef):
- raise Exception("weakref_deref() arg 2 must be a llweakref, "
+ if not (isinstance(s_wref, SomePtr) and
+ s_wref.ll_ptrtype == llmemory.WeakRefPtr):
+ raise Exception("weakref_deref() arg 2 must be a WeakRefPtr, "
"got %s" % (s_wref,))
return SomePtr(s_ptrtype.const)
Modified: pypy/branch/cleanup-weakref/pypy/annotation/model.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/annotation/model.py (original)
+++ pypy/branch/cleanup-weakref/pypy/annotation/model.py Tue Sep 11 21:13:38 2007
@@ -510,12 +510,6 @@
def can_be_none(self):
return False
-class SomeLLWeakRef(SomeObject):
- immutable = True
-
- def can_be_none(self):
- return False
-
# ____________________________________________________________
# memory addresses
@@ -593,7 +587,6 @@
(SomeChar(), lltype.Char),
(SomeUnicodeCodePoint(), lltype.UniChar),
(SomeAddress(), llmemory.Address),
- (SomeLLWeakRef(), llmemory.WeakRef),
]
def annotation_to_lltype(s_val, info=None):
Modified: pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/llmemory.py Tue Sep 11 21:13:38 2007
@@ -487,75 +487,66 @@
def cast_int_to_adr(int):
raise NotImplementedError("cast_int_to_adr")
-
# ____________________________________________________________
+# Weakrefs.
#
-# WeakRef - like in RPython, they are pointers that don't keep their
-# target malloc'ed structure alive. When the target dies
-# all WeakRefs to it are cleared.
+# An object of type WeakRef is a small GC-managed object that contains
+# a weak reference to another GC-managed object, as in regular Python.
#
-# ____________________________________________________________
-
-class fakeweakref(object):
- # XXX convoluted code to support both lltype._ptr and simulatorptr
- def __init__(self, ob):
- if ob is not None:
- if isinstance(ob, lltype._ptr):
- ob = lltype.normalizeptr(ob)._obj
- self.obref = weakref.ref(ob)
- self.ref = self.get # backward compatibility
- # umpf
- from pypy.rpython.memory import lltypesimulation
- if isinstance(ob, (lltype._ptr,lltypesimulation.simulatorptr)):
- self.id = ob._cast_to_int()
- else:
- self.id = id(ob)
- else:
- self.obref = None
- self.ref = None
- def get(self):
- if self.obref is None:
- return None
- ob = self.obref()
- # xxx stop-gap
- #if ob is None:
- # raise DanglingPointerError
- if isinstance(ob, lltype._container):
- ob = ob._as_ptr()
- return ob
- def __repr__(self):
- if self.obref is None:
- s = 'NULL'
- else:
- s = str(self.obref)
- return '<%s %s>' % (self.__class__.__name__, s)
- #def cast_to_int(self):
- # # this is not always the behaviour that is really happening
- # # but make sure that nobody depends on it
- # return self.id ^ ~3
-
-
-WeakRef = lltype.Primitive("WeakRef", fakeweakref(None))
-
-def weakref_create(obj):
- PTRTYPE = lltype.typeOf(obj)
+class _WeakRefType(lltype.ContainerType):
+ _gckind = 'gc'
+ def __str__(self):
+ return "WeakRef"
+
+WeakRef = _WeakRefType()
+WeakRefPtr = lltype.Ptr(WeakRef)
+
+def weakref_create(ptarget):
+ # ptarget should not be a nullptr
+ PTRTYPE = lltype.typeOf(ptarget)
assert isinstance(PTRTYPE, lltype.Ptr)
assert PTRTYPE.TO._gckind == 'gc'
- return fakeweakref(obj)
+ assert ptarget
+ return _wref(ptarget)._as_ptr()
-def weakref_deref(PTRTYPE, wref):
+def weakref_deref(PTRTYPE, pwref):
+ # pwref should not be a nullptr
assert isinstance(PTRTYPE, lltype.Ptr)
assert PTRTYPE.TO._gckind == 'gc'
- assert lltype.typeOf(wref) == WeakRef
- p = wref.get()
+ assert lltype.typeOf(pwref) == WeakRefPtr
+ p = pwref._obj._dereference()
if p is None:
return lltype.nullptr(PTRTYPE.TO)
else:
return lltype.cast_pointer(PTRTYPE, p)
-fakeweakref._TYPE = WeakRef
-WEAKREFNULL = fakeweakref(None)
+class _wref(lltype._container):
+ _gckind = 'gc'
+ _TYPE = WeakRef
+
+ def __init__(self, ptarget):
+ if ptarget is None:
+ self._obref = lambda: None
+ else:
+ obj = lltype.normalizeptr(ptarget)._obj
+ self._obref = weakref.ref(obj)
+
+ def _dereference(self):
+ obj = self._obref()
+ if obj is None:
+ return None
+ else:
+ return obj._as_ptr()
+
+ def __repr__(self):
+ return '<%s>' % (self,)
+
+ def __str__(self):
+ return 'wref -> %s' % (self._obref(),)
+
+# a prebuilt pointer to a dead low-level weakref
+dead_wref = _wref(None)._as_ptr()
# ____________________________________________________________
Modified: pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lloperation.py Tue Sep 11 21:13:38 2007
@@ -91,6 +91,9 @@
(self in (llop.getfield, llop.getarrayitem) and
ARGTYPES[0].TO._hints.get('immutable')))
+ def __repr__(self):
+ return '<LLOp %s>' % (getattr(self, 'opname', '?'),)
+
def enum_ops_without_sideeffects(raising_is_ok=False):
"""Enumerate operations that have no side-effects
Modified: pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/lltypesystem/lltype.py Tue Sep 11 21:13:38 2007
@@ -161,7 +161,10 @@
def _nofield(self, name):
raise AttributeError("no field %r" % name)
-
+
+ def _container_example(self):
+ raise NotImplementedError
+
class Struct(ContainerType):
_gckind = 'raw'
Modified: pypy/branch/cleanup-weakref/pypy/rpython/memory/gctransform/boehm.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/memory/gctransform/boehm.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/memory/gctransform/boehm.py Tue Sep 11 21:13:38 2007
@@ -43,10 +43,10 @@
self.malloc_varsize_ptr = self.inittime_helper(
ll_malloc_varsize, [lltype.Signed]*4, llmemory.Address, inline=False)
self.weakref_create_ptr = self.inittime_helper(
- ll_weakref_create, [llmemory.Address], llmemory.WeakRef,
+ ll_weakref_create, [llmemory.Address], llmemory.WeakRefPtr,
inline=False)
self.weakref_deref_ptr = self.inittime_helper(
- ll_weakref_deref, [llmemory.WeakRef], llmemory.Address)
+ ll_weakref_deref, [llmemory.WeakRefPtr], llmemory.Address)
self.mixlevelannotator.finish() # for now
self.mixlevelannotator.backend_optimize()
@@ -137,7 +137,7 @@
resulttype=llmemory.Address)
v_wref = hop.genop("direct_call",
[self.weakref_create_ptr, v_addr],
- resulttype=llmemory.WeakRef)
+ resulttype=llmemory.WeakRefPtr)
hop.cast_result(v_wref)
def gct_weakref_deref(self, hop):
@@ -149,34 +149,33 @@
########## weakrefs ##########
-# Boehm: we implement weakrefs with an extra indirection: GCWeakRef is a
-# pointer to malloced data containing only a Boehm disappearing link.
-# This allows the disappearing link to remain at a fixed address.
-# We also don't have to hide the link's value with HIDE_POINTER(),
-# because we use GC_MALLOC_ATOMIC().
-
-# Declared in gc.py: typedef GC_PTR *GCWeakRef;
+# Boehm: weakref objects are small structures containing only a Boehm
+# disappearing link. We don't have to hide the link's value with
+# HIDE_POINTER(), because we explicitly use GC_MALLOC_ATOMIC().
WEAKLINK = lltype.FixedSizeArray(llmemory.Address, 1)
sizeof_weakreflink = llmemory.sizeof(WEAKLINK)
+empty_weaklink = lltype.malloc(WEAKLINK, immortal=True)
+empty_weaklink[0] = llmemory.NULL
def ll_weakref_create(targetaddr):
link = llop.boehm_malloc_atomic(llmemory.Address, sizeof_weakreflink)
link.address[0] = targetaddr
llop.boehm_disappearing_link(lltype.Void, link, targetaddr)
- # abuse of llop.cast_pointer()
- return llop.cast_pointer(llmemory.WeakRef, link)
+ return llmemory.cast_adr_to_ptr(link, llmemory.WeakRefPtr)
def ll_weakref_deref(wref):
- # abuse of llop.cast_pointer()
- link = llop.cast_pointer(llmemory.Address, wref)
+ link = llmemory.cast_ptr_to_adr(wref)
return link and link.address[0]
-def convert_prebuilt_weakref_to(targetptr):
+def convert_weakref_to(targetptr):
# Prebuilt weakrefs don't really need to be weak at all,
# but we need to emulate the structure expected by ll_weakref_deref().
# This is essentially the same code as in ll_weakref_create(), but I'm
# not sure trying to share it is worth the hassle...
- link = lltype.malloc(WEAKLINK, immortal=True)
- link[0] = llmemory.cast_ptr_to_adr(targetptr)
- return link
+ if not targetptr:
+ return empty_weaklink
+ else:
+ link = lltype.malloc(WEAKLINK, immortal=True)
+ link[0] = llmemory.cast_ptr_to_adr(targetptr)
+ return link
Modified: pypy/branch/cleanup-weakref/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/rbuiltin.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/rbuiltin.py Tue Sep 11 21:13:38 2007
@@ -602,10 +602,11 @@
# Note: this code also works for the RPython-level calls 'weakref.ref(x)'.
vlist = hop.inputargs(hop.args_r[0])
hop.exception_cannot_occur()
- return hop.genop('weakref_create', vlist, resulttype=llmemory.WeakRef)
+ return hop.genop('weakref_create', vlist, resulttype=llmemory.WeakRefPtr)
def rtype_weakref_deref(hop):
- c_ptrtype, v_wref = hop.inputargs(lltype.Void, llmemory.WeakRef)
+ c_ptrtype, v_wref = hop.inputargs(lltype.Void, hop.args_r[1])
+ assert v_wref.concretetype == llmemory.WeakRefPtr
hop.exception_cannot_occur()
return hop.genop('weakref_deref', [v_wref], resulttype=c_ptrtype.value)
Modified: pypy/branch/cleanup-weakref/pypy/rpython/rweakref.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/rpython/rweakref.py (original)
+++ pypy/branch/cleanup-weakref/pypy/rpython/rweakref.py Tue Sep 11 21:13:38 2007
@@ -6,19 +6,9 @@
from pypy.rpython.rclass import getinstancerepr
from pypy.rpython.lltypesystem import lltype, llmemory
-
-class __extend__(annmodel.SomeLLWeakRef):
- def rtyper_makerepr(self, rtyper):
- return LLWeakRefRepr()
- def rtyper_makekey(self):
- return self.__class__,
-
-class LLWeakRefRepr(Repr):
- lowleveltype = llmemory.WeakRef
-
# ____________________________________________________________
#
-# RPython-level weakrefs
+# RTyping of RPython-level weakrefs
class __extend__(annmodel.SomeWeakRef):
def rtyper_makerepr(self, rtyper):
@@ -28,7 +18,7 @@
class WeakRefRepr(Repr):
- lowleveltype = llmemory.WeakRef
+ lowleveltype = llmemory.WeakRefPtr
def __init__(self, rtyper):
self.rtyper = rtyper
@@ -48,7 +38,7 @@
# obscure! if the annotator hasn't seen this object before,
# we don't want to look at it now (confusion tends to result).
if instance is None or not bk.have_seen(instance):
- return llmemory.WeakRef._defl()
+ return llmemory.dead_wref
else:
repr = self.rtyper.bindingrepr(Constant(instance))
llinstance = repr.convert_const(instance)
Modified: pypy/branch/cleanup-weakref/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/c/database.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/c/database.py Tue Sep 11 21:13:38 2007
@@ -3,7 +3,7 @@
Struct, Array, FuncType, PyObject, Void, \
ContainerType, OpaqueType, FixedSizeArray, _uninitialized
from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.lltypesystem.llmemory import Address
+from pypy.rpython.lltypesystem.llmemory import Address, WeakRef, _WeakRefType
from pypy.rpython.lltypesystem.rffi import CConstant
from pypy.tool.sourcetools import valid_identifier
from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
@@ -17,6 +17,8 @@
from pypy import conftest
from pypy.translator.c import gc
+class NoCorrespondingNode(Exception):
+ pass
# ____________________________________________________________
@@ -84,8 +86,11 @@
node = ArrayDefNode(self, T, varlength)
elif isinstance(T, OpaqueType) and hasattr(T, '_exttypeinfo'):
node = ExtTypeOpaqueDefNode(self, T)
+ elif T == WeakRef:
+ REALT = self.gcpolicy.get_real_weakref_type()
+ node = self.gettypedefnode(REALT)
else:
- raise Exception("don't know about %r" % (T,))
+ raise NoCorrespondingNode("don't know about %r" % (T,))
self.structdefnodes[key] = node
self.pendingsetupnodes.append(node)
return node
@@ -94,14 +99,16 @@
if isinstance(T, Primitive):
return PrimitiveType[T]
elif isinstance(T, Ptr):
- if isinstance(T.TO, FixedSizeArray):
- # /me blames C
+ try:
node = self.gettypedefnode(T.TO)
- return node.getptrtype()
+ except NoCorrespondingNode:
+ pass
else:
- typename = self.gettype(T.TO) # who_asks not propagated
- return typename.replace('@', '*@')
- elif isinstance(T, (Struct, Array)):
+ if hasattr(node, 'getptrtype'):
+ return node.getptrtype() # special-casing because of C
+ typename = self.gettype(T.TO) # who_asks not propagated
+ return typename.replace('@', '*@')
+ elif isinstance(T, (Struct, Array, _WeakRefType)):
node = self.gettypedefnode(T, varlength=varlength)
if who_asks is not None:
who_asks.dependencies[node] = True
Modified: pypy/branch/cleanup-weakref/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/c/gc.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/c/gc.py Tue Sep 11 21:13:38 2007
@@ -175,10 +175,6 @@
class BoehmGcPolicy(BasicGcPolicy):
transformerclass = boehm.BoehmGCTransformer
- def __init__(self, *args, **kwds):
- BasicGcPolicy.__init__(self, *args, **kwds)
- self.weakref_llwrapper_cache = {}
-
def array_setup(self, arraydefnode):
pass
@@ -208,7 +204,7 @@
yield '#define USING_BOEHM_GC'
def pre_gc_code(self):
- return ['typedef GC_PTR *GCWeakRef;']
+ return []
def gc_startup_code(self):
if sys.platform == 'win32':
@@ -217,16 +213,11 @@
yield 'GC_all_interior_pointers = 0;'
yield 'GC_init();'
- def name_weakref_to(self, target):
- # the cache is essential to ensure that repeated calls to
- # db.get(weakref) don't return new llwrapper structures all
- # the time, which defeats the db.complete() logic.
- try:
- llwrapper = self.weakref_llwrapper_cache[target._obj]
- except KeyError:
- llwrapper = boehm.convert_prebuilt_weakref_to(target)
- self.weakref_llwrapper_cache[target._obj] = llwrapper
- return '((GCWeakRef)%s)' % (self.db.get(llwrapper),)
+ def get_real_weakref_type(self):
+ return boehm.WEAKLINK
+
+ def convert_weakref_to(self, ptarget):
+ return boehm.convert_weakref_to(ptarget)
def OP_GC_FETCH_EXCEPTION(self, funcgen, op):
result = funcgen.expr(op.result)
Modified: pypy/branch/cleanup-weakref/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/c/node.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/c/node.py Tue Sep 11 21:13:38 2007
@@ -4,6 +4,7 @@
GcStruct, GcArray, RttiStruct, PyStruct, ContainerType, \
parentlink, Ptr, PyObject, Void, OpaqueType, Float, \
RuntimeTypeInfo, getRuntimeTypeInfo, Char, _subarray, _pyobjheader
+from pypy.rpython.lltypesystem import llmemory
from pypy.translator.c.funcgen import FunctionCodeGenerator
from pypy.translator.c.external import CExternalFunctionCodeGenerator
from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
@@ -859,6 +860,16 @@
return PyObjectNode(db, T, obj)
+def weakrefnode_factory(db, T, obj):
+ assert isinstance(obj, llmemory._wref)
+ ptarget = obj._dereference()
+ wrapper = db.gcpolicy.convert_weakref_to(ptarget)
+ container = wrapper._obj
+ T = typeOf(container)
+ nodefactory = ContainerNodeFactory[T.__class__]
+ return nodefactory(db, T, container)
+
+
ContainerNodeFactory = {
Struct: StructNode,
GcStruct: StructNode,
@@ -869,4 +880,5 @@
FuncType: FuncNode,
OpaqueType: opaquenode_factory,
PyObjectType: objectnode_factory,
+ llmemory._WeakRefType: weakrefnode_factory,
}
Modified: pypy/branch/cleanup-weakref/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/c/primitive.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/c/primitive.py Tue Sep 11 21:13:38 2007
@@ -6,7 +6,7 @@
from pypy.rpython.lltypesystem.llmemory import Address, \
AddressOffset, ItemOffset, ArrayItemsOffset, FieldOffset, \
CompositeOffset, ArrayLengthOffset, \
- GCHeaderOffset, WeakRef, fakeweakref
+ GCHeaderOffset
from pypy.translator.c.support import cdecl
# ____________________________________________________________
@@ -112,14 +112,6 @@
else:
return 'NULL'
-def name_weakref(value, db):
- assert isinstance(value, fakeweakref)
- target = value.get()
- if target is None:
- return 'NULL'
- else:
- return db.gcpolicy.name_weakref_to(target)
-
# On 64 bit machines, SignedLongLong and Signed are the same, so the
# order matters, because we want the Signed implementation.
PrimitiveName = {
@@ -133,7 +125,6 @@
Bool: name_bool,
Void: name_void,
Address: name_address,
- WeakRef: name_weakref,
}
PrimitiveType = {
@@ -147,7 +138,6 @@
Bool: 'bool_t @',
Void: 'void @',
Address: 'void* @',
- WeakRef: 'GCWeakRef @',
}
PrimitiveErrorValue = {
@@ -161,7 +151,6 @@
Bool: '0 /* error */',
Void: '/* error */',
Address: 'NULL',
- WeakRef: 'NULL',
}
def define_c_primitive(ll_type, c_name):
Modified: pypy/branch/cleanup-weakref/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/c/test/test_boehm.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/c/test/test_boehm.py Tue Sep 11 21:13:38 2007
@@ -146,38 +146,6 @@
assert 0 < res1 <= 10
assert 0 < res2 <= 5
- def test_weakgcaddress_is_weak(self):
- py.test.skip("weakgcaddress as we know it is fragile")
- from pypy.rpython.lltypesystem.lloperation import llop
- from pypy.rlib.objectmodel import cast_object_to_weakgcaddress
- class State:
- pass
- s = State()
- class A(object):
- def __del__(self):
- s.a_dels += 1
- def f(i):
- if i:
- s.a_dels = 0
- a = A()
- # this should not keep a alive
- s.a = cast_object_to_weakgcaddress(a)
- a = None
- llop.gc__collect(lltype.Void)
- llop.gc__collect(lltype.Void)
- llop.gc__collect(lltype.Void)
- return s.a_dels
- fn = self.getcompiled(f, [int])
- # we can't demand that boehm has collected all of the objects,
- # even with the gc__collect call. calling the compiled
- # function twice seems to help, though.
- fn(1)
- fn(0)
- fn(0)
- res = fn(0)
- print res
- assert res == 1
-
def test_del_raises(self):
from pypy.rpython.lltypesystem.lloperation import llop
import os
Modified: pypy/branch/cleanup-weakref/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/exceptiontransform.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/exceptiontransform.py Tue Sep 11 21:13:38 2007
@@ -24,7 +24,6 @@
lltype.UniChar: unichr(0xFFFF), # XXX is this always right?
lltype.Bool: True,
llmemory.Address: NULL,
- llmemory.WeakRef: llmemory.fakeweakref(None),
lltype.Void: None}
def error_value(T):
Modified: pypy/branch/cleanup-weakref/pypy/translator/stackless/code.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/stackless/code.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/stackless/code.py Tue Sep 11 21:13:38 2007
@@ -296,7 +296,6 @@
self.retval_float = 0.0
self.retval_addr = llmemory.NULL
self.retval_ref = frame.null_saved_ref
- self.retval_weak = llmemory.WEAKREFNULL
self.exception = None
self.masterarray = lltype.malloc(frame.FRAME_INFO_ARRAY, 0,
immortal=True)
@@ -339,9 +338,6 @@
elif retval_code == frame.RETVAL_LONGLONG:
global_state.retval_longlong = (
call_function_retval_longlong(fn, signature_index))
- elif retval_code == frame.RETVAL_WEAK:
- global_state.retval_weak = (
- call_function_retval_weak(fn, signature_index))
else:
assert False
call_function.stackless_explicit = True
@@ -449,12 +445,3 @@
global_state.retval_ref = frame.null_saved_ref
return res
fetch_retval_ref.stackless_explicit = True
-
-def fetch_retval_weak():
- e = global_state.exception
- if e:
- global_state.exception = None
- raise e
- else:
- return global_state.retval_weak
-fetch_retval_weak.stackless_explicit = True
Modified: pypy/branch/cleanup-weakref/pypy/translator/stackless/frame.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/stackless/frame.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/stackless/frame.py Tue Sep 11 21:13:38 2007
@@ -20,7 +20,6 @@
(lltype.SignedLongLong, 'longlong'),
(lltype.Signed, 'long'),
(lltype.Float, 'float'),
- (llmemory.WeakRef, 'weak'),
]
STORAGE_TYPES = []
@@ -55,8 +54,6 @@
return lltype.SignedLongLong
elif T is llmemory.Address:
return llmemory.Address
- elif T is llmemory.WeakRef:
- return llmemory.WeakRef
elif isinstance(T, lltype.Primitive):
return lltype.Signed
else:
Modified: pypy/branch/cleanup-weakref/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/branch/cleanup-weakref/pypy/translator/stackless/transform.py (original)
+++ pypy/branch/cleanup-weakref/pypy/translator/stackless/transform.py Tue Sep 11 21:13:38 2007
@@ -370,8 +370,6 @@
code.fetch_retval_addr, [], annmodel.SomeAddress()),
SAVED_REFERENCE: mixlevelannotator.constfunc(
code.fetch_retval_ref, [], annmodel.SomePtr(SAVED_REFERENCE)),
- llmemory.WeakRef: mixlevelannotator.constfunc(
- code.fetch_retval_weak, [], annmodel.SomeLLWeakRef()),
}
s_StatePtr = annmodel.SomePtr(frame.OPAQUE_STATE_HEADER_PTR)
@@ -422,10 +420,6 @@
code.resume_after_ref,
[s_StatePtr, annmodel.SomePtr(SAVED_REFERENCE)],
annmodel.s_None),
- llmemory.WeakRef: mixlevelannotator.constfunc(
- code.resume_after_weak,
- [s_StatePtr, annmodel.SomeLLWeakRef()],
- annmodel.s_None),
}
exception_def = bk.getuniqueclassdef(Exception)
self.resume_after_raising_ptr = mixlevelannotator.constfunc(
More information about the Pypy-commit
mailing list