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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
eendebakpt committed Nov 28, 2024
commit 6bd2c2e70fbca04ff4da856532e24a5ca973a6bb
15 changes: 3 additions & 12 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,6 @@ static PyObject *
methodcaller_vectorcall(
methodcallerobject *mc, PyObject *const *args, size_t nargsf, PyObject* kwnames)
{
//printf("methodcaller_vectorcall\n");
if (!_PyArg_CheckPositional("methodcaller", PyVectorcall_NARGS(nargsf), 1, 1)
|| !_PyArg_NoKwnames("methodcaller", kwnames)) {
return NULL;
Expand All @@ -1619,21 +1618,16 @@ methodcaller_vectorcall(
Py_ssize_t number_of_arguments = PyTuple_GET_SIZE(mc->args) +
(mc->vectorcall_kwnames? PyTuple_GET_SIZE(mc->vectorcall_kwnames):0);

//printf("methodcaller_vectorcall: number_of_arguments %ld\n", number_of_arguments);

PyObject *tmp_args[_METHODCALLER_MAX_ARGS];
tmp_args[0] = args[0];
tmp_args[1] = Py_None;
if (number_of_arguments) {
assert(1 + number_of_arguments <= _METHODCALLER_MAX_ARGS);
memcpy(tmp_args + 1, mc->vectorcall_args, sizeof(PyObject *) * number_of_arguments);
}
assert(1 + number_of_arguments <= _METHODCALLER_MAX_ARGS);
memcpy(tmp_args + 1, mc->vectorcall_args, sizeof(PyObject *) * number_of_arguments);

PyObject *result = PyObject_VectorcallMethod(
Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you, but I'd write this without the temporary result variable like:

return PyObject_VectorcallMethod(...);

mc->name, tmp_args,
(1 + PyTuple_GET_SIZE(mc->args)) | PY_VECTORCALL_ARGUMENTS_OFFSET,
mc->vectorcall_kwnames);

//printf("methodcaller_vectorcall done\n");
return result;
}

Expand All @@ -1643,8 +1637,6 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
PyObject* kwds = mc->kwds;

Py_ssize_t nargs = PyTuple_GET_SIZE(args);
// printf("_methodcaller_initialize_vectorcall: nargs %ld, vectorcall_args size \n", nargs, nargs + (kwds ? PyDict_Size(kwds) : 0));

mc->vectorcall_args = PyMem_Calloc(
nargs + (kwds ? PyDict_Size(kwds) : 0),
sizeof(PyObject*));
Expand Down Expand Up @@ -1712,7 +1704,6 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
_PyUnicode_InternMortal(interp, &name);
mc->name = name;

//printf("methodcaller_new: %ld \n", PyTuple_GET_SIZE(args));
mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
if (mc->args == NULL) {
Py_DECREF(mc);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy