From 338d615e12ce41ee021724551841de3cbe0bc1df Mon Sep 17 00:00:00 2001 From: ffreckle Date: Thu, 15 Feb 2018 17:38:57 -0800 Subject: [PATCH] Temporary fix for the return value cast problem. pybind11::cast_error: return_value_policy = copy, but the object is non-copyable! May be the same/related issue as described here: https://github.com/pybind/pybind11/issues/1241 --- include/pybind11/cast.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 3ec6f7288c..f96d6aec75 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -530,13 +530,14 @@ class type_caster_generic { break; case return_value_policy::copy: - if (copy_constructor) + if (copy_constructor) { valueptr = copy_constructor(src); - else - throw cast_error("return_value_policy = copy, but the " - "object is non-copyable!"); - wrapper->owned = true; - break; + wrapper->owned = true; + } else { // Instead of throwing an error, treat as if return_value_policy::reference. + valueptr = src; + wrapper->owned = false; + } + break; case return_value_policy::move: if (move_constructor)