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
Prev Previous commit
Next Next commit
enable ft
  • Loading branch information
< 8000 /include-fragment>
eendebakpt committed Nov 23, 2024
commit 4ce123381731cd7178fdd8eabd3e11440a24423e
15 changes: 3 additions & 12 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ typedef struct {
vectorcallfunc vectorcall;
} methodcallerobject;

#ifndef Py_GIL_DISABLED

static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
static int
_methodcaller_initialize_vectorcall(methodcallerobject *mc)

{
PyObject* args = mc->xargs;
Expand Down Expand Up @@ -1662,10 +1662,10 @@ methodcaller_vectorcall(

assert(mc->vectorcall_args != 0);
size_t buffer_size = sizeof(PyObject *) * (number_of_arguments + 1);
PyObject **tmp_args = (PyObject **) PyMem_Malloc buffer_size);
PyObject **tmp_args = (PyObject **) PyMem_Malloc(buffer_size);
if (tmp_args == NULL) {
PyErr_NoMemory();
return -1;
return NULL;
}
memcpy(tmp_args, mc->vectorcall_args, buffer_size);
tmp_args[0] = args[0];
Expand All @@ -1676,7 +1676,6 @@ methodcaller_vectorcall(

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


/* AC 3.5: variable number of arguments, not currently support by AC */
Expand Down Expand Up @@ -1715,15 +1714,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
mc->kwds = Py_XNewRef(kwds);
mc->vectorcall_args = 0;


#ifdef Py_GIL_DISABLED
// gh-127065: The current implementation of methodcaller_vectorcall
// is not thread-safe because it modifies the `vectorcall_args` array,
// which is shared across calls.
mc->vectorcall = NULL;
#else
mc->vectorcall = (vectorcallfunc)methodcaller_vectorcall;
#endif

PyObject_GC_Track(mc);
return (PyObject *)mc;
Expand Down
Loading
0