|
@@ -14,6 +14,7 @@
|
|
|
#include "descr.h"
|
|
|
#include "internals.h"
|
|
|
#include "typeid.h"
|
|
|
+#include "value_and_holder.h"
|
|
|
|
|
|
#include <cstdint>
|
|
|
#include <iterator>
|
|
@@ -260,67 +261,6 @@ PYBIND11_NOINLINE handle find_registered_python_instance(void *src,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-struct value_and_holder {
|
|
|
- instance *inst = nullptr;
|
|
|
- size_t index = 0u;
|
|
|
- const detail::type_info *type = nullptr;
|
|
|
- void **vh = nullptr;
|
|
|
-
|
|
|
- // Main constructor for a found value/holder:
|
|
|
- value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
|
|
|
- : inst{i}, index{index}, type{type},
|
|
|
- vh{inst->simple_layout ? inst->simple_value_holder
|
|
|
- : &inst->nonsimple.values_and_holders[vpos]} {}
|
|
|
-
|
|
|
- // Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
|
|
|
- value_and_holder() = default;
|
|
|
-
|
|
|
- // Used for past-the-end iterator
|
|
|
- explicit value_and_holder(size_t index) : index{index} {}
|
|
|
-
|
|
|
- template <typename V = void>
|
|
|
- V *&value_ptr() const {
|
|
|
- return reinterpret_cast<V *&>(vh[0]);
|
|
|
- }
|
|
|
- // True if this `value_and_holder` has a non-null value pointer
|
|
|
- explicit operator bool() const { return value_ptr() != nullptr; }
|
|
|
-
|
|
|
- template <typename H>
|
|
|
- H &holder() const {
|
|
|
- return reinterpret_cast<H &>(vh[1]);
|
|
|
- }
|
|
|
- bool holder_constructed() const {
|
|
|
- return inst->simple_layout
|
|
|
- ? inst->simple_holder_constructed
|
|
|
- : (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
|
|
|
- }
|
|
|
- // NOLINTNEXTLINE(readability-make-member-function-const)
|
|
|
- void set_holder_constructed(bool v = true) {
|
|
|
- if (inst->simple_layout) {
|
|
|
- inst->simple_holder_constructed = v;
|
|
|
- } else if (v) {
|
|
|
- inst->nonsimple.status[index] |= instance::status_holder_constructed;
|
|
|
- } else {
|
|
|
- inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
|
|
|
- }
|
|
|
- }
|
|
|
- bool instance_registered() const {
|
|
|
- return inst->simple_layout
|
|
|
- ? inst->simple_instance_registered
|
|
|
- : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
|
|
|
- }
|
|
|
- // NOLINTNEXTLINE(readability-make-member-function-const)
|
|
|
- void set_instance_registered(bool v = true) {
|
|
|
- if (inst->simple_layout) {
|
|
|
- inst->simple_instance_registered = v;
|
|
|
- } else if (v) {
|
|
|
- inst->nonsimple.status[index] |= instance::status_instance_registered;
|
|
|
- } else {
|
|
|
- inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
|
|
|
- }
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
// Container for accessing and iterating over an instance's values/holders
|
|
|
struct values_and_holders {
|
|
|
private:
|
|
@@ -496,7 +436,7 @@ PYBIND11_NOINLINE void instance::allocate_layout() {
|
|
|
// NOLINTNEXTLINE(readability-make-member-function-const)
|
|
|
PYBIND11_NOINLINE void instance::deallocate_layout() {
|
|
|
if (!simple_layout) {
|
|
|
- PyMem_Free(nonsimple.values_and_holders);
|
|
|
+ PyMem_Free(reinterpret_cast<void *>(nonsimple.values_and_holders));
|
|
|
}
|
|
|
}
|
|
|
|