8000 gh-127065: Make methodcaller thread-safe and re-entrant by eendebakpt · Pull Request #127245 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-127065: Make methodcaller thread-safe and re-entrant #127245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make methodcalled thread-safe
  • Loading branch information
eendebakpt committed Nov 23, 2024
commit 223d650804eae20c9a3969b24a67983c8963839d
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyMem_Free is after the return statement

}
#endif

Expand Down
0