This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Support libffi implementations that cannot support invocations with 1024 arguments
Type: behavior Stage: patch review
Components: ctypes, Tests Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, christian.heimes, hoodchatham, meador.inge
Priority: normal Keywords: patch

Created on 2022-04-04 00:27 by hoodchatham, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 32297 merged christian.heimes, 2022-04-04 06:59
Messages (4)
msg416646 - (view) Author: Hood Chatham (hoodchatham) * Date: 2022-04-04 00:27
ctypes defines `CTYPES_MAX_ARGCOUNT` to be 1024:
https://github.com/python/cpython/blob/6db2db91b96aaa1270c200ec931a2250fe2799c7/Modules/_ctypes/ctypes.h#L21

If a function call is attempted with more than 1024 arguments, it will fail. The libffi emscripten port github.com/hoodmane/libffi-emscripten can only support function calls with at most 122 arguments due to limitations in Emscripten / Wasm:
https://github.com/emscripten-core/emscripten/pull/16653

I propose to allow the libffi port to define FFI_MAX_CLOSURE_ARGS and if this is defined then use this number instead for `CTYPES_MAX_ARGCOUNT`.
https://github.com/libffi/libffi/issues/703

The test `test_callback_too_many_args` should also be updated to respect the value of `CTYPES_MAX_ARGCOUNT` rather than hardcoding 1024 into the test.
msg416677 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-04-04 17:13
New changeset d1b1c885d8f276a0b1ff2e327270916396a8b842 by Christian Heimes in branch 'main':
bpo-47208: Allow vendors to override CTYPES_MAX_ARGCOUNT (GH-32297)
https://github.com/python/cpython/commit/d1b1c885d8f276a0b1ff2e327270916396a8b842
msg416678 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-04-04 17:15
GH-32297 adds #ifndef CTYPES_MAX_ARGCOUNT and exposes the constant in the _ctypes extension module, so the test case can use the constant. It allows you to override CTYPES_MAX_ARGCOUNT until libffi upstream agrees on FFI_MAX_CLOSURE_ARGS.
msg416692 - (view) Author: Hood Chatham (hoodchatham) * Date: 2022-04-04 19:07
Ideally the library should be able to define a different macro, e.g., CTYPES_CUSTOM_MAX_ARGCOUNT. This way the libffi port can define CTYPES_CUSTOM_MAX_ARGCOUNT and it will be compatible with older Python versions without causing Warning: "CTYPES_MAX_ARGCOUNT redefined`.
History
Date User Action Args
2022-04-11 14:59:58adminsetgithub: 91364
2022-04-04 19:07:48hoodchathamsetmessages: + msg416692
2022-04-04 17:15:36christian.heimessettype: behavior
components: + Tests
versions: + Python 3.11
2022-04-04 17:15:19christian.heimessetmessages: + msg416678
2022-04-04 17:13:50christian.heimessetmessages: + msg416677
2022-04-04 06:59:50christian.heimessetkeywords: + patch
stage: patch review
pull_requests: + pull_request30356
2022-04-04 00:28:20hoodchathamsetnosy: + amaury.forgeotdarc, belopolsky, christian.heimes, meador.inge
2022-04-04 00:27:44hoodchathamcreate