]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF31196] : Porting for numpy2 compatibility agy/31196_numpy_2
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 17 Oct 2024 15:26:43 +0000 (17:26 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 17 Oct 2024 15:26:43 +0000 (17:26 +0200)
CMakeLists.txt
src/MEDCoupling_Swig/CMakeLists.txt
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDLoader/Swig/CMakeLists.txt
src/MEDPartitioner_Swig/CMakeLists.txt
src/ParaMEDMEM_Swig/CMakeLists.txt
src/PyWrapping/CMakeLists.txt
src/RENUMBER_Swig/CMakeLists.txt

index f817bca189b6f5ec82d041ffa517b8499850b2af..f2edb8383fd08f68192331488b543c4eda70998a 100644 (file)
@@ -348,6 +348,10 @@ ENDIF(WIN32)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
 
+IF(MEDCOUPLING_ENABLE_PYTHON AND NUMPY_FOUND)
+  ADD_DEFINITIONS( "-DNPY_NO_DEPRECATED_API" )
+ENDIF(MEDCOUPLING_ENABLE_PYTHON AND NUMPY_FOUND)
+
 ADD_SUBDIRECTORY(src)
 
 IF(MEDCOUPLING_BUILD_DOC)
index 7474395cabec8cbc6d87d6695b316a6d063c58a3..1e26d4dcd35e4ea29af85112eca8d283354aaa6b 100644 (file)
@@ -72,8 +72,8 @@ SET (MC_Swig_interf
 )
 
 INCLUDE_DIRECTORIES(
-  ${PYTHON_INCLUDE_DIRS}
   ${NUMPY_INCLUDE_DIR}
+  ${PYTHON_INCLUDE_DIRS}
   ${PTHREAD_INCLUDE_DIR} # pthread dependency due to python2.7 library
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_BINARY_DIR}
@@ -133,15 +133,15 @@ SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES CPLUSPLUS ON)
 IF(WIN32)
   SET_PROPERTY(SOURCE MEDCouplingRemapper.i PROPERTY COMPILE_DEFINITIONS WIN32)
 ENDIF()
-IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
-  SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_FLAGS "-py3")
-ELSE()
-  SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_DEFINITIONS "-shadow")
-ENDIF()
-SET(SWIG_MODULE_MEDCouplingRemapper_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
-IF(MEDCOUPLING_USE_64BIT_IDS)
-  STRING(APPEND SWIG_MODULE_MEDCouplingRemapper_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
-ENDIF(MEDCOUPLING_USE_64BIT_IDS)
+#IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
+#  SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_FLAGS "-py3")
+#ELSE()
+#  SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+#ENDIF()
+#SET(SWIG_MODULE_MEDCouplingRemapper_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}")
+#IF(MEDCOUPLING_USE_64BIT_IDS)
+#  STRING(APPEND SWIG_MODULE_MEDCouplingRemapper_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
+#ENDIF(MEDCOUPLING_USE_64BIT_IDS)
 
 # _ABR_ Ensure dependency mechanism on all SWIG files and headers
 SET (SWIG_MODULE_MEDCouplingRemapper_EXTRA_DEPS ${MEDCoupling_SWIG_DPYS_FILES}
@@ -149,26 +149,27 @@ SET (SWIG_MODULE_MEDCouplingRemapper_EXTRA_DEPS ${MEDCoupling_SWIG_DPYS_FILES}
     ${interpkernel_HEADERS_HXX} ${interpkernel_HEADERS_TXX})
 
 
-IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
-  SWIG_ADD_MODULE(MEDCouplingRemapper python MEDCouplingRemapper.i)  
-ELSE()
-  SWIG_ADD_LIBRARY(MEDCouplingRemapper LANGUAGE python SOURCES MEDCouplingRemapper.i)
-ENDIF()
+#IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
+#  SWIG_ADD_MODULE(MEDCouplingRemapper python MEDCouplingRemapper.i)  
+#ELSE()
+#  SWIG_ADD_LIBRARY(MEDCouplingRemapper LANGUAGE python SOURCES MEDCouplingRemapper.i)
+#ENDIF()
 
-IF(WIN32 OR CYGWIN)
-  SWIG_LINK_LIBRARIES(MEDCouplingRemapper ${PYTHON_LIBRARIES} medcouplingremapper)
-ELSE(WIN32 OR CYGWIN)
-  # ${PYTHON_LIBRARIES} not needed see https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
-  SWIG_LINK_LIBRARIES(MEDCouplingRemapper medcouplingremapper)
-ENDIF(WIN32 OR CYGWIN)
+#IF(WIN32 OR CYGWIN)
+#  SWIG_LINK_LIBRARIES(MEDCouplingRemapper ${PYTHON_LIBRARIES} medcouplingremapper)
+#ELSE(WIN32 OR CYGWIN)
+#  # ${PYTHON_LIBRARIES} not needed see https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
+#  SWIG_LINK_LIBRARIES(MEDCouplingRemapper medcouplingremapper)
+#ENDIF(WIN32 OR CYGWIN)
 
 IF(WIN32)
   SET_TARGET_PROPERTIES(_MEDCouplingRemapper PROPERTIES DEBUG_OUTPUT_NAME _MEDCouplingRemapper_d)
   SET_TARGET_PROPERTIES(_${MEDCouling_target_name} PROPERTIES DEBUG_OUTPUT_NAME _${MEDCouling_target_name}_d)
 ENDIF(WIN32)
-INSTALL(TARGETS ${SWIG_MODULE_${MEDCouling_target_name}_REAL_NAME} ${SWIG_MODULE_MEDCouplingRemapper_REAL_NAME} DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
+INSTALL(TARGETS ${SWIG_MODULE_${MEDCouling_target_name}_REAL_NAME} DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
+#INSTALL(TARGETS ${SWIG_MODULE_${MEDCouling_target_name}_REAL_NAME} ${SWIG_MODULE_MEDCouplingRemapper_REAL_NAME} DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
 
-SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingRemapper.py)
+#SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingRemapper.py)
 IF(WIN32)
   SET(PYFILES_TO_INSTALL ${PYFILES_TO_INSTALL} ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingCompat.py)
 ELSE()
index 9208a72f44867f5702f18c949343429555858eb3..7bb28fb3c2100bcfa6a1286d0a625b667c69f4a7 100644 (file)
@@ -159,8 +159,9 @@ void numarrdeal2(void *pt, void *obj)
 }
 
 template<class MCData, class T>
-MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
+MCData *BuildNewInstance(PyObject *elt0Arr, int npyObjectType, PyTypeObject *pytype, const char *msg)
 {
+  PyArrayObject *elt0 = reinterpret_cast<PyArrayObject *>( elt0Arr );//PyObject_HEAD on top of struct tagPyArrayObject
   int ndim=PyArray_NDIM(elt0);
   if(ndim!=1 && ndim!=2)
     throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
@@ -175,7 +176,7 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype
   npy_intp sz0=PyArray_DIM(elt0,0);
   npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
   //
-  int itemSize=PyArray_ITEMSIZE(elt0);
+  auto itemSize=PyArray_ITEMSIZE(elt0);
   if(itemSize!=sizeof(T))
     {
       std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
@@ -194,7 +195,7 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype
       PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
       int mask=MED_NUMPY_OWNDATA; mask=~mask;
       elt0C->flags&=mask;
-      PyObject *deepestObj=elt0;
+      PyObject *deepestObj=elt0Arr;
       PyObject *base=elt0C->base;
       if(base) deepestObj=base;
       bool isSpetialCase(false);
@@ -228,7 +229,7 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype
           PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
           cb->_pt_mc=ret;
           ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::DeallocType::C_DEALLOC,sz0,sz1);
-          PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
+          PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(deepestObj),(PyObject *)cb);
           void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
           mma.setParameterForDeallocator(objs);
           mma.setSpecificDeallocator(numarrdeal2<MCData>);
index 479afcf421c314de23543ae5883ceeeb83a92020..bc13f294c01aff0e545ed3580483ea70574a4cd6 100644 (file)
@@ -43,8 +43,8 @@ SET (MEDLoader_SWIG_DPYS_FILES
     MEDLoaderTypemaps.i)
 
 INCLUDE_DIRECTORIES(
-  ${PYTHON_INCLUDE_DIRS}
   ${NUMPY_INCLUDE_DIR}
+  ${PYTHON_INCLUDE_DIRS}
   ${MEDFILE_INCLUDE_DIRS}
   ${HDF5_INCLUDE_DIRS}
   ${CMAKE_CURRENT_SOURCE_DIR}
index 696df4459f9a7b868ce39e63bc33990bcec7231e..2227bace23f521cdcc5d6446936ab50fcd75bd8a 100644 (file)
@@ -37,9 +37,9 @@ SET (MEDPartitioner_SWIG_DPYS_FILES
     MEDPartitionerCommon.i)
 
 INCLUDE_DIRECTORIES(
+  ${NUMPY_INCLUDE_DIR}
   ${PYTHON_INCLUDE_DIRS}
   ${PTHREAD_INCLUDE_DIR} # pthread dependency due to python2.7 library
-  ${NUMPY_INCLUDE_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_BINARY_DIR}
   ${HDF5_INCLUDE_DIRS}
index 4e7f502b4376b9b1c079b434def21c32f31a3696..e1fdb6f0795493624fcd5e9e86af8dc8eb7d4fc5 100644 (file)
@@ -38,8 +38,8 @@ IF(MEDCOUPLING_USE_64BIT_IDS)
 ENDIF(MEDCOUPLING_USE_64BIT_IDS)
 
 INCLUDE_DIRECTORIES(
-  ${PYTHON_INCLUDE_DIRS}
   ${NUMPY_INCLUDE_DIR}
+  ${PYTHON_INCLUDE_DIRS}
   ${MPI_INCLUDE_DIRS}
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM
index e1b4e2f5a7efe312f725cf40ec177de8bae6c743..9c8039d9a5c408d8c077eb511db70a4c58a04433 100644 (file)
@@ -40,8 +40,8 @@ ENDIF(MEDCOUPLING_USE_64BIT_IDS)
 SET(medcoupling_SWIG_DPYS_FILES medcoupling.i)
 
 INCLUDE_DIRECTORIES(
-  ${PYTHON_INCLUDE_DIRS}
   ${NUMPY_INCLUDE_DIR}
+  ${PYTHON_INCLUDE_DIRS}
   ${MEDFILE_INCLUDE_DIRS}
   ${HDF5_INCLUDE_DIRS}
   ${CMAKE_CURRENT_SOURCE_DIR}
index 462bcb34812e5ce3c1975ffc03d01801da40771e..a927ed3654fd1a3009966a343def0fde256060e6 100644 (file)
@@ -41,10 +41,10 @@ SET (MEDRenumber_SWIG_DPYS_FILES
   MEDRenumberImpl.i)
 
 INCLUDE_DIRECTORIES(
+  ${NUMPY_INCLUDE_DIR}
   ${PYTHON_INCLUDE_DIRS}
   ${PTHREAD_INCLUDE_DIR} # pthread dependency due to python2.7 library
   ${CMAKE_CURRENT_SOURCE_DIR}
-  ${NUMPY_INCLUDE_DIR}
   ${CMAKE_CURRENT_BINARY_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}/../RENUMBER
   ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling_Swig