-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Add private _PyThreadState_UncheckedGet() to get the current thread state #70342
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
Comments
The issue bpo-25150 modified pystate.h to hide _PyThreadState_Current. Sadly, this change broke the vmprof project: Attached patches adds a new private _PyThreadState_FastGet() function to get the current thread state but don't call Py_FatalError() if it is NULL. The patch also uses replace direct access to _PyThreadState_Current with _PyThreadState_FastGet(), except inside ceval.c and pystate.c. Calling Py_FatalError() to handle errors is not really a great API... Bad that's a different story, I don't want to break anything here. I want to add the private function to Python 3.5.2 because I consider that the removal of the _PyThreadState_Current symbol is a regression introduced in Python 3.5.1. We have no rule for the Python private API, it can change *anytime*. |
Name should be _PyThreadState_UncheckedGet |
Overall +1 to this private API. I like the UncheckedGet name better than FastGet but don't really care what the name is so long as it keeps this property: It must be non-blocking and safe to call from a signal handler. Returning NULL in the event the value could not be obtained in such a manner is fine (unlikely to happen from the looks of the 3.5 code). They are private and this fixes the regression in 3.5.1. people (ab)using these private APIs should be fine writing conditional compilation code to deal with that. We've got a similar patch on our CPython 2.7 interpreter at work (more complicated as it must do a non-blocking lock acquire in the old 2.7 code). |
New changeset f9461f1e0559 by Victor Stinner in branch '3.5': New changeset d4f13c9a2b07 by Victor Stinner in branch 'default': |
Function added @fijal: Sorry for the annoyance of the Python 3.5.1 regression. |
I've also run into this regression. FWIW this is what I've ended up using to work around it (it's a mess, but what are we to do..) #if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200
extern "C" {
/* Manually import _PyThreadState_Current symbol */
struct _Py_atomic_address { void *value; };
PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
};
#endif
PyThreadState *get_thread_state_unchecked() {
#if PY_VERSION_HEX < 0x03000000
return _PyThreadState_Current;
#elif PY_VERSION_HEX < 0x03050000
return (PyThreadState*) _Py_atomic_load_relaxed(&_PyThreadState_Current);
#elif PY_VERSION_HEX < 0x03050200
return (PyThreadState*) _PyThreadState_Current.value;
#else
return _PyThreadState_UncheckedGet();
#endif
} |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: