-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patching in snapshot of (already closed) PR #4316
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Nov 10, 2022
1 parent
c204c9b
commit 41bc371
Showing
10 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <pybind11/stl.h> | ||
|
||
#include "pybind11_tests.h" | ||
|
||
namespace test_named_namespace { | ||
struct any_struct {}; | ||
} // namespace test_named_namespace | ||
|
||
PYBIND11_MODULE(named_namespace_a, m) { | ||
m.attr("name") = "NA"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry_named_namespace[std::type_index( | ||
typeid(test_named_namespace::any_struct))] | ||
.push_back("NA"); | ||
|
||
m.def("std_type_index_registry_dump", []() { | ||
py::list items; | ||
for (const auto &it : | ||
py::detail::get_internals().std_type_index_registry_named_namespace) { | ||
items.append(py::make_tuple(it.first.name(), it.second)); | ||
} | ||
return items; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace test_named_namespace { | ||
struct any_struct {}; | ||
} // namespace test_named_namespace | ||
|
||
PYBIND11_MODULE(named_namespace_b, m) { | ||
m.attr("name") = "NB"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry_named_namespace[std::type_index( | ||
typeid(test_named_namespace::any_struct))] | ||
.push_back("NB"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import named_namespace_a as m | ||
import pytest | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "NA" | ||
reg = m.std_type_index_registry_dump() | ||
if len(reg) == 1: | ||
assert tuple(sorted(reg[0][1])) == ("NA", "NB") | ||
pytest.skip("std::type_index-EQ-GOOD") | ||
if len(reg) == 2: | ||
assert reg[0][0] == reg[1][0] | ||
assert tuple(sorted(reg[0][1] + reg[1][1])) == ("NA", "NB") | ||
pytest.skip("std::type_index-NE-BAD") | ||
assert reg is None # Sure to fail. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import named_namespace_b as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "NB" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <pybind11/stl.h> | ||
|
||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_a, m) { | ||
m.attr("name") = "UA"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry_unnamed_namespace[std::type_index(typeid(any_struct))] | ||
.push_back("UA"); | ||
|
||
m.def("std_type_index_registry_dump", []() { | ||
py::list items; | ||
for (const auto &it : | ||
py::detail::get_internals().std_type_index_registry_unnamed_namespace) { | ||
items.append(py::make_tuple(it.first.name(), it.second)); | ||
} | ||
return items; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
from pybind11_tests import unnamed_namespace_a as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "UA" | ||
reg = m.std_type_index_registry_dump() | ||
if len(reg) == 1: | ||
assert tuple(sorted(reg[0][1])) == ("UA", "UB") | ||
pytest.skip("std::type_index-EQ-BAD") | ||
if len(reg) == 2: | ||
assert tuple(sorted([reg[0][1][0], reg[1][1][0]])) == ("UA", "UB") | ||
pytest.skip("std::type_index-NE-GOOD") | ||
assert reg is None # Sure to fail. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_b, m) { | ||
m.attr("name") = "UB"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry_unnamed_namespace[std::type_index(typeid(any_struct))] | ||
.push_back("UB"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pybind11_tests import unnamed_namespace_b as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "UB" |