def detect_model_from_c_compiler(): # based on http://sourceforge.net/p/predef/wiki/Architectures/ # and http://msdn.microsoft.com/en-us/library/b0084kay.aspx mapping = { MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64', '_M_X64', '_M_AMD64'], MODEL_ARM: ['__arm__', '__thumb__','_M_ARM_EP'], MODEL_X86: ['i386', '__i386', '__i386__', '__i686__','_M_IX86'], MODEL_PPC_64: ['__powerpc64__'], } for k, v in mapping.iteritems(): for macro in v: if not getdefined(macro, ''): continue return k raise ProcessorAutodetectError, "Cannot detect processor using compiler macros"
def detect_model_from_c_compiler(): # based on http://sourceforge.net/p/predef/wiki/Architectures/ mapping = { MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64'], MODEL_ARM: ['__arm__', '__thumb__'], MODEL_X86: ['i386', '__i386', '__i386__', '__i686__'], MODEL_PPC_64: ['__powerpc64__'], MODEL_ASMJS: ['__EMSCRIPTEN__'], } for k, v in mapping.iteritems(): for macro in v: if not getdefined(macro, ''): continue return k raise ProcessorAutodetectError, "Cannot detect processor using compiler macros"
wrapfn="newtext_or_none"), __doc__ = """ C Dynamically loaded library use CDLL(libname) to create a handle to a C library (the argument is processed the same way as dlopen processes it). On such a library you can call: lib.ptr(func_name, argtype_list, restype) where argtype_list is a list of single characters and restype is a single character. The character meanings are more or less the same as in the struct module, except that s has trailing \x00 added, while p is considered a raw buffer.""" # xxx fix doc ) unroll_letters_for_numbers = unrolling_iterable(TYPEMAP_NUMBER_LETTERS) unroll_letters_for_floats = unrolling_iterable(TYPEMAP_FLOAT_LETTERS) _ARM = rffi_platform.getdefined('__arm__', '') @specialize.arg(2) def read_ptr(ptr, ofs, TP): T = lltype.Ptr(rffi.CArray(TP)) for c in unroll_letters_for_floats: # Note: if we are on ARM and have a float-ish value that is not word # aligned accessing it directly causes a SIGBUS. Instead we use memcpy # to avoid the problem if (_ARM and LL_TYPEMAP[c] is TP and rffi.cast(lltype.Signed, ptr) & 3 != 0): if ofs != 0: ptr = rffi.ptradd(ptr, ofs*rffi.sizeof(TP)) with lltype.scoped_alloc(T.TO, 1) as t_array: rffi.c_memcpy( rffi.cast(rffi.VOIDP, t_array),
from rpython.tool.ansi_print import ansi_log log = py.log.Producer("libffi") py.log.setconsumer("libffi", ansi_log) # maaaybe isinstance here would be better. Think _MSVC = platform.name == "msvc" _MINGW = platform.name == "mingw32" _WIN32 = _MSVC or _MINGW _WIN64 = _WIN32 and is_emulated_long _MAC_OS = platform.name == "darwin" _FREEBSD_7 = platform.name == "freebsd7" _LITTLE_ENDIAN = sys.byteorder == 'little' _BIG_ENDIAN = sys.byteorder == 'big' _ARM = rffi_platform.getdefined('__arm__', '') if _WIN32: from rpython.rlib import rwin32 if _WIN32: separate_module_sources = [''' #include "src/precommondefs.h" #include <stdio.h> #include <windows.h> /* Get the module where the "fopen" function resides in */ RPY_EXTERN HANDLE pypy_get_libc_handle() { MEMORY_BASIC_INFORMATION mi; char buf[1000];
def test_defined(): res = rffi_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE', '') assert not res res = rffi_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE', '#define ALFKJLKJFLKJFKLEJDLKEWMECEE') assert res
except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("array size would overflow a ssize_t")) extra = '[%d]' % length # ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra) return ctype # ____________________________________________________________ SF_MSVC_BITFIELDS = 1 SF_GCC_ARM_BITFIELDS = 2 if sys.platform == 'win32': DEFAULT_SFLAGS = SF_MSVC_BITFIELDS elif rffi_platform.getdefined('__arm__', ''): DEFAULT_SFLAGS = SF_GCC_ARM_BITFIELDS else: DEFAULT_SFLAGS = 0 @unwrap_spec(name=str) def new_struct_type(space, name): return ctypestruct.W_CTypeStruct(space, name) @unwrap_spec(name=str) def new_union_type(space, name): return ctypestruct.W_CTypeUnion(space, name) @unwrap_spec(w_ctype=ctypeobj.W_CType, totalsize=int, totalalignment=int, sflags=int) def complete_struct_or_union(space, w_ctype, w_fields, w_ignored=None,
SF_MSVC_BITFIELDS = 0x01 SF_GCC_ARM_BITFIELDS = 0x02 SF_GCC_X86_BITFIELDS = 0x10 SF_GCC_BIG_ENDIAN = 0x04 SF_GCC_LITTLE_ENDIAN = 0x40 SF_PACKED = 0x08 SF_STD_FIELD_POS = 0x80 if sys.platform == "win32": DEFAULT_SFLAGS_PLATFORM = SF_MSVC_BITFIELDS else: if rffi_platform.getdefined("__arm__", ""): DEFAULT_SFLAGS_PLATFORM = SF_GCC_ARM_BITFIELDS else: DEFAULT_SFLAGS_PLATFORM = SF_GCC_X86_BITFIELDS if sys.byteorder == "big": DEFAULT_SFLAGS_ENDIAN = SF_GCC_BIG_ENDIAN else: DEFAULT_SFLAGS_ENDIAN = SF_GCC_LITTLE_ENDIAN def complete_sflags(sflags): # add one of the SF_xxx_BITFIELDS flags if none is specified if not (sflags & (SF_MSVC_BITFIELDS | SF_GCC_ARM_BITFIELDS | SF_GCC_X86_BITFIELDS)): sflags |= DEFAULT_SFLAGS_PLATFORM # add one of SF_GCC_xx_ENDIAN if none is specified
SF_GCC_BIG_ENDIAN = 0x04 SF_GCC_LITTLE_ENDIAN = 0x40 SF_PACKED = 0x08 SF_STD_FIELD_POS = 0x80 if sys.platform == 'win32': SF_DEFAULT_PACKING = 8 else: SF_DEFAULT_PACKING = 0x40000000 # a huge power of two if sys.platform == 'win32': DEFAULT_SFLAGS_PLATFORM = SF_MSVC_BITFIELDS else: if (rffi_platform.getdefined('__arm__', '') or rffi_platform.getdefined('__aarch64__', '')): DEFAULT_SFLAGS_PLATFORM = SF_GCC_ARM_BITFIELDS else: DEFAULT_SFLAGS_PLATFORM = SF_GCC_X86_BITFIELDS if sys.byteorder == 'big': DEFAULT_SFLAGS_ENDIAN = SF_GCC_BIG_ENDIAN else: DEFAULT_SFLAGS_ENDIAN = SF_GCC_LITTLE_ENDIAN def complete_sflags(sflags): # add one of the SF_xxx_BITFIELDS flags if none is specified if not (sflags & (SF_MSVC_BITFIELDS | SF_GCC_ARM_BITFIELDS | SF_GCC_X86_BITFIELDS)):