Skip to content

Commit ca950e1

Browse files
ManifoldFRjcarpent
andauthored
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 <[email protected]>
1 parent 257e0af commit ca950e1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/eigenpy/optional.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
///
12
/// Copyright (c) 2023 CNRS INRIA
3+
///
24
/// Definitions for exposing boost::optional<T> types.
35
/// Also works with std::optional.
46

@@ -7,6 +9,8 @@
79

810
#include "eigenpy/fwd.hpp"
911
#include "eigenpy/eigen-from-python.hpp"
12+
#include "eigenpy/registration.hpp"
13+
1014
#include <boost/optional.hpp>
1115
#ifdef EIGENPY_WITH_CXX17_SUPPORT
1216
#include <optional>
@@ -35,6 +39,7 @@ struct expected_pytype_for_arg<std::optional<T> > : expected_pytype_for_arg<T> {
3539
} // namespace boost
3640

3741
namespace eigenpy {
42+
3843
namespace detail {
3944

4045
/// Helper struct to decide which type is the "none" type for a specific
@@ -61,7 +66,9 @@ struct NoneToPython {
6166
static PyObject *convert(const NoneType &) { Py_RETURN_NONE; }
6267

6368
static void registration() {
64-
bp::to_python_converter<NoneType, NoneToPython, false>();
69+
if (!check_registration<NoneType>()) {
70+
bp::to_python_converter<NoneType, NoneToPython, false>();
71+
}
6572
}
6673
};
6774

@@ -81,7 +88,9 @@ struct OptionalToPython {
8188
}
8289

8390
static void registration() {
84-
bp::to_python_converter<OptionalTpl<T>, OptionalToPython, true>();
91+
if (!check_registration<OptionalTpl<T> >()) {
92+
bp::to_python_converter<OptionalTpl<T>, OptionalToPython, true>();
93+
}
8594
}
8695
};
8796

src/optional.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
///
12
/// Copyright 2023 CNRS, INRIA
3+
///
24

35
#include "eigenpy/optional.hpp"
46

0 commit comments

Comments
 (0)