diff --git a/include/nanobind/nb_class.h b/include/nanobind/nb_class.h index 6ddff294..6825c987 100644 --- a/include/nanobind/nb_class.h +++ b/include/nanobind/nb_class.h @@ -58,16 +58,10 @@ enum class type_flags : uint32_t { /// The class implements __class_getitem__ similar to typing.Generic is_generic = (1 << 15), - /// Is this an arithmetic enumeration? - is_arithmetic = (1 << 16), - - /// Is the number type underlying the enumeration signed? - is_signed = (1 << 17), - /// Does the type implement a custom __new__ operator? - has_new = (1 << 18) + has_new = (1 << 16) - // No more bits bits available without needing a larger reorganization + // Two more bits bits available without needing a larger reorganization }; /// Flags about a type that are only relevant when it is being created. @@ -192,6 +186,14 @@ NB_INLINE void type_extra_apply(type_init_data &t, supplement) { t.supplement = sizeof(T); } +enum class enum_flags : uint32_t { + /// Is this an arithmetic enumeration? + is_arithmetic = (1 << 1), + + /// Is the number type underlying the enumeration signed? + is_signed = (1 << 2) +}; + struct enum_init_data { const std::type_info *type; PyObject *scope; @@ -201,7 +203,7 @@ struct enum_init_data { }; NB_INLINE void enum_extra_apply(enum_init_data &e, is_arithmetic) { - e.flags |= (uint32_t) type_flags::is_arithmetic; + e.flags |= (uint32_t) enum_flags::is_arithmetic; } NB_INLINE void enum_extra_apply(enum_init_data &e, const char *doc) { @@ -719,7 +721,7 @@ template class enum_ : public object { ed.scope = scope.ptr(); ed.name = name; ed.flags = std::is_signed_v - ? (uint32_t) detail::type_flags::is_signed + ? (uint32_t) detail::enum_flags::is_signed : 0; (detail::enum_extra_apply(ed, extra), ...); m_ptr = detail::enum_create(&ed); diff --git a/src/nb_enum.cpp b/src/nb_enum.cpp index d81d415d..2969be9e 100644 --- a/src/nb_enum.cpp +++ b/src/nb_enum.cpp @@ -27,7 +27,7 @@ PyObject *enum_create(enum_init_data *ed) noexcept { handle scope(ed->scope); - bool is_arithmetic = ed->flags & (uint32_t) type_flags::is_arithmetic; + bool is_arithmetic = ed->flags & (uint32_t) enum_flags::is_arithmetic; str name(ed->name), qualname = name; object modname; @@ -99,7 +99,7 @@ void enum_append(PyObject *tp_, const char *name_, int64_t value_, type_data *t = enum_get_type_data(tp); object val; - if (t->flags & (uint32_t) type_flags::is_signed) + if (t->flags & (uint32_t) enum_flags::is_signed) val = steal(PyLong_FromLongLong((long long) value_)); else val = steal(PyLong_FromUnsignedLongLong((unsigned long long) value_)); @@ -161,7 +161,7 @@ bool enum_from_python(const std::type_info *tp, PyObject *o, int64_t *out, uint8 if (flags & (uint8_t) cast_flags::convert) { enum_map *fwd = (enum_map *) t->enum_tbl.fwd; - if (t->flags & (uint32_t) type_flags::is_signed) { + if (t->flags & (uint32_t) enum_flags::is_signed) { long long value = PyLong_AsLongLong(o); if (value == -1 && PyErr_Occurred()) { PyErr_Clear(); @@ -204,7 +204,7 @@ PyObject *enum_from_cpp(const std::type_info *tp, int64_t key) noexcept { return value; } - if (t->flags & (uint32_t) type_flags::is_signed) + if (t->flags & (uint32_t) enum_flags::is_signed) PyErr_Format(PyExc_ValueError, "%lli is not a valid %s.", (long long) key, t->name); else