diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 874f504ab..f9539843b 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -55,7 +55,7 @@ inline std::unordered_map &odr_guard_registry() namespace { template -bool odr_guard_impl(const std::type_index & it_ti, const std::uint64_t& tc_id) { +bool odr_guard_impl(const std::type_index &it_ti, const std::uint64_t &tc_id) { printf("\nLOOOK %s %llu\n", type_id().c_str(), (long long) tc_id); fflush(stdout); auto [reg_iter, added] = odr_guard_registry().insert({it_ti, tc_id}); @@ -73,10 +73,9 @@ struct type_caster_odr_guard : type_caster { }; template -int type_caster_odr_guard::translation_unit_local = [](){ - odr_guard_impl( - std::type_index(typeid(IntrinsicType)), - type_caster::universally_unique_identifier); +int type_caster_odr_guard::translation_unit_local = []() { + odr_guard_impl(std::type_index(typeid(IntrinsicType)), + type_caster::universally_unique_identifier.value); return 0; }(); @@ -85,6 +84,10 @@ int type_caster_odr_guard::translation_unit_local = [](){ template using make_caster = type_caster_odr_guard>; +#define PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(...) \ + if (::pybind11::detail::make_caster<__VA_ARGS__>::translation_unit_local) { \ + } + template struct type_uses_smart_holder_type_caster { static constexpr bool value @@ -94,15 +97,13 @@ struct type_uses_smart_holder_type_caster { // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T template typename make_caster::template cast_op_type cast_op(make_caster &caster) { // LOOOK - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return caster.operator typename make_caster::template cast_op_type(); } template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { // LOOOK - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return std::move(caster).operator typename make_caster:: template cast_op_type::type>(); } @@ -124,7 +125,7 @@ private: public: bool load(handle src, bool convert) { return subcaster.load(src, convert); } static constexpr auto name = caster_t::name; - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(const std::reference_wrapper &src, return_value_policy policy, handle parent) { // It is definitely wrong to take ownership of this pointer, so mask that rvp @@ -296,7 +297,7 @@ public: } PYBIND11_TYPE_CASTER(T, const_name::value>("int", "float")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template @@ -312,7 +313,7 @@ public: return none().inc_ref(); } PYBIND11_TYPE_CASTER(T, const_name("None")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template <> @@ -360,7 +361,7 @@ public: using cast_op_type = void *&; explicit operator void *&() { return value; } static constexpr auto name = const_name("capsule"); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) private: void *value = nullptr; @@ -417,7 +418,7 @@ public: return handle(src ? Py_True : Py_False).inc_ref(); } PYBIND11_TYPE_CASTER(bool, const_name("bool")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; // Helper class for UTF-{8,16,32} C++ stl strings: @@ -510,7 +511,7 @@ struct string_caster { } PYBIND11_TYPE_CASTER(StringType, const_name(PYBIND11_STRING_NAME)); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) private: static handle decode_utfN(const char *buffer, ssize_t nbytes) { @@ -683,7 +684,7 @@ public: } static constexpr auto name = const_name(PYBIND11_STRING_NAME); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) template using cast_op_type = pybind11::detail::cast_op_type<_T>; }; @@ -728,7 +729,7 @@ public: static constexpr auto name = const_name("Tuple[") + concat(make_caster::name...) + const_name("]"); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) template using cast_op_type = type; @@ -901,7 +902,7 @@ struct move_only_holder_caster { return type_caster_base::cast_holder(ptr, std::addressof(src)); } static constexpr auto name = type_caster_base::name; - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT @@ -1011,7 +1012,7 @@ struct pyobject_caster { return src.inc_ref(); } PYBIND11_TYPE_CASTER(type, handle_type_name::name); - static constexpr std::uint64_t universally_unique_identifier = 3434; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(3434) }; template @@ -1106,8 +1107,7 @@ type_caster &load_type(type_caster &conv, const handle &ha // Wrapper around the above that also constructs and returns a type_caster template make_caster load_type(const handle &handle) { - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) make_caster conv; load_type(conv, handle); return conv; @@ -1145,8 +1145,7 @@ object cast(T &&value, : std::is_lvalue_reference::value ? return_value_policy::copy : return_value_policy::move; } - if (detail::make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return reinterpret_steal( detail::make_caster::cast(std::forward(value), policy, parent)); } @@ -1247,8 +1246,7 @@ using override_caster_t = conditional_t enable_if_t::value, T> cast_ref(object &&o, make_caster &caster) { - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return cast_op(load_type(caster, o)); } template @@ -1360,8 +1358,7 @@ private: type(type_id()) #endif { - if (detail::make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) // Workaround! See: // https://github.com/pybind/pybind11/issues/2336 // https://github.com/pybind/pybind11/pull/2685#issuecomment-731286700 @@ -1592,8 +1589,7 @@ public: private: template void process(list &args_list, T &&x) { - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) auto o = reinterpret_steal( detail::make_caster::cast(std::forward(x), policy, {})); if (!o) { @@ -1738,8 +1734,7 @@ handle type::handle_of() { detail::type_uses_smart_holder_type_caster>::value, "py::type::of only supports the case where T is a registered C++ types."); - if (detail::make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return detail::get_type_handle(typeid(T), true); } diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index 6342f0ab6..971802846 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -97,7 +97,7 @@ public: } PYBIND11_TYPE_CASTER(type, const_name("datetime.timedelta")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; inline std::tm *localtime_thread_safe(const std::time_t *time, std::tm *buf) { @@ -209,7 +209,7 @@ public: us.count()); } PYBIND11_TYPE_CASTER(type, const_name("datetime.datetime")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; // Other clocks that are not the system clock are not measured as datetime.datetime objects diff --git a/include/pybind11/complex.h b/include/pybind11/complex.h index 118f7073e..27cead1cc 100644 --- a/include/pybind11/complex.h +++ b/include/pybind11/complex.h @@ -69,7 +69,7 @@ public: } PYBIND11_TYPE_CASTER(std::complex, const_name("complex")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index 8e383e48d..dee0b04b7 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -27,7 +27,7 @@ public: using cast_op_type = value_and_holder &; explicit operator value_and_holder &() { return *value; } static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) private: value_and_holder *value = nullptr; diff --git a/include/pybind11/detail/smart_holder_type_casters.h b/include/pybind11/detail/smart_holder_type_casters.h index dedfad0a1..b8152aa2a 100644 --- a/include/pybind11/detail/smart_holder_type_casters.h +++ b/include/pybind11/detail/smart_holder_type_casters.h @@ -616,7 +616,7 @@ template struct smart_holder_type_caster : smart_holder_type_caster_load, smart_holder_type_caster_class_hooks { static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) // static handle cast(T, ...) // is redundant (leads to ambiguous overloads). @@ -778,7 +778,7 @@ template struct smart_holder_type_caster> : smart_holder_type_caster_load, smart_holder_type_caster_class_hooks { static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(const std::shared_ptr &src, return_value_policy policy, handle parent) { switch (policy) { @@ -843,7 +843,7 @@ template struct smart_holder_type_caster> : smart_holder_type_caster_load, smart_holder_type_caster_class_hooks { static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(const std::shared_ptr &src, return_value_policy policy, handle parent) { @@ -864,7 +864,7 @@ template struct smart_holder_type_caster> : smart_holder_type_caster_load, smart_holder_type_caster_class_hooks { static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(std::unique_ptr &&src, return_value_policy policy, handle parent) { if (policy != return_value_policy::automatic @@ -948,7 +948,7 @@ template struct smart_holder_type_caster> : smart_holder_type_caster_load, smart_holder_type_caster_class_hooks { static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(std::unique_ptr &&src, return_value_policy policy, handle parent) { diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 3e2590bf9..2629fd709 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -904,6 +904,17 @@ struct polymorphic_type_hook : public polymorphic_type_hook_base {}; PYBIND11_NAMESPACE_BEGIN(detail) +namespace { +template +struct universally_unique_identifier_holder { + static constexpr std::uint64_t value = Value; +}; +} // namespace + +#define PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(...) \ + static constexpr ::pybind11::detail::universally_unique_identifier_holder<__VA_ARGS__> \ + universally_unique_identifier; + /// Generic type caster for objects stored on the heap template class type_caster_base : public type_caster_generic { @@ -911,7 +922,7 @@ class type_caster_base : public type_caster_generic { public: static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) type_caster_base() : type_caster_base(typeid(type)) {} explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) {} diff --git a/include/pybind11/eigen.h b/include/pybind11/eigen.h index 41dd2496c..b5096b5c7 100644 --- a/include/pybind11/eigen.h +++ b/include/pybind11/eigen.h @@ -392,7 +392,7 @@ public: } static constexpr auto name = props::descriptor; - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) // NOLINTNEXTLINE(google-explicit-constructor) operator Type *() { return &value; } @@ -437,7 +437,7 @@ public: } static constexpr auto name = props::descriptor; - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return // types but not bound arguments). We still provide them (with an explicitly delete) so that @@ -625,7 +625,7 @@ public: } static constexpr auto name = props::descriptor; - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return // types but not bound arguments). We still provide them (with an explicitly delete) so that @@ -702,7 +702,7 @@ struct type_caster::value>> { const_name<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[") + npy_format_descriptor::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; PYBIND11_NAMESPACE_END(detail) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 8c4e3d5ea..5fc5fb317 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -124,7 +124,7 @@ public: const_name("Callable[[") + concat(make_caster::name...) + const_name("], ") + make_caster::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; PYBIND11_NAMESPACE_END(detail) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 6611387ce..de74f8023 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -1214,7 +1214,7 @@ struct pyobject_caster> { return src.inc_ref(); } PYBIND11_TYPE_CASTER(type, handle_type_name::name); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index af96dec4d..8196f2b50 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -87,7 +87,7 @@ struct set_caster { } PYBIND11_TYPE_CASTER(type, const_name("Set[") + key_conv::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template @@ -137,7 +137,7 @@ struct map_caster { PYBIND11_TYPE_CASTER(Type, const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template @@ -190,7 +190,7 @@ public: } PYBIND11_TYPE_CASTER(Type, const_name("List[") + value_conv::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template @@ -260,7 +260,7 @@ public: const_name("[") + const_name() + const_name("]")) + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; template @@ -319,7 +319,7 @@ struct optional_caster { } PYBIND11_TYPE_CASTER(Type, const_name("Optional[") + value_conv::name + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; #if defined(PYBIND11_HAS_OPTIONAL) @@ -349,8 +349,7 @@ struct variant_caster_visitor { template result_type operator()(T &&src) const { - if (make_caster::translation_unit_local) { - } + PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return make_caster::cast(std::forward(src), policy, parent); } }; @@ -408,7 +407,7 @@ struct variant_caster> { PYBIND11_TYPE_CASTER(Type, const_name("Union[") + detail::concat(make_caster::name...) + const_name("]")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; #if defined(PYBIND11_HAS_VARIANT) diff --git a/include/pybind11/stl/filesystem.h b/include/pybind11/stl/filesystem.h index c5ac3faab..fff90cf36 100644 --- a/include/pybind11/stl/filesystem.h +++ b/include/pybind11/stl/filesystem.h @@ -99,7 +99,7 @@ public: } PYBIND11_TYPE_CASTER(T, const_name("os.PathLike")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) }; #endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) diff --git a/tests/pybind11_tests.h b/tests/pybind11_tests.h index 7ddd6c837..5ed373d6f 100644 --- a/tests/pybind11_tests.h +++ b/tests/pybind11_tests.h @@ -61,7 +61,7 @@ template <> class type_caster { public: PYBIND11_TYPE_CASTER(RValueCaster, const_name("RValueCaster")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); } diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp index b063599f1..156880c1f 100644 --- a/tests/test_builtin_casters.cpp +++ b/tests/test_builtin_casters.cpp @@ -28,7 +28,7 @@ template <> class type_caster { public: static constexpr auto name = const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) // Input is unimportant, a new value will always be constructed based on the // cast operator. diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index 5cd9d8550..4c6ac2c74 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -106,7 +106,7 @@ PYBIND11_NAMESPACE_BEGIN(detail) template <> struct type_caster { PYBIND11_TYPE_CASTER(MoveOnlyInt, const_name("MoveOnlyInt")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle src, bool) { value = MoveOnlyInt(src.cast()); return true; @@ -119,7 +119,7 @@ struct type_caster { template <> struct type_caster { PYBIND11_TYPE_CASTER(MoveOrCopyInt, const_name("MoveOrCopyInt")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle src, bool) { value = MoveOrCopyInt(src.cast()); return true; @@ -136,7 +136,7 @@ protected: public: static constexpr auto name = const_name("CopyOnlyInt"); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle src, bool) { value = CopyOnlyInt(src.cast()); return true; diff --git a/tests/test_custom_type_casters.cpp b/tests/test_custom_type_casters.cpp index 911b30c35..8a3b32ebc 100644 --- a/tests/test_custom_type_casters.cpp +++ b/tests/test_custom_type_casters.cpp @@ -32,7 +32,7 @@ public: #else PYBIND11_TYPE_CASTER(ArgInspector1, const_name("ArgInspector1")); #endif - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle src, bool convert) { value.arg = "loading ArgInspector1 argument " + std::string(convert ? "WITH" : "WITHOUT") @@ -50,7 +50,7 @@ template <> struct type_caster { public: PYBIND11_TYPE_CASTER(ArgInspector2, const_name("ArgInspector2")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle src, bool convert) { value.arg = "loading ArgInspector2 argument " + std::string(convert ? "WITH" : "WITHOUT") @@ -68,7 +68,7 @@ template <> struct type_caster { public: PYBIND11_TYPE_CASTER(ArgAlwaysConverts, const_name("ArgAlwaysConverts")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle, bool convert) { return convert; } @@ -100,7 +100,7 @@ namespace detail { template <> struct type_caster { PYBIND11_TYPE_CASTER(DestructionTester, const_name("DestructionTester")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(handle, bool) { return true; } static handle cast(const DestructionTester &, return_value_policy, handle) { @@ -123,7 +123,7 @@ namespace py_ = ::pybind11; // don't have any symbol collision when using macro mixin. struct my_caster { PYBIND11_TYPE_CASTER(MyType, py_::detail::const_name("MyType")); - static constexpr std::uint64_t universally_unique_identifier = 1655073597; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597) bool load(py_::handle, bool) { return true; } static py_::handle cast(const MyType &, py_::return_value_policy, py_::handle) { diff --git a/tests/test_odr_guard_1.cpp b/tests/test_odr_guard_1.cpp index fb0703e14..bb55eec32 100644 --- a/tests/test_odr_guard_1.cpp +++ b/tests/test_odr_guard_1.cpp @@ -8,7 +8,7 @@ struct type_mrc { struct minimal_real_caster { static constexpr auto name = py::detail::const_name(); - static constexpr std::uint64_t universally_unique_identifier = 1000; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1000) static py::handle cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) { diff --git a/tests/test_odr_guard_2.cpp b/tests/test_odr_guard_2.cpp index 3fedb08ce..c67d99a5e 100644 --- a/tests/test_odr_guard_2.cpp +++ b/tests/test_odr_guard_2.cpp @@ -8,7 +8,7 @@ struct type_mrc { struct minimal_real_caster { static constexpr auto name = py::detail::const_name(); - static constexpr std::uint64_t universally_unique_identifier = 2000; + PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(2000) static py::handle cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) {