Skip to content

Commit c2b1297

Browse files
committed
Add test to ensure that local typemap is local
1 parent d12c025 commit c2b1297

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

tests/pybind11_local_bindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ PYBIND11_MODULE(pybind11_local_bindings, m) {
5050
m.def("register_nonlocal_stl2", [m]() {
5151
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::module_local(false));
5252
});
53+
54+
// test_internal_locals_differ
55+
m.def("local_cpp_types_addr", []() { return (uintptr_t) &py::detail::registered_local_types_cpp(); });
5356
}

tests/test_local_bindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ TEST_SUBMODULE(local_bindings, m) {
5555
bind_local<NonLocal2, 10>(m, "NonLocal2");
5656
py::bind_vector<std::vector<NonLocal2>>(m, "NonLocalVec", py::module_local(false));
5757
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::module_local(false));
58+
59+
// test_internal_locals_differ
60+
m.def("local_cpp_types_addr", []() { return (uintptr_t) &py::detail::registered_local_types_cpp(); });
5861
}

tests/test_local_bindings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ def test_stl_bind_global():
9797
with pytest.raises(RuntimeError) as excinfo:
9898
m2.register_nonlocal_stl2()
9999
assert str(excinfo.value) == 'generic_type: type "NonLocalMap" is already registered!'
100+
101+
102+
def test_internal_locals_differ():
103+
"""Makes sure the internal local type map differs across the two modules"""
104+
import pybind11_local_bindings as m2
105+
assert m1.local_cpp_types_addr() != m2.local_cpp_types_addr()

0 commit comments

Comments
 (0)