[pypy-commit] pypy stm-gc: Improve testing before translation.
arigo
noreply at buildbot.pypy.org
Tue Apr 24 15:54:46 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54720:93a836c8b6b1
Date: 2012-04-24 15:21 +0200
http://bitbucket.org/pypy/pypy/changeset/93a836c8b6b1/
Log: Improve testing before translation.
diff --git a/pypy/rpython/lltypesystem/lltype.py b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -1198,6 +1198,15 @@
raise AttributeError("%r instance has no field %r" % (self._T,
field_name))
+ def __delattr__(self, field_name):
+ if isinstance(self._T, Struct):
+ if field_name in self._T._flds:
+ T1 = self._T._flds[field_name]
+ setattr(self._obj, field_name, _uninitialized(T1))
+ return
+ raise AttributeError("cannot delete %r on %r instance" % (field_name,
+ self._T))
+
def __getitem__(self, i): # ! can only return basic or ptr !
if isinstance(self._T, (Array, FixedSizeArray)):
start, stop = self._obj.getbounds()
diff --git a/pypy/rpython/lltypesystem/test/test_lltype.py b/pypy/rpython/lltypesystem/test/test_lltype.py
--- a/pypy/rpython/lltypesystem/test/test_lltype.py
+++ b/pypy/rpython/lltypesystem/test/test_lltype.py
@@ -862,6 +862,15 @@
assert F.RESULT == Signed
assert F.ARGS == (Signed,)
+def test_make_field_uninitialized_again():
+ S = lltype.GcStruct('S', ('x', lltype.Signed))
+ s = lltype.malloc(S)
+ py.test.raises(UninitializedMemoryAccess, "s.x")
+ s.x = 42
+ assert s.x == 42
+ del s.x # not RPython
+ py.test.raises(UninitializedMemoryAccess, "s.x")
+
class TestTrackAllocation:
def test_automatic_tracking(self):
diff --git a/pypy/rpython/memory/gc/stmtls.py b/pypy/rpython/memory/gc/stmtls.py
--- a/pypy/rpython/memory/gc/stmtls.py
+++ b/pypy/rpython/memory/gc/stmtls.py
@@ -118,8 +118,8 @@
obj = hdr.version
ll_assert(hdr.tid & GCFLAG_GLOBAL == 0, "already GLOBAL [2]")
ll_assert(hdr.tid & GCFLAG_VISITED != 0, "missing VISITED [2]")
- hdr.version = NULL
hdr.tid += GCFLAG_GLOBAL - GCFLAG_VISITED
+ self._clear_version_for_global_object(hdr)
if not we_are_translated():
del self.mt_global_turned_local # don't use any more
@@ -320,8 +320,18 @@
obj = hdr.version
ll_assert(hdr.tid & GCFLAG_GLOBAL == 0, "already GLOBAL [1]")
ll_assert(hdr.tid & GCFLAG_VISITED == 0, "unexpected VISITED [1]")
+ hdr.tid |= GCFLAG_GLOBAL
+ self._clear_version_for_global_object(hdr)
+
+ def _clear_version_for_global_object(self, hdr):
+ # Reset the 'version' to initialize a newly global object.
+ # When translated with C code, we set it to NULL (version 0).
+ # When non-translated, we reset it instead to '_uninitialized'
+ # to simulate the fact that the C code might change it.
+ if we_are_translated():
hdr.version = NULL
- hdr.tid |= GCFLAG_GLOBAL
+ else:
+ del hdr.version
def _cleanup_state(self):
#if self.rawmalloced_objects:
More information about the pypy-commit
mailing list