diff --git a/CMakeLists.txt b/CMakeLists.txt index 4962eb9b1..8acb0ef35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ SET(HEADERS src/map.hpp src/geometry.hpp src/memory.hpp + src/registration.hpp src/angle-axis.hpp src/quaternion.hpp ) diff --git a/src/details.hpp b/src/details.hpp index 9ab072b0c..406b13389 100644 --- a/src/details.hpp +++ b/src/details.hpp @@ -24,6 +24,7 @@ #include #include "eigenpy/eigenpy.hpp" +#include "eigenpy/registration.hpp" #include "eigenpy/exception.hpp" #include "eigenpy/map.hpp" @@ -190,7 +191,7 @@ namespace eigenpy typename MapNumpy::EigenMap numpyMap = MapNumpy::map(pyArray); void* storage = ((bp::converter::rvalue_from_python_storage*) - (memory))->storage.bytes; + ((void*)memory))->storage.bytes; assert( (numpyMap.rows() void enableEigenPySpecific() { - import_array(); - -#ifdef EIGEN_DONT_VECTORIZE - - boost::python::to_python_converter >(); - eigenpy::EigenFromPy(); -#else - - boost::python::to_python_converter >(); - eigenpy::EigenFromPy(); + if(check_registration()) return; + numpy_import_array(); - typedef typename eigenpy::UnalignedEquivalent::type MatTypeDontAlign; -#ifndef EIGENPY_ALIGNED - boost::python::to_python_converter >(); - eigenpy::EigenFromPy(); -#endif -#endif - - + boost::python::to_python_converter >(); + EigenFromPy(); } } // namespace eigenpy diff --git a/src/exception.cpp b/src/exception.cpp index b8ac24cad..e67b29876 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 LAAS-CNRS + * Copyright (c) 2015-2016 LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or @@ -14,7 +14,8 @@ * with eigenpy. If not, see . */ -#include +#include "eigenpy/exception.hpp" +#include "eigenpy/registration.hpp" namespace eigenpy @@ -30,6 +31,8 @@ namespace eigenpy void Exception::registerException() { + if(check_registration()) return; + pyType = boost::python::class_ ("Exception",boost::python::init()) .add_property("message", &eigenpy::Exception::copyMessage) diff --git a/src/memory.hpp b/src/memory.hpp index 99d5d4f3e..8c7390b66 100644 --- a/src/memory.hpp +++ b/src/memory.hpp @@ -77,8 +77,8 @@ namespace boost { namespace python { namespace objects { \ Holder* holder = Derived::construct(&instance->storage, (PyObject*)instance, x); \ holder->install(raw_result); \ \ - size_t holder_offset = reinterpret_cast(holder) \ - - reinterpret_cast(&instance->storage) \ + Py_ssize_t holder_offset = reinterpret_cast(holder) \ + - reinterpret_cast(&instance->storage) \ + offsetof(instance_t, storage); \ Py_SIZE(instance) = holder_offset; \ \ diff --git a/src/registration.hpp b/src/registration.hpp new file mode 100644 index 000000000..482335f38 --- /dev/null +++ b/src/registration.hpp @@ -0,0 +1,45 @@ +/* + * Copyright 2016, Justin Carpentier, LAAS-CNRS + * + * This file is part of eigenpy. + * eigenpy is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * eigenpy is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. You should + * have received a copy of the GNU Lesser General Public License along + * with eigenpy. If not, see . + */ + +#ifndef __eigenpy_registration_hpp__ +#define __eigenpy_registration_hpp__ + +#include + +namespace eigenpy +{ + /// + /// \brief Check at runtime the registration of the type T inside the boost python registry. + /// + /// \tparam T The type to check the registration. + /// + /// \returns true if the type T is already registered. + /// + template + inline bool check_registration() + { + namespace bp = boost::python; + + const bp::type_info info = bp::type_id(); + const bp::converter::registration* reg = bp::converter::registry::query(info); + if (reg == NULL) return false; + else if ((*reg).m_to_python == NULL) return false; + + return true; + } +} + +#endif // ifndef __eigenpy_registration_hpp__