Bug 615473 - Make ctypes.stdcall_abi and ctypes.winapi_abi aliases to the sole ABI on Win64. r=dwitte

This commit is contained in:
Siddharth Agarwal 2011-08-11 01:02:49 +05:30
parent 6f0dedec70
commit 7147e45572
4 changed files with 22 additions and 18 deletions

View File

@ -4548,6 +4548,11 @@ GetABI(JSContext* cx, jsval abiType, ffi_abi* result)
#if (defined(_WIN32) && !defined(_WIN64)) || defined(_OS2)
*result = FFI_STDCALL;
return true;
#elif (defined(_WIN64))
// We'd like the same code to work across Win32 and Win64, so stdcall_api
// and winapi_abi become aliases to the lone Win64 ABI.
*result = FFI_WIN64;
return true;
#endif
case INVALID_ABI:
break;
@ -4692,6 +4697,7 @@ FunctionType::BuildSymbolName(JSContext* cx,
break;
case ABI_STDCALL: {
#if (defined(_WIN32) && !defined(_WIN64)) || defined(_OS2)
// On WIN32, stdcall functions look like:
// _foo@40
// where 'foo' is the function name, and '40' is the aligned size of the
@ -4708,6 +4714,11 @@ FunctionType::BuildSymbolName(JSContext* cx,
}
IntegerToString(size, 10, result);
#elif defined(_WIN64)
// On Win64, stdcall is an alias to the default ABI for compatibility, so no
// mangling is done.
AppendString(result, name);
#endif
break;
}

View File

@ -120,7 +120,7 @@ sum_many_##name##_##suffix( \
#include "typedefs.h"
#undef ABI
#if defined(_WIN32) && !defined(_WIN64)
#if defined(_WIN32)
void NS_STDCALL
test_void_t_stdcall()
@ -134,7 +134,7 @@ test_void_t_stdcall()
#include "typedefs.h"
#undef ABI
#endif /* defined(_WIN32) && !defined(_WIN64) */
#endif /* defined(_WIN32) */
#define DEFINE_TYPE(name, type, ffiType) \
struct align_##name { \
@ -321,13 +321,13 @@ test_closure_cdecl(PRInt8 i, test_func_ptr f)
return f(i);
}
#if defined(_WIN32) && !defined(_WIN64)
#if defined(_WIN32)
PRInt32
test_closure_stdcall(PRInt8 i, test_func_ptr_stdcall f)
{
return f(i);
}
#endif /* defined(_WIN32) && !defined(_WIN64) */
#endif /* defined(_WIN32) */
template <typename T> struct PromotedTraits {
typedef T type;

View File

@ -69,7 +69,7 @@ NS_EXTERN_C
#include "typedefs.h"
#if defined(_WIN32) && !defined(_WIN64)
#if defined(_WIN32)
EXPORT_STDCALL(void) test_void_t_stdcall();
EXPORT_STDCALL(void*) get_voidptr_t_stdcall();
@ -89,7 +89,7 @@ NS_EXTERN_C
#include "typedefs.h"
#endif /* defined(_WIN32) && !defined(_WIN64) */
#endif /* defined(_WIN32) */
NS_EXPORT PRInt32 test_ansi_len(const char*);
NS_EXPORT PRInt32 test_wide_len(const PRUnichar*);
@ -190,10 +190,10 @@ NS_EXTERN_C
typedef PRInt32 (* test_func_ptr)(PRInt8);
NS_EXPORT PRInt32 test_closure_cdecl(PRInt8, test_func_ptr);
#if defined(_WIN32) && !defined(_WIN64)
#if defined(_WIN32)
typedef PRInt32 (NS_STDCALL * test_func_ptr_stdcall)(PRInt8);
NS_EXPORT PRInt32 test_closure_stdcall(PRInt8, test_func_ptr_stdcall);
#endif /* defined(_WIN32) && !defined(_WIN64) */
#endif /* defined(_WIN32) */
NS_EXPORT PRInt32 test_callme(PRInt8);
NS_EXPORT void* test_getfn();

View File

@ -681,7 +681,6 @@ function run_basic_abi_tests(library, t, name, toprimitive,
toprimitive, get_test, set_tests, sum_tests, sum_many_tests);
#ifdef WIN32
#ifndef HAVE_64BIT_OS
function declare_fn_stdcall(fn_t, prefix) {
return library.declare(prefix + name + "_stdcall", fn_t);
}
@ -696,7 +695,6 @@ function run_basic_abi_tests(library, t, name, toprimitive,
ctypes.char.ptr);
let hello = ctypes.char.array()("hello!");
do_check_eq(charupper(hello).readString(), "HELLO!");
#endif
#endif
// Check the alignment of the type, and its behavior in a struct,
@ -1877,14 +1875,12 @@ function run_FunctionType_tests() {
do_check_eq(f3_t.name, "char*(*(**[][8])())[]");
#ifdef WIN32
#ifndef HAVE_64BIT_OS
f3_t = ctypes.FunctionType(ctypes.stdcall_abi,
ctypes.char.ptr.array().ptr).ptr.ptr.array(8).array();
do_check_eq(f3_t.name, "char*(*(__stdcall **[][8])())[]");
f3_t = ctypes.FunctionType(ctypes.winapi_abi,
ctypes.char.ptr.array().ptr).ptr.ptr.array(8).array();
do_check_eq(f3_t.name, "char*(*(WINAPI **[][8])())[]");
#endif
#endif
let f4_t = ctypes.FunctionType(ctypes.default_abi,
@ -2090,11 +2086,12 @@ function run_void_tests(library) {
}, Error);
#ifdef WIN32
#ifndef HAVE_64BIT_OS
test_void_t = library.declare("test_void_t_stdcall", ctypes.stdcall_abi, ctypes.void_t);
do_check_eq(test_void_t(), undefined);
// Check that WINAPI symbol lookup for a regular stdcall function fails.
// Check that WINAPI symbol lookup for a regular stdcall function fails on
// Win32 (it's all the same on Win64 though).
#ifndef HAVE_64BIT_OS
do_check_throws(function() {
let test_winapi_t = library.declare("test_void_t_stdcall", ctypes.winapi_abi, ctypes.void_t);
}, Error);
@ -2253,7 +2250,6 @@ function run_closure_tests(library)
{
run_single_closure_tests(library, ctypes.default_abi, "cdecl");
#ifdef WIN32
#ifndef HAVE_64BIT_OS
run_single_closure_tests(library, ctypes.stdcall_abi, "stdcall");
// Check that attempting to construct a ctypes.winapi_abi closure throws.
@ -2264,7 +2260,6 @@ function run_closure_tests(library)
let fn_t = ctypes.FunctionType(ctypes.winapi_abi, ctypes.int32_t, []).ptr;
do_check_throws(function() { fn_t(closure_fn) }, Error);
#endif
#endif
}
function run_single_closure_tests(library, abi, suffix)
@ -2324,7 +2319,6 @@ function run_variadic_tests(library) {
}, Error);
#ifdef WIN32
#ifndef HAVE_64BIT_OS
do_check_throws(function() {
ctypes.FunctionType(ctypes.stdcall_abi, ctypes.bool,
[ctypes.bool, "..."]);
@ -2333,7 +2327,6 @@ function run_variadic_tests(library) {
ctypes.FunctionType(ctypes.winapi_abi, ctypes.bool,
[ctypes.bool, "..."]);
}, Error);
#endif
#endif
do_check_throws(function() {