From ca950e1033e1c00cf5207c9c8bb13dbe5a5ca513 Mon Sep 17 00:00:00 2001 From: Wilson <wilson.jallet@polytechnique.org> Date: Tue, 16 May 2023 14:46:38 +0200 Subject: [PATCH] optional: check registration of none type and optional type before exposing converter (#368) * optional: check registration of none type and optional type * core: remove useless include * core: fix include --------- Co-authored-by: Justin Carpentier <justin.carpentier@inria.fr> --- include/eigenpy/optional.hpp | 13 +++++++++++-- src/optional.cpp | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/eigenpy/optional.hpp b/include/eigenpy/optional.hpp index be6fbe4..5daffd5 100644 --- a/include/eigenpy/optional.hpp +++ b/include/eigenpy/optional.hpp @@ -1,4 +1,6 @@ +/// /// Copyright (c) 2023 CNRS INRIA +/// /// Definitions for exposing boost::optional<T> types. /// Also works with std::optional. @@ -7,6 +9,8 @@ #include "eigenpy/fwd.hpp" #include "eigenpy/eigen-from-python.hpp" +#include "eigenpy/registration.hpp" + #include <boost/optional.hpp> #ifdef EIGENPY_WITH_CXX17_SUPPORT #include <optional> @@ -35,6 +39,7 @@ struct expected_pytype_for_arg<std::optional<T> > : expected_pytype_for_arg<T> { } // namespace boost namespace eigenpy { + namespace detail { /// Helper struct to decide which type is the "none" type for a specific @@ -61,7 +66,9 @@ struct NoneToPython { static PyObject *convert(const NoneType &) { Py_RETURN_NONE; } static void registration() { - bp::to_python_converter<NoneType, NoneToPython, false>(); + if (!check_registration<NoneType>()) { + bp::to_python_converter<NoneType, NoneToPython, false>(); + } } }; @@ -81,7 +88,9 @@ struct OptionalToPython { } static void registration() { - bp::to_python_converter<OptionalTpl<T>, OptionalToPython, true>(); + if (!check_registration<OptionalTpl<T> >()) { + bp::to_python_converter<OptionalTpl<T>, OptionalToPython, true>(); + } } }; diff --git a/src/optional.cpp b/src/optional.cpp index eb56912..3edf878 100644 --- a/src/optional.cpp +++ b/src/optional.cpp @@ -1,4 +1,6 @@ +/// /// Copyright 2023 CNRS, INRIA +/// #include "eigenpy/optional.hpp" -- GitLab