[pypy-svn] pypy jitypes2: (antocuni, arigo): fix test_byval_arguments: we need to put the address of the
antocuni
commits-noreply at bitbucket.org
Thu Dec 23 15:51:35 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40208:dc4fdb5ea284
Date: 2010-12-23 15:51 +0100
http://bitbucket.org/pypy/pypy/changeset/dc4fdb5ea284/
Log: (antocuni, arigo): fix test_byval_arguments: we need to put the
address of the buffer directly inside ll_args, for which we use a
new RawArg class
diff --git a/pypy/module/_ffi/test/test__ffi.py b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -228,22 +228,16 @@
expected = maxint64 + 3
assert res == expected
- def test_byval(self):
- r"""
+ def test_byval_argument(self):
+ """
struct Point {
long x;
long y;
};
- #include <stdio.h>
long sum_point(struct Point p) {
- printf("p.x = %ld\np.y = %ld\n", p.x, p.y);
return p.x + p.y;
}
-
- void checkbuf(long* buf) {
- printf("buf[0] = %ld\nbuf[1] = %ld\n", buf[0], buf[1]);
- }
"""
import _rawffi
from _ffi import CDLL, types
@@ -251,14 +245,12 @@
ffi_point = POINT.get_ffi_type()
libfoo = CDLL(self.libfoo_name)
sum_point = libfoo.getfunc('sum_point', [ffi_point], types.slong)
- checkbuf = libfoo.getfunc('checkbuf', [types.pointer], types.void)
-
+ #
p = POINT()
p.x = 30
p.y = 12
- checkbuf(p.buffer)
res = sum_point(p.buffer)
- #assert res == 42
+ assert res == 42
def test_TypeError_numargs(self):
from _ffi import CDLL, types
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -65,9 +65,7 @@
elif ffi_type is types.sint64: return 'I'
elif ffi_type is types.uint64: return 'U'
#
- elif ffi_type.c_type == FFI_TYPE_STRUCT:
- # it's a struct
- return 'u' # XXX?
+ elif ffi_type.c_type == FFI_TYPE_STRUCT: return 'S'
raise KeyError
types._import()
@@ -122,6 +120,9 @@
self._append(cls(val))
return self
+ def arg_raw(self, val):
+ self._append(RawArg(val))
+
def arg_longlong(self, val):
"""
Note: this is a hack. So far, the JIT does not support long longs, so
@@ -163,6 +164,7 @@
def push(self, func, ll_args, i):
func._push_int(self.intval, ll_args, i)
+
class FloatArg(AbstractArg):
""" An argument holding a python float (i.e. a C double)
"""
@@ -173,6 +175,15 @@
def push(self, func, ll_args, i):
func._push_float(self.floatval, ll_args, i)
+class RawArg(AbstractArg):
+ """ An argument holding a raw pointer to put inside ll_args
+ """
+
+ def __init__(self, intval):
+ self.ptrval = rffi.cast(rffi.CCHARP, intval)
+
+ def push(self, func, ll_args, i):
+ func._push_raw(self.ptrval, ll_args, i)
class SingleFloatArg(AbstractArg):
""" An argument representing a C float (but holding a C double)
@@ -327,6 +338,10 @@
def _push_int(self, value, ll_args, i):
self._push_arg(value, ll_args, i)
+ @jit.dont_look_inside
+ def _push_raw(self, value, ll_args, i):
+ ll_args[i] = value
+
@jit.oopspec('libffi_push_float(self, value, ll_args, i)')
@enforceargs( None, float, None, int) # fix the annotation for tests
def _push_float(self, value, ll_args, i):
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
@@ -79,6 +79,9 @@
argchain.arg(intmask(space.uint_w(w_arg)))
elif kind == 'f':
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)))
elif kind == 's':
argchain.arg_singlefloat(space.float_w(w_arg))
elif kind == 'I' or kind == 'U':
More information about the Pypy-commit
mailing list