The issue #25150 modified pystate.h to hide _PyThreadState_Current. Sadly, this change broke the vmprof project: https://mail.python.org/pipermail/python-dev/2016-January/142767.html 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*.
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).
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 }
status: open -> closedresolution: fixedmessages: + title: Add private _PyThreadState_FastGet() to get the current thread state -> Add private _PyThreadState_UncheckedGet() to get the current thread state