Skip to content

gh-84461: Fix ctypes and test_ctypes on Emscripten #94142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-84461: Fix ctypes and test_ctypes on Emscripten
- c_longlong and c_longdouble need experimental WASM bigint.
- Skip tests that need threading
- Define ``CTYPES_MAX_ARGCOUNT`` for Emscripten. According to tests 122
  args is the maximum value.
  • Loading branch information
tiran committed Jun 24, 2022
commit 6914430d2641c2cf45c0d834c8d193c01b1d8e81
2 changes: 2 additions & 0 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
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']

Expand Down Expand Up @@ -723,6 +724,7 @@ def test_get_set(self):
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.
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_ctypes/test_as_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def callback(value):
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
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_ctypes/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ def test_long(self):
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)

Expand All @@ -82,6 +84,7 @@ def test_double(self):
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)
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_ctypes/test_cfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,28 @@ def test_ulong_plus(self):
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)
Expand Down Expand Up @@ -159,12 +163,14 @@ def test_double_plus(self):
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)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_ctypes/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_doubleresult(self):
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]
Expand Down
6 changes: 5 additions & 1 deletion Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
* to avoid allocating a massive buffer on the stack.
*/
#ifndef CTYPES_MAX_ARGCOUNT
#define CTYPES_MAX_ARGCOUNT 1024
#ifdef __EMSCRIPTEN__
#define CTYPES_MAX_ARGCOUNT 122
#else
#define CTYPES_MAX_ARGCOUNT 1024
#endif
#endif

typedef struct tagPyCArgObject PyCArgObject;
Expand Down
2 changes: 2 additions & 0 deletions Tools/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy