From 309a85ba59879bde27ca25111d3fc48f46cf9bbc Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 8 Mar 2016 17:59:10 +0100 Subject: [PATCH] support std::shared_ptr and types that indirectly derive from std::enable_shared_from_this --- include/pybind11/cast.h | 4 ++-- include/pybind11/pybind11.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 5dda8f7d..38918ee8 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -204,7 +204,7 @@ public: protected: template ::value, int>::type = 0> static void *copy_constructor(const void *arg) { - return new type(*((const type *) arg)); + return (void *) new type(*((const type *) arg)); } template ::value, int>::type = 0> static void *copy_constructor(const void *) { return nullptr; } @@ -508,7 +508,7 @@ public: return true; } else if (PyType_IsSubtype(Py_TYPE(src.ptr()), typeinfo->type)) { auto inst = (instance *) src.ptr(); - value = inst->value; + value = (void *) inst->value; holder = inst->holder; return true; } diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index c78f1e22..4cf8ead1 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -864,7 +864,7 @@ private: template static void init_holder_helper(instance_type *inst, const holder_type * /* unused */, const std::enable_shared_from_this * /* dummy */) { try { - new (&inst->holder) holder_type(inst->value->shared_from_this()); + new (&inst->holder) holder_type(std::static_pointer_cast(inst->value->shared_from_this())); } catch (const std::bad_weak_ptr &) { new (&inst->holder) holder_type(inst->value); }