Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r75857:79ec4673db42
Date: 2015-02-13 16:39 +0100
http://bitbucket.org/pypy/pypy/changeset/79ec4673db42/
Log: Add rstm.allocate_preexisting()
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -162,6 +162,12 @@
def stm_count():
return llop.stm_count(lltype.Signed)
[email protected]()
+def allocate_preexisting(p):
+ TP = lltype.typeOf(p)
+ size = llmemory.sizeof(TP.TO)
+ return llop.stm_allocate_preexisting(TP, size, p)
+
# ____________________________________________________________
class _Entry(ExtRegistryEntry):
diff --git a/rpython/rtyper/lltypesystem/lloperation.py
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -418,6 +418,7 @@
'stm_allocate_weakref': LLOp(sideeffects=False, canmallocgc=True),
'stm_allocate_finalizer': LLOp(sideeffects=False, canmallocgc=True),
'stm_allocate_f_light': LLOp(sideeffects=False, canmallocgc=True),
+ 'stm_allocate_preexisting':LLOp(sideeffects=False, canmallocgc=True),
'stm_get_from_obj': LLOp(sideeffects=False),
'stm_get_from_obj_const': LLOp(canfold=True),
'stm_set_into_obj': LLOp(),
diff --git a/rpython/translator/stm/funcgen.py
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -108,6 +108,15 @@
'((rpyobj_t *)%s)->tid = %s;\n' % (result, arg_type_id) +
'stm_enable_light_finalizer((object_t *)%s);' % (result,))
+def stm_allocate_preexisting(funcgen, op):
+ arg_size = funcgen.expr(op.args[0])
+ arg_idata = funcgen.expr(op.args[1])
+ result = funcgen.expr(op.result)
+ resulttype = cdecl(funcgen.lltypename(op.result), '')
+ return ('%s = (%s)stm_allocate_preexisting(%s,'
+ ' _stm_real_address((object_t *)%s));' % (
+ result, resulttype, arg_size, arg_idata))
+
def stm_get_from_obj(funcgen, op):
assert op.args[0].concretetype == llmemory.GCREF
arg_obj = funcgen.expr(op.args[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
@@ -603,3 +603,20 @@
t, cbuilder = self.compile(main, backendopt=True)
data = cbuilder.cmdexec('')
assert 'ok!\n' in data
+
+ def test_allocate_preexisting(self):
+ S = lltype.GcStruct('S', ('n', lltype.Signed))
+
+ def main(argv):
+ s1 = lltype.malloc(S)
+ s1.n = 42
+ s2 = rstm.allocate_preexisting(s1)
+ s1.n += 1
+ assert s2.n == 42
+ #
+ print "ok!"
+ return 0
+
+ t, cbuilder = self.compile(main)
+ data = cbuilder.cmdexec('')
+ assert 'ok!\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit