[pypy-svn] pypy jitypes2: slightly change the libffi interface for using struct by value as arguments: now it explicitly requires a void*, instead of a long
antocuni
commits-noreply at bitbucket.org
Fri Dec 24 14:30:40 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40222:d737ef36fcd2
Date: 2010-12-24 14:20 +0100
http://bitbucket.org/pypy/pypy/changeset/d737ef36fcd2/
Log: slightly change the libffi interface for using struct by value as
arguments: now it explicitly requires a void*, instead of a long
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -183,8 +183,8 @@
""" An argument holding a raw pointer to put inside ll_args
"""
- def __init__(self, intval):
- self.ptrval = rffi.cast(rffi.CCHARP, intval)
+ def __init__(self, ptrval):
+ self.ptrval = ptrval
def push(self, func, ll_args, i):
func._push_raw(self.ptrval, ll_args, i)
@@ -412,6 +412,7 @@
TP = lltype.Ptr(rffi.CArray(RESULT))
buf = rffi.cast(TP, ll_result)
if types.is_struct(self.restype):
+ assert RESULT == rffi.LONG
# for structs, we directly return the buffer and transfer the
# ownership
res = rffi.cast(RESULT, buf)
diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py
--- a/pypy/module/_ffi/interp_ffi.py
+++ b/pypy/module/_ffi/interp_ffi.py
@@ -81,7 +81,9 @@
argchain.arg(space.float_w(w_arg))
elif kind == 'S': # struct
# arg_raw directly takes value to put inside ll_args
- argchain.arg_raw(intmask(space.uint_w(w_arg)))
+ uintval = space.uint_w(w_arg)
+ ptrval = rffi.cast(rffi.VOIDP, uintval)
+ argchain.arg_raw(ptrval)
elif kind == 's':
argchain.arg_singlefloat(space.float_w(w_arg))
elif kind == 'I' or kind == 'U':
diff --git a/pypy/rlib/test/test_libffi.py b/pypy/rlib/test/test_libffi.py
--- a/pypy/rlib/test/test_libffi.py
+++ b/pypy/rlib/test/test_libffi.py
@@ -401,7 +401,7 @@
buf = lltype.malloc(ARRAY, 2, flavor='raw')
buf[0] = 30
buf[1] = 12
- adr = rffi.cast(rffi.ULONG, buf)
+ adr = rffi.cast(rffi.VOIDP, buf)
res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG, init_result=0)
assert res == 42
# check that we still have the ownership on the buffer
More information about the Pypy-commit
mailing list