[pypy-svn] r77241 - in pypy/trunk/pypy/rpython/lltypesystem: . test

afa at codespeak.net afa at codespeak.net
Tue Sep 21 18:40:12 CEST 2010


Author: afa
Date: Tue Sep 21 18:40:10 2010
New Revision: 77241

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Test and fix for a crash in test__rawffi.py:
Copy the _storage pointer instead of simply reference another pointer,
which may change without notice.


Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	Tue Sep 21 18:40:10 2010
@@ -734,10 +734,10 @@
         elif isinstance(T.TO, lltype.Array):
             if T.TO._hints.get('nolength', False):
                 container = _array_of_unknown_length(T.TO)
-                container._storage = cobj
+                container._storage = type(cobj)(cobj.contents)
             else:
                 container = _array_of_known_length(T.TO)
-                container._storage = cobj
+                container._storage = type(cobj)(cobj.contents)
         elif isinstance(T.TO, lltype.FuncType):
             cobjkey = intmask(ctypes.cast(cobj, ctypes.c_void_p).value)
             if cobjkey in _int2obj:

Modified: pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Tue Sep 21 18:40:10 2010
@@ -1252,6 +1252,32 @@
         assert i == llmemory.cast_adr_to_int(a, "forced")
         lltype.free(p, flavor='raw')
 
+    def test_freelist(self):
+        S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
+        SP = lltype.Ptr(S)
+        chunk = lltype.malloc(rffi.CArrayPtr(S).TO, 10, flavor='raw')
+        assert lltype.typeOf(chunk) == rffi.CArrayPtr(S)
+        free_list = lltype.nullptr(rffi.VOIDP.TO)
+        # build list
+        current = chunk
+        for i in range(10):
+            rffi.cast(rffi.VOIDPP, current)[0] = free_list
+            free_list = rffi.cast(rffi.VOIDP, current)
+            current = rffi.ptradd(current, 1)
+        # get one
+        p = free_list
+        free_list = rffi.cast(rffi.VOIDPP, p)[0]
+        rffi.cast(SP, p).x = 0
+        # get two
+        p = free_list
+        free_list = rffi.cast(rffi.VOIDPP, p)[0]
+        rffi.cast(SP, p).x = 0
+        # get three
+        p = free_list
+        free_list = rffi.cast(rffi.VOIDPP, p)[0]
+        rffi.cast(SP, p).x = 0
+        lltype.free(chunk, flavor='raw')
+
 class TestPlatform(object):
     def test_lib_on_libpaths(self):
         from pypy.translator.platform import platform



More information about the Pypy-commit mailing list