forked from pybind/pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Experiment]
boost::typeindex::type_index
& unnamed namespace
Related to PR pybind#4313
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Nov 6, 2022
1 parent
ee2b522
commit c4f6602
Showing
6 changed files
with
80 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,30 @@ | ||
#include <pybind11/stl.h> | ||
|
||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_a, m) { | ||
m.attr("name") = "A"; | ||
|
||
#if defined(PYBIND11_TEST_BOOST) | ||
py::detail::get_internals() | ||
.boost_type_index_registry[boost::typeindex::type_index( | ||
boost::typeindex::type_id<any_struct>())] | ||
.push_back("A"); | ||
#endif | ||
|
||
m.def("boost_type_index_registry_dump", []() { | ||
#if defined(PYBIND11_TEST_BOOST) | ||
py::list items; | ||
for (const auto &it : py::detail::get_internals().boost_type_index_registry) { | ||
items.append(py::make_tuple(it.first.pretty_name(), it.second)); | ||
} | ||
return items; | ||
#else | ||
return py::none(); | ||
#endif | ||
}); | ||
} |
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,17 @@ | ||
import pytest | ||
|
||
from pybind11_tests import unnamed_namespace_a as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "A" | ||
reg = m.boost_type_index_registry_dump() | ||
if reg is None: | ||
pytest.skip("boost::typeindex::type_index-NotAvailable") | ||
if len(reg) == 1: | ||
assert tuple(sorted(reg[0][1])) == ("A", "B") | ||
pytest.skip("boost::typeindex::type_index-EQ-BAD") | ||
if len(reg) == 2: | ||
assert tuple(sorted([reg[0][1][0], reg[1][1][0]])) == ("A", "B") | ||
pytest.skip("boost::typeindex::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,16 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_b, m) { | ||
m.attr("name") = "B"; | ||
|
||
#if defined(PYBIND11_TEST_BOOST) | ||
py::detail::get_internals() | ||
.boost_type_index_registry[boost::typeindex::type_index( | ||
boost::typeindex::type_id<any_struct>())] | ||
.push_back("B"); | ||
#endif | ||
} |
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 == "B" |