Bug 927535 - interrogate ctypes to find out about win32/win64 bits instead of preprocessor macros; r=bholley
authorNathan Froyd <froydnj@mozilla.com>
Wed, 16 Oct 2013 12:10:09 -0400
changeset 166655 921bdd41fbce644073290d8f482105001716ea41
parent 166654 09fcb0805831f8e131a9bed075c32f1822a2de29
child 166656 169b3659b6c3c79f7d015cee56ee85d657ce2fa3
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs927535
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 927535 - interrogate ctypes to find out about win32/win64 bits instead of preprocessor macros; r=bholley
toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
--- a/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
+++ b/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
@@ -621,32 +621,32 @@ function run_basic_abi_tests(library, t,
                              get_test, set_tests, sum_tests, sum_many_tests) {
   // Test the function call ABI for calls involving the type.
   function declare_fn_cdecl(fn_t, prefix) {
     return library.declare(prefix + name + "_cdecl", fn_t);
   }
   run_single_abi_tests(declare_fn_cdecl, ctypes.default_abi, t,
     toprimitive, get_test, set_tests, sum_tests, sum_many_tests);
 
-#ifdef WIN32
-  function declare_fn_stdcall(fn_t, prefix) {
-    return library.declare(prefix + name + "_stdcall", fn_t);
+  if ("winLastError" in ctypes) {
+    function declare_fn_stdcall(fn_t, prefix) {
+      return library.declare(prefix + name + "_stdcall", fn_t);
+    }
+    run_single_abi_tests(declare_fn_stdcall, ctypes.stdcall_abi, t,
+                         toprimitive, get_test, set_tests, sum_tests, sum_many_tests);
+
+    // Check that declaring a WINAPI function gets the right symbol name.
+    let libuser32 = ctypes.open("user32.dll");
+    let charupper = libuser32.declare("CharUpperA",
+                                      ctypes.winapi_abi,
+                                      ctypes.char.ptr,
+                                      ctypes.char.ptr);
+    let hello = ctypes.char.array()("hello!");
+    do_check_eq(charupper(hello).readString(), "HELLO!");
   }
-  run_single_abi_tests(declare_fn_stdcall, ctypes.stdcall_abi, t,
-    toprimitive, get_test, set_tests, sum_tests, sum_many_tests);
-
-  // Check that declaring a WINAPI function gets the right symbol name.
-  let libuser32 = ctypes.open("user32.dll");
-  let charupper = libuser32.declare("CharUpperA",
-                                    ctypes.winapi_abi,
-                                    ctypes.char.ptr,
-                                    ctypes.char.ptr);
-  let hello = ctypes.char.array()("hello!");
-  do_check_eq(charupper(hello).readString(), "HELLO!");
-#endif
 
   // Check the alignment of the type, and its behavior in a struct,
   // against what C says.
   check_struct_stats(library, t);
 
   // Check the ToSource functions defined in the namespace ABI
   do_check_eq(ctypes.default_abi.toSource(), "ctypes.default_abi");
 
@@ -1921,24 +1921,24 @@ function run_FunctionType_tests() {
   // Test some more complex names.
   do_check_eq(fp_t.array().name, "g_t(*[])()");
   do_check_eq(fp_t.array().ptr.name, "g_t(*(*)[])()");
 
   let f3_t = ctypes.FunctionType(ctypes.default_abi,
     ctypes.char.ptr.array().ptr).ptr.ptr.array(8).array();
   do_check_eq(f3_t.name, "char*(*(**[][8])())[]");
 
-#ifdef WIN32
-  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
+  if ("winLastError" in ctypes) {
+    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])())[]");
+  }
 
   let f4_t = ctypes.FunctionType(ctypes.default_abi,
     ctypes.char.ptr.array().ptr, [ ctypes.int32_t, fp_t ]);
   do_check_true(f4_t.argTypes.length == 2);
   do_check_true(f4_t.argTypes[0] === ctypes.int32_t);
   do_check_true(f4_t.argTypes[1] === fp_t);
 /* disabled temporarily per bug 598225.
   do_check_throws(function() { f4_t.argTypes.z = 0; }, Error);
@@ -2223,28 +2223,28 @@ function run_void_tests(library) {
   let test_void_t = library.declare("test_void_t_cdecl", ctypes.default_abi, ctypes.void_t);
   do_check_eq(test_void_t(), undefined);
 
   // Test that library.declare throws with void function args.
   do_check_throws(function() {
     library.declare("test_void_t_cdecl", ctypes.default_abi, ctypes.void_t, ctypes.void_t);
   }, Error);
 
-#ifdef WIN32
-  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 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);
-#endif
-#endif
+  if ("winLastError" in ctypes) {
+    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 on
+    // Win32 (it's all the same on Win64 though).
+    if (ctypes.voidptr_t.size == 8) {
+      do_check_throws(function() {
+        let test_winapi_t = library.declare("test_void_t_stdcall", ctypes.winapi_abi, ctypes.void_t);
+      }, Error);
+    }
+  }
 }
 
 function run_string_tests(library) {
   let test_ansi_len = library.declare("test_ansi_len", ctypes.default_abi, ctypes.int32_t, ctypes.char.ptr);
   do_check_eq(test_ansi_len(""), 0);
   do_check_eq(test_ansi_len("hello world"), 11);
 
   // don't convert anything else to a string
@@ -2557,27 +2557,27 @@ function run_function_tests(library)
   do_check_throws(function() { test_ansi_len_2.value = null; }, Error);
   do_check_eq(ptrValue(test_ansi_len_2), ptrValue(ptr));
 */
 }
 
 function run_closure_tests(library)
 {
   run_single_closure_tests(library, ctypes.default_abi, "cdecl");
-#ifdef WIN32
-  run_single_closure_tests(library, ctypes.stdcall_abi, "stdcall");
-
-  // Check that attempting to construct a ctypes.winapi_abi closure throws.
-  function closure_fn()
-  {
-    return 1;
+  if ("winLastError" in ctypes) {
+    run_single_closure_tests(library, ctypes.stdcall_abi, "stdcall");
+
+    // Check that attempting to construct a ctypes.winapi_abi closure throws.
+    function closure_fn()
+    {
+      return 1;
+    }
+    let fn_t = ctypes.FunctionType(ctypes.winapi_abi, ctypes.int32_t, []).ptr;
+    do_check_throws(function() { fn_t(closure_fn) }, Error);
   }
-  let fn_t = ctypes.FunctionType(ctypes.winapi_abi, ctypes.int32_t, []).ptr;
-  do_check_throws(function() { fn_t(closure_fn) }, Error);
-#endif
 }
 
 function run_single_closure_tests(library, abi, suffix)
 {
   let b = 23;
 
   function closure_fn(i)
   {
@@ -2669,26 +2669,26 @@ function run_variadic_tests(library) {
     ctypes.FunctionType(ctypes.default_abi, ctypes.bool,
                         [ctypes.bool, "...", ctypes.bool]);
   }, Error);
 
   do_check_throws(function() {
     ctypes.FunctionType(ctypes.default_abi, ctypes.bool, ["..."]);
   }, Error);
 
-#ifdef WIN32
-  do_check_throws(function() {
+  if ("winLastError" in ctypes) {
+    do_check_throws(function() {
       ctypes.FunctionType(ctypes.stdcall_abi, ctypes.bool,
                           [ctypes.bool, "..."]);
-  }, Error);
-  do_check_throws(function() {
+    }, Error);
+    do_check_throws(function() {
       ctypes.FunctionType(ctypes.winapi_abi, ctypes.bool,
                           [ctypes.bool, "..."]);
-  }, Error);
-#endif
+    }, Error);
+  }
 
   do_check_throws(function() {
     // No variadic closure callbacks allowed.
     sum_va_type(function(){});
   }, Error);
 
   let count_true_va = library.declare("test_sum_va_cdecl", ctypes.default_abi, ctypes.uint8_t,
                                       ctypes.uint8_t, "...");