Skip to content

Commit c0cbf1a

Browse files
committed
Fix one more destruction issue
Should now just be able to delete the internals PP on destruction
1 parent 15cb855 commit c0cbf1a

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

include/pybind11/detail/common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@
342342
#define PYBIND11_STRINGIFY(x) #x
343343
#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
344344
#define PYBIND11_CONCAT(first, second) first##second
345-
#define PYBIND11_ENSURE_INTERNALS_READY pybind11::detail::get_internals();
345+
#define PYBIND11_ENSURE_INTERNALS_READY \
346+
{ \
347+
pybind11::detail::get_internals_pp_manager().unref(); \
348+
pybind11::detail::get_internals(); \
349+
}
346350

347351
#if !defined(GRAALVM_PYTHON)
348352
# define PYBIND11_PYCFUNCTION_GET_DOC(func) ((func)->m_ml->ml_doc)

include/pybind11/detail/internals.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class internals_pp_manager {
518518
#if PYBIND11_HAS_SUBINTERPRETER_SUPPORT
519519
if (get_num_interpreters_seen() > 1) {
520520
auto *tstate = get_thread_state_unchecked();
521-
// this could be called without an active interpreter, that's OK, just use what we
521+
// this could be called without an active interpreter, just use what was cached
522522
if (!tstate || tstate->interp == last_istate_.get()) {
523523
auto tpp = internals_tls_p_.get();
524524
if (tpp) {
@@ -529,11 +529,7 @@ class internals_pp_manager {
529529
return;
530530
}
531531
#endif
532-
// we can never delete the main interpreter PP because other modules may hold a copy of it
533-
if (internals_singleton_pp_) {
534-
// but we CAN and DO delete the internals inside.
535-
internals_singleton_pp_->reset();
536-
}
532+
delete internals_singleton_pp_;
537533
unref();
538534
}
539535

0 commit comments

Comments
 (0)