[pypy-commit] stmgc default: Prebuilt weakrefs, needed for pypy.

arigo noreply at buildbot.pypy.org
Thu Mar 13 11:42:21 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r997:c4e8d6220b74
Date: 2014-03-13 11:42 +0100
http://bitbucket.org/pypy/stmgc/changeset/c4e8d6220b74/

Log:	Prebuilt weakrefs, needed for pypy.

diff --git a/c7/stm/weakref.c b/c7/stm/weakref.c
--- a/c7/stm/weakref.c
+++ b/c7/stm/weakref.c
@@ -17,6 +17,16 @@
 }
 
 
+object_t *stm_setup_prebuilt_weakref(object_t *obj)
+{
+    ssize_t size = 16;
+
+    obj = stm_setup_prebuilt(obj);
+    *WEAKREF_PTR(obj, size) = stm_setup_prebuilt(*WEAKREF_PTR(obj, size));
+    return obj;
+}
+
+
 static void _set_weakref_in_all_segments(object_t *weakref, object_t *value)
 {
     ssize_t size = 16;
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -282,6 +282,9 @@
    static structure, but it should never be used anyway.) */
 object_t *stm_setup_prebuilt(object_t *);
 
+/* The same, if the prebuilt object is actually a weakref. */
+object_t *stm_setup_prebuilt_weakref(object_t *);
+
 /* Hash, id.  The id is just the address of the object (of the address
    where it *will* be after the next minor collection).  The hash is the
    same, mangled -- except on prebuilt objects, where it can be
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -33,6 +33,7 @@
 void stm_register_thread_local(stm_thread_local_t *tl);
 void stm_unregister_thread_local(stm_thread_local_t *tl);
 object_t *stm_setup_prebuilt(object_t *);
+object_t *stm_setup_prebuilt_weakref(object_t *);
 
 bool _checked_stm_write(object_t *obj);
 bool _stm_was_read(object_t *obj);
diff --git a/c7/test/test_weakref.py b/c7/test/test_weakref.py
--- a/c7/test/test_weakref.py
+++ b/c7/test/test_weakref.py
@@ -253,3 +253,21 @@
         self.start_transaction()
         assert stm_get_weakref(lp1) == ffi.NULL
         print stm_get_real_address(lp1)
+
+    def test_prebuit_weakref(self):
+        from test_prebuilt import prebuilt
+        static1 = prebuilt(16)     # a prebuit dead weakref
+        lp1 = lib.stm_setup_prebuilt_weakref(static1)
+        static2 = prebuilt(16)     # some random prebuilt object
+        ffi.cast("char *", static2)[8:11] = 'ABC'
+        lp2 = lib.stm_setup_prebuilt(static2)
+        static3 = prebuilt(16)     # a prebuilt weakref to static2
+        ffi.cast("object_t **", static3)[1] = static2
+        lp3 = lib.stm_setup_prebuilt_weakref(static3)
+        #
+        self.start_transaction()
+        assert stm_get_char(lp2, 8) == 'A'
+        assert stm_get_char(lp2, 9) == 'B'
+        assert stm_get_char(lp2, 10) == 'C'
+        assert stm_get_weakref(lp1) == ffi.NULL
+        assert stm_get_weakref(lp3) == lp2


More information about the pypy-commit mailing list