[pypy-svn] r77673 - in pypy/branch/jitffi/pypy/module: _ffi _ffi/test _rawffi
antocuni at codespeak.net
antocuni at codespeak.net
Thu Oct 7 11:44:54 CEST 2010
Author: antocuni
Date: Thu Oct 7 11:44:52 2010
New Revision: 77673
Added:
pypy/branch/jitffi/pypy/module/_ffi/
pypy/branch/jitffi/pypy/module/_ffi/__init__.py (contents, props changed)
pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py (contents, props changed)
pypy/branch/jitffi/pypy/module/_ffi/test/
pypy/branch/jitffi/pypy/module/_ffi/test/__init__.py (contents, props changed)
pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py (contents, props changed)
Modified:
pypy/branch/jitffi/pypy/module/_rawffi/__init__.py
Log:
start to write an applevel module to expose rlib.libffi
Added: pypy/branch/jitffi/pypy/module/_ffi/__init__.py
==============================================================================
--- (empty file)
+++ pypy/branch/jitffi/pypy/module/_ffi/__init__.py Thu Oct 7 11:44:52 2010
@@ -0,0 +1,10 @@
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+
+ interpleveldefs = {
+ 'CDLL' : 'interp_ffi.W_CDLL',
+# 'FuncPtr' : 'interp_ffi.W_FuncPtr',
+ }
+
+ appleveldefs = {}
Added: pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py Thu Oct 7 11:44:52 2010
@@ -0,0 +1,29 @@
+import sys
+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.typedef import TypeDef, GetSetProperty
+
+from pypy.rlib.libffi import CDLL
+from pypy.rlib.rdynload import DLOpenError
+
+class W_CDLL(Wrappable):
+ def __init__(self, space, name):
+ try:
+ self.cdll = CDLL(name)
+ except DLOpenError, e:
+ raise operationerrfmt(space.w_OSError, '%s: %s', name,
+ e.msg or 'unspecified error')
+ self.name = name
+ 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]
+
+W_CDLL.typedef = TypeDef(
+ 'CDLL',
+ __new__ = interp2app(descr_new_cdll),
+ )
Added: pypy/branch/jitffi/pypy/module/_ffi/test/__init__.py
==============================================================================
Added: pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py Thu Oct 7 11:44:52 2010
@@ -0,0 +1,49 @@
+from pypy.conftest import gettestobjspace
+from pypy.translator.platform import platform
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.module._rawffi.interp_rawffi import TYPEMAP
+from pypy.module._rawffi.tracker import Tracker
+from pypy.translator.platform import platform
+
+import os, sys, py
+
+class AppTestFfi:
+
+ @classmethod
+ def prepare_c_example(cls):
+ from pypy.tool.udir import udir
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+ from pypy.translator.platform import platform
+
+ c_file = udir.ensure("test__ffi", dir=1).join("foolib.c")
+ # automatically collect the C source from the docstrings of the tests
+ snippets = []
+ for name in dir(cls):
+ if name.startswith('test_'):
+ meth = getattr(cls, name)
+ # the heuristic to determine it it's really C code could be
+ # improved: so far we just check that there is a '{' :-)
+ if meth.__doc__ is not None and '{' in meth.__doc__:
+ snippets.append(meth.__doc__)
+ #
+ c_file.write(py.code.Source('\n'.join(snippets)))
+ eci = ExternalCompilationInfo(export_symbols=[])
+ return str(platform.compile([c_file], eci, 'x', standalone=False))
+
+
+ def setup_class(cls):
+ from pypy.rlib.libffi import get_libc_name
+ from pypy.rlib.test.test_libffi import get_libm_name
+ space = gettestobjspace(usemodules=('_ffi',))
+ cls.space = space
+ cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
+ cls.w_libc_name = space.wrap(get_libc_name())
+ cls.w_libc_name = space.wrap(get_libm_name(sys.platform))
+
+ def test_libload(self):
+ import _ffi
+ _ffi.CDLL(self.libc_name)
+
+ def test_libload_fail(self):
+ import _ffi
+ raises(OSError, _ffi.CDLL, "xxxxx_this_name_does_not_exist_xxxxx")
Modified: pypy/branch/jitffi/pypy/module/_rawffi/__init__.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_rawffi/__init__.py (original)
+++ pypy/branch/jitffi/pypy/module/_rawffi/__init__.py Thu Oct 7 11:44:52 2010
@@ -1,5 +1,5 @@
-""" Low-level interface to libffi
+""" Low-level interface to clibffi
"""
from pypy.interpreter.mixedmodule import MixedModule
More information about the Pypy-commit
mailing list