Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions Lib/ctypes/test/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ctypes import *
from ctypes.test import need_symbol
from _ctypes import CTYPES_MAX_ARGCOUNT
import _ctypes_test

class Callbacks(unittest.TestCase):
Expand Down Expand Up @@ -293,8 +294,6 @@ def test_callback_too_many_args(self):
def func(*args):
return len(args)

CTYPES_MAX_ARGCOUNT = 1024

# valid call with nargs <= CTYPES_MAX_ARGCOUNT
proto = CFUNCTYPE(c_int, *(c_int,) * CTYPES_MAX_ARGCOUNT)
cb = proto(func)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow vendors to override :const:`CTYPES_MAX_ARGCOUNT`.
1 change: 1 addition & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5781,6 +5781,7 @@ _ctypes_add_objects(PyObject *mod)
#endif
MOD_ADD("RTLD_LOCAL", PyLong_FromLong(RTLD_LOCAL));
MOD_ADD("RTLD_GLOBAL", PyLong_FromLong(RTLD_GLOBAL));
MOD_ADD("CTYPES_MAX_ARGCOUNT", PyLong_FromLong(CTYPES_MAX_ARGCOUNT));
MOD_ADD("ArgumentError", Py_NewRef(PyExc_ArgError));
return 0;
#undef MOD_ADD
Expand Down
4 changes: 3 additions & 1 deletion Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
* This limit is enforced for the `alloca()` call in `_ctypes_callproc`,
* to avoid allocating a massive buffer on the stack.
*/
#define CTYPES_MAX_ARGCOUNT 1024
#ifndef CTYPES_MAX_ARGCOUNT
#define CTYPES_MAX_ARGCOUNT 1024
#endif

typedef struct tagPyCArgObject PyCArgObject;
typedef struct tagCDataObject CDataObject;
Expand Down