Skip to content

Commit e8ba231

Browse files
committed
Update comments
1 parent f3a8123 commit e8ba231

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/test_with_catch/test_subinterpreter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,18 @@ TEST_CASE("gil_safe_call_once_and_store per-interpreter isolation") {
386386
py::object sub_ordered_dict_type = get_ordered_dict_type_object();
387387
py::object sub_default_dict_type = get_default_dict_type_object();
388388

389-
REQUIRE(sub_dict_type.is(dict_type)); // dict is a static type
390-
REQUIRE(sub_ordered_dict_type.is(ordered_dict_type)); // OrderedDict is a static type
389+
// Verify that the subinterpreter has its own cached type objects.
390+
// For static types, they should be the same object across interpreters.
391+
// See also: https://docs.python.org/3/c-api/typeobj.html#static-types
392+
REQUIRE(sub_dict_type.is(dict_type)); // dict is a static type
393+
REQUIRE(sub_ordered_dict_type.is(ordered_dict_type)); // OrderedDict is a static type
394+
// For heap types, they are dynamically created per-interpreter.
395+
// See also: https://docs.python.org/3/c-api/typeobj.html#heap-types
391396
REQUIRE_FALSE(sub_default_dict_type.is(default_dict_type)); // defaultdict is a heap type
392397

398+
// Set up a weakref callback to detect when the subinterpreter's cached default_dict_type
399+
// is destroyed so the gil_safe_call_once_and_store storage is not leaked when the
400+
// subinterpreter is shutdown.
393401
(void) py::weakref(sub_default_dict_type,
394402
py::cpp_function([&](py::handle weakref) -> void {
395403
sub_default_dict_type_destroyed = true;

0 commit comments

Comments
 (0)