From 63532ae2bdd19cea6ad7613aea3e20d433c83c69 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 6 Dec 2021 18:30:57 +0000 Subject: [PATCH] fix regression in python binding for move_storage() 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bindings/python/src/converters.cpp b/bindings/python/src/converters.cpp index 68ca2cf..7d9eb1f 100644 --- a/bindings/python/src/converters.cpp +++ b/bindings/python/src/converters.cpp @@ -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 #include @@ -342,6 +343,30 @@ struct to_strong_typedef } }; +template +struct to_enum_class +{ + using underlying_type = typename std::underlying_type::type; + + to_enum_class() + { + converter::registry::push_back( + &convertible, &construct, type_id() + ); + } + + 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*)data)->storage.bytes; + data->convertible = new (storage) T(static_cast(static_cast(extract(object(borrowed(x)))))); + } +}; + template struct from_bitfield_flag { @@ -495,6 +520,7 @@ void bind_converters() to_strong_typedef(); to_strong_typedef(); to_strong_typedef(); + to_enum_class(); to_bitfield_flag(); to_bitfield_flag(); to_bitfield_flag(); -- 2.30.2