@@ -168,9 +168,8 @@ TEST_CASE("There can be only one interpreter") {
168
168
py::initialize_interpreter ();
169
169
}
170
170
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);
174
173
};
175
174
176
175
bool has_pybind11_internals_static () {
@@ -181,7 +180,7 @@ bool has_pybind11_internals_static() {
181
180
TEST_CASE (" Restart the interpreter" ) {
182
181
// Verify pre-restart state.
183
182
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 ());
185
184
REQUIRE (has_pybind11_internals_static ());
186
185
REQUIRE (py::module_::import (" external_module" ).attr (" A" )(123 ).attr (" value" ).cast <int >()
187
186
== 123 );
@@ -198,10 +197,10 @@ TEST_CASE("Restart the interpreter") {
198
197
REQUIRE (Py_IsInitialized () == 1 );
199
198
200
199
// Internals are deleted after a restart.
201
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
200
+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
202
201
REQUIRE_FALSE (has_pybind11_internals_static ());
203
202
pybind11::detail::get_internals ();
204
- REQUIRE (has_pybind11_internals_builtin ());
203
+ REQUIRE (has_pybind11_internals_capsule ());
205
204
REQUIRE (has_pybind11_internals_static ());
206
205
REQUIRE (reinterpret_cast <uintptr_t >(*py::detail::get_internals_pp ())
207
206
== py::module_::import (" external_module" ).attr (" internals_at" )().cast <uintptr_t >());
@@ -216,13 +215,13 @@ TEST_CASE("Restart the interpreter") {
216
215
py::detail::get_internals ();
217
216
*static_cast <bool *>(ran) = true ;
218
217
});
219
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
218
+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
220
219
REQUIRE_FALSE (has_pybind11_internals_static ());
221
220
REQUIRE_FALSE (ran);
222
221
py::finalize_interpreter ();
223
222
REQUIRE (ran);
224
223
py::initialize_interpreter ();
225
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
224
+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
226
225
REQUIRE_FALSE (has_pybind11_internals_static ());
227
226
228
227
// C++ modules can be reloaded.
@@ -244,7 +243,7 @@ TEST_CASE("Subinterpreter") {
244
243
245
244
REQUIRE (m.attr (" add" )(1 , 2 ).cast <int >() == 3 );
246
245
}
247
- REQUIRE (has_pybind11_internals_builtin ());
246
+ REQUIRE (has_pybind11_internals_capsule ());
248
247
REQUIRE (has_pybind11_internals_static ());
249
248
250
249
// / Create and switch to a subinterpreter.
@@ -254,7 +253,7 @@ TEST_CASE("Subinterpreter") {
254
253
// Subinterpreters get their own copy of builtins. detail::get_internals() still
255
254
// works by returning from the static variable, i.e. all interpreters share a single
256
255
// global pybind11::internals;
257
- REQUIRE_FALSE (has_pybind11_internals_builtin ());
256
+ REQUIRE_FALSE (has_pybind11_internals_capsule ());
258
257
REQUIRE (has_pybind11_internals_static ());
259
258
260
259
// Modules tags should be gone.
0 commit comments