|
14 | 14 |
|
15 | 15 | #include <stdbool.h> |
16 | 16 |
|
| 17 | +#ifdef MS_WIN32 |
| 18 | +# include <malloc.h> |
| 19 | +#endif |
| 20 | + |
17 | 21 | #include <ffi.h> |
18 | 22 | #include "ctypes.h" |
19 | 23 |
|
| 24 | +#ifdef HAVE_ALLOCA_H |
| 25 | +/* AIX needs alloca.h for alloca() */ |
| 26 | +#include <alloca.h> |
| 27 | +#endif |
| 28 | + |
20 | 29 | /**************************************************************/ |
21 | 30 |
|
22 | 31 | static void |
@@ -148,32 +157,17 @@ static void _CallPythonObject(void *mem, |
148 | 157 | void **pArgs) |
149 | 158 | { |
150 | 159 | PyObject *result = NULL; |
151 | | - PyObject **args = NULL; |
152 | 160 | Py_ssize_t i = 0, j = 0, nargs = 0; |
153 | 161 | PyObject *error_object = NULL; |
154 | 162 | int *space; |
155 | 163 | PyGILState_STATE state = PyGILState_Ensure(); |
156 | 164 |
|
157 | 165 | assert(PyTuple_Check(converters)); |
158 | 166 | nargs = PyTuple_GET_SIZE(converters); |
159 | | - /* Hm. What to return in case of error? |
160 | | - For COM, 0xFFFFFFFF seems better than 0. |
161 | | - */ |
162 | | - if (nargs < 0) { |
163 | | - PrintError("BUG: PySequence_Length"); |
164 | | - goto Done; |
165 | | - } |
166 | | - |
167 | | - PyObject *args_stack[CTYPES_MAX_ARGCOUNT]; |
168 | | - if (nargs <= CTYPES_MAX_ARGCOUNT) { |
169 | | - args = args_stack; |
170 | | - } |
171 | | - else { |
172 | | - args = PyMem_Malloc(nargs * sizeof(PyObject *)); |
173 | | - if (args == NULL) { |
174 | | - PyErr_NoMemory(); |
175 | | - goto Done; |
176 | | - } |
| 167 | + assert(nargs <= CTYPES_MAX_ARGCOUNT); |
| 168 | + PyObject **args = NULL; |
| 169 | + if (nargs > 0) { |
| 170 | + args = alloca(nargs * sizeof(PyObject *)); |
177 | 171 | } |
178 | 172 |
|
179 | 173 | PyObject **cnvs = PySequence_Fast_ITEMS(converters); |
@@ -310,9 +304,6 @@ static void _CallPythonObject(void *mem, |
310 | 304 | for (j = 0; j < i; j++) { |
311 | 305 | Py_DECREF(args[j]); |
312 | 306 | } |
313 | | - if (args != args_stack) { |
314 | | - PyMem_Free(args); |
315 | | - } |
316 | 307 | PyGILState_Release(state); |
317 | 308 | } |
318 | 309 |
|
|
0 commit comments