[pypy-svn] pypy jitypes2: teach _rawffi structures how to return their ffi type at applevel, so that
antocuni
commits-noreply at bitbucket.org
Thu Dec 23 15:00:44 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40206:7a3bd5b3f9a7
Date: 2010-12-23 13:24 +0100
http://bitbucket.org/pypy/pypy/changeset/7a3bd5b3f9a7/
Log: teach _rawffi structures how to return their ffi type at applevel,
so that they can be used togheter with _ffi. The test still fails
because _ffi does not know how to handle the arguments
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
@@ -35,7 +35,7 @@
from pypy.rpython.lltypesystem import rffi
from pypy.rlib.libffi import get_libc_name, CDLL, types
from pypy.rlib.test.test_libffi import get_libm_name
- space = gettestobjspace(usemodules=('_ffi',))
+ space = gettestobjspace(usemodules=('_ffi', '_rawffi'))
cls.space = space
cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
cls.w_libc_name = space.wrap(get_libc_name())
@@ -228,6 +228,29 @@
expected = maxint64 + 3
assert res == expected
+ def test_byval(self):
+ """
+ struct Point {
+ long x;
+ long y;
+ };
+
+ long sum_point(struct Point p) {
+ return p.x + p.y;
+ }
+ """
+ # failing test so far
+ import _rawffi
+ from _ffi import CDLL, types
+ POINT = _rawffi.Structure([('x', 'l'), ('y', 'l')])
+ ffi_point = POINT.get_ffi_type()
+ libfoo = CDLL(self.libfoo_name)
+ sum_point = libfoo.getfunc('sum_point', [ffi_point], types.slong)
+ p = POINT()
+ p.x = 30
+ p.y = 12
+ res = sum_point(p)
+ assert res == 42
def test_TypeError_numargs(self):
from _ffi import CDLL, types
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -2,7 +2,7 @@
from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable, \
Arguments
from pypy.interpreter.error import OperationError, wrap_oserror, operationerrfmt
-from pypy.interpreter.gateway import interp2app, NoneNotWrapped
+from pypy.interpreter.gateway import interp2app, NoneNotWrapped, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.rlib.clibffi import *
@@ -246,6 +246,14 @@
def get_basic_ffi_type(self):
raise NotImplementedError
+ @unwrap_spec('self', ObjSpace)
+ def descr_get_ffi_type(self, space):
+ # XXX: this assumes that you have the _ffi module enabled. In the long
+ # term, probably we will move the code for build structures and arrays
+ # from _rawffi to _ffi
+ from pypy.module._ffi.interp_ffi import W_FFIType
+ return W_FFIType('<name>', self.get_basic_ffi_type())
+
def descr_size_alignment(self, space, n=1):
return space.newtuple([space.wrap(self.size * n),
space.wrap(self.alignment)])
diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -158,7 +158,8 @@
size = interp_attrproperty('size', W_Structure),
alignment = interp_attrproperty('alignment', W_Structure),
fieldoffset = interp2app(W_Structure.descr_fieldoffset),
- size_alignment = interp2app(W_Structure.descr_size_alignment)
+ size_alignment = interp2app(W_Structure.descr_size_alignment),
+ get_ffi_type = interp2app(W_Structure.descr_get_ffi_type),
)
W_Structure.typedef.acceptable_as_base_class = False
More information about the Pypy-commit
mailing list