fix regression in python binding for move_storage()
authorarvidn <arvid@libtorrent.org>
Fri, 30 Apr 2021 05:51:42 +0000 (06:51 +0100)
committerPetter Reinholdtsen <pere@debian.org>
Fri, 30 Apr 2021 05:51:42 +0000 (06:51 +0100)
Origin: upstream, commit 386596aa88a19dcba3d4f5925dbce3c517065ea2
Last-Update: 2021-04-30
Bugs-Debian: https://bugs.debian.org/987306

Gbp-Pq: Name 0001-python-move-storage.patch

bindings/python/src/converters.cpp

index 68ca2cf663b2b6375dbd96150c972be3396ea8f6..7d9eb1f9bc40029c460931995d2793d767d53f70 100644 (file)
@@ -23,6 +23,7 @@
 #include "libtorrent/peer_class.hpp"
 #include "libtorrent/pex_flags.hpp"
 #include "libtorrent/string_view.hpp"
+#include "libtorrent/storage_defs.hpp"
 #include <vector>
 #include <map>
 
@@ -342,6 +343,30 @@ struct to_strong_typedef
     }
 };
 
+template<typename T>
+struct to_enum_class
+{
+   using underlying_type = typename std::underlying_type<T>::type;
+
+   to_enum_class()
+   {
+        converter::registry::push_back(
+            &convertible, &construct, type_id<T>()
+        );
+    }
+
+    static void* convertible(PyObject* x)
+    {
+        return PyNumber_Check(x) ? x : nullptr;
+    }
+
+    static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
+    {
+        void* storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
+        data->convertible = new (storage) T(static_cast<T>(static_cast<underlying_type>(extract<underlying_type>(object(borrowed(x))))));
+    }
+};
+
 template<class T>
 struct from_bitfield_flag
 {
@@ -495,6 +520,7 @@ void bind_converters()
     to_strong_typedef<lt::file_index_t>();
     to_strong_typedef<lt::port_mapping_t>();
     to_strong_typedef<lt::peer_class_t>();
+    to_enum_class<lt::move_flags_t>();
     to_bitfield_flag<lt::torrent_flags_t>();
     to_bitfield_flag<lt::peer_flags_t>();
     to_bitfield_flag<lt::peer_source_flags_t>();