[pypy-commit] pypy win32-fixes4: abi differentiation could be cleaner?
mattip
noreply at buildbot.pypy.org
Mon Mar 24 21:22:38 CET 2014
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-fixes4
Changeset: r70264:13cf0ac5274e
Date: 2014-03-24 22:21 +0200
http://bitbucket.org/pypy/pypy/changeset/13cf0ac5274e/
Log: abi differentiation could be cleaner?
diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -66,9 +66,11 @@
self.args = args
class CallDescr(AbstractDescr):
- def __init__(self, RESULT, ARGS, extrainfo):
+ from rpython.rlib.clibffi import FFI_DEFAULT_ABI
+ def __init__(self, RESULT, ARGS, extrainfo, ABI=FFI_DEFAULT_ABI):
self.RESULT = RESULT
self.ARGS = ARGS
+ self.ABI = ABI
self.extrainfo = extrainfo
def __repr__(self):
@@ -428,7 +430,7 @@
try:
return self.descrs[key]
except KeyError:
- descr = CallDescr(RESULT, ARGS, extrainfo)
+ descr = CallDescr(RESULT, ARGS, extrainfo, ABI=cif_description.abi)
self.descrs[key] = descr
return descr
@@ -949,7 +951,7 @@
# graph, not to directly execute the python function
result = self.cpu.maybe_on_top_of_llinterp(func, call_args, descr.RESULT)
else:
- FUNC = lltype.FuncType(descr.ARGS, descr.RESULT)
+ FUNC = lltype.FuncType(descr.ARGS, descr.RESULT, descr.ABI)
func_to_call = rffi.cast(lltype.Ptr(FUNC), func)
result = func_to_call(*call_args)
del self.force_guard_op
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -358,6 +358,13 @@
if isinstance(T, lltype.Ptr):
if isinstance(T.TO, lltype.FuncType):
+
+ functype = ctypes.CFUNCTYPE
+ if sys.platform == 'win32':
+ from rpython.rlib.clibffi import FFI_STDCALL, FFI_DEFAULT_ABI
+ if getattr(T.TO, 'ABI', FFI_DEFAULT_ABI) == FFI_STDCALL:
+ # for win32 system call
+ functype = ctypes.WINFUNCTYPE
argtypes = [get_ctypes_type(ARG) for ARG in T.TO.ARGS
if ARG is not lltype.Void]
if T.TO.RESULT is lltype.Void:
@@ -366,16 +373,10 @@
restype = get_ctypes_type(T.TO.RESULT)
try:
kwds = {'use_errno': True}
- if getattr(T.TO, 'ABI', 'FFI_STDCALL'):
- # for win32 system call
- return ctypes.WINFUNCTYPE(restype, *argtypes, **kwds)
- return ctypes.CFUNCTYPE(restype, *argtypes, **kwds)
+ return functype(restype, *argtypes, **kwds)
except TypeError:
# unexpected 'use_errno' argument, old ctypes version
- if getattr(T.TO, 'ABI', 'FFI_STDCALL'):
- # for win32 system call
- return ctypes.WINFUNCTYPE(restype, *argtypes)
- return ctypes.CFUNCTYPE(restype, *argtypes)
+ return functype(restype, *argtypes)
elif isinstance(T.TO, lltype.OpaqueType):
return ctypes.c_void_p
else:
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -537,7 +537,7 @@
class FuncType(ContainerType):
_gckind = 'raw'
__name__ = 'func'
- def __init__(self, args, result):
+ def __init__(self, args, result, abi='FFI_DEFAULT_ABI'):
for arg in args:
assert isinstance(arg, LowLevelType)
# There are external C functions eating raw structures, not
@@ -547,6 +547,7 @@
if isinstance(result, ContainerType):
raise TypeError, "function result can only be primitive or pointer"
self.RESULT = result
+ self.ABI = abi
def __str__(self):
args = ', '.join(map(str, self.ARGS))
More information about the pypy-commit
mailing list