Skip to content
Snippets Groups Projects
Commit f8a2ff7a authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

python wrappers : support python 2.6 (fallback to pyCObject instead of PyCapsule)

parent f4d67b53
No related branches found
No related tags found
No related merge requests found
...@@ -91,10 +91,17 @@ ...@@ -91,10 +91,17 @@
} }
%#ifdef HAVE_NUMPY %#ifdef HAVE_NUMPY
%#if PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6
static void deleteCapsuleArray(void *capsule)
{
delete [](double*)(capsule);
}
%#else
static void deleteCapsuleArray(PyObject *capsule) static void deleteCapsuleArray(PyObject *capsule)
{ {
delete [](double*)PyCapsule_GetPointer(capsule, NULL); delete [](double*)PyCapsule_GetPointer(capsule, NULL);
} }
%#endif
PyObject *fullMatrix2PyArray(fullMatrix<double> &fm) PyObject *fullMatrix2PyArray(fullMatrix<double> &fm)
{ {
npy_intp dims[2] = {fm.size1(), fm.size2()}; npy_intp dims[2] = {fm.size1(), fm.size2()};
...@@ -107,7 +114,11 @@ ...@@ -107,7 +114,11 @@
PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED); PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED);
if (fm.getOwnData()) { if (fm.getOwnData()) {
fm.setOwnData(false); fm.setOwnData(false);
%#if PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6
PyObject *capsule = PyCObject_FromVoidPtr((void*)data, deleteCapsuleArray);
%#else
PyObject *capsule = PyCapsule_New((void*) data, NULL, deleteCapsuleArray); PyObject *capsule = PyCapsule_New((void*) data, NULL, deleteCapsuleArray);
%#endif
PyArray_SetBaseObject((PyArrayObject*)array, capsule); PyArray_SetBaseObject((PyArrayObject*)array, capsule);
} }
return array; return array;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment