@@ -478,7 +478,7 @@ template <typename InternalsType>
478478class internals_pp_manager {
479479public:
480480 using on_fetch_function = void (InternalsType *);
481- explicit internals_pp_manager (char const *id, on_fetch_function *on_fetch = nullptr )
481+ internals_pp_manager (char const *id, on_fetch_function *on_fetch)
482482 : holder_id_(id), on_fetch_(on_fetch) {}
483483
484484 // / Get the current pointer-to-pointer, allocating it if it does not already exist. May
@@ -571,29 +571,35 @@ class internals_pp_manager {
571571 std::unique_ptr<InternalsType> *internals_singleton_pp_;
572572};
573573
574- inline void on_internals_fetch (internals *internals_ptr) {
575- // If We loaded the internals through `state_dict`, our `error_already_set`
576- // and `builtin_exception` may be different local classes than the ones set up in the
577- // initial exception translator, below, so add another for our local exception classes.
578- //
579- // libstdc++ doesn't require this (types there are identified only by name)
580- // libc++ with CPython doesn't require this (types are explicitly exported)
581- // libc++ with PyPy still need it, awaiting further investigation
582- if (internals_ptr) {
583574#if !defined(__GLIBCXX__)
575+ // If We loaded the internals through `state_dict`, our `error_already_set`
576+ // and `builtin_exception` may be different local classes than the ones set up in the
577+ // initial exception translator, below, so add another for our local exception classes.
578+ //
579+ // libstdc++ doesn't require this (types there are identified only by name)
580+ // libc++ with CPython doesn't require this (types are explicitly exported)
581+ // libc++ with PyPy still need it, awaiting further investigation
582+ inline void check_internals_local_exception_translator (internals *internals_ptr) {
583+ if (internals_ptr) {
584584 for (auto et : internals_ptr->registered_exception_translators ) {
585585 if (et == &translate_local_exception) {
586586 return ;
587587 }
588588 }
589589 internals_ptr->registered_exception_translators .push_front (&translate_local_exception);
590- #endif
591590 }
592591}
592+ #endif
593593
594594inline internals_pp_manager<internals> &get_internals_pp_manager () {
595+ #if defined(__GLIBCXX__)
596+ # define ON_FETCH_FN nullptr
597+ #else
598+ # define ON_FETCH_FN &check_internals_local_exception_translator
599+ #endif
595600 static internals_pp_manager<internals> internals_pp_manager (PYBIND11_INTERNALS_ID,
596- &on_internals_fetch);
601+ ON_FETCH_FN);
602+ #undef ON_FETCH_FN
597603 return internals_pp_manager;
598604}
599605
@@ -623,7 +629,7 @@ inline internals_pp_manager<local_internals> &get_local_internals_pp_manager() {
623629 = PYBIND11_MODULE_LOCAL_ID
624630 + std::to_string (reinterpret_cast <uintptr_t >(&this_module_idstr));
625631 static internals_pp_manager<local_internals> local_internals_pp_manager (
626- this_module_idstr.c_str ());
632+ this_module_idstr.c_str (), nullptr );
627633 return local_internals_pp_manager;
628634}
629635
0 commit comments