Sisyphus repositório
Última atualização: 31 maio 2020 | SRPMs: 17572 | Visitas: 18656699
en ru br
ALT Linux repositórios
S:2.5.0-alt1

Group :: Desenvolvimento/Outros
RPM: pybind11

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs e FR  Repocop 

Patch: alt-e2k-workaround-for-missing-copy-elision.patch
Download


diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h
index 605acb3..0aab878 100644
--- a/include/pybind11/cast.h
+++ b/include/pybind11/cast.h
@@ -18,6 +18,7 @@
 #include <limits>
 #include <tuple>
 #include <type_traits>
+#include <utility>
 
 #if defined(PYBIND11_CPP17)
 #  if defined(__has_include)
@@ -1657,7 +1658,7 @@ template <typename T> make_caster<T> load_type(const handle &handle) {
 NAMESPACE_END(detail)
 
 // pytype -> C++ type
-template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
+template <typename T, detail::enable_if_t<std::is_copy_constructible<T>::value && (!detail::is_pyobject<T>::value), int> = 0>
 T cast(const handle &handle) {
     using namespace detail;
     static_assert(!cast_is_temporary_value_reference<T>::value,
@@ -1665,12 +1666,25 @@ T cast(const handle &handle) {
     return cast_op<T>(load_type<T>(handle));
 }
 
+// pytype -> C++ type
+template <typename T, detail::enable_if_t<(!std::is_copy_constructible<T>::value) && (!detail::is_pyobject<T>::value), int> = 0>
+T cast(const handle &handle) {
+    using namespace detail;
+    static_assert(!cast_is_temporary_value_reference<T>::value,
+            "Unable to cast type to reference: value is local to type caster");
+    return std::move(cast_op<T>(load_type<T>(handle)));
+}
+
 // pytype -> pytype (calls converting constructor)
-template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>
+template <typename T, detail::enable_if_t<std::is_copy_constructible<T>::value && detail::is_pyobject<T>::value, int> = 0>
 T cast(const handle &handle) { return T(reinterpret_borrow<object>(handle)); }
 
+// pytype -> pytype (calls converting constructor)
+template <typename T, detail::enable_if_t<(!std::is_copy_constructible<T>::value) && detail::is_pyobject<T>::value, int> = 0>
+T cast(const handle &handle) { return std::move(T(std::move(reinterpret_borrow<object>(handle)))); }
+
 // C++ type -> py::object
-template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
+template <typename T, detail::enable_if_t<std::is_copy_constructible<T>::value && (!detail::is_pyobject<T>::value), int> = 0>
 object cast(const T &value, return_value_policy policy = return_value_policy::automatic_reference,
             handle parent = handle()) {
     if (policy == return_value_policy::automatic)
@@ -1680,6 +1694,17 @@ object cast(const T &value, return_value_policy policy = return_value_policy::au
     return reinterpret_steal<object>(detail::make_caster<T>::cast(value, policy, parent));
 }
 
+// C++ type -> py::object
+template <typename T, detail::enable_if_t<(!std::is_copy_constructible<T>::value) && (!detail::is_pyobject<T>::value), int> = 0>
+object cast(const T &value, return_value_policy policy = return_value_policy::automatic_reference,
+            handle parent = handle()) {
+    if (policy == return_value_policy::automatic)
+        policy = std::is_pointer<T>::value ? return_value_policy::take_ownership : return_value_policy::copy;
+    else if (policy == return_value_policy::automatic_reference)
+        policy = std::is_pointer<T>::value ? return_value_policy::reference : return_value_policy::copy;
+    return std::move(reinterpret_steal<object>(std::move(detail::make_caster<T>::cast(value, policy, parent))));
+}
+
 template <typename T> T handle::cast() const { return pybind11::cast<T>(*this); }
 template <> inline void handle::cast() const { return; }
 
diff --git a/tests/test_factory_constructors.py b/tests/test_factory_constructors.py
index 78a3910..d561473 100644
--- a/tests/test_factory_constructors.py
+++ b/tests/test_factory_constructors.py
@@ -1,5 +1,6 @@
 import pytest
 import re
+import os
 
 from pybind11_tests import factory_constructors as m
 from pybind11_tests.factory_constructors import tag
@@ -330,6 +331,7 @@ def strip_comments(s):
     return re.sub(r'\s+#.*', '', s)
 
 
+@pytest.mark.skipif('SKIP_E2K' in os.environ, reason="forced test skip")
 def test_reallocations(capture, msg):
     """When the constructor is overloaded, previous overloads can require a preallocated value.
     This test makes sure that such preallocated values only happen when they might be necessary,
diff --git a/tests/test_virtual_functions.py b/tests/test_virtual_functions.py
index 5ce9abd..68ed253 100644
--- a/tests/test_virtual_functions.py
+++ b/tests/test_virtual_functions.py
@@ -1,4 +1,5 @@
 import pytest
+import os
 
 from pybind11_tests import virtual_functions as m
 from pybind11_tests import ConstructorStats
@@ -161,6 +162,7 @@ def test_alias_delay_initialization2(capture):
 # to fail in ncv1.print_nc()
 @pytest.unsupported_on_pypy
 @pytest.mark.skipif(not hasattr(m, "NCVirt"), reason="NCVirt test broken on ICPC")
+@pytest.mark.skipif('SKIP_E2K' in os.environ, reason="forced test skip")
 def test_move_support():
     class NCVirtExt(m.NCVirt):
         def get_noncopyable(self, a, b):
 
projeto & código: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
mantenedor atual: Michael Shigorin
mantenedor da tradução: Fernando Martini aka fmartini © 2009