From ae388893229ef87bda4395c79abb349c853db24b Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 1 Jul 2022 18:15:32 -0700 Subject: [PATCH] Remove PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL macro completely. --- include/pybind11/cast.h | 17 +---------------- include/pybind11/detail/type_caster_odr_guard.h | 4 ---- include/pybind11/pybind11.h | 7 ++----- include/pybind11/stl.h | 1 - 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 8cf42721a..9f94f2902 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -69,13 +69,11 @@ 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) { - 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) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return std::move(caster).operator typename make_caster:: template cast_op_type::type>(); } @@ -95,15 +93,11 @@ private: "`operator T &()` or `operator const T &()`"); public: - bool load(handle src, bool convert) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type) - return subcaster.load(src, convert); - } + bool load(handle src, bool convert) { return subcaster.load(src, convert); } static constexpr auto name = caster_t::name; PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE static handle cast(const std::reference_wrapper &src, return_value_policy policy, handle parent) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type) // It is definitely wrong to take ownership of this pointer, so mask that rvp if (policy == return_value_policy::take_ownership || policy == return_value_policy::automatic) { @@ -580,7 +574,6 @@ struct type_caster::value>> { public: bool load(handle src, bool convert) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType) if (!src) { return false; } @@ -596,7 +589,6 @@ public: } static handle cast(const CharT *src, return_value_policy policy, handle parent) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType) if (src == nullptr) { return pybind11::none().inc_ref(); } @@ -604,7 +596,6 @@ public: } static handle cast(CharT src, return_value_policy policy, handle parent) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType) if (std::is_same::value) { handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr); if (!s) { @@ -1098,7 +1089,6 @@ make_caster_intrinsic &load_type(make_caster_intrinsic &conv, const handle // Wrapper around the above that also constructs and returns a type_caster template make_caster load_type(const handle &handle) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) make_caster conv; load_type(conv, handle); return conv; @@ -1136,7 +1126,6 @@ object cast(T &&value, : std::is_lvalue_reference::value ? return_value_policy::copy : return_value_policy::move; } - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return reinterpret_steal( detail::make_caster::cast(std::forward(value), policy, parent)); } @@ -1237,7 +1226,6 @@ using override_caster_t = conditional_t enable_if_t::value, T> cast_ref(object &&o, make_caster &caster) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return cast_op(load_type(caster, o)); } template @@ -1349,7 +1337,6 @@ private: type(type_id()) #endif { - 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 @@ -1580,7 +1567,6 @@ public: private: template void process(list &args_list, T &&x) { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) auto o = reinterpret_steal( detail::make_caster::cast(std::forward(x), policy, {})); if (!o) { @@ -1725,7 +1711,6 @@ 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."); - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return detail::get_type_handle(typeid(T), true); } diff --git a/include/pybind11/detail/type_caster_odr_guard.h b/include/pybind11/detail/type_caster_odr_guard.h index bfe28a79b..3ec839c87 100644 --- a/include/pybind11/detail/type_caster_odr_guard.h +++ b/include/pybind11/detail/type_caster_odr_guard.h @@ -19,8 +19,6 @@ # define PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE -# define PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(...) - #else # if !defined(PYBIND11_CPP20) && defined(__GNUC__) && !defined(__clang__) @@ -211,6 +209,4 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) static constexpr auto source_file_line \ = ::pybind11::detail::tu_local_const_name(__FILE__ ":" PYBIND11_TOSTRING(__LINE__)); -# define PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(...) - #endif diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 03681f1d1..382f4bb92 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -213,9 +213,8 @@ protected: /* Type casters for the function arguments and return value */ using cast_in = argument_loader; - using make_caster_type_out = conditional_t::value, void_type, Return>; - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(make_caster_type_out) - using cast_out = make_caster; + using cast_out + = make_caster::value, void_type, Return>>; static_assert( expected_num_args( @@ -1855,7 +1854,6 @@ public: auto *ptr = new capture{std::forward(func)}; install_buffer_funcs( [](PyObject *obj, void *ptr) -> buffer_info * { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type) detail::make_caster caster; if (!caster.load(obj, false)) { return nullptr; @@ -2717,7 +2715,6 @@ void implicitly_convertible() { return nullptr; } set_flag flag_helper(currently_used); - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(InputType) if (!detail::make_caster().load(obj, false)) { return nullptr; } diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 6fe0bea37..ab30ecac0 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -344,7 +344,6 @@ struct variant_caster_visitor { template result_type operator()(T &&src) const { - PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(T) return make_caster::cast(std::forward(src), policy, parent); } };