Skip to content

Commit d1b1c88

Browse files
authored
bpo-47208: Allow vendors to override CTYPES_MAX_ARGCOUNT (GH-32297)
1 parent 1ecfe3d commit d1b1c88

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

Lib/ctypes/test/test_callbacks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from ctypes import *
66
from ctypes.test import need_symbol
7+
from _ctypes import CTYPES_MAX_ARGCOUNT
78
import _ctypes_test
89

910
class Callbacks(unittest.TestCase):
@@ -293,8 +294,6 @@ def test_callback_too_many_args(self):
293294
def func(*args):
294295
return len(args)
295296

296-
CTYPES_MAX_ARGCOUNT = 1024
297-
298297
# valid call with nargs <= CTYPES_MAX_ARGCOUNT
299298
proto = CFUNCTYPE(c_int, *(c_int,) * CTYPES_MAX_ARGCOUNT)
300299
cb = proto(func)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow vendors to override :const:`CTYPES_MAX_ARGCOUNT`.

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,6 +5781,7 @@ _ctypes_add_objects(PyObject *mod)
57815781
#endif
57825782
MOD_ADD("RTLD_LOCAL", PyLong_FromLong(RTLD_LOCAL));
57835783
MOD_ADD("RTLD_GLOBAL", PyLong_FromLong(RTLD_GLOBAL));
5784+
MOD_ADD("CTYPES_MAX_ARGCOUNT", PyLong_FromLong(CTYPES_MAX_ARGCOUNT));
57845785
MOD_ADD("ArgumentError", Py_NewRef(PyExc_ArgError));
57855786
return 0;
57865787
#undef MOD_ADD

Modules/_ctypes/ctypes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
* This limit is enforced for the `alloca()` call in `_ctypes_callproc`,
1919
* to avoid allocating a massive buffer on the stack.
2020
*/
21-
#define CTYPES_MAX_ARGCOUNT 1024
21+
#ifndef CTYPES_MAX_ARGCOUNT
22+
#define CTYPES_MAX_ARGCOUNT 1024
23+
#endif
2224

2325
typedef struct tagPyCArgObject PyCArgObject;
2426
typedef struct tagCDataObject CDataObject;

0 commit comments

Comments
 (0)