From 78efea552a649ab93ddd1d5b830fef1e54f35740 Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Wed, 26 Feb 2020 09:08:45 +0100
Subject: [PATCH] core: patch Win32

which is not able to retrieve EIGENPY_ARRAY_API when compiling other module because the symbol is not exported
---
 include/eigenpy/numpy-allocator.hpp | 22 ++++++++++------------
 include/eigenpy/numpy.hpp           | 23 ++++++++++++++++++++++-
 src/numpy.cpp                       | 19 +++++++++++++++++++
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/include/eigenpy/numpy-allocator.hpp b/include/eigenpy/numpy-allocator.hpp
index 59885b37..8b9f7f36 100644
--- a/include/eigenpy/numpy-allocator.hpp
+++ b/include/eigenpy/numpy-allocator.hpp
@@ -20,8 +20,8 @@ namespace eigenpy
     {
       typedef typename SimilarMatrixType::Scalar Scalar;
       
-      PyArrayObject * pyArray = (PyArrayObject*) PyArray_SimpleNew(nd, shape,
-                                                                   NumpyEquivalentType<Scalar>::type_code);
+      PyArrayObject * pyArray = (PyArrayObject*) call_PyArray_SimpleNew(nd, shape,
+                                                                        NumpyEquivalentType<Scalar>::type_code);
       
       // Copy data
       EigenAllocator<SimilarMatrixType>::copy(mat,pyArray);
@@ -40,11 +40,10 @@ namespace eigenpy
       typedef typename SimilarMatrixType::Scalar Scalar;
       enum { NPY_ARRAY_MEMORY_CONTIGUOUS = SimilarMatrixType::IsRowMajor ? NPY_ARRAY_CARRAY : NPY_ARRAY_FARRAY };
       
-      PyArrayObject * pyArray = (PyArrayObject*) PyArray_New(&PyArray_Type, nd, shape,
-                                                             NumpyEquivalentType<Scalar>::type_code, NULL,
-                                                             mat.data(), 0,
-                                                             NPY_ARRAY_MEMORY_CONTIGUOUS | NPY_ARRAY_ALIGNED,
-                                                             NULL);
+      PyArrayObject * pyArray = (PyArrayObject*) call_PyArray_New(nd, shape,
+                                                             NumpyEquivalentType<Scalar>::type_code,
+                                                             mat.data(),
+                                                             NPY_ARRAY_MEMORY_CONTIGUOUS | NPY_ARRAY_ALIGNED);
       
       return pyArray;
     }
@@ -69,11 +68,10 @@ namespace eigenpy
       typedef typename SimilarMatrixType::Scalar Scalar;
       enum { NPY_ARRAY_MEMORY_CONTIGUOUS_RO = SimilarMatrixType::IsRowMajor ? NPY_ARRAY_CARRAY_RO : NPY_ARRAY_FARRAY_RO };
       
-      PyArrayObject * pyArray = (PyArrayObject*) PyArray_New(&PyArray_Type, nd, shape,
-                                                             NumpyEquivalentType<Scalar>::type_code, NULL,
-                                                             const_cast<SimilarMatrixType &>(mat.derived()).data(), 0,
-                                                             NPY_ARRAY_MEMORY_CONTIGUOUS_RO | NPY_ARRAY_ALIGNED,
-                                                             NULL);
+      PyArrayObject * pyArray = (PyArrayObject*) call_PyArray_New(nd, shape,
+                                                             NumpyEquivalentType<Scalar>::type_code,
+                                                             const_cast<SimilarMatrixType &>(mat.derived()).data(),
+                                                             NPY_ARRAY_MEMORY_CONTIGUOUS_RO | NPY_ARRAY_ALIGNED);
       
       return pyArray;
     }
diff --git a/include/eigenpy/numpy.hpp b/include/eigenpy/numpy.hpp
index c8780a2c..89db4801 100644
--- a/include/eigenpy/numpy.hpp
+++ b/include/eigenpy/numpy.hpp
@@ -19,11 +19,32 @@
 
 #include <numpy/noprefix.h>
 
-#define EIGENPY_GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
+#if defined _WIN32 || defined __CYGWIN__
+  #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
+    call_PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
+#else
+  #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
+    PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
+#endif
 
 namespace eigenpy
 {
   void EIGENPY_DLLEXPORT import_numpy();
 }
 
+#if defined _WIN32 || defined __CYGWIN__
+namespace eigenpy
+{
+  EIGENPY_DLLEXPORT PyArrayObject*  call_PyArray_SimpleNew(npy_intp nd, npy_intp * shape, NPY_TYPES np_type);
+
+  EIGENPY_DLLEXPORT PyArrayObject* call_PyArray_New(npy_intp nd, npy_intp * shape, NPY_TYPES np_type, void * data_ptr, npy_intp options);
+
+  EIGENPY_DLLEXPORT int call_PyArray_ObjectType(PyObject *, int);
+}
+#else
+  #define call_PyArray_SimpleNew PyArray_SimpleNew
+  #define call_PyArray_New(nd,shape,np_type,data_ptr,options) \
+    PyArray_New(&PyArray_Type,nd,shape,np_type,NULL,data_ptr,0,options,NULL)
+#endif
+
 #endif // ifndef __eigenpy_numpy_hpp__
diff --git a/src/numpy.cpp b/src/numpy.cpp
index 61a91f33..7a1e8111 100644
--- a/src/numpy.cpp
+++ b/src/numpy.cpp
@@ -14,4 +14,23 @@ namespace eigenpy
       PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
     }
   }
+
+#if defined _WIN32 || defined __CYGWIN__
+
+  PyArrayObject* call_PyArray_SimpleNew(npy_intp nd, npy_intp * shape, NPY_TYPES np_type)
+  {
+    return PyArray_SimpleNew(nd,shape,np_type);
+  }
+
+  PyArrayObject* call_PyArray_New(npy_intp nd, npy_intp * shape, NPY_TYPES np_type, void * data_ptr, npy_intp options)
+  {
+    return PyArray_New(&PyArray_Type,nd,shape,np_type,NULL,data_ptr,0,options,NULL);
+  }
+  
+  int call_PyArray_ObjectType(PyObject * obj, int val)
+  {
+    return PyArray_ObjectType(obj,val);
+  }
+
+#endif
 }
-- 
GitLab