[pypy-commit] pypy ffistruct: low-level support for single float fields
antocuni
noreply at buildbot.pypy.org
Wed Nov 9 19:12:09 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r49040:eb02c4c1c0f0
Date: 2011-11-09 18:14 +0100
http://bitbucket.org/pypy/pypy/changeset/eb02c4c1c0f0/
Log: low-level support for single float fields
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -469,6 +469,16 @@
_struct_setfield(lltype.Float, addr, offset, value)
+ at jit.oopspec('libffi_struct_getfield(ffitype, addr, offset)')
+def struct_getfield_singlefloat(ffitype, addr, offset):
+ value = _struct_getfield(lltype.SingleFloat, addr, offset)
+ return value
+
+ at jit.oopspec('libffi_struct_setfield(ffitype, addr, offset, value)')
+def struct_setfield_singlefloat(ffitype, addr, offset, value):
+ _struct_setfield(lltype.SingleFloat, addr, offset, value)
+
+
@specialize.arg(0)
def _struct_getfield(TYPE, addr, offset):
"""
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
@@ -7,7 +7,8 @@
from pypy.rlib.libffi import CDLL, Func, get_libc_name, ArgChain, types
from pypy.rlib.libffi import (IS_32_BIT, struct_getfield_int, struct_setfield_int,
struct_getfield_longlong, struct_setfield_longlong,
- struct_getfield_float, struct_setfield_float)
+ struct_getfield_float, struct_setfield_float,
+ struct_getfield_singlefloat, struct_setfield_singlefloat)
class TestLibffiMisc(BaseFfiTest):
@@ -117,6 +118,27 @@
lltype.free(p, flavor='raw')
+ def test_struct_fields_singlefloat(self):
+ POINT = lltype.Struct('POINT',
+ ('x', rffi.FLOAT),
+ ('y', rffi.FLOAT)
+ )
+ y_ofs = 4
+ p = lltype.malloc(POINT, flavor='raw')
+ p.x = r_singlefloat(123.4)
+ p.y = r_singlefloat(567.8)
+ addr = rffi.cast(rffi.VOIDP, p)
+ assert struct_getfield_singlefloat(types.double, addr, 0) == r_singlefloat(123.4)
+ assert struct_getfield_singlefloat(types.double, addr, y_ofs) == r_singlefloat(567.8)
+ #
+ struct_setfield_singlefloat(types.double, addr, 0, r_singlefloat(321.0))
+ struct_setfield_singlefloat(types.double, addr, y_ofs, r_singlefloat(876.5))
+ assert p.x == r_singlefloat(321.0)
+ assert p.y == r_singlefloat(876.5)
+ #
+ lltype.free(p, flavor='raw')
+
+
class TestLibffiCall(BaseFfiTest):
"""
Test various kind of calls through libffi.
More information about the pypy-commit
mailing list