Author: Armin Rigo <[email protected]>
Branch: marker
Changeset: r1168:035e1c7879be
Date: 2014-04-19 12:38 +0200
http://bitbucket.org/pypy/stmgc/changeset/035e1c7879be/

Log:    Move the macros. Add a function, for tests mostly

diff --git a/c7/stm/marker.c b/c7/stm/marker.c
--- a/c7/stm/marker.c
+++ b/c7/stm/marker.c
@@ -34,6 +34,15 @@
     }
 }
 
+char *_stm_expand_marker(void)
+{
+    struct stm_priv_segment_info_s *pseg =
+        get_priv_segment(STM_SEGMENT->segment_num);
+    pseg->marker_self[0] = 0;
+    marker_fetch_expand(pseg);
+    return pseg->marker_self;
+}
+
 static void marker_copy(stm_thread_local_t *tl,
                         struct stm_priv_segment_info_s *pseg,
                         enum stm_time_e attribute_to, double time)
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -274,30 +274,6 @@
 #define STM_STACK_MARKER_NEW   2
 #define STM_STACK_MARKER_OLD   6
 
-#define STM_PUSH_MARKER(tl, odd_num, p)   do {  \
-    uintptr_t _odd_num = (odd_num);             \
-    assert(_odd_num & 1);                       \
-    STM_PUSH_ROOT(tl, _odd_num);                \
-    STM_PUSH_ROOT(tl, p);                       \
-} while (0)
-
-#define STM_POP_MARKER(tl)   ({                 \
-    object_t *_popped = STM_POP_ROOT_RET(tl);   \
-    STM_POP_ROOT_RET(tl);                       \
-    _popped;                                    \
-})
-
-#define STM_UPDATE_MARKER_NUM(tl, odd_num)  do {                \
-    uintptr_t _odd_num = (odd_num);                             \
-    assert(_odd_num & 1);                                       \
-    struct stm_shadowentry_s *_ss = (tl).shadowstack - 2;       \
-    while (!(((uintptr_t)(_ss->ss)) & 1)) {                     \
-        _ss--;                                                  \
-        assert(_ss >= (tl).shadowstack_base);                   \
-    }                                                           \
-    _ss->ss = (object_t *)_odd_num;                             \
-} while (0)
-
 
 /* Every thread needs to have a corresponding stm_thread_local_t
    structure.  It may be a "__thread" global variable or something else.
@@ -406,6 +382,33 @@
                                    object_t *following_object,
                                    char *outputbuf, size_t outputbufsize);
 
+/* Conventience macros to push the markers into the shadowstack */
+#define STM_PUSH_MARKER(tl, odd_num, p)   do {  \
+    uintptr_t _odd_num = (odd_num);             \
+    assert(_odd_num & 1);                       \
+    STM_PUSH_ROOT(tl, _odd_num);                \
+    STM_PUSH_ROOT(tl, p);                       \
+} while (0)
+
+#define STM_POP_MARKER(tl)   ({                 \
+    object_t *_popped = STM_POP_ROOT_RET(tl);   \
+    STM_POP_ROOT_RET(tl);                       \
+    _popped;                                    \
+})
+
+#define STM_UPDATE_MARKER_NUM(tl, odd_num)  do {                \
+    uintptr_t _odd_num = (odd_num);                             \
+    assert(_odd_num & 1);                                       \
+    struct stm_shadowentry_s *_ss = (tl).shadowstack - 2;       \
+    while (!(((uintptr_t)(_ss->ss)) & 1)) {                     \
+        _ss--;                                                  \
+        assert(_ss >= (tl).shadowstack_base);                   \
+    }                                                           \
+    _ss->ss = (object_t *)_odd_num;                             \
+} while (0)
+
+char *_stm_expand_marker(void);
+
 
 /* ==================== END ==================== */
 
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -129,6 +129,7 @@
 void stm_push_marker(stm_thread_local_t *, uintptr_t, object_t *);
 void stm_update_marker_num(stm_thread_local_t *, uintptr_t);
 void stm_pop_marker(stm_thread_local_t *);
+char *_stm_expand_marker(void);
 """)
 
 
diff --git a/c7/test/test_marker.py b/c7/test/test_marker.py
--- a/c7/test/test_marker.py
+++ b/c7/test/test_marker.py
@@ -114,3 +114,19 @@
         lib.stm_push_marker(tl, 29, p)
         lib.stm_pop_marker(tl)
         py.test.raises(EmptyStack, self.pop_root)
+
+    def test_stm_expand_marker(self):
+        @ffi.callback("void(uintptr_t, object_t *, char *, size_t)")
+        def expand_marker(number, ptr, outbuf, outbufsize):
+            s = '%d %r\x00' % (number, ptr)
+            assert len(s) <= outbufsize
+            outbuf[0:len(s)] = s
+        lib.stmcb_expand_marker = expand_marker
+        self.start_transaction()
+        p = stm_allocate(16)
+        self.push_root(ffi.cast("object_t *", 29))
+        self.push_root(p)
+        self.push_root(stm_allocate(32))
+        self.push_root(stm_allocate(16))
+        raw = lib._stm_expand_marker()
+        assert ffi.string(raw) == '29 %r' % (p,)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to