[pypy-commit] pypy stm: More tests, fixes.
arigo
noreply at buildbot.pypy.org
Sat Nov 5 17:25:20 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48790:cf31b07133b5
Date: 2011-11-05 16:24 +0100
http://bitbucket.org/pypy/pypy/changeset/cf31b07133b5/
Log: More tests, fixes.
diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py
--- a/pypy/translator/stm/llstminterp.py
+++ b/pypy/translator/stm/llstminterp.py
@@ -95,7 +95,7 @@
assert 0
def opstm_getarrayitem(self, array, index):
- ARRAY = lltype.typeOf(struct).TO
+ ARRAY = lltype.typeOf(array).TO
if ARRAY._immutable_field():
# immutable item reads are always allowed
return LLFrame.op_getarrayitem(self, array, index)
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
@@ -79,6 +79,10 @@
#print 'getting %x, mask=%x, replacing with %x' % (word, mask, val)
_rffi_stm.stm_write_word(p, val)
+def stm_getarrayitem(arrayptr, index):
+ "NOT_RPYTHON"
+ raise NotImplementedError("sorry")
+
def begin_transaction():
"NOT_RPYTHON. For tests only"
raise NotImplementedError("hard to really emulate")
@@ -131,6 +135,21 @@
class ExtEntry(ExtRegistryEntry):
+ _about_ = stm_getarrayitem
+
+ def compute_result_annotation(self, s_arrayptr, s_index):
+ from pypy.tool.pairtype import pair
+ return pair(s_arrayptr, s_index).getitem()
+
+ def specialize_call(self, hop):
+ r_arrayptr = hop.args_r[0]
+ v_arrayptr, v_index = hop.inputargs(r_arrayptr, lltype.Signed)
+ hop.exception_cannot_occur()
+ return hop.genop('stm_getarrayitem', [v_arrayptr, v_index],
+ resulttype = hop.r_result)
+
+
+class ExtEntry(ExtRegistryEntry):
_about_ = (begin_transaction, commit_transaction,
begin_inevitable_transaction, transaction_boundary)
diff --git a/pypy/translator/stm/test/test_llstminterp.py b/pypy/translator/stm/test/test_llstminterp.py
--- a/pypy/translator/stm/test/test_llstminterp.py
+++ b/pypy/translator/stm/test/test_llstminterp.py
@@ -46,6 +46,24 @@
res = eval_stm_graph(interp, graph, [p], stm_mode="inevitable_transaction")
assert res == 42
+def test_stm_getarrayitem():
+ A = lltype.GcArray(lltype.Signed)
+ p = lltype.malloc(A, 5, immortal=True)
+ p[3] = 42
+ def func(p):
+ return rstm.stm_getarrayitem(p, 3)
+ interp, graph = get_interpreter(func, [p])
+ # forbidden in "not_in_transaction" mode
+ py.test.raises(ForbiddenInstructionInSTMMode,
+ eval_stm_graph, interp, graph, [p],
+ stm_mode="not_in_transaction")
+ # works in "regular_transaction" mode
+ res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
+ assert res == 42
+ # works in "inevitable_transaction" mode
+ res = eval_stm_graph(interp, graph, [p], stm_mode="inevitable_transaction")
+ assert res == 42
+
def test_getfield_immutable():
S = lltype.GcStruct('S', ('x', lltype.Signed), hints = {'immutable': True})
p = lltype.malloc(S, immortal=True)
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -141,6 +141,19 @@
eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction",
final_stm_mode="inevitable_transaction")
+def test_unsupported_getarrayitem_raw():
+ A = lltype.Array(lltype.Signed)
+ p = lltype.malloc(A, 5, immortal=True)
+ p[3] = 42
+ def func(p):
+ return p[3]
+ interp, graph = get_interpreter(func, [p])
+ transform_graph(graph)
+ assert summary(graph) == {'stm_try_inevitable': 1, 'getarrayitem': 1}
+ res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction",
+ final_stm_mode="inevitable_transaction")
+ assert res == 42
+
# ____________________________________________________________
class CompiledSTMTests(StandaloneTests):
More information about the pypy-commit
mailing list