Skip to content

Commit 79e6983

Browse files
committed
Add nullptr checks to istate as Cursor suggested
1 parent 08ea6ca commit 79e6983

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/detail/internals.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ struct internals {
343343
// completely shut down, In that case, we should not decref these objects because pymalloc
344344
// is gone. This also applies across sub-interpreters, we should only DECREF when the
345345
// original owning interpreter is active.
346-
if (get_interpreter_state_unchecked() == istate) {
346+
auto *cur_istate = get_interpreter_state_unchecked();
347+
if (cur_istate && cur_istate == istate) {
347348
Py_CLEAR(instance_base);
348349
Py_CLEAR(default_metaclass);
349350
Py_CLEAR(static_property_type);
@@ -375,7 +376,8 @@ struct local_internals {
375376
// completely shut down, In that case, we should not decref these objects because pymalloc
376377
// is gone. This also applies across sub-interpreters, we should only DECREF when the
377378
// original owning interpreter is active.
378-
if (get_interpreter_state_unchecked() == istate) {
379+
auto *cur_istate = get_interpreter_state_unchecked();
380+
if (cur_istate && cur_istate == istate) {
379381
Py_CLEAR(function_record_py_type);
380382
}
381383
}

0 commit comments

Comments
 (0)