8000 MAINT: Just use fixed-sized array as MSVC doesn't like alloca · numpy/numpy@70a8f83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70a8f83

Browse files
committed
MAINT: Just use fixed-sized array as MSVC doesn't like alloca
1 parent 6b6b791 commit 70a8f83

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

numpy/core/src/multiarray/methods.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ npy_forward_method(
7171
PyObject *callable, PyObject *self,
7272
PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
7373
{
74-
PyObject **new_args;
74+
PyObject *args_buffer[NPY_MAXARGS];
75+
/* Practically guaranteed NPY_MAXARGS is enough. */
76+
PyObject **new_args = args_buffer;
7577

7678
/*
77-
* Unfortunately, `PY_VECTORCALL_ARGUMENTS_OFFSET` seems currently never
78-
* set for methods at this time, so not implementing just modifying
79-
* args[-1] here.
79+
* `PY_VECTORCALL_ARGUMENTS_OFFSET` seems never set, probably `args[-1]`
80+
* is always `self` but do not rely on it unless Python documents that.
8081
*/
8182
npy_intp len_kwargs = kwnames != NULL ? PyTuple_GET_SIZE(kwnames) : 0;
8283
size_t original_arg_size = (len_args + len_kwargs) * sizeof(PyObject *);
@@ -92,10 +93,6 @@ npy_forward_method(
9293
return PyErr_NoMemory();
9394
}
9495
}
95-
else {
96-
/* Almost guaranteed a stack allocation is enough. */
97-
new_args = alloca(original_arg_size + sizeof(PyObject *));
98-
}
9996

10097
new_args[0] = self;
10198
memcpy(&new_args[1], args, original_arg_size);

0 commit comments

Comments
 (0)
0