Manually picked diffs for pybind11.h (from remove_cross_extension_shared_state)

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-31 14:21:27 -07:00
parent a4c5ab4b24
commit cae3cf99b6

View File

@ -13,6 +13,7 @@
#include "detail/class.h"
#include "detail/dynamic_raw_ptr_cast_if_possible.h"
#include "detail/init.h"
#include "detail/native_enum_data.h"
#include "detail/using_smart_holder.h"
#include "attr.h"
#include "gil.h"
@ -1352,6 +1353,11 @@ public:
// For Python 2, reinterpret_borrow was correct.
return reinterpret_borrow<module_>(m);
}
module_ &operator+=(const detail::native_enum_data &data) {
detail::native_enum_add_to_parent(*this, data);
return *this;
}
};
PYBIND11_NAMESPACE_BEGIN(detail)
@ -2161,6 +2167,11 @@ public:
return *this;
}
class_ &operator+=(const detail::native_enum_data &data) {
detail::native_enum_add_to_parent(*this, data);
return *this;
}
private:
/// Initialize holder object, variant 1: object derives from enable_shared_from_this
template <typename T>
@ -2619,6 +2630,14 @@ public:
template <typename... Extra>
enum_(const handle &scope, const char *name, const Extra &...extra)
: class_<Type>(scope, name, extra...), m_base(*this, scope) {
{
if (detail::global_internals_native_enum_type_map_contains(
std::type_index(typeid(Type)))) {
pybind11_fail("pybind11::enum_ \"" + std::string(name)
+ "\" is already registered as a pybind11::native_enum!");
}
}
constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
constexpr bool is_convertible = std::is_convertible<Type, Underlying>::value;
m_base.init(is_arithmetic, is_convertible);