File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 24
24
#include < iterator>
25
25
#include < memory>
26
26
#include < string>
27
+ #include < system_error>
27
28
#include < tuple>
28
29
#include < type_traits>
30
+ #include < typeindex>
31
+ #include < unordered_map>
29
32
#include < utility>
30
33
#include < vector>
31
34
@@ -44,8 +47,26 @@ class type_caster_for_class_ : public type_caster_base<T> {};
44
47
template <typename type, typename SFINAE = void >
45
48
class type_caster : public type_caster_for_class_ <type> {};
46
49
50
+ inline std::unordered_map<std::type_index, std::type_index> &odr_guard_registry () {
51
+ static std::unordered_map<std::type_index, std::type_index> reg;
52
+ return reg;
53
+ }
54
+
47
55
template <typename IntrinsicType>
48
- struct type_caster_odr_guard : type_caster<IntrinsicType> {};
56
+ struct type_caster_odr_guard : type_caster<IntrinsicType> {
57
+ type_caster_odr_guard () {
58
+ auto it_ti = std::type_index (typeid (IntrinsicType));
59
+ auto tc_ti = std::type_index (typeid (type_caster<IntrinsicType>));
60
+ auto match = odr_guard_registry ().find (it_ti);
61
+ if (match == odr_guard_registry ().end ()) {
62
+ odr_guard_registry ().insert ({it_ti, tc_ti});
63
+ } else if (match->second != tc_ti) {
64
+ throw std::system_error (std::make_error_code (std::errc::state_not_recoverable),
65
+ " pybind11::detail::type_caster<" + type_id<IntrinsicType>()
66
+ + " > ODR VIOLATION DETECTED" );
67
+ }
68
+ }
69
+ };
49
70
50
71
template <typename type>
51
72
using make_caster = type_caster_odr_guard<intrinsic_t <type>>;
You can’t perform that action at this time.
0 commit comments