Skip to content

Commit 2d31330

Browse files
authored
Merge pull request #58 from jmirabel/devel
Fix SEGV with Python 3.
2 parents b33a854 + 274d09b commit 2d31330

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

include/eigenpy/details.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "eigenpy/fwd.hpp"
1010

11+
#include <patchlevel.h> // For PY_MAJOR_VERSION
1112
#include <numpy/arrayobject.h>
1213
#include <iostream>
1314

@@ -93,11 +94,14 @@ namespace eigenpy
9394
NumpyType()
9495
{
9596
pyModule = bp::import("numpy");
97+
#if PY_MAJOR_VERSION >= 3
98+
// TODO I don't know why this Py_INCREF is necessary.
99+
// Without it, the destructor of NumpyType SEGV sometimes.
100+
Py_INCREF(pyModule.ptr());
101+
#endif
96102

97103
NumpyMatrixObject = pyModule.attr("matrix");
98104
NumpyMatrixType = reinterpret_cast<PyTypeObject*>(NumpyMatrixObject.ptr());
99-
NumpyAsMatrixObject = pyModule.attr("asmatrix");
100-
NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());
101105
NumpyArrayObject = pyModule.attr("ndarray");
102106
NumpyArrayType = reinterpret_cast<PyTypeObject*>(NumpyArrayObject.ptr());
103107

@@ -109,7 +113,6 @@ namespace eigenpy
109113

110114
// Numpy types
111115
bp::object NumpyMatrixObject; PyTypeObject * NumpyMatrixType;
112-
bp::object NumpyAsMatrixObject; PyTypeObject * NumpyAsMatrixType;
113116
bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType;
114117
};
115118

0 commit comments

Comments
 (0)