Python 2.7.x fixes for new gil_scoped_release

This commit is contained in:
Wenzel Jakob 2016-04-25 09:16:41 +02:00
parent 084ca0e553
commit 2f6662e174

View File

@ -1122,15 +1122,26 @@ class gil_scoped_release {
public: public:
gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { gil_scoped_release(bool disassoc = false) : disassoc(disassoc) {
tstate = PyEval_SaveThread(); tstate = PyEval_SaveThread();
if (disassoc) if (disassoc) {
PyThread_set_key_value(detail::get_internals().tstate, nullptr); int key = detail::get_internals().tstate;
#if PY_MAJOR_VERSION < 3
PyThread_delete_key_value(key);
#else
PyThread_set_key_value(key, nullptr);
#endif
}
} }
~gil_scoped_release() { ~gil_scoped_release() {
if (!tstate) if (!tstate)
return; return;
PyEval_RestoreThread(tstate); PyEval_RestoreThread(tstate);
if (disassoc) if (disassoc) {
PyThread_set_key_value(detail::get_internals().tstate, tstate); int key = detail::get_internals().tstate;
#if PY_MAJOR_VERSION < 3
PyThread_delete_key_value(key);
#endif
PyThread_set_key_value(key, tstate);
}
} }
private: private:
PyThreadState *tstate; PyThreadState *tstate;