Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r1284:541a90941078 Date: 2013-07-18 20:57 +0200 http://bitbucket.org/cffi/cffi/changeset/541a90941078/
Log: Attempt to get rid of USE_C_LIBFFI_MSVC by really fixing libffi_msvc. diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -3885,19 +3885,6 @@ } assert(cf == NULL); -#ifdef USE_C_LIBFFI_MSVC - /* MSVC returns small structures in registers. Pretend int32 or - int64 return type. This is needed as a workaround for what - is really a bug of libffi_msvc seen as an independent library - (ctypes has a similar workaround). */ - if (is_result_type) { - if (ct->ct_size <= 4) - return &ffi_type_sint32; - if (ct->ct_size <= 8) - return &ffi_type_sint64; - } -#endif - /* next, allocate and fill the flattened list */ elements = fb_alloc(fb, (nflat + 1) * sizeof(ffi_type*)); nflat = 0; diff --git a/c/libffi_msvc/ffi.c b/c/libffi_msvc/ffi.c --- a/c/libffi_msvc/ffi.c +++ b/c/libffi_msvc/ffi.c @@ -46,7 +46,7 @@ register ffi_type **p_arg; argp = stack; - if (ecif->cif->rtype->type == FFI_TYPE_STRUCT) + if (ecif->cif->flags == FFI_TYPE_STRUCT) { *(void **) argp = ecif->rvalue; argp += sizeof(void *); @@ -124,7 +124,6 @@ switch (cif->rtype->type) { case FFI_TYPE_VOID: - case FFI_TYPE_STRUCT: case FFI_TYPE_SINT64: case FFI_TYPE_FLOAT: case FFI_TYPE_DOUBLE: @@ -132,6 +131,18 @@ cif->flags = (unsigned) cif->rtype->type; break; + case FFI_TYPE_STRUCT: + /* MSVC returns small structures in registers. Put in cif->flags + the value FFI_TYPE_STRUCT only if the structure is big enough; + otherwise, put the 4- or 8-bytes integer type. */ + if (cif->rtype->size <= 4) + cif->flags = FFI_TYPE_INT; + else if (cif->rtype->size <= 8) + cif->flags = FFI_TYPE_SINT64; + else + cif->flags = FFI_TYPE_STRUCT; + break; + case FFI_TYPE_UINT64: #ifdef _WIN64 case FFI_TYPE_POINTER: @@ -180,7 +191,7 @@ /* value address then we need to make one */ if ((rvalue == NULL) && - (cif->rtype->type == FFI_TYPE_STRUCT)) + (cif->flags == FFI_TYPE_STRUCT)) { /*@-sysunrecog@*/ ecif.rvalue = alloca(cif->rtype->size); @@ -338,7 +349,7 @@ argp = stack; - if ( cif->rtype->type == FFI_TYPE_STRUCT ) { + if ( cif->flags == FFI_TYPE_STRUCT ) { *rvalue = *(void **) argp; argp += 4; } diff --git a/c/libffi_msvc/prep_cif.c b/c/libffi_msvc/prep_cif.c --- a/c/libffi_msvc/prep_cif.c +++ b/c/libffi_msvc/prep_cif.c @@ -116,9 +116,9 @@ #if !defined M68K && !defined __x86_64__ && !defined S390 /* Make space for the return structure pointer */ if (cif->rtype->type == FFI_TYPE_STRUCT - /* MSVC returns small structures in registers. But we have a different - workaround: pretend int32 or int64 return type, and converting to - structure afterwards. */ +#ifdef _WIN32 + && (cif->rtype->size > 8) /* MSVC returns small structs in registers */ +#endif #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) #endif diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -72,7 +72,6 @@ extra_link_args.append(os.path.join(COMPILE_LIBFFI, 'win64.obj')) sources.extend(os.path.join(COMPILE_LIBFFI, filename) for filename in _filenames) - define_macros.append(('USE_C_LIBFFI_MSVC', '1')) else: use_pkg_config() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit