[pypy-svn] r54012 - pypy/dist/pypy/translator/c/test
fijal at codespeak.net
fijal at codespeak.net
Tue Apr 22 14:48:34 CEST 2008
Author: fijal
Date: Tue Apr 22 14:48:32 2008
New Revision: 54012
Modified:
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
A test for gc.collect in callback
Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py Tue Apr 22 14:48:32 2008
@@ -813,6 +813,50 @@
c_fn = self.getcompiled(f)
assert c_fn() == 0
+ def test_callback_with_collect(self):
+ py.test.skip("Segfaults")
+ from pypy.rlib.libffi import ffi_type_pointer, ffi_type_slong,\
+ CDLL, ffi_type_void, CallbackFuncPtr, ffi_type_sint
+ from pypy.rpython.lltypesystem import rffi
+ from pypy.rlib import rgc
+ import gc
+
+ def callback(ll_args, ll_res, stuff):
+ a1 = rffi.cast(rffi.INTP, rffi.cast(rffi.VOIDPP, ll_args[0])[0])[0]
+ a2 = rffi.cast(rffi.INTP, rffi.cast(rffi.VOIDPP, ll_args[0])[1])[0]
+ res = rffi.cast(rffi.INTP, ll_res)
+ if a1 > a2:
+ res[0] = 1
+ else:
+ res[0] = -1
+ gc.collect()
+
+ def f():
+ libc = CDLL('libc.so.6')
+ qsort = libc.getpointer('qsort', [ffi_type_pointer, ffi_type_slong,
+ ffi_type_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')
+ return int(result)
+
+ c_fn = self.getcompiled(f)
+ assert c_fn() == 1
class TestUsingStacklessFramework(TestUsingFramework):
More information about the Pypy-commit
mailing list