[pypy-commit] pypy stm: stm_setfield.

arigo noreply at buildbot.pypy.org
Tue Sep 27 15:24:08 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r47625:d0c0f88ba590
Date: 2011-09-27 14:47 +0200
http://bitbucket.org/pypy/pypy/changeset/d0c0f88ba590/

Log:	stm_setfield.

diff --git a/pypy/translator/stm/rstm.py b/pypy/translator/stm/rstm.py
--- a/pypy/translator/stm/rstm.py
+++ b/pypy/translator/stm/rstm.py
@@ -7,3 +7,9 @@
     p = rffi.cast(rffi.VOIDPP, p)
     res = _rffi_stm.stm_read_word(p)
     return rffi.cast(lltype.Signed, res)
+
+def stm_setfield(structptr, fieldname, newvalue):
+    p = lltype.direct_fieldptr(structptr, fieldname)
+    p = rffi.cast(rffi.VOIDPP, p)
+    pval = rffi.cast(rffi.VOIDP, newvalue)
+    _rffi_stm.stm_write_word(p, pval)
diff --git a/pypy/translator/stm/test/test_rstm.py b/pypy/translator/stm/test/test_rstm.py
--- a/pypy/translator/stm/test/test_rstm.py
+++ b/pypy/translator/stm/test/test_rstm.py
@@ -26,3 +26,25 @@
                         lltype.nullptr(rffi.VOIDP.TO))
     descriptor_done()
     assert a.x == 420
+
+def test_stm_setfield():
+    A = lltype.Struct('A', ('x', lltype.Signed), ('y', lltype.Signed))
+    a = lltype.malloc(A, immortal=True, flavor='raw')
+    a.x = -611
+    a.y = 0
+    def callback1(x):
+        assert a.x == -611
+        assert stm_getfield(a, 'x') == -611
+        stm_setfield(a, 'x', 42 * a.y)
+        assert stm_getfield(a, 'x') == 42 * a.y
+        assert a.x == -611 # xxx still the old value when reading non-transact.
+        if a.y < 10:
+            a.y += 1    # non-transactionally
+            abort_and_retry()
+        else:
+            return lltype.nullptr(rffi.VOIDP.TO)
+    descriptor_init()
+    perform_transaction(llhelper(CALLBACK, callback1),
+                        lltype.nullptr(rffi.VOIDP.TO))
+    descriptor_done()
+    assert a.x == 420


More information about the pypy-commit mailing list