@@ -255,10 +255,10 @@ TEST_CASE("Add program dir to path using PyConfig") {
255255}
256256#endif
257257
258- bool has_pybind11_internals_builtin () {
259- auto builtins = py::handle ( PyEval_GetBuiltins ());
260- return builtins. contains (PYBIND11_INTERNALS_ID );
261- };
258+ bool has_state_dict_internals_obj () {
259+ return bool (
260+ py::detail::get_internals_obj_from_state_dict ( py::detail::get_python_state_dict ()) );
261+ }
262262
263263bool has_pybind11_internals_static () {
264264 auto **&ipp = py::detail::get_internals_pp ();
@@ -268,7 +268,7 @@ bool has_pybind11_internals_static() {
268268TEST_CASE (" Restart the interpreter" ) {
269269 // Verify pre-restart state.
270270 REQUIRE (py::module_::import (" widget_module" ).attr (" add" )(1 , 2 ).cast <int >() == 3 );
271- REQUIRE (has_pybind11_internals_builtin ());
271+ REQUIRE (has_state_dict_internals_obj ());
272272 REQUIRE (has_pybind11_internals_static ());
273273 REQUIRE (py::module_::import (" external_module" ).attr (" A" )(123 ).attr (" value" ).cast <int >()
274274 == 123 );
@@ -285,10 +285,10 @@ TEST_CASE("Restart the interpreter") {
285285 REQUIRE (Py_IsInitialized () == 1 );
286286
287287 // Internals are deleted after a restart.
288- REQUIRE_FALSE (has_pybind11_internals_builtin ());
288+ REQUIRE_FALSE (has_state_dict_internals_obj ());
289289 REQUIRE_FALSE (has_pybind11_internals_static ());
290290 pybind11::detail::get_internals ();
291- REQUIRE (has_pybind11_internals_builtin ());
291+ REQUIRE (has_state_dict_internals_obj ());
292292 REQUIRE (has_pybind11_internals_static ());
293293 REQUIRE (reinterpret_cast <uintptr_t >(*py::detail::get_internals_pp ())
294294 == py::module_::import (" external_module" ).attr (" internals_at" )().cast <uintptr_t >());
@@ -303,13 +303,13 @@ TEST_CASE("Restart the interpreter") {
303303 py::detail::get_internals ();
304304 *static_cast <bool *>(ran) = true ;
305305 });
306- REQUIRE_FALSE (has_pybind11_internals_builtin ());
306+ REQUIRE_FALSE (has_state_dict_internals_obj ());
307307 REQUIRE_FALSE (has_pybind11_internals_static ());
308308 REQUIRE_FALSE (ran);
309309 py::finalize_interpreter ();
310310 REQUIRE (ran);
311311 py::initialize_interpreter ();
312- REQUIRE_FALSE (has_pybind11_internals_builtin ());
312+ REQUIRE_FALSE (has_state_dict_internals_obj ());
313313 REQUIRE_FALSE (has_pybind11_internals_static ());
314314
315315 // C++ modules can be reloaded.
@@ -331,7 +331,7 @@ TEST_CASE("Subinterpreter") {
331331
332332 REQUIRE (m.attr (" add" )(1 , 2 ).cast <int >() == 3 );
333333 }
334- REQUIRE (has_pybind11_internals_builtin ());
334+ REQUIRE (has_state_dict_internals_obj ());
335335 REQUIRE (has_pybind11_internals_static ());
336336
337337 // / Create and switch to a subinterpreter.
@@ -341,7 +341,7 @@ TEST_CASE("Subinterpreter") {
341341 // Subinterpreters get their own copy of builtins. detail::get_internals() still
342342 // works by returning from the static variable, i.e. all interpreters share a single
343343 // global pybind11::internals;
344- REQUIRE_FALSE (has_pybind11_internals_builtin ());
344+ REQUIRE_FALSE (has_state_dict_internals_obj ());
345345 REQUIRE (has_pybind11_internals_static ());
346346
347347 // Modules tags should be gone.
0 commit comments