[pypy-svn] r74610 - in pypy/trunk/pypy/rpython/lltypesystem: . test
afa at codespeak.net
afa at codespeak.net
Thu May 20 23:09:34 CEST 2010
Author: afa
Date: Thu May 20 23:09:33 2010
New Revision: 74610
Modified:
pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Allows ll2ctypes to return a COpaquePtr allocated by an external function.
Now you can use fopen(), fwrite() and fclose() in rpython code!
Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py Thu May 20 23:09:33 2010
@@ -208,6 +208,8 @@
else:
restype = get_ctypes_type(T.TO.RESULT)
return ctypes.CFUNCTYPE(restype, *argtypes)
+ elif isinstance(T.TO, lltype.OpaqueType):
+ return ctypes.c_void_p
else:
return ctypes.POINTER(get_ctypes_type(T.TO, delayed_builders))
elif T is lltype.Void:
@@ -635,10 +637,15 @@
cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']())
else:
cbuf = ctypes.create_string_buffer("\x00")
+ cbuf = ctypes.cast(cbuf, ctypes.c_void_p)
add_storage(container, _parentable_mixin, cbuf)
else:
raise NotImplementedError(T)
container._ctypes_storage_was_allocated()
+
+ if isinstance(T.TO, lltype.OpaqueType):
+ return container._storage
+
storage = container._storage
p = ctypes.pointer(storage)
if index:
@@ -729,6 +736,7 @@
container = _llgcopaque(cobj)
else:
container = lltype._opaque(T.TO)
+ container._storage = ctypes.cast(cobj, ctypes.c_void_p)
else:
raise NotImplementedError(T)
llobj = lltype._ptr(T, container, solid=True)
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 Thu May 20 23:09:33 2010
@@ -344,7 +344,6 @@
assert not ALLOCATED # detects memory leaks in the test
def test_opaque_obj_2(self):
- py.test.skip("FIXME")
FILEP = rffi.COpaquePtr('FILE')
fopen = rffi.llexternal('fopen', [rffi.CCHARP, rffi.CCHARP], FILEP)
fclose = rffi.llexternal('fclose', [FILEP], rffi.INT)
@@ -353,8 +352,7 @@
assert ll_file
fclose(ll_file)
assert tmppath.check(file=1)
- #assert not ALLOCATED --- fails, because ll2ctypes misses the
- # fact that fclose() frees 'll_file'
+ assert not ALLOCATED # detects memory leaks in the test
def test_simple_cast(self):
assert rffi.cast(rffi.SIGNEDCHAR, 0x123456) == 0x56
More information about the Pypy-commit
mailing list