Fixing up cast.h and smart_holder.h after rebase.

parent 6ed9cc90
......@@ -13,8 +13,8 @@
#include "pytypes.h"
#include "detail/common.h"
#include "detail/descr.h"
#include "detail/type_caster_base.h"
#include "detail/typeid.h"
#include "detail/internals.h"
#include "detail/smart_holder_poc.h"
#include <array>
#include <cstring>
#include <functional>
......@@ -45,6 +45,9 @@
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
using pybindit::memory::smart_holder;
PYBIND11_NAMESPACE_BEGIN(detail)
/// A life support system for temporary objects created by `type_caster::load()`.
......@@ -1239,8 +1242,10 @@ struct smart_holder_type_caster_load {
return std::shared_ptr<T>(void_ptr, convert_type(void_ptr.get()));
}
std::unique_ptr<T> loaded_as_unique_ptr() {
holder().ensure_can_release_ownership();
template <typename D = std::default_delete<T>>
std::unique_ptr<T, D> loaded_as_unique_ptr(const char *context = "loaded_as_unique_ptr") {
holder().template ensure_compatible_rtti_uqp_del<T, D>(context);
holder().ensure_use_count_1(context);
auto raw_void_ptr = holder().template as_raw_ptr_unowned<void>();
// MISSING: Safety checks for type conversions
// (T must be polymorphic or meet certain other conditions).
......@@ -1248,7 +1253,7 @@ struct smart_holder_type_caster_load {
// Critical transfer-of-ownership section. This must stay together.
holder().release_ownership();
auto result = std::unique_ptr<T>(raw_type_ptr);
auto result = std::unique_ptr<T, D>(raw_type_ptr);
void *value_void_ptr
= load_impl.loaded_v_h.value_ptr(); // Expected to be identical to raw_void_ptr.
......@@ -1503,12 +1508,12 @@ struct smart_holder_type_caster<std::shared_ptr<T const>> : smart_holder_type_ca
operator std::shared_ptr<T const>() { return this->loaded_as_shared_ptr(); } // Mutbl2Const
};
template <typename T>
struct smart_holder_type_caster<std::unique_ptr<T>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks {
static constexpr auto name = _<std::unique_ptr<T>>();
template <typename T, typename D>
struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks {
static constexpr auto name = _<std::unique_ptr<T, D>>();
static handle cast(std::unique_ptr<T> &&src, return_value_policy policy, handle parent) {
static handle cast(std::unique_ptr<T, D> &&src, return_value_policy policy, handle parent) {
if (policy != return_value_policy::automatic
&& policy != return_value_policy::reference_internal) {
// IMPROVABLE: Error message.
......@@ -1541,27 +1546,28 @@ struct smart_holder_type_caster<std::unique_ptr<T>> : smart_holder_type_caster_l
}
template <typename>
using cast_op_type = std::unique_ptr<T>;
using cast_op_type = std::unique_ptr<T, D>;
operator std::unique_ptr<T>() { return this->loaded_as_unique_ptr(); }
operator std::unique_ptr<T, D>() { return this->template loaded_as_unique_ptr<D>(); }
};
template <typename T>
struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_caster_load<T>,
smart_holder_type_caster_class_hooks {
static constexpr auto name = _<std::unique_ptr<T const>>();
template <typename T, typename D>
struct smart_holder_type_caster<std::unique_ptr<T const, D>>
: smart_holder_type_caster_load<T>, smart_holder_type_caster_class_hooks {
static constexpr auto name = _<std::unique_ptr<T const, D>>();
static handle cast(std::unique_ptr<T const> &&src, return_value_policy policy, handle parent) {
return smart_holder_type_caster<std::unique_ptr<T>>::cast(
std::unique_ptr<T>(const_cast<T *>(src.release())), // Const2Mutbl
static handle
cast(std::unique_ptr<T const, D> &&src, return_value_policy policy, handle parent) {
return smart_holder_type_caster<std::unique_ptr<T, D>>::cast(
std::unique_ptr<T, D>(const_cast<T *>(src.release())), // Const2Mutbl
policy,
parent);
}
template <typename>
using cast_op_type = std::unique_ptr<T const>;
using cast_op_type = std::unique_ptr<T const, D>;
operator std::unique_ptr<T const>() { return this->loaded_as_unique_ptr(); }
operator std::unique_ptr<T const, D>() { return this->template loaded_as_unique_ptr<D>(); }
};
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
......@@ -1576,12 +1582,12 @@ struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_ca
template <> \
class type_caster<std::shared_ptr<T const>> \
: public smart_holder_type_caster<std::shared_ptr<T const>> {}; \
template <> \
class type_caster<std::unique_ptr<T>> : public smart_holder_type_caster<std::unique_ptr<T>> { \
}; \
template <> \
class type_caster<std::unique_ptr<T const>> \
: public smart_holder_type_caster<std::unique_ptr<T const>> {}; \
template <typename D> \
class type_caster<std::unique_ptr<T, D>> \
: public smart_holder_type_caster<std::unique_ptr<T, D>> {}; \
template <typename D> \
class type_caster<std::unique_ptr<T const, D>> \
: public smart_holder_type_caster<std::unique_ptr<T const, D>> {}; \
} \
}
#endif
......@@ -1603,12 +1609,13 @@ template <typename T>
class type_caster<std::shared_ptr<T const>>
: public smart_holder_type_caster<std::shared_ptr<T const>> {};
template <typename T>
class type_caster<std::unique_ptr<T>> : public smart_holder_type_caster<std::unique_ptr<T>> {};
template <typename T, typename D>
class type_caster<std::unique_ptr<T, D>>
: public smart_holder_type_caster<std::unique_ptr<T, D>> {};
template <typename T>
class type_caster<std::unique_ptr<T const>>
: public smart_holder_type_caster<std::unique_ptr<T const>> {};
template <typename T, typename D>
class type_caster<std::unique_ptr<T const, D>>
: public smart_holder_type_caster<std::unique_ptr<T const, D>> {};
#define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T)
......
......@@ -4,7 +4,6 @@
#pragma once
#include "detail/smart_holder_type_casters.h"
#include "pybind11.h"
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment