Skip to content

Commit

Permalink
Make methodcalled thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Nov 23, 2024
1 parent e3038e9 commit 223d650
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,9 @@ static PyObject *
methodcaller_vectorcall(
methodcallerobject *mc, PyObject *const *args, size_t nargsf, PyObject* kwnames)
{
if (!_PyArg_CheckPositional("methodcaller", PyVectorcall_NARGS(nargsf), 1, 1)
Py_ssize_t number_of_arguments = PyVectorcall_NARGS(nargsf);

if (!_PyArg_CheckPositional("methodcaller", number_of_arguments, 1, 1)
|| !_PyArg_NoKwnames("methodcaller", kwnames)) {
return NULL;
}
Expand All @@ -1659,11 +1661,16 @@ methodcaller_vectorcall(
}

assert(mc->vectorcall_args != 0);
mc->vectorcall_args[0] = args[0];
number_of_arguments++;
PyObject **tmp_args = (PyObject **) PyMem_Malloc(number_of_arguments * sizeof(PyObject *));
memcpy(tmp_args, mc->vectorcall_args, sizeof(PyObject *) * number_of_arguments );
tmp_args[0] = args[0];
return PyObject_VectorcallMethod(
mc->name, mc->vectorcall_args,
mc->name, tmp_args,
(PyTuple_GET_SIZE(mc->xargs)) | PY_VECTORCALL_ARGUMENTS_OFFSET,
mc->vectorcall_kwnames);

PyMem_Free(tmp_args);
}
#endif

Expand Down

0 comments on commit 223d650

Please sign in to comment.