Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r983:c6ed145863b4
Date: 2014-03-12 17:18 +0100
http://bitbucket.org/pypy/stmgc/changeset/c6ed145863b4/

Log:    Support prebuilt objects that are only aligned on multiples of 4
        bytes as static data.

diff --git a/c7/stm/prebuilt.c b/c7/stm/prebuilt.c
--- a/c7/stm/prebuilt.c
+++ b/c7/stm/prebuilt.c
@@ -16,9 +16,13 @@
         return;
 
     /* If the object was already moved, it is stored in 'tree_prebuilt_objs'.
+       For now we use this dictionary, with keys being equal to the double
+       of the numeric address of the prebuilt object.  We double them in
+       order to support addresses that are only 4-byte-aligned in the
+       static data.
      */
     wlog_t *item;
-    TREE_FIND(*tree_prebuilt_objs, (uintptr_t)obj, item, goto not_found);
+    TREE_FIND(*tree_prebuilt_objs, 2 * (uintptr_t)obj, item, goto not_found);
 
     *pstaticobj_invalid = (object_t *)item->val;    /* already moved */
     return;
@@ -38,7 +42,7 @@
     nobj->stm_flags = GCFLAG_WRITE_BARRIER;
 
     /* Add the object to the tree */
-    tree_insert(tree_prebuilt_objs, (uintptr_t)obj, (uintptr_t)nobj);
+    tree_insert(tree_prebuilt_objs, 2 * (uintptr_t)obj, (uintptr_t)nobj);
 
     /* Done */
     *pstaticobj_invalid = nobj;
diff --git a/c7/test/test_prebuilt.py b/c7/test/test_prebuilt.py
--- a/c7/test/test_prebuilt.py
+++ b/c7/test/test_prebuilt.py
@@ -83,3 +83,17 @@
 
     def test_multiple_calls_to_stm_setup_prebuilt_2(self):
         self.test_multiple_calls_to_stm_setup_prebuilt_1(reverse=True)
+
+    def test_prebuilt_align_4_byte(self):
+        static0 = prebuilt(16)
+        p0 = ffi.cast("char *", static0)
+        for i in reversed(range(12)):
+            p0[i + 4] = p0[i]
+        static1 = ffi.cast("object_t *", p0 + 4)
+        ffi.cast("char *", static1)[8:11] = 'ABC'
+        lp = lib.stm_setup_prebuilt(static1)
+        #
+        self.start_transaction()
+        assert stm_get_char(lp, 8) == 'A'
+        assert stm_get_char(lp, 9) == 'B'
+        assert stm_get_char(lp, 10) == 'C'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to