This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-06-20 17:03:43 -07:00
parent 55530437fc
commit 1522f57d2d
17 changed files with 73 additions and 68 deletions

View File

@ -55,7 +55,7 @@ inline std::unordered_map<std::type_index, std::uint64_t> &odr_guard_registry()
namespace { namespace {
template <typename IntrinsicType> template <typename IntrinsicType>
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<IntrinsicType>().c_str(), (long long) tc_id); printf("\nLOOOK %s %llu\n", type_id<IntrinsicType>().c_str(), (long long) tc_id);
fflush(stdout); fflush(stdout);
auto [reg_iter, added] = odr_guard_registry().insert({it_ti, tc_id}); auto [reg_iter, added] = odr_guard_registry().insert({it_ti, tc_id});
@ -73,10 +73,9 @@ struct type_caster_odr_guard : type_caster<IntrinsicType> {
}; };
template <typename IntrinsicType> template <typename IntrinsicType>
int type_caster_odr_guard<IntrinsicType>::translation_unit_local = [](){ int type_caster_odr_guard<IntrinsicType>::translation_unit_local = []() {
odr_guard_impl<IntrinsicType>( odr_guard_impl<IntrinsicType>(std::type_index(typeid(IntrinsicType)),
std::type_index(typeid(IntrinsicType)), type_caster<IntrinsicType>::universally_unique_identifier.value);
type_caster<IntrinsicType>::universally_unique_identifier);
return 0; return 0;
}(); }();
@ -85,6 +84,10 @@ int type_caster_odr_guard<IntrinsicType>::translation_unit_local = [](){
template <typename type> template <typename type>
using make_caster = type_caster_odr_guard<intrinsic_t<type>>; using make_caster = type_caster_odr_guard<intrinsic_t<type>>;
#define PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(...) \
if (::pybind11::detail::make_caster<__VA_ARGS__>::translation_unit_local) { \
}
template <typename T> template <typename T>
struct type_uses_smart_holder_type_caster { struct type_uses_smart_holder_type_caster {
static constexpr bool value 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 // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T
template <typename T> template <typename T>
typename make_caster<T>::template cast_op_type<T> cast_op(make_caster<T> &caster) { // LOOOK typename make_caster<T>::template cast_op_type<T> cast_op(make_caster<T> &caster) { // LOOOK
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return caster.operator typename make_caster<T>::template cast_op_type<T>(); return caster.operator typename make_caster<T>::template cast_op_type<T>();
} }
template <typename T> template <typename T>
typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type> typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>
cast_op(make_caster<T> &&caster) { // LOOOK cast_op(make_caster<T> &&caster) { // LOOOK
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return std::move(caster).operator typename make_caster<T>:: return std::move(caster).operator typename make_caster<T>::
template cast_op_type<typename std::add_rvalue_reference<T>::type>(); template cast_op_type<typename std::add_rvalue_reference<T>::type>();
} }
@ -124,7 +125,7 @@ private:
public: public:
bool load(handle src, bool convert) { return subcaster.load(src, convert); } bool load(handle src, bool convert) { return subcaster.load(src, convert); }
static constexpr auto name = caster_t::name; static constexpr auto name = caster_t::name;
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
static handle static handle
cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) { cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) {
// It is definitely wrong to take ownership of this pointer, so mask that rvp // 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<std::is_integral<T>::value>("int", "float")); PYBIND11_TYPE_CASTER(T, const_name<std::is_integral<T>::value>("int", "float"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
template <typename T> template <typename T>
@ -312,7 +313,7 @@ public:
return none().inc_ref(); return none().inc_ref();
} }
PYBIND11_TYPE_CASTER(T, const_name("None")); PYBIND11_TYPE_CASTER(T, const_name("None"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
template <> template <>
@ -360,7 +361,7 @@ public:
using cast_op_type = void *&; using cast_op_type = void *&;
explicit operator void *&() { return value; } explicit operator void *&() { return value; }
static constexpr auto name = const_name("capsule"); static constexpr auto name = const_name("capsule");
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
private: private:
void *value = nullptr; void *value = nullptr;
@ -417,7 +418,7 @@ public:
return handle(src ? Py_True : Py_False).inc_ref(); return handle(src ? Py_True : Py_False).inc_ref();
} }
PYBIND11_TYPE_CASTER(bool, const_name("bool")); 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: // 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)); 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: private:
static handle decode_utfN(const char *buffer, ssize_t nbytes) { 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 auto name = const_name(PYBIND11_STRING_NAME);
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
template <typename _T> template <typename _T>
using cast_op_type = pybind11::detail::cast_op_type<_T>; using cast_op_type = pybind11::detail::cast_op_type<_T>;
}; };
@ -728,7 +729,7 @@ public:
static constexpr auto name static constexpr auto name
= const_name("Tuple[") + concat(make_caster<Ts>::name...) + const_name("]"); = const_name("Tuple[") + concat(make_caster<Ts>::name...) + const_name("]");
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
template <typename T> template <typename T>
using cast_op_type = type; using cast_op_type = type;
@ -901,7 +902,7 @@ struct move_only_holder_caster {
return type_caster_base<type>::cast_holder(ptr, std::addressof(src)); return type_caster_base<type>::cast_holder(ptr, std::addressof(src));
} }
static constexpr auto name = type_caster_base<type>::name; static constexpr auto name = type_caster_base<type>::name;
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
@ -1011,7 +1012,7 @@ struct pyobject_caster {
return src.inc_ref(); return src.inc_ref();
} }
PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name); PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name);
static constexpr std::uint64_t universally_unique_identifier = 3434; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(3434)
}; };
template <typename T> template <typename T>
@ -1106,8 +1107,7 @@ type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &ha
// Wrapper around the above that also constructs and returns a type_caster // Wrapper around the above that also constructs and returns a type_caster
template <typename T> template <typename T>
make_caster<T> load_type(const handle &handle) { make_caster<T> load_type(const handle &handle) {
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
make_caster<T> conv; make_caster<T> conv;
load_type(conv, handle); load_type(conv, handle);
return conv; return conv;
@ -1145,8 +1145,7 @@ object cast(T &&value,
: std::is_lvalue_reference<T>::value ? return_value_policy::copy : std::is_lvalue_reference<T>::value ? return_value_policy::copy
: return_value_policy::move; : return_value_policy::move;
} }
if (detail::make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return reinterpret_steal<object>( return reinterpret_steal<object>(
detail::make_caster<T>::cast(std::forward<T>(value), policy, parent)); detail::make_caster<T>::cast(std::forward<T>(value), policy, parent));
} }
@ -1247,8 +1246,7 @@ using override_caster_t = conditional_t<cast_is_temporary_value_reference<ret_ty
template <typename T> template <typename T>
enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&o, enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&o,
make_caster<T> &caster) { make_caster<T> &caster) {
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return cast_op<T>(load_type(caster, o)); return cast_op<T>(load_type(caster, o));
} }
template <typename T> template <typename T>
@ -1360,8 +1358,7 @@ private:
type(type_id<T>()) type(type_id<T>())
#endif #endif
{ {
if (detail::make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
// Workaround! See: // Workaround! See:
// https://github.com/pybind/pybind11/issues/2336 // https://github.com/pybind/pybind11/issues/2336
// https://github.com/pybind/pybind11/pull/2685#issuecomment-731286700 // https://github.com/pybind/pybind11/pull/2685#issuecomment-731286700
@ -1592,8 +1589,7 @@ public:
private: private:
template <typename T> template <typename T>
void process(list &args_list, T &&x) { void process(list &args_list, T &&x) {
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
auto o = reinterpret_steal<object>( auto o = reinterpret_steal<object>(
detail::make_caster<T>::cast(std::forward<T>(x), policy, {})); detail::make_caster<T>::cast(std::forward<T>(x), policy, {}));
if (!o) { if (!o) {
@ -1738,8 +1734,7 @@ handle type::handle_of() {
detail::type_uses_smart_holder_type_caster<T>>::value, detail::type_uses_smart_holder_type_caster<T>>::value,
"py::type::of<T> only supports the case where T is a registered C++ types."); "py::type::of<T> only supports the case where T is a registered C++ types.");
if (detail::make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return detail::get_type_handle(typeid(T), true); return detail::get_type_handle(typeid(T), true);
} }

View File

@ -97,7 +97,7 @@ public:
} }
PYBIND11_TYPE_CASTER(type, const_name("datetime.timedelta")); 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) { inline std::tm *localtime_thread_safe(const std::time_t *time, std::tm *buf) {
@ -209,7 +209,7 @@ public:
us.count()); us.count());
} }
PYBIND11_TYPE_CASTER(type, const_name("datetime.datetime")); 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 // Other clocks that are not the system clock are not measured as datetime.datetime objects

View File

@ -69,7 +69,7 @@ public:
} }
PYBIND11_TYPE_CASTER(std::complex<T>, const_name("complex")); PYBIND11_TYPE_CASTER(std::complex<T>, 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(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -27,7 +27,7 @@ public:
using cast_op_type = value_and_holder &; using cast_op_type = value_and_holder &;
explicit operator value_and_holder &() { return *value; } explicit operator value_and_holder &() { return *value; }
static constexpr auto name = const_name<value_and_holder>(); static constexpr auto name = const_name<value_and_holder>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
private: private:
value_and_holder *value = nullptr; value_and_holder *value = nullptr;

View File

@ -616,7 +616,7 @@ template <typename T>
struct smart_holder_type_caster : smart_holder_type_caster_load<T>, struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks { smart_holder_type_caster_class_hooks {
static constexpr auto name = const_name<T>(); static constexpr auto name = const_name<T>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
// static handle cast(T, ...) // static handle cast(T, ...)
// is redundant (leads to ambiguous overloads). // is redundant (leads to ambiguous overloads).
@ -778,7 +778,7 @@ template <typename T>
struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_load<T>, struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks { smart_holder_type_caster_class_hooks {
static constexpr auto name = const_name<T>(); static constexpr auto name = const_name<T>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) { static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) {
switch (policy) { switch (policy) {
@ -843,7 +843,7 @@ template <typename T>
struct smart_holder_type_caster<std::shared_ptr<T const>> : smart_holder_type_caster_load<T>, struct smart_holder_type_caster<std::shared_ptr<T const>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks { smart_holder_type_caster_class_hooks {
static constexpr auto name = const_name<T>(); static constexpr auto name = const_name<T>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
static handle static handle
cast(const std::shared_ptr<T const> &src, return_value_policy policy, handle parent) { cast(const std::shared_ptr<T const> &src, return_value_policy policy, handle parent) {
@ -864,7 +864,7 @@ template <typename T, typename D>
struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caster_load<T>, struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks { smart_holder_type_caster_class_hooks {
static constexpr auto name = const_name<T>(); static constexpr auto name = const_name<T>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
static handle cast(std::unique_ptr<T, D> &&src, return_value_policy policy, handle parent) { static handle cast(std::unique_ptr<T, D> &&src, return_value_policy policy, handle parent) {
if (policy != return_value_policy::automatic if (policy != return_value_policy::automatic
@ -948,7 +948,7 @@ template <typename T, typename D>
struct smart_holder_type_caster<std::unique_ptr<T const, D>> struct smart_holder_type_caster<std::unique_ptr<T const, D>>
: smart_holder_type_caster_load<T>, smart_holder_type_caster_class_hooks { : smart_holder_type_caster_load<T>, smart_holder_type_caster_class_hooks {
static constexpr auto name = const_name<T>(); static constexpr auto name = const_name<T>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
static handle static handle
cast(std::unique_ptr<T const, D> &&src, return_value_policy policy, handle parent) { cast(std::unique_ptr<T const, D> &&src, return_value_policy policy, handle parent) {

View File

@ -904,6 +904,17 @@ struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {};
PYBIND11_NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
namespace {
template <std::uint64_t Value>
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 /// Generic type caster for objects stored on the heap
template <typename type> template <typename type>
class type_caster_base : public type_caster_generic { class type_caster_base : public type_caster_generic {
@ -911,7 +922,7 @@ class type_caster_base : public type_caster_generic {
public: public:
static constexpr auto name = const_name<type>(); static constexpr auto name = const_name<type>();
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
type_caster_base() : type_caster_base(typeid(type)) {} type_caster_base() : type_caster_base(typeid(type)) {}
explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) {} explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) {}

View File

@ -392,7 +392,7 @@ public:
} }
static constexpr auto name = props::descriptor; 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) // NOLINTNEXTLINE(google-explicit-constructor)
operator Type *() { return &value; } operator Type *() { return &value; }
@ -437,7 +437,7 @@ public:
} }
static constexpr auto name = props::descriptor; 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 // 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 // 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 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 // 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 // types but not bound arguments). We still provide them (with an explicitly delete) so that
@ -702,7 +702,7 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
const_name<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", const_name<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[",
"scipy.sparse.csc_matrix[") "scipy.sparse.csc_matrix[")
+ npy_format_descriptor<Scalar>::name + const_name("]")); + npy_format_descriptor<Scalar>::name + const_name("]"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)

View File

@ -124,7 +124,7 @@ public:
const_name("Callable[[") + concat(make_caster<Args>::name...) const_name("Callable[[") + concat(make_caster<Args>::name...)
+ const_name("], ") + make_caster<retval_type>::name + const_name("], ") + make_caster<retval_type>::name
+ const_name("]")); + const_name("]"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)

View File

@ -1214,7 +1214,7 @@ struct pyobject_caster<array_t<T, ExtraFlags>> {
return src.inc_ref(); return src.inc_ref();
} }
PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name); PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name);
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
template <typename T> template <typename T>

View File

@ -87,7 +87,7 @@ struct set_caster {
} }
PYBIND11_TYPE_CASTER(type, const_name("Set[") + key_conv::name + const_name("]")); 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 <typename Type, typename Key, typename Value> template <typename Type, typename Key, typename Value>
@ -137,7 +137,7 @@ struct map_caster {
PYBIND11_TYPE_CASTER(Type, PYBIND11_TYPE_CASTER(Type,
const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name
+ const_name("]")); + const_name("]"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
template <typename Type, typename Value> template <typename Type, typename Value>
@ -190,7 +190,7 @@ public:
} }
PYBIND11_TYPE_CASTER(Type, const_name("List[") + value_conv::name + const_name("]")); 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 <typename Type, typename Alloc> template <typename Type, typename Alloc>
@ -260,7 +260,7 @@ public:
const_name("[") + const_name<Size>() const_name("[") + const_name<Size>()
+ const_name("]")) + const_name("]"))
+ const_name("]")); + const_name("]"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
template <typename Type, size_t Size> template <typename Type, size_t Size>
@ -319,7 +319,7 @@ struct optional_caster {
} }
PYBIND11_TYPE_CASTER(Type, const_name("Optional[") + value_conv::name + const_name("]")); 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) #if defined(PYBIND11_HAS_OPTIONAL)
@ -349,8 +349,7 @@ struct variant_caster_visitor {
template <typename T> template <typename T>
result_type operator()(T &&src) const { result_type operator()(T &&src) const {
if (make_caster<T>::translation_unit_local) { PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T)
}
return make_caster<T>::cast(std::forward<T>(src), policy, parent); return make_caster<T>::cast(std::forward<T>(src), policy, parent);
} }
}; };
@ -408,7 +407,7 @@ struct variant_caster<V<Ts...>> {
PYBIND11_TYPE_CASTER(Type, PYBIND11_TYPE_CASTER(Type,
const_name("Union[") + detail::concat(make_caster<Ts>::name...) const_name("Union[") + detail::concat(make_caster<Ts>::name...)
+ const_name("]")); + const_name("]"));
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
}; };
#if defined(PYBIND11_HAS_VARIANT) #if defined(PYBIND11_HAS_VARIANT)

View File

@ -99,7 +99,7 @@ public:
} }
PYBIND11_TYPE_CASTER(T, const_name("os.PathLike")); 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) #endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)

View File

@ -61,7 +61,7 @@ template <>
class type_caster<RValueCaster> { class type_caster<RValueCaster> {
public: public:
PYBIND11_TYPE_CASTER(RValueCaster, const_name("RValueCaster")); 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) { static handle cast(RValueCaster &&, return_value_policy, handle) {
return py::str("rvalue").release(); return py::str("rvalue").release();
} }

View File

@ -28,7 +28,7 @@ template <>
class type_caster<ConstRefCasted> { class type_caster<ConstRefCasted> {
public: public:
static constexpr auto name = const_name<ConstRefCasted>(); static constexpr auto name = const_name<ConstRefCasted>();
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 // Input is unimportant, a new value will always be constructed based on the
// cast operator. // cast operator.

View File

@ -106,7 +106,7 @@ PYBIND11_NAMESPACE_BEGIN(detail)
template <> template <>
struct type_caster<MoveOnlyInt> { struct type_caster<MoveOnlyInt> {
PYBIND11_TYPE_CASTER(MoveOnlyInt, const_name("MoveOnlyInt")); 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) { bool load(handle src, bool) {
value = MoveOnlyInt(src.cast<int>()); value = MoveOnlyInt(src.cast<int>());
return true; return true;
@ -119,7 +119,7 @@ struct type_caster<MoveOnlyInt> {
template <> template <>
struct type_caster<MoveOrCopyInt> { struct type_caster<MoveOrCopyInt> {
PYBIND11_TYPE_CASTER(MoveOrCopyInt, const_name("MoveOrCopyInt")); 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) { bool load(handle src, bool) {
value = MoveOrCopyInt(src.cast<int>()); value = MoveOrCopyInt(src.cast<int>());
return true; return true;
@ -136,7 +136,7 @@ protected:
public: public:
static constexpr auto name = const_name("CopyOnlyInt"); 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) { bool load(handle src, bool) {
value = CopyOnlyInt(src.cast<int>()); value = CopyOnlyInt(src.cast<int>());
return true; return true;

View File

@ -32,7 +32,7 @@ public:
#else #else
PYBIND11_TYPE_CASTER(ArgInspector1, const_name("ArgInspector1")); PYBIND11_TYPE_CASTER(ArgInspector1, const_name("ArgInspector1"));
#endif #endif
static constexpr std::uint64_t universally_unique_identifier = 1655073597; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1655073597)
bool load(handle src, bool convert) { bool load(handle src, bool convert) {
value.arg = "loading ArgInspector1 argument " + std::string(convert ? "WITH" : "WITHOUT") value.arg = "loading ArgInspector1 argument " + std::string(convert ? "WITH" : "WITHOUT")
@ -50,7 +50,7 @@ template <>
struct type_caster<ArgInspector2> { struct type_caster<ArgInspector2> {
public: public:
PYBIND11_TYPE_CASTER(ArgInspector2, const_name("ArgInspector2")); 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) { bool load(handle src, bool convert) {
value.arg = "loading ArgInspector2 argument " + std::string(convert ? "WITH" : "WITHOUT") value.arg = "loading ArgInspector2 argument " + std::string(convert ? "WITH" : "WITHOUT")
@ -68,7 +68,7 @@ template <>
struct type_caster<ArgAlwaysConverts> { struct type_caster<ArgAlwaysConverts> {
public: public:
PYBIND11_TYPE_CASTER(ArgAlwaysConverts, const_name("ArgAlwaysConverts")); 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; } bool load(handle, bool convert) { return convert; }
@ -100,7 +100,7 @@ namespace detail {
template <> template <>
struct type_caster<DestructionTester> { struct type_caster<DestructionTester> {
PYBIND11_TYPE_CASTER(DestructionTester, const_name("DestructionTester")); 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; } bool load(handle, bool) { return true; }
static handle cast(const DestructionTester &, return_value_policy, handle) { 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. // don't have any symbol collision when using macro mixin.
struct my_caster { struct my_caster {
PYBIND11_TYPE_CASTER(MyType, py_::detail::const_name("MyType")); 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; } bool load(py_::handle, bool) { return true; }
static py_::handle cast(const MyType &, py_::return_value_policy, py_::handle) { static py_::handle cast(const MyType &, py_::return_value_policy, py_::handle) {

View File

@ -8,7 +8,7 @@ struct type_mrc {
struct minimal_real_caster { struct minimal_real_caster {
static constexpr auto name = py::detail::const_name<type_mrc>(); static constexpr auto name = py::detail::const_name<type_mrc>();
static constexpr std::uint64_t universally_unique_identifier = 1000; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(1000)
static py::handle static py::handle
cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) { cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) {

View File

@ -8,7 +8,7 @@ struct type_mrc {
struct minimal_real_caster { struct minimal_real_caster {
static constexpr auto name = py::detail::const_name<type_mrc>(); static constexpr auto name = py::detail::const_name<type_mrc>();
static constexpr std::uint64_t universally_unique_identifier = 2000; PYBIND11_TYPE_CASTER_UNIQUE_IDENTIFIER(2000)
static py::handle static py::handle
cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) { cast(type_mrc const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) {