Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r69935:286aec3bffff
Date: 2014-03-13 20:52 +0100
http://bitbucket.org/pypy/pypy/changeset/286aec3bffff/

Log:    Fix rrawarray for stm

diff --git a/rpython/rlib/rrawarray.py b/rpython/rlib/rrawarray.py
--- a/rpython/rlib/rrawarray.py
+++ b/rpython/rlib/rrawarray.py
@@ -1,6 +1,6 @@
 from rpython.rtyper.llannotation import lltype_to_annotation
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib import jit
+from rpython.rlib import jit, rgc
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pair
@@ -50,6 +50,10 @@
 
 @jit.dont_look_inside
 def ll_copy_list_to_raw_array(ll_list, dst_ptr):
+    if rgc.stm_is_enabled():
+        for i in range(ll_list.ll_length()):
+            dst_ptr[i] = ll_list.ll_getitem_fast(i)
+        return
     # this code is delicate: we must ensure that there are no GC operations
     # around the call to raw_memcopy
     #
@@ -64,9 +68,13 @@
 
 @jit.dont_look_inside
 def ll_populate_list_from_raw_array(ll_list, src_ptr, length):
+    ll_list._ll_resize(length)
+    if rgc.stm_is_enabled():
+        for i in range(length):
+            ll_list.ll_setitem_fast(i, src_ptr[i])
+        return
     ITEM = lltype.typeOf(src_ptr).TO.OF
     size = llmemory.sizeof(ITEM) * length
-    ll_list._ll_resize(length)
     # start of no-GC section
     src_adr = get_raw_buf(src_ptr)
     dst_adr = get_raw_buf(ll_list.ll_items())
diff --git a/rpython/rlib/test/test_rrawarray.py 
b/rpython/rlib/test/test_rrawarray.py
--- a/rpython/rlib/test/test_rrawarray.py
+++ b/rpython/rlib/test/test_rrawarray.py
@@ -2,11 +2,24 @@
                                    populate_list_from_raw_array
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.test.tool import BaseRtypingTest
+from rpython.rtyper.test.test_llinterp import clear_tcache
+from rpython.rlib import rgc
 
 
 
 class TestRArray(BaseRtypingTest):
 
+    def interpret_twice(self, f, args):
+        self.interpret(f, args)
+        #
+        old = rgc.stm_is_enabled
+        try:
+            rgc.stm_is_enabled = lambda: True
+            clear_tcache()
+            self.interpret(f, args)
+        finally:
+            rgc.stm_is_enabled = old
+
     def test_copy_list_to_raw_array(self):
         ARRAY = rffi.CArray(lltype.Signed)
         buf = lltype.malloc(ARRAY, 4, flavor='raw')
@@ -35,7 +48,7 @@
             #
             lltype.free(buf, flavor='raw')
             lltype.free(buf2, flavor='raw')
-        self.interpret(fn, [])
+        self.interpret_twice(fn, [])
 
     def test_new_list_from_raw_array(self):
         INTARRAY = rffi.CArray(lltype.Signed)
@@ -62,4 +75,4 @@
             assert lst == [1, 2, 3, 4]
             lltype.free(buf, flavor='raw')
         #
-        self.interpret(fn, [])
+        self.interpret_twice(fn, [])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to