[pypy-commit] pypy win64-stage1: test_libffi works almost. Only the two byval tests are left for further investigation
ctismer
noreply at buildbot.pypy.org
Fri Dec 2 21:43:06 CET 2011
Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r50078:df6d8c92cc30
Date: 2011-12-02 21:38 +0100
http://bitbucket.org/pypy/pypy/changeset/df6d8c92cc30/
Log: test_libffi works almost. Only the two byval tests are left for
further investigation
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -35,6 +35,7 @@
cls.ulong = clibffi.cast_type_to_ffitype(rffi.ULONG)
cls.slonglong = clibffi.cast_type_to_ffitype(rffi.LONGLONG)
cls.ulonglong = clibffi.cast_type_to_ffitype(rffi.ULONGLONG)
+ cls.signed = clibffi.cast_type_to_ffitype(rffi.SIGNED)
cls.wchar_t = clibffi.cast_type_to_ffitype(lltype.UniChar)
del cls._import
@@ -121,7 +122,7 @@
_check_type(TYPE)
if _fits_into_signed(TYPE):
cls = IntArg
- val = rffi.cast(rffi.LONG, val)
+ val = rffi.cast(rffi.SIGNED, val)
elif TYPE is rffi.DOUBLE:
cls = FloatArg
elif TYPE is rffi.LONGLONG or TYPE is rffi.ULONGLONG:
@@ -313,7 +314,7 @@
@jit.oopspec('libffi_call_int(self, funcsym, ll_args)')
def _do_call_int(self, funcsym, ll_args):
- return self._do_call(funcsym, ll_args, rffi.LONG)
+ return self._do_call(funcsym, ll_args, rffi.SIGNED)
@jit.oopspec('libffi_call_float(self, funcsym, ll_args)')
def _do_call_float(self, funcsym, ll_args):
@@ -326,7 +327,7 @@
@jit.dont_look_inside
def _do_call_raw(self, funcsym, ll_args):
# same as _do_call_int, but marked as jit.dont_look_inside
- return self._do_call(funcsym, ll_args, rffi.LONG)
+ return self._do_call(funcsym, ll_args, rffi.SIGNED)
@jit.oopspec('libffi_call_longlong(self, funcsym, ll_args)')
def _do_call_longlong(self, funcsym, ll_args):
@@ -364,7 +365,7 @@
TP = lltype.Ptr(rffi.CArray(RESULT))
buf = rffi.cast(TP, ll_result)
if types.is_struct(self.restype):
- assert RESULT == rffi.LONG
+ assert RESULT == rffi.SIGNED
# for structs, we directly return the buffer and transfer the
# ownership
res = rffi.cast(RESULT, buf)
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
@@ -34,8 +34,8 @@
# .arg() only supports integers and floats
chain = ArgChain()
x = lltype.malloc(lltype.GcStruct('xxx'))
- y = lltype.malloc(lltype.GcArray(rffi.LONG), 3)
- z = lltype.malloc(lltype.Array(rffi.LONG), 4, flavor='raw')
+ y = lltype.malloc(lltype.GcArray(rffi.SIGNED), 3)
+ z = lltype.malloc(lltype.Array(rffi.SIGNED), 4, flavor='raw')
py.test.raises(TypeError, "chain.arg(x)")
py.test.raises(TypeError, "chain.arg(y)")
py.test.raises(TypeError, "chain.arg(z)")
@@ -123,7 +123,7 @@
c_file.write(py.code.Source('\n'.join(snippets)))
eci = ExternalCompilationInfo(
export_symbols=exports,
- include_dirs = [str(py.path.local(autopath.pypydir).join('translator', 'c'))])
+ include_dirs=[str(py.path.local(autopath.pypydir).join('translator', 'c'))])
cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
standalone=False))
@@ -158,14 +158,15 @@
# ------------------------------------------------------------------------
def test_very_simple(self):
- """
- int diff_xy(int x, long y)
+ """ #include "src/signed_defn.h"
+
+ int diff_xy(int x, Signed y)
{
return x - y;
}
"""
libfoo = self.get_libfoo()
- func = (libfoo, 'diff_xy', [types.sint, types.slong], types.sint)
+ func = (libfoo, 'diff_xy', [types.sint, types.signed], types.sint)
res = self.call(func, [50, 8], lltype.Signed)
assert res == 42
@@ -208,7 +209,7 @@
"""
libfoo = self.get_libfoo()
func = (libfoo, 'many_args', [types.uchar, types.sint], types.sint)
- res = self.call(func, [chr(20), 22], rffi.LONG)
+ res = self.call(func, [chr(20), 22], rffi.SIGNED)
assert res == 42
def test_char_args(self):
@@ -250,12 +251,12 @@
}
"""
libfoo = self.get_libfoo()
- func = (libfoo, 'inc', [types.pointer], types.slong)
+ func = (libfoo, 'inc', [types.pointer], types.signed)
null = lltype.nullptr(rffi.SIGNEDP.TO)
res = self.call(func, [null], rffi.SIGNED)
assert res == -1
#
- ptr_result = lltype.malloc(LONGP.TO, 1, flavor='raw')
+ ptr_result = lltype.malloc(rffi.SIGNEDP.TO, 1, flavor='raw')
ptr_result[0] = 41
res = self.call(func, [ptr_result], rffi.SIGNED)
if self.__class__ is TestLibffiCall:
@@ -275,23 +276,23 @@
lltype.free(ptr_result, flavor='raw')
def test_return_pointer(self):
- """
+ """ #include "src/signed_defn.h"
+
struct pair {
- long a;
- long b;
+ Signed a;
+ Signed b;
};
struct pair my_static_pair = {10, 20};
- long* get_pointer_to_b()
+ Signed* get_pointer_to_b()
{
return &my_static_pair.b;
}
"""
libfoo = self.get_libfoo()
func = (libfoo, 'get_pointer_to_b', [], types.pointer)
- LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
- res = self.call(func, [], LONGP)
+ res = self.call(func, [], rffi.SIGNEDP)
assert res[0] == 20
def test_void_result(self):
@@ -304,12 +305,12 @@
set_dummy = (libfoo, 'set_dummy', [types.sint], types.void)
get_dummy = (libfoo, 'get_dummy', [], types.sint)
#
- initval = self.call(get_dummy, [], rffi.LONG)
+ initval = self.call(get_dummy, [], rffi.SIGNED)
#
res = self.call(set_dummy, [initval+1], lltype.Void)
assert res is None
#
- res = self.call(get_dummy, [], rffi.LONG)
+ res = self.call(get_dummy, [], rffi.SIGNED)
assert res == initval+1
def test_single_float_args(self):
@@ -389,32 +390,33 @@
else:
assert False, 'Did not raise'
- my_raises("self.call(func, [38], rffi.LONG)") # one less
- my_raises("self.call(func, [38, 12.3, 42], rffi.LONG)") # one more
+ my_raises("self.call(func, [38], rffi.SIGNED)") # one less
+ my_raises("self.call(func, [38, 12.3, 42], rffi.SIGNED)") # one more
def test_byval_argument(self):
- """
+ """ #include "src/signed_defn.h"
+
struct Point {
- long x;
- long y;
+ Signed x;
+ Signed y;
};
- long sum_point(struct Point p) {
+ Signed sum_point(struct Point p) {
return p.x + p.y;
}
"""
libfoo = CDLL(self.libfoo_name)
- ffi_point_struct = make_struct_ffitype_e(0, 0, [types.slong, types.slong])
+ ffi_point_struct = make_struct_ffitype_e(0, 0, [types.signed, types.signed])
ffi_point = ffi_point_struct.ffistruct
- sum_point = (libfoo, 'sum_point', [ffi_point], types.slong)
+ sum_point = (libfoo, 'sum_point', [ffi_point], types.signed)
#
- ARRAY = rffi.CArray(rffi.LONG)
+ ARRAY = rffi.CArray(rffi.SIGNED)
buf = lltype.malloc(ARRAY, 2, flavor='raw')
buf[0] = 30
buf[1] = 12
adr = rffi.cast(rffi.VOIDP, buf)
- res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG,
+ res = self.call(sum_point, [('arg_raw', adr)], rffi.SIGNED,
jitif=["byval"])
assert res == 42
# check that we still have the ownership on the buffer
@@ -424,8 +426,9 @@
lltype.free(ffi_point_struct, flavor='raw')
def test_byval_result(self):
- """
- struct Point make_point(long x, long y) {
+ """ #include "src/signed_defn.h"
+
+ struct Point make_point(Signed x, Signed y) {
struct Point p;
p.x = x;
p.y = y;
@@ -433,11 +436,11 @@
}
"""
libfoo = CDLL(self.libfoo_name)
- ffi_point_struct = make_struct_ffitype_e(0, 0, [types.slong, types.slong])
+ ffi_point_struct = make_struct_ffitype_e(0, 0, [types.signed, types.signed])
ffi_point = ffi_point_struct.ffistruct
libfoo = CDLL(self.libfoo_name)
- make_point = (libfoo, 'make_point', [types.slong, types.slong], ffi_point)
+ make_point = (libfoo, 'make_point', [types.signed, types.signed], ffi_point)
#
PTR = lltype.Ptr(rffi.CArray(rffi.LONG))
p = self.call(make_point, [12, 34], PTR, is_struct=True,
More information about the pypy-commit
mailing list