mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
Add work-around to crash in ~object_base().
For the free-threaded build (and possibly the debug build), it is not safe to call Py_DECREF() if there is no valid Python thread-state.
This commit is contained in:
@@ -419,6 +419,16 @@ inline api::object_base& api::object_base::operator=(api::object_base const& rhs
|
||||
|
||||
inline api::object_base::~object_base()
|
||||
{
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// This is a not very elegant fix for a problem that occurs with the
|
||||
// free-threaded build of Python. If this is called when the interpreter
|
||||
// has already been finalized, the thread-state can be null. Unlike the
|
||||
// GIL-enabled build, Py_DECREF() requires a valid thread-state. This
|
||||
// causes a memory leak, rather than crash, which seems preferable.
|
||||
if (PyThreadState_GetUnchecked() == NULL) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
assert( Py_REFCNT(m_ptr) > 0 );
|
||||
Py_DECREF(m_ptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user