Skip to content

gh-127065: Make methodcaller thread-safe and re-entrant (v2) #127746

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

Merged
merged 29 commits into from
Dec 11, 2024

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Dec 8, 2024

Py_VISIT(mc->kwds);
Py_VISIT(mc->vectorcall_args);
Py_VISIT(mc->vectorcall_kwnames);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note mc->vectorcall_kwnames is a tuple of strings, but the strings can be subclasses of str, so we need to visit this.

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

Looks good. A few small comments below

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this!

@colesbury colesbury merged commit b0f278f into python:main Dec 11, 2024
45 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
…GH-127746)

The function `operator.methodcaller` was not thread-safe since the additional
of the vectorcall method in pythongh-89013. In the free threading build the issue
is easy to trigger, for the normal build harder.

This makes the `methodcaller` safe by:

* Replacing the lazy initialization with initialization in the constructor.
* Using a stack allocated space for the vectorcall arguments and falling back
  to `tp_call` for calls with more than 8 arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants