]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-47208: Allow vendors to override CTYPES_MAX_ARGCOUNT (GH-32297)
authorChristian Heimes <christian@python.org>
Mon, 4 Apr 2022 17:13:42 +0000 (20:13 +0300)
committerGitHub <noreply@github.com>
Mon, 4 Apr 2022 17:13:42 +0000 (19:13 +0200)
Lib/ctypes/test/test_callbacks.py
Misc/NEWS.d/next/Library/2022-04-04-08-54-31.bpo-47208.cOh9xZ.rst [new file with mode: 0644]
Modules/_ctypes/_ctypes.c
Modules/_ctypes/ctypes.h

index 5561ffefe12f7522ca0141eb191018b088cfc9ed..1099cf9a69c6b1a9f8a73f4bd9ccebcdbb140c07 100644 (file)
@@ -4,6 +4,7 @@ from test import support
 
 from ctypes import *
 from ctypes.test import need_symbol
+from _ctypes import CTYPES_MAX_ARGCOUNT
 import _ctypes_test
 
 class Callbacks(unittest.TestCase):
@@ -293,8 +294,6 @@ class SampleCallbacksTestCase(unittest.TestCase):
         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)
diff --git a/Misc/NEWS.d/next/Library/2022-04-04-08-54-31.bpo-47208.cOh9xZ.rst b/Misc/NEWS.d/next/Library/2022-04-04-08-54-31.bpo-47208.cOh9xZ.rst
new file mode 100644 (file)
index 0000000..a5da321
--- /dev/null
@@ -0,0 +1 @@
+Allow vendors to override :const:`CTYPES_MAX_ARGCOUNT`.
index 9177225f3f92904c27ee5c9714fb184250f7403f..0415923694129297a106ef32e2b303f02460e81d 100644 (file)
@@ -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
index 0badb48b2a410b1ce79713b134c3d553bf3b017a..da1941caf3927d92c42ceb28ad1d228d4b7c3c16 100644 (file)
@@ -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;