| 1 | """ Low-level interface to clibffi |
| 2 | """ |
| 3 | |
| 4 | from pypy.interpreter.mixedmodule import MixedModule |
| 5 | from pypy.module._rawffi.alt.moduledef import Module as AltModule |
| 6 | |
| 7 | class Module(MixedModule): |
| 8 | interpleveldefs = { |
| 9 | 'CDLL' : 'interp_rawffi.W_CDLL', |
| 10 | 'FuncPtr' : 'interp_rawffi.W_FuncPtr', |
| 11 | 'Structure' : 'structure.W_Structure', |
| 12 | 'StructureInstance' : 'structure.W_StructureInstance', |
| 13 | 'StructureInstanceAutoFree' : 'structure.W_StructureInstanceAutoFree', |
| 14 | 'Array' : 'interp_array.W_Array', |
| 15 | 'ArrayInstance' : 'interp_array.W_ArrayInstance', |
| 16 | 'ArrayInstanceAutoFree': 'interp_array.W_ArrayInstanceAutoFree', |
| 17 | 'sizeof' : 'interp_rawffi.sizeof', |
| 18 | 'alignment' : 'interp_rawffi.alignment', |
| 19 | 'charp2string' : 'interp_rawffi.charp2string', |
| 20 | 'wcharp2unicode' : 'interp_rawffi.wcharp2unicode', |
| 21 | 'charp2rawstring' : 'interp_rawffi.charp2rawstring', |
| 22 | 'wcharp2rawunicode' : 'interp_rawffi.wcharp2rawunicode', |
| 23 | 'rawstring2charp' : 'interp_rawffi.rawstring2charp', |
| 24 | 'CallbackPtr' : 'callback.W_CallbackPtr', |
| 25 | '_num_of_allocated_objects': 'tracker.num_of_allocated_objects', |
| 26 | 'get_libc' : 'interp_rawffi.get_libc', |
| 27 | 'get_errno' : 'interp_rawffi.get_errno', |
| 28 | 'set_errno' : 'interp_rawffi.set_errno', |
| 29 | 'get_last_error' : 'interp_rawffi.get_last_error', |
| 30 | 'set_last_error' : 'interp_rawffi.set_last_error', |
| 31 | 'SegfaultException' : 'space.new_exception_class("_rawffi.SegfaultException")', |
| 32 | 'exit' : 'interp_exit.exit', |
| 33 | } |
| 34 | |
| 35 | appleveldefs = { |
| 36 | } |
| 37 | |
| 38 | submodules = { |
| 39 | 'alt': AltModule, |
| 40 | } |
| 41 | |
| 42 | def buildloaders(cls): |
| 43 | from pypy.module._rawffi import interp_rawffi |
| 44 | |
| 45 | if hasattr(interp_rawffi, 'FormatError'): |
| 46 | Module.interpleveldefs['FormatError'] = 'interp_rawffi.FormatError' |
| 47 | if hasattr(interp_rawffi, 'check_HRESULT'): |
| 48 | Module.interpleveldefs['check_HRESULT'] = 'interp_rawffi.check_HRESULT' |
| 49 | |
| 50 | from rpython.rlib import clibffi |
| 51 | for name in ['FUNCFLAG_STDCALL', 'FUNCFLAG_CDECL', 'FUNCFLAG_PYTHONAPI', |
| 52 | 'FUNCFLAG_USE_ERRNO', 'FUNCFLAG_USE_LASTERROR', |
| 53 | ]: |
| 54 | if hasattr(clibffi, name): |
| 55 | Module.interpleveldefs[name] = "space.wrap(%r)" % getattr(clibffi, name) |
| 56 | |
| 57 | super(Module, cls).buildloaders() |
| 58 | buildloaders = classmethod(buildloaders) |