File tree 2 files changed +8
-10
lines changed 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -1484,7 +1484,7 @@ class module_ : public object {
1484
1484
using slots_array = std::array<PyModuleDef_Slot, 4 >;
1485
1485
1486
1486
/* * \rst
1487
- Initialized a module def for use with multi-phase module initialization.
1487
+ Initialize a module def for use with multi-phase module initialization.
1488
1488
1489
1489
``def`` should point to a statically allocated module_def.
1490
1490
``slots`` must already contain a Py_mod_exec or Py_mod_create slot and will be filled with
@@ -1544,6 +1544,10 @@ class module_ : public object {
1544
1544
}
1545
1545
pybind11_fail (" Internal error in module_::initialize_multiphase_module_def()" );
1546
1546
}
1547
+ // since def was statically allocated, this object should be immortal.
1548
+ #ifdef _Py_IMMORTAL_REFCNT
1549
+ Py_SET_REFCNT (m, _Py_IMMORTAL_REFCNT);
1550
+ #endif
1547
1551
return reinterpret_borrow<object>(m);
1548
1552
}
1549
1553
};
Original file line number Diff line number Diff line change @@ -527,13 +527,7 @@ TEST_CASE("Per-Subinterpreter GIL") {
527
527
T_REQUIRE (caught);
528
528
529
529
// widget_module did provide the per_interpreter_gil tag, so it this does not throw
530
- try {
531
- py::module_::import (" widget_module" );
532
- caught = false ;
533
- } catch (pybind11::error_already_set &) {
534
- caught = true ;
535
- }
536
- T_REQUIRE (!caught);
530
+ py::module_::import (" widget_module" );
537
531
538
532
T_REQUIRE (!py::hasattr (py::module_::import (" external_module" ), " multi_interp" ));
539
533
py::module_::import (" external_module" ).attr (" multi_interp" ) = std::to_string (num);
@@ -557,8 +551,8 @@ TEST_CASE("Per-Subinterpreter GIL") {
557
551
558
552
Py_EndInterpreter (sub);
559
553
560
- PyThreadState_Swap (
561
- main_tstate); // switch back so the scoped_acquire can release the GIL properly
554
+ // switch back so the scoped_acquire can release the GIL properly
555
+ PyThreadState_Swap ( main_tstate);
562
556
};
563
557
564
558
std::thread t1 (thread_main, 1 );
You can’t perform that action at this time.
0 commit comments