[pypy-svn] r58575 - pypy/branch/gc-experiments/pypy/rpython/memory/test

fijal at codespeak.net fijal at codespeak.net
Thu Oct 2 17:24:33 CEST 2008


Author: fijal
Date: Thu Oct  2 17:24:32 2008
New Revision: 58575

Modified:
   pypy/branch/gc-experiments/pypy/rpython/memory/test/test_gc.py
Log:
Test copied from test_newgc.py. Happily fails here as well


Modified: pypy/branch/gc-experiments/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/memory/test/test_gc.py	Thu Oct  2 17:24:32 2008
@@ -9,7 +9,7 @@
 from pypy.rpython.lltypesystem.rstr import STR
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib.objectmodel import compute_unique_id
+from pypy.rlib.objectmodel import compute_unique_id, keepalive_until_here
 
 
 def stdout_ignore_ll_functions(msg):
@@ -479,6 +479,57 @@
 
         assert self.interpret(f, []) == 2
 
+    
+    def test_callback_with_collect(self):
+        from pypy.rlib.libffi import ffi_type_pointer, cast_type_to_ffitype,\
+             CDLL, ffi_type_void, CallbackFuncPtr, ffi_type_sint
+        from pypy.rpython.lltypesystem import rffi, ll2ctypes
+        from pypy.rlib import rgc
+        import gc
+        slong = cast_type_to_ffitype(rffi.LONG)
+
+        from pypy.rpython.lltypesystem.ll2ctypes import libc_name
+
+        def callback(ll_args, ll_res, stuff):
+            gc.collect()
+            p_a1 = rffi.cast(rffi.VOIDPP, ll_args[0])[0]
+            p_a2 = rffi.cast(rffi.VOIDPP, ll_args[1])[0]
+            a1 = rffi.cast(rffi.INTP, p_a1)[0]
+            a2 = rffi.cast(rffi.INTP, p_a2)[0]
+            res = rffi.cast(rffi.INTP, ll_res)
+            if a1 > a2:
+                res[0] = 1
+            else:
+                res[0] = -1
+
+        def f():
+            libc = CDLL(libc_name)
+            qsort = libc.getpointer('qsort', [ffi_type_pointer, slong,
+                                              slong, ffi_type_pointer],
+                                ffi_type_void)
+
+            ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
+                                  ffi_type_sint, callback)
+
+            TP = rffi.CArray(rffi.INT)
+            to_sort = lltype.malloc(TP, 4, flavor='raw')
+            to_sort[0] = 4
+            to_sort[1] = 3
+            to_sort[2] = 1
+            to_sort[3] = 2
+            qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
+            qsort.push_arg(rffi.sizeof(rffi.INT))
+            qsort.push_arg(4)
+            qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
+            qsort.call(lltype.Void)
+            result = [to_sort[i] for i in range(4)] == [1,2,3,4]
+            lltype.free(to_sort, flavor='raw')
+            keepalive_until_here(ptr)
+            return int(result)
+
+        res = self.interpret(f, [])
+        assert res == 1
+
 class TestMarkSweepGC(GCTest):
     from pypy.rpython.memory.gc.marksweep import MarkSweepGC as GCClass
 



More information about the Pypy-commit mailing list