[pypy-commit] pypy ffistruct: implement FFIType.sizeof(); put some test logic into a base class
antocuni
noreply at buildbot.pypy.org
Tue Sep 6 18:04:36 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r47107:318937fd8e2e
Date: 2011-09-05 16:24 +0200
http://bitbucket.org/pypy/pypy/changeset/318937fd8e2e/
Log: implement FFIType.sizeof(); put some test logic into a base class
diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_ffi/__init__.py
--- a/pypy/module/_ffi/__init__.py
+++ b/pypy/module/_ffi/__init__.py
@@ -10,4 +10,7 @@
'get_libc':'interp_ffi.get_libc',
}
- appleveldefs = {}
+ appleveldefs = {
+ 'Structure': 'app_struct.Structure',
+ 'Field': 'app_struct.Field',
+ }
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
@@ -30,6 +30,12 @@
return space.w_None
return self.w_pointer_to
+ def descr_sizeof(self, space):
+ return space.wrap(self.sizeof())
+
+ def sizeof(self):
+ return intmask(self.ffitype.c_size)
+
def repr(self, space):
return space.wrap(self.__repr__())
@@ -86,6 +92,7 @@
'FFIType',
__repr__ = interp2app(W_FFIType.repr),
deref_pointer = interp2app(W_FFIType.descr_deref_pointer),
+ sizeof = interp2app(W_FFIType.descr_sizeof),
)
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
@@ -7,7 +7,7 @@
import os, sys, py
-class AppTestFfi:
+class BaseAppTestFFI(object):
@classmethod
def prepare_c_example(cls):
@@ -36,7 +36,6 @@
eci = ExternalCompilationInfo(export_symbols=[])
return str(platform.compile([c_file], eci, 'x', standalone=False))
-
def setup_class(cls):
from pypy.rpython.lltypesystem import rffi
from pypy.rlib.libffi import get_libc_name, CDLL, types
@@ -52,7 +51,12 @@
pow = libm.getpointer('pow', [], types.void)
pow_addr = rffi.cast(rffi.LONG, pow.funcsym)
cls.w_pow_addr = space.wrap(pow_addr)
- #
+
+class AppTestFFI(BaseAppTestFFI):
+
+ def setup_class(cls):
+ BaseAppTestFFI.setup_class.im_func(cls)
+ space = cls.space
# these are needed for test_single_float_args
from ctypes import c_float
f_12_34 = c_float(12.34).value
@@ -82,7 +86,12 @@
from _ffi import types
assert str(types.sint) == "<ffi type sint>"
assert str(types.uint) == "<ffi type uint>"
-
+
+ def test_sizeof(self):
+ from _ffi import types
+ assert types.sbyte.sizeof() == 1
+ assert types.sint.sizeof() == 4
+
def test_callfunc(self):
from _ffi import CDLL, types
libm = CDLL(self.libm_name)
More information about the pypy-commit
mailing list