Skip to content

Commit cf6b79b

Browse files
committed
fix memory error
1 parent 4ce1233 commit cf6b79b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/_operator.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,7 @@ static PyObject *
16481648
methodcaller_vectorcall(
16491649
methodcallerobject *mc, PyObject *const *args, size_t nargsf, PyObject* kwnames)
16501650
{
1651-
Py_ssize_t number_of_arguments = PyVectorcall_NARGS(nargsf);
1652-
1653-
if (!_PyArg_CheckPositional("methodcaller", number_of_arguments, 1, 1)
1651+
if (!_PyArg_CheckPositional("methodcaller", PyVectorcall_NARGS(nargsf), 1, 1)
16541652
|| !_PyArg_NoKwnames("methodcaller", kwnames)) {
16551653
return NULL;
16561654
}
@@ -1661,7 +1659,12 @@ methodcaller_vectorcall(
16611659
}
16621660

16631661
assert(mc->vectorcall_args != 0);
1662+
1663+
Py_ssize_t number_of_arguments = PyTuple_GET_SIZE(mc->xargs) +
1664+
(mc->vectorcall_kwnames? PyTuple_GET_SIZE(mc->vectorcall_kwnames):0) + 1;
16641665
size_t buffer_size = sizeof(PyObject *) * (number_of_arguments + 1);
1666+
1667+
// for number_of_arguments == 1 we could optimize by setting tmp_args equal to &args
16651668
PyObject **tmp_args = (PyObject **) PyMem_Malloc(buffer_size);
16661669
if (tmp_args == NULL) {
16671670
PyErr_NoMemory();

0 commit comments

Comments
 (0)