@@ -168,9 +168,8 @@ TEST_CASE("There can be only one interpreter") {
168168 py::initialize_interpreter ();
169169}
170170
171- bool has_pybind11_internals_builtin () {
172- auto builtins = py::handle (PyEval_GetBuiltins ());
173- return builtins.contains (PYBIND11_INTERNALS_ID);
171+ bool has_pybind11_internals_capsule () {
172+ return py::detail::get_python_state_dict ().contains (PYBIND11_INTERNALS_ID);
174173};
175174
176175bool has_pybind11_internals_static () {
@@ -181,7 +180,7 @@ bool has_pybind11_internals_static() {
181180TEST_CASE (" Restart the interpreter" ) {
182181 // Verify pre-restart state.
183182 REQUIRE (py::module_::import (" widget_module" ).attr (" add" )(1 , 2 ).cast <int >() == 3 );
184- REQUIRE (has_pybind11_internals_builtin ());
183+ REQUIRE (has_pybind11_internals_capsule ());
185184 REQUIRE (has_pybind11_internals_static ());
186185 REQUIRE (py::module_::import (" external_module" ).attr (" A" )(123 ).attr (" value" ).cast <int >()
187186 == 123 );
@@ -198,10 +197,10 @@ TEST_CASE("Restart the interpreter") {
198197 REQUIRE (Py_IsInitialized () == 1 );
199198
200199 // Internals are deleted after a restart.
201- REQUIRE_FALSE (has_pybind11_internals_builtin ());
200+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
202201 REQUIRE_FALSE (has_pybind11_internals_static ());
203202 pybind11::detail::get_internals ();
204- REQUIRE (has_pybind11_internals_builtin ());
203+ REQUIRE (has_pybind11_internals_capsule ());
205204 REQUIRE (has_pybind11_internals_static ());
206205 REQUIRE (reinterpret_cast <uintptr_t >(*py::detail::get_internals_pp ())
207206 == py::module_::import (" external_module" ).attr (" internals_at" )().cast <uintptr_t >());
@@ -216,13 +215,13 @@ TEST_CASE("Restart the interpreter") {
216215 py::detail::get_internals ();
217216 *static_cast <bool *>(ran) = true ;
218217 });
219- REQUIRE_FALSE (has_pybind11_internals_builtin ());
218+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
220219 REQUIRE_FALSE (has_pybind11_internals_static ());
221220 REQUIRE_FALSE (ran);
222221 py::finalize_interpreter ();
223222 REQUIRE (ran);
224223 py::initialize_interpreter ();
225- REQUIRE_FALSE (has_pybind11_internals_builtin ());
224+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
226225 REQUIRE_FALSE (has_pybind11_internals_static ());
227226
228227 // C++ modules can be reloaded.
@@ -244,7 +243,7 @@ TEST_CASE("Subinterpreter") {
244243
245244 REQUIRE (m.attr (" add" )(1 , 2 ).cast <int >() == 3 );
246245 }
247- REQUIRE (has_pybind11_internals_builtin ());
246+ REQUIRE (has_pybind11_internals_capsule ());
248247 REQUIRE (has_pybind11_internals_static ());
249248
250249 // / Create and switch to a subinterpreter.
@@ -254,7 +253,7 @@ TEST_CASE("Subinterpreter") {
254253 // Subinterpreters get their own copy of builtins. detail::get_internals() still
255254 // works by returning from the static variable, i.e. all interpreters share a single
256255 // global pybind11::internals;
257- REQUIRE_FALSE (has_pybind11_internals_builtin ());
256+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
258257 REQUIRE (has_pybind11_internals_static ());
259258
260259 // Modules tags should be gone.
0 commit comments