]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-84461: Fix ctypes and test_ctypes on Emscripten (#94142)
authorChristian Heimes <christian@python.org>
Fri, 24 Jun 2022 10:40:43 +0000 (12:40 +0200)
committerGitHub <noreply@github.com>
Fri, 24 Jun 2022 10:40:43 +0000 (12:40 +0200)
- c_longlong and c_longdouble need experimental WASM bigint.
- Skip tests that need threading
- Define ``CTYPES_MAX_ARGCOUNT`` for Emscripten. libffi-emscripten 2022-06-23 supports up to 1000 args.

Lib/test/test_code.py
Lib/test/test_ctypes/test_as_parameter.py
Lib/test/test_ctypes/test_callbacks.py
Lib/test/test_ctypes/test_cfuncs.py
Lib/test/test_ctypes/test_functions.py
Modules/_ctypes/ctypes.h
Tools/wasm/README.md
configure
configure.ac

index a6857dc4f841203a901c8894fcb85256fb475ec1..308141aaf10e557919bf79a0418319e1a66f6719 100644 (file)
@@ -141,6 +141,7 @@ from test.support import (cpython_only,
                           check_impl_detail, requires_debug_ranges,
                           gc_collect)
 from test.support.script_helper import assert_python_ok
+from test.support import threading_helper
 from opcode import opmap
 COPY_FREE_VARS = opmap['COPY_FREE_VARS']
 
@@ -723,6 +724,7 @@ if check_impl_detail(cpython=True) and ctypes is not None:
             self.assertEqual(extra.value, 300)
             del f
 
+        @threading_helper.requires_working_threading()
         def test_free_different_thread(self):
             # Freeing a code object on a different thread then
             # where the co_extra was set should be safe.
index b35defb15851a0d5440ab5111da63a3917afc44a..e9ec9ad847b487f440343e2f286fefb30f1ed17b 100644 (file)
@@ -122,6 +122,7 @@ class BasicWrapTestCase(unittest.TestCase):
         result = f(self.wrap(-10), self.wrap(cb))
         self.assertEqual(result, -18)
 
+    @need_symbol('c_longlong')
     def test_longlong_callbacks(self):
 
         f = dll._testfunc_callback_q_qf
index 2758720d4a9543406e02940a5fd65104ed10bee4..b5bef04e14d20857cad54c67535fd6973980ea86 100644 (file)
@@ -65,10 +65,12 @@ class Callbacks(unittest.TestCase):
     def test_ulong(self):
         self.check_type(c_ulong, 42)
 
+    @need_symbol('c_longlong')
     def test_longlong(self):
         self.check_type(c_longlong, 42)
         self.check_type(c_longlong, -42)
 
+    @need_symbol('c_ulonglong')
     def test_ulonglong(self):
         self.check_type(c_ulonglong, 42)
 
@@ -82,6 +84,7 @@ class Callbacks(unittest.TestCase):
         self.check_type(c_double, 3.14)
         self.check_type(c_double, -3.14)
 
+    @need_symbol('c_longdouble')
     def test_longdouble(self):
         self.check_type(c_longdouble, 3.14)
         self.check_type(c_longdouble, -3.14)
index 0a9394bf31359fec17ae28cd67b062596a238076..7cba4b0e527f4d9ad965f0b8540671f80d35f77a 100644 (file)
@@ -111,24 +111,28 @@ class CFunctions(unittest.TestCase):
         self.assertEqual(self._dll.tf_bL(b' ', 4294967295), 1431655765)
         self.assertEqual(self.U(), 4294967295)
 
+    @need_symbol('c_longlong')
     def test_longlong(self):
         self._dll.tf_q.restype = c_longlong
         self._dll.tf_q.argtypes = (c_longlong, )
         self.assertEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602)
         self.assertEqual(self.S(), -9223372036854775806)
 
+    @need_symbol('c_longlong')
     def test_longlong_plus(self):
         self._dll.tf_bq.restype = c_longlong
         self._dll.tf_bq.argtypes = (c_byte, c_longlong)
         self.assertEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602)
         self.assertEqual(self.S(), -9223372036854775806)
 
+    @need_symbol('c_ulonglong')
     def test_ulonglong(self):
         self._dll.tf_Q.restype = c_ulonglong
         self._dll.tf_Q.argtypes = (c_ulonglong, )
         self.assertEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205)
         self.assertEqual(self.U(), 18446744073709551615)
 
+    @need_symbol('c_ulonglong')
     def test_ulonglong_plus(self):
         self._dll.tf_bQ.restype = c_ulonglong
         self._dll.tf_bQ.argtypes = (c_byte, c_ulonglong)
@@ -159,12 +163,14 @@ class CFunctions(unittest.TestCase):
         self.assertEqual(self._dll.tf_bd(0, 42.), 14.)
         self.assertEqual(self.S(), 42)
 
+    @need_symbol('c_longdouble')
     def test_longdouble(self):
         self._dll.tf_D.restype = c_longdouble
         self._dll.tf_D.argtypes = (c_longdouble,)
         self.assertEqual(self._dll.tf_D(42.), 14.)
         self.assertEqual(self.S(), 42)
 
+    @need_symbol('c_longdouble')
     def test_longdouble_plus(self):
         self._dll.tf_bD.restype = c_longdouble
         self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
index 4a784c8d7989493bd2474b21c57ca9d0c98b89df..a3db0033533fbbfed117f936ba30097e8f1a1ecc 100644 (file)
@@ -128,6 +128,7 @@ class FunctionTestCase(unittest.TestCase):
         self.assertEqual(result, -21)
         self.assertEqual(type(result), float)
 
+    @need_symbol('c_longdouble')
     def test_longdoubleresult(self):
         f = dll._testfunc_D_bhilfD
         f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
index da1941caf3927d92c42ceb28ad1d228d4b7c3c16..88eb9f59922a0498b42ca41092b4f2546034d60f 100644 (file)
  * to avoid allocating a massive buffer on the stack.
  */
 #ifndef CTYPES_MAX_ARGCOUNT
-  #define CTYPES_MAX_ARGCOUNT 1024
+  #ifdef __EMSCRIPTEN__
+    #define CTYPES_MAX_ARGCOUNT 1000
+  #else
+    #define CTYPES_MAX_ARGCOUNT 1024
+  #endif
 #endif
 
 typedef struct tagPyCArgObject PyCArgObject;
index 4a711a6eb56271adf9dd4e9b59ae0af009605fa6..94b3729a5daadb216b4a17d116e6a564ec644adb 100644 (file)
@@ -173,6 +173,8 @@ functions.
   [bpo-46390](https://bugs.python.org/issue46390).
 - Python's object allocator ``obmalloc`` is disabled by default.
 - ``ensurepip`` is not available.
+- Some ``ctypes`` features like ``c_longlong`` and ``c_longdouble`` may need
+   NodeJS option ``--experimental-wasm-bigint``.
 
 ## wasm32-emscripten in browsers
 
index c7bafb3b94969a3e1f58dad44102737bd0590f1a..34de0f7f1b66c5f3991a90bcf868ddab3a13d0eb 100755 (executable)
--- a/configure
+++ b/configure
@@ -6775,13 +6775,11 @@ then
   case $ac_sys_system/$ac_sys_emscripten_target in #(
   Emscripten/node*) :
 
+      # bigint for ctypes c_longlong, c_longdouble
+      HOSTRUNNER="node --experimental-wasm-bigint"
       if test "x$enable_wasm_pthreads" = xyes; then :
 
-        HOSTRUNNER='node --experimental-wasm-threads --experimental-wasm-bulk-memory'
-
-else
-
-        HOSTRUNNER='node'
+        HOSTRUNNER="$HOSTRUNNER --experimental-wasm-threads --experimental-wasm-bulk-memory"
 
 fi
      ;; #(
index 4f8e7e3cd468400d3150571dee35feecb1a05ffe..3b70532e4d0e1ac7fafc1c84ffba7a3a51cf279b 100644 (file)
@@ -1486,10 +1486,10 @@ if test -z "$HOSTRUNNER"
 then
   AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
     [Emscripten/node*], [
+      # bigint for ctypes c_longlong, c_longdouble
+      HOSTRUNNER="node --experimental-wasm-bigint"
       AS_VAR_IF([enable_wasm_pthreads], [yes], [
-        HOSTRUNNER='node --experimental-wasm-threads --experimental-wasm-bulk-memory'
-      ], [
-        HOSTRUNNER='node'
+        HOSTRUNNER="$HOSTRUNNER --experimental-wasm-threads --experimental-wasm-bulk-memory"
       ])
     ],
     dnl TODO: support other WASI runtimes