diff options
author | Armin Rigo <arigo@tunes.org> | 2015-10-05 20:05:17 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-10-05 20:05:17 +0200 |
commit | 52c1a75736ca235a91122f732eae710e12aef7e8 (patch) | |
tree | ce325c4f8af4fb2ddfd7dead3500cd52ecfcbd17 /cffi/model.py | |
parent | ec65919e86fd2a81a2735727033902fdf29f8ed4 (diff) | |
download | cffi-52c1a75736ca235a91122f732eae710e12aef7e8.tar.gz |
Starting, with exactly two function types: no-abi (i.e. cdecl on windows), or stdcall.
Diffstat (limited to 'cffi/model.py')
-rw-r--r-- | cffi/model.py | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/cffi/model.py b/cffi/model.py index 6eb6f5a..2ecfbfd 100644 --- a/cffi/model.py +++ b/cffi/model.py @@ -193,18 +193,21 @@ class UnknownFloatType(BasePrimitiveType): class BaseFunctionType(BaseType): - _attrs_ = ('args', 'result', 'ellipsis') + _attrs_ = ('args', 'result', 'ellipsis', 'abi') - def __init__(self, args, result, ellipsis): + def __init__(self, args, result, ellipsis, abi=None): self.args = args self.result = result self.ellipsis = ellipsis + self.abi = abi # reprargs = [arg._get_c_name() for arg in self.args] if self.ellipsis: reprargs.append('...') reprargs = reprargs or ['void'] replace_with = self._base_pattern % (', '.join(reprargs),) + if abi is not None: + replace_with = replace_with[:1] + abi + ' ' + replace_with[1:] self.c_name_with_marker = ( self.result.c_name_with_marker.replace('&', replace_with)) @@ -222,7 +225,7 @@ class RawFunctionType(BaseFunctionType): "type, not a pointer-to-function type" % (self,)) def as_function_pointer(self): - return FunctionPtrType(self.args, self.result, self.ellipsis) + return FunctionPtrType(self.args, self.result, self.ellipsis, self.abi) class FunctionPtrType(BaseFunctionType): @@ -233,11 +236,25 @@ class FunctionPtrType(BaseFunctionType): args = [] for tp in self.args: args.append(tp.get_cached_btype(ffi, finishlist)) + if self.abi is None: + abi_args = () + elif self.abi == "stdcall": + try: + abi_args = (ffi._backend.FFI_STDCALL,) + except AttributeError: + if sys.platform == "win32": + raise NotImplementedError("%r: stdcall with ctypes backend") + else: + from . import api + raise api.CDefError("%r: '__stdcall' only for Windows") + import pdb;pdb.set_trace() + else: + raise NotImplementedError("abi=%r" % (self.abi,)) return global_cache(self, ffi, 'new_function_type', - tuple(args), result, self.ellipsis) + tuple(args), result, self.ellipsis, *abi_args) def as_raw_function(self): - return RawFunctionType(self.args, self.result, self.ellipsis) + return RawFunctionType(self.args, self.result, self.ellipsis, self.abi) class PointerType(BaseType): |