Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move native_enum_type_map into internals and remove cross_extension_shared_states feature. #30140

Merged
merged 3 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ endif()

# NB: when adding a header don't forget to also add it to setup.py
set(PYBIND11_HEADERS
include/pybind11/detail/abi_platform_id.h
include/pybind11/detail/class.h
include/pybind11/detail/common.h
include/pybind11/detail/cross_extension_shared_state.h
include/pybind11/detail/descr.h
include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h
include/pybind11/detail/function_record_pyobject.h
Expand All @@ -162,7 +160,6 @@ set(PYBIND11_HEADERS
include/pybind11/detail/smart_holder_type_casters.h
include/pybind11/detail/type_caster_base.h
include/pybind11/detail/type_caster_odr_guard.h
include/pybind11/detail/type_map.h
include/pybind11/detail/typeid.h
include/pybind11/detail/value_and_holder.h
include/pybind11/attr.h
Expand Down
28 changes: 13 additions & 15 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class type_caster_enum_type {

template <typename SrcType>
static handle cast(SrcType &&src, return_value_policy, handle parent) {
auto const &natives = cross_extension_shared_states::native_enum_type_map::get();
auto found = natives.find(std::type_index(typeid(EnumType)));
if (found != natives.end()) {
return handle(found->second)(static_cast<Underlying>(src)).release();
handle native_enum
= global_internals_native_enum_type_map_get_item(std::type_index(typeid(EnumType)));
if (native_enum) {
return native_enum(static_cast<Underlying>(src)).release();
}
return type_caster_for_class_<EnumType>::cast(
std::forward<SrcType>(src),
Expand All @@ -101,10 +101,10 @@ class type_caster_enum_type {
}

bool load(handle src, bool convert) {
auto const &natives = cross_extension_shared_states::native_enum_type_map::get();
auto found = natives.find(std::type_index(typeid(EnumType)));
if (found != natives.end()) {
if (!isinstance(src, found->second)) {
handle native_enum
= global_internals_native_enum_type_map_get_item(std::type_index(typeid(EnumType)));
if (native_enum) {
if (!isinstance(src, native_enum)) {
return false;
}
type_caster<Underlying> underlying_caster;
Expand Down Expand Up @@ -180,12 +180,11 @@ struct type_caster_classh_enum_aware<

template <typename T, detail::enable_if_t<std::is_enum<T>::value, int> = 0>
bool isinstance_native_enum_impl(handle obj, const std::type_info &tp) {
auto const &natives = cross_extension_shared_states::native_enum_type_map::get();
auto found = natives.find(tp);
if (found == natives.end()) {
handle native_enum = global_internals_native_enum_type_map_get_item(tp);
if (!native_enum) {
return false;
}
return isinstance(obj, found->second);
return isinstance(obj, native_enum);
}

template <typename T, detail::enable_if_t<!std::is_enum<T>::value, int> = 0>
Expand Down Expand Up @@ -1351,9 +1350,8 @@ T cast(const handle &handle) {
"Unable to cast type to reference: value is local to type caster");
#ifndef NDEBUG
if (is_enum_cast && cast_is_temporary_value_reference<T>::value) {
if (cross_extension_shared_states::native_enum_type_map::get().count(
std::type_index(typeid(intrinsic_t<T>)))
!= 0) {
if (detail::global_internals_native_enum_type_map_contains(
std::type_index(typeid(intrinsic_t<T>)))) {
pybind11_fail("Unable to cast native enum type to reference");
}
}
Expand Down
112 changes: 0 additions & 112 deletions include/pybind11/detail/abi_platform_id.h

This file was deleted.

143 changes: 0 additions & 143 deletions include/pybind11/detail/cross_extension_shared_state.h

This file was deleted.

3 changes: 2 additions & 1 deletion include/pybind11/detail/function_record_pyobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../attr.h"
#include "../pytypes.h"
#include "common.h"
#include "internals.h"

#include <cstring>

Expand Down Expand Up @@ -45,7 +46,7 @@ PYBIND11_WARNING_POP
// Note that this name is versioned.
constexpr char tp_name_impl[]
= "pybind11_detail_function_record_" PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID
"_" PYBIND11_PLATFORM_ABI_ID_V4;
PYBIND11_INTERNALS_ID;

PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods)

Expand Down
Loading