Skip to content

Commit 15bcbf8

Browse files
committed
Update comments and assertion messages
1 parent 6820ead commit 15bcbf8

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

include/pybind11/detail/internals.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ class internals_pp_manager {
698698
if (!tstate || tstate->interp == last_istate_tls()) {
699699
auto tpp = internals_p_tls();
700700
{
701-
std::lock_guard<std::mutex> lock(pps_creation_mutex_);
701+
std::lock_guard<std::mutex> lock(pp_set_mutex_);
702702
pps_have_created_content_.erase(tpp);
703703
delete tpp;
704704
}
@@ -708,32 +708,29 @@ class internals_pp_manager {
708708
}
709709
#endif
710710
{
711-
std::lock_guard<std::mutex> lock(pps_creation_mutex_);
711+
std::lock_guard<std::mutex> lock(pp_set_mutex_);
712712
pps_have_created_content_.erase(internals_singleton_pp_);
713713
delete internals_singleton_pp_;
714714
}
715715
unref();
716716
}
717717

718718
void create_pp_content_once(std::unique_ptr<InternalsType> *pp) {
719-
// Assume the GIL is held
720-
{
721-
std::lock_guard<std::mutex> lock(pps_creation_mutex_);
722-
723-
// Prevent re-creation of internals after destruction during interpreter shutdown.
724-
// If pybind11 code (e.g., tp_traverse/tp_clear calling py::cast) runs after internals
725-
// have been destroyed, a new empty internals would be created, causing type lookup
726-
// failures. See https://github.com/pybind/pybind11/pull/5958#discussion_r2717645230.
727-
if (pps_have_created_content_.find(pp) != pps_have_created_content_.end()) {
728-
pybind11_fail(
729-
"pybind11::detail::internals_pp_manager::create_pp_content_once() FAILED: "
730-
"reentrant call detected while fetching pybind11 internals!");
731-
}
732-
// Each pp can only create its internals once.
733-
pps_have_created_content_.insert(pp);
719+
std::lock_guard<std::mutex> lock(pp_set_mutex_);
720+
721+
// Prevent re-creation of internals after destruction during interpreter shutdown.
722+
// If pybind11 code (e.g., tp_traverse/tp_clear calling py::cast) runs after internals
723+
// have been destroyed, a new empty internals would be created, causing type lookup
724+
// failures. See https://github.com/pybind/pybind11/pull/5958#discussion_r2717645230.
725+
if (pps_have_created_content_.find(pp) != pps_have_created_content_.end()) {
726+
pybind11_fail("pybind11::detail::internals_pp_manager::create_pp_content_once() "
727+
"FAILED: reentrant call detected while fetching pybind11 internals!");
734728
}
729+
// Each pp can only create its internals once.
730+
pps_have_created_content_.insert(pp);
735731

736-
// Create the internals content. May call back into Python.
732+
// Assume the GIL is held here. May call back into Python.
733+
// Create the internals content.
737734
pp->reset(new InternalsType());
738735
}
739736

@@ -781,7 +778,7 @@ class internals_pp_manager {
781778
// Tracks pointer-to-pointers whose internals have been created, to detect re-entrancy.
782779
// Use instance member over static due to singleton pattern of this class.
783780
std::unordered_set<std::unique_ptr<InternalsType> *> pps_have_created_content_;
784-
std::mutex pps_creation_mutex_;
781+
std::mutex pp_set_mutex_;
785782
};
786783

787784
// If We loaded the internals through `state_dict`, our `error_already_set`

0 commit comments

Comments
 (0)