Skip to content

Commit 4359336

Browse files
authored
Merge pull request #13 from jcarpent/devel
Correct warnings + introduce check or registration
2 parents 113671d + 90ff656 commit 4359336

File tree

5 files changed

+61
-27
lines changed

5 files changed

+61
-27
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ SET(HEADERS
8181
src/map.hpp
8282
src/geometry.hpp
8383
src/memory.hpp
84+
src/registration.hpp
8485
src/angle-axis.hpp
8586
src/quaternion.hpp
8687
)

src/details.hpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <iostream>
2525

2626
#include "eigenpy/eigenpy.hpp"
27+
#include "eigenpy/registration.hpp"
2728
#include "eigenpy/exception.hpp"
2829
#include "eigenpy/map.hpp"
2930

@@ -190,7 +191,7 @@ namespace eigenpy
190191
typename MapNumpy<EquivalentEigenType>::EigenMap numpyMap = MapNumpy<EquivalentEigenType>::map(pyArray);
191192

192193
void* storage = ((bp::converter::rvalue_from_python_storage<MatType>*)
193-
(memory))->storage.bytes;
194+
((void*)memory))->storage.bytes;
194195
assert( (numpyMap.rows()<INT_MAX) && (numpyMap.cols()<INT_MAX)
195196
&& "Map range larger than int ... can never happen." );
196197
int r=(int)numpyMap.rows(),c=(int)numpyMap.cols();
@@ -201,32 +202,16 @@ namespace eigenpy
201202
eigenMatrix = numpyMap;
202203
}
203204
};
204-
205+
#define numpy_import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } }
206+
205207
template<typename MatType,typename EigenEquivalentType>
206208
void enableEigenPySpecific()
207209
{
208-
import_array();
209-
210-
#ifdef EIGEN_DONT_VECTORIZE
211-
212-
boost::python::to_python_converter<MatType,
213-
eigenpy::EigenToPy<MatType,MatType> >();
214-
eigenpy::EigenFromPy<MatType,MatType>();
215-
#else
216-
217-
boost::python::to_python_converter<MatType,
218-
eigenpy::EigenToPy<MatType,MatType> >();
219-
eigenpy::EigenFromPy<MatType,MatType>();
210+
if(check_registration<MatType>()) return;
211+
numpy_import_array();
220212

221-
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
222-
#ifndef EIGENPY_ALIGNED
223-
boost::python::to_python_converter<MatTypeDontAlign,
224-
eigenpy::EigenToPy<MatTypeDontAlign,MatTypeDontAlign> >();
225-
eigenpy::EigenFromPy<MatTypeDontAlign,MatTypeDontAlign>();
226-
#endif
227-
#endif
228-
229-
213+
boost::python::to_python_converter<MatType,EigenToPy<MatType,MatType> >();
214+
EigenFromPy<MatType,MatType>();
230215
}
231216

232217
} // namespace eigenpy

src/exception.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 LAAS-CNRS
2+
* Copyright (c) 2015-2016 LAAS-CNRS
33
*
44
* This file is part of eigenpy.
55
* eigenpy is free software: you can redistribute it and/or
@@ -14,7 +14,8 @@
1414
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17-
#include <eigenpy/exception.hpp>
17+
#include "eigenpy/exception.hpp"
18+
#include "eigenpy/registration.hpp"
1819

1920

2021
namespace eigenpy
@@ -30,6 +31,8 @@ namespace eigenpy
3031

3132
void Exception::registerException()
3233
{
34+
if(check_registration<eigenpy::Exception>()) return;
35+
3336
pyType = boost::python::class_<eigenpy::Exception>
3437
("Exception",boost::python::init<std::string>())
3538
.add_property("message", &eigenpy::Exception::copyMessage)

src/memory.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ namespace boost { namespace python { namespace objects { \
7777
Holder* holder = Derived::construct(&instance->storage, (PyObject*)instance, x); \
7878
holder->install(raw_result); \
7979
\
80-
size_t holder_offset = reinterpret_cast<size_t>(holder) \
81-
- reinterpret_cast<size_t>(&instance->storage) \
80+
Py_ssize_t holder_offset = reinterpret_cast<Py_ssize_t>(holder) \
81+
- reinterpret_cast<Py_ssize_t>(&instance->storage) \
8282
+ offsetof(instance_t, storage); \
8383
Py_SIZE(instance) = holder_offset; \
8484
\

src/registration.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2016, Justin Carpentier, LAAS-CNRS
3+
*
4+
* This file is part of eigenpy.
5+
* eigenpy is free software: you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public License
7+
* as published by the Free Software Foundation, either version 3 of
8+
* the License, or (at your option) any later version.
9+
* eigenpy is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details. You should
13+
* have received a copy of the GNU Lesser General Public License along
14+
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#ifndef __eigenpy_registration_hpp__
18+
#define __eigenpy_registration_hpp__
19+
20+
#include <boost/python.hpp>
21+
22+
namespace eigenpy
23+
{
24+
///
25+
/// \brief Check at runtime the registration of the type T inside the boost python registry.
26+
///
27+
/// \tparam T The type to check the registration.
28+
///
29+
/// \returns true if the type T is already registered.
30+
///
31+
template<typename T>
32+
inline bool check_registration()
33+
{
34+
namespace bp = boost::python;
35+
36+
const bp::type_info info = bp::type_id<T>();
37+
const bp::converter::registration* reg = bp::converter::registry::query(info);
38+
if (reg == NULL) return false;
39+
else if ((*reg).m_to_python == NULL) return false;
40+
41+
return true;
42+
}
43+
}
44+
45+
#endif // ifndef __eigenpy_registration_hpp__

0 commit comments

Comments
 (0)