Skip to content
Snippets Groups Projects
Unverified Commit ca950e10 authored by Wilson Jallet's avatar Wilson Jallet :clapper: Committed by GitHub
Browse files

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: default avatarJustin Carpentier <justin.carpentier@inria.fr>
parent 257e0afe
No related branches found
No related tags found
No related merge requests found
///
/// 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>();
}
}
};
......
///
/// Copyright 2023 CNRS, INRIA
///
#include "eigenpy/optional.hpp"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment