summaryrefslogtreecommitdiff
path: root/pyuno/source/module/pyuno_runtime.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno/source/module/pyuno_runtime.cxx')
-rw-r--r--pyuno/source/module/pyuno_runtime.cxx45
1 files changed, 40 insertions, 5 deletions
diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx
index 751c104dca04..4f115d44e5bc 100644
--- a/pyuno/source/module/pyuno_runtime.cxx
+++ b/pyuno/source/module/pyuno_runtime.cxx
@@ -74,7 +74,11 @@ static PyTypeObject RuntimeImpl_Type =
sizeof (RuntimeImpl),
0,
RuntimeImpl::del,
- nullptr,
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // Py_ssize_t tp_vectorcall_offset
+#else
+ nullptr, // printfunc tp_print
+#endif
nullptr,
nullptr,
nullptr,
@@ -118,6 +122,19 @@ static PyTypeObject RuntimeImpl_Type =
, 0
#if PY_VERSION_HEX >= 0x03040000
, nullptr
+#if PY_VERSION_HEX >= 0x03080000
+ , nullptr // vectorcallfunc tp_vectorcall
+#if PY_VERSION_HEX < 0x03090000
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ , nullptr // tp_print
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+#endif
+#endif
#endif
};
@@ -969,8 +986,16 @@ Any Runtime::extractUnoException( const PyRef & excType, const PyRef &excValue,
PyThreadAttach::PyThreadAttach( PyInterpreterState *interp)
+ : m_isNewState(false)
{
- tstate = PyThreadState_New( interp );
+ // note: *may* be called recursively, with PyThreadDetach between - in
+ // that case, don't create *new* PyThreadState but reuse!
+ tstate = PyGILState_GetThisThreadState(); // from TLS, possibly detached
+ if (!tstate)
+ {
+ m_isNewState = true;
+ tstate = PyThreadState_New( interp );
+ }
if( !tstate )
throw RuntimeException( "Couldn't create a pythreadstate" );
PyEval_AcquireThread( tstate);
@@ -978,9 +1003,19 @@ PyThreadAttach::PyThreadAttach( PyInterpreterState *interp)
PyThreadAttach::~PyThreadAttach()
{
- PyThreadState_Clear( tstate );
- PyEval_ReleaseThread( tstate );
- PyThreadState_Delete( tstate );
+ if (m_isNewState)
+ { // Clear needs GIL!
+ PyThreadState_Clear( tstate );
+ }
+ if (m_isNewState)
+ { // note: PyThreadState_Delete(tstate) cannot be called, it will assert
+ // because it requires a PyThreadState to be set, but not the tstate!
+ PyThreadState_DeleteCurrent();
+ }
+ else
+ {
+ PyEval_ReleaseThread( tstate );
+ }
}
PyThreadDetach::PyThreadDetach()