Skip to content

Commit 3ab149b

Browse files
authored
Merge pull request #471 from ManifoldFR/topic/fix-register-symbolic-link
Add unit test multiple_registration, fix register_symbolic_link_to_registered_type() for multiple successive registrations
2 parents 3b7cdb7 + 7b27e7a commit 3ab149b

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
### Added
1010
- Added a deprecation call policy shortcut ([#466](https://github.com/stack-of-tasks/eigenpy/pull/466))
1111

12+
### Fixed
13+
- Fix register_symbolic_link_to_registered_type() for multiple successive registrations ([#471](https://github.com/stack-of-tasks/eigenpy/pull/471))
14+
1215
## [3.5.1] - 2024-04-25
1316

1417
### Fixed

include/eigenpy/registration.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ inline bool register_symbolic_link_to_registered_type() {
4545
const bp::converter::registration* reg =
4646
bp::converter::registry::query(info);
4747
bp::handle<> class_obj(reg->get_class_object());
48+
bp::incref(class_obj.get());
4849
bp::scope().attr(reg->get_class_object()->tp_name) = bp::object(class_obj);
4950
return true;
5051
}
@@ -61,6 +62,7 @@ inline bool register_symbolic_link_to_registered_type(const Visitor& visitor) {
6162
const bp::converter::registration* reg =
6263
bp::converter::registry::query(info);
6364
bp::handle<> class_obj(reg->get_class_object());
65+
bp::incref(class_obj.get());
6466
bp::object object(class_obj);
6567
bp::scope().attr(reg->get_class_object()->tp_name) = object;
6668
registration_class<T> cl(object);

unittest/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ endmacro(ADD_LIB_UNIT_TEST)
3030

3131
add_dependencies(build_tests ${PYWRAP})
3232
add_lib_unit_test(matrix)
33+
add_lib_unit_test(multiple_registration)
3334
if(BUILD_TESTING_SCIPY)
3435
find_scipy()
3536
add_lib_unit_test(sparse_matrix)
@@ -101,6 +102,8 @@ endif()
101102
add_lib_unit_test(bind_virtual_factory)
102103

103104
add_python_lib_unit_test("py-matrix" "unittest/python/test_matrix.py")
105+
add_python_lib_unit_test("py-multiple-registration"
106+
"unittest/python/test_multiple_registration.py")
104107

105108
add_python_lib_unit_test("py-tensor" "unittest/python/test_tensor.py")
106109
add_python_lib_unit_test("py-geometry" "unittest/python/test_geometry.py")

unittest/multiple_registration.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "eigenpy/registration.hpp"
2+
#include <cstdio>
3+
4+
namespace bp = boost::python;
5+
6+
class X {
7+
public:
8+
X() {}
9+
void operator()() { printf("DOOT\n"); }
10+
};
11+
12+
class X_wrapper : public X, bp::wrapper<X> {
13+
public:
14+
static void expose() {
15+
if (!eigenpy::register_symbolic_link_to_registered_type<X>()) {
16+
bp::class_<X>("X", bp::init<>()).def("__call__", &X::operator());
17+
}
18+
}
19+
};
20+
21+
BOOST_PYTHON_MODULE(multiple_registration) {
22+
X_wrapper::expose();
23+
X_wrapper::expose();
24+
X_wrapper::expose();
25+
X_wrapper::expose();
26+
X_wrapper::expose();
27+
X_wrapper::expose();
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import multiple_registration # noqa

0 commit comments

Comments
 (0)