Blob Blame History Raw
From 8f12e3c2e0232456eff06642e1620a9538811f29 Mon Sep 17 00:00:00 2001
From: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Date: Sat, 11 May 2019 14:27:50 +0100
Subject: [PATCH] Fixes for Python3 and loading the python module on MacOS

Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
---
 openvdb/python/CMakeLists.txt     | 9 ++++++++-
 openvdb/python/pyOpenVDBModule.cc | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/openvdb/python/CMakeLists.txt b/openvdb/python/CMakeLists.txt
index c1e7a2b2..b255483a 100644
--- a/openvdb/python/CMakeLists.txt
+++ b/openvdb/python/CMakeLists.txt
@@ -182,9 +182,16 @@ target_link_libraries(pyopenvdb
 )
 
 set_target_properties(pyopenvdb PROPERTIES
-  PREFIX ""
+  PREFIX ""  # no 'lib' prefix
 )
 
+if(UNIX)
+  # must be .so (not .dylib)
+  set_target_properties(pyopenvdb PROPERTIES
+    SUFFIX ".so"
+  )
+endif()
+
 if(OPENVDB_ENABLE_RPATH)
   # @todo There is probably a better way to do this for imported targets
   set(RPATHS "")
diff --git a/openvdb/python/pyOpenVDBModule.cc b/openvdb/python/pyOpenVDBModule.cc
index b41095bb..5f423176 100644
--- a/openvdb/python/pyOpenVDBModule.cc
+++ b/openvdb/python/pyOpenVDBModule.cc
@@ -320,7 +320,11 @@ struct PointIndexConverter
     /// @return nullptr if the given Python object is not convertible to the PointIndex.
     static void* convertible(PyObject* obj)
     {
+#if PY_MAJOR_VERSION >= 3
+        if (!PyLong_Check(obj)) return nullptr; // not a Python integer
+#else
         if (!PyInt_Check(obj)) return nullptr; // not a Python integer
+#endif
         return obj;
     }
 
@@ -336,8 +340,11 @@ struct PointIndexConverter
 
         // Extract the PointIndex from the python integer
         PointIndexT* index = static_cast<PointIndexT*>(storage);
-
+#if PY_MAJOR_VERSION >= 3
+        *index = static_cast<IntType>(PyLong_AsLong(obj));
+#else
         *index = static_cast<IntType>(PyInt_AsLong(obj));
+#endif
     }
 
     /// Register both the PointIndex-to-integer and the integer-to-PointIndex converters.