@@ -255,10 +255,10 @@ TEST_CASE("Add program dir to path using PyConfig") {
255
255
}
256
256
#endif
257
257
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
+ }
262
262
263
263
bool has_pybind11_internals_static () {
264
264
auto **&ipp = py::detail::get_internals_pp ();
@@ -268,7 +268,7 @@ bool has_pybind11_internals_static() {
268
268
TEST_CASE (" Restart the interpreter" ) {
269
269
// Verify pre-restart state.
270
270
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 ());
272
272
REQUIRE (has_pybind11_internals_static ());
273
273
REQUIRE (py::module_::import (" external_module" ).attr (" A" )(123 ).attr (" value" ).cast <int >()
274
274
== 123 );
@@ -285,10 +285,10 @@ TEST_CASE("Restart the interpreter") {
285
285
REQUIRE (Py_IsInitialized () == 1 );
286
286
287
287
// Internals are deleted after a restart.
288
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
288
+ REQUIRE_FALSE (has_state_dict_internals_obj ());
289
289
REQUIRE_FALSE (has_pybind11_internals_static ());
290
290
pybind11::detail::get_internals ();
291
- REQUIRE (has_pybind11_internals_builtin ());
291
+ REQUIRE (has_state_dict_internals_obj ());
292
292
REQUIRE (has_pybind11_internals_static ());
293
293
REQUIRE (reinterpret_cast <uintptr_t >(*py::detail::get_internals_pp ())
294
294
== py::module_::import (" external_module" ).attr (" internals_at" )().cast <uintptr_t >());
@@ -303,13 +303,13 @@ TEST_CASE("Restart the interpreter") {
303
303
py::detail::get_internals ();
304
304
*static_cast <bool *>(ran) = true ;
305
305
});
306
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
306
+ REQUIRE_FALSE (has_state_dict_internals_obj ());
307
307
REQUIRE_FALSE (has_pybind11_internals_static ());
308
308
REQUIRE_FALSE (ran);
309
309
py::finalize_interpreter ();
310
310
REQUIRE (ran);
311
311
py::initialize_interpreter ();
312
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
312
+ REQUIRE_FALSE (has_state_dict_internals_obj ());
313
313
REQUIRE_FALSE (has_pybind11_internals_static ());
314
314
315
315
// C++ modules can be reloaded.
@@ -331,7 +331,7 @@ TEST_CASE("Subinterpreter") {
331
331
332
332
REQUIRE (m.attr (" add" )(1 , 2 ).cast <int >() == 3 );
333
333
}
334
- REQUIRE (has_pybind11_internals_builtin ());
334
+ REQUIRE (has_state_dict_internals_obj ());
335
335
REQUIRE (has_pybind11_internals_static ());
336
336
337
337
// / Create and switch to a subinterpreter.
@@ -341,7 +341,7 @@ TEST_CASE("Subinterpreter") {
341
341
// Subinterpreters get their own copy of builtins. detail::get_internals() still
342
342
// works by returning from the static variable, i.e. all interpreters share a single
343
343
// global pybind11::internals;
344
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
344
+ REQUIRE_FALSE (has_state_dict_internals_obj ());
345
345
REQUIRE (has_pybind11_internals_static ());
346
346
347
347
// Modules tags should be gone.
0 commit comments