[pypy-svn] r77679 - in pypy/branch/jitffi/pypy: module/_ffi module/_ffi/test rlib
antocuni at codespeak.net
antocuni at codespeak.net
Thu Oct 7 14:54:34 CEST 2010
Author: antocuni
Date: Thu Oct 7 14:54:32 2010
New Revision: 77679
Modified:
pypy/branch/jitffi/pypy/module/_ffi/__init__.py
pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
pypy/branch/jitffi/pypy/rlib/libffi.py
Log:
create an applevel wrapper for each ffi primitive type
Modified: pypy/branch/jitffi/pypy/module/_ffi/__init__.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/__init__.py (original)
+++ pypy/branch/jitffi/pypy/module/_ffi/__init__.py Thu Oct 7 14:54:32 2010
@@ -1,10 +1,12 @@
from pypy.interpreter.mixedmodule import MixedModule
+from pypy.module._ffi import interp_ffi
class Module(MixedModule):
interpleveldefs = {
'CDLL' : 'interp_ffi.W_CDLL',
# 'FuncPtr' : 'interp_ffi.W_FuncPtr',
+ 'types': 'interp_ffi.W_types',
}
appleveldefs = {}
Modified: pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py (original)
+++ pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py Thu Oct 7 14:54:32 2010
@@ -4,9 +4,42 @@
from pypy.interpreter.gateway import interp2app, NoneNotWrapped
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.rlib.libffi import CDLL
+from pypy.rlib.libffi import CDLL, types
from pypy.rlib.rdynload import DLOpenError
+class W_FFIType(Wrappable):
+ def __init__(self, name, ffitype):
+ self.name = name
+ self.ffitype = ffitype
+
+ def str(self, space):
+ return space.wrap('<ffi type %s>' % self.name)
+ str.unwrap_spec = ['self', ObjSpace]
+
+
+W_FFIType.typedef = TypeDef(
+ 'FFIType',
+ __str__ = interp2app(W_FFIType.str),
+ )
+
+
+class W_types(Wrappable):
+ pass
+
+def build_ffi_types():
+ tdict = {}
+ for key, value in types.__dict__.iteritems():
+ if key.startswith('__'):
+ continue
+ tdict[key] = W_FFIType(key, value)
+ return tdict
+
+W_types.typedef = TypeDef(
+ 'types',
+ **build_ffi_types())
+
+# ========================================================================
+
class W_CDLL(Wrappable):
def __init__(self, space, name):
try:
@@ -18,7 +51,6 @@
self.space = space
-
def descr_new_cdll(space, w_type, name):
return space.wrap(W_CDLL(space, name))
descr_new_cdll.unwrap_spec = [ObjSpace, W_Root, str]
@@ -27,3 +59,5 @@
'CDLL',
__new__ = interp2app(descr_new_cdll),
)
+
+# ========================================================================
Modified: pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py (original)
+++ pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py Thu Oct 7 14:54:32 2010
@@ -47,3 +47,9 @@
def test_libload_fail(self):
import _ffi
raises(OSError, _ffi.CDLL, "xxxxx_this_name_does_not_exist_xxxxx")
+
+ def test_simple_types(self):
+ from _ffi import types
+ assert str(types.sint) == '<ffi type sint>'
+ assert str(types.uint) == '<ffi type uint>'
+
Modified: pypy/branch/jitffi/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/rlib/libffi.py (original)
+++ pypy/branch/jitffi/pypy/rlib/libffi.py Thu Oct 7 14:54:32 2010
@@ -30,6 +30,7 @@
setattr(cls, name, value)
cls.slong = clibffi.cast_type_to_ffitype(rffi.LONG)
cls.ulong = clibffi.cast_type_to_ffitype(rffi.ULONG)
+ del cls._import
types._import()
More information about the Pypy-commit
mailing list