[pypy-commit] pypy stmgc-c7: Test and fix: the "counter" argument we pass to the callback

arigo noreply at buildbot.pypy.org
Mon Apr 28 19:25:07 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r71049:f6dab9f69e7c
Date: 2014-04-28 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/f6dab9f69e7c/

Log:	Test and fix: the "counter" argument we pass to the callback from
	pypy_stm_perform_transaction() should start at 0.

diff --git a/rpython/translator/stm/src_stm/stmgcintf.c b/rpython/translator/stm/src_stm/stmgcintf.c
--- a/rpython/translator/stm/src_stm/stmgcintf.c
+++ b/rpython/translator/stm/src_stm/stmgcintf.c
@@ -140,6 +140,7 @@
     STM_PUSH_ROOT(stm_thread_local, arg);
 
     while (1) {
+        long counter;
 
         if (pypy_stm_ready_atomic == 1) {
             /* Not in an atomic transaction; but it might be an inevitable
@@ -156,11 +157,13 @@
                declared below than this point only.
             */
             while (__builtin_setjmp(jmpbuf) == 1) { /*redo setjmp*/ }
+            counter = v_counter;
             pypy_stm_start_transaction(&jmpbuf, &v_counter);
         }
         else {
             /* In an atomic transaction */
             assert(pypy_stm_nursery_low_fill_mark == (uintptr_t) -1);
+            counter = v_counter;
         }
 
         /* invoke the callback in the new transaction */
@@ -168,7 +171,7 @@
         assert(v_old_shadowstack == stm_thread_local.shadowstack - 1);
         STM_PUSH_ROOT(stm_thread_local, arg);
 
-        long result = v_callback(arg, v_counter);
+        long result = v_callback(arg, counter);
         if (result <= 0)
             break;
         v_counter = 0;
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -130,6 +130,23 @@
         data, dataerr = cbuilder.cmdexec('4 5000', err=True)
         assert 'check ok!' in data
 
+    def test_retry_counter_starts_at_zero(self):
+        #
+        def check(foobar, retry_counter):
+            print '<', retry_counter, '>'
+            return 0
+        #
+        S = lltype.GcStruct('S', ('got_exception', OBJECTPTR))
+        PS = lltype.Ptr(S)
+        perform_transaction = rstm.make_perform_transaction(check, PS)
+        def entry_point(argv):
+            perform_transaction(lltype.malloc(S))
+            return 0
+        #
+        t, cbuilder = self.compile(entry_point, backendopt=True)
+        data = cbuilder.cmdexec('a b c d')
+        assert '< 0 >\n' in data
+
     def test_bug1(self):
         #
         def check(foobar, retry_counter):


More information about the pypy-commit mailing list