ee76930
From 8f12e3c2e0232456eff06642e1620a9538811f29 Mon Sep 17 00:00:00 2001
ee76930
From: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
ee76930
Date: Sat, 11 May 2019 14:27:50 +0100
ee76930
Subject: [PATCH] Fixes for Python3 and loading the python module on MacOS
ee76930
ee76930
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
ee76930
---
ee76930
 openvdb/python/CMakeLists.txt     | 9 ++++++++-
ee76930
 openvdb/python/pyOpenVDBModule.cc | 9 ++++++++-
ee76930
 2 files changed, 16 insertions(+), 2 deletions(-)
ee76930
ee76930
diff --git a/openvdb/python/CMakeLists.txt b/openvdb/python/CMakeLists.txt
ee76930
index c1e7a2b2..b255483a 100644
ee76930
--- a/openvdb/python/CMakeLists.txt
ee76930
+++ b/openvdb/python/CMakeLists.txt
ee76930
@@ -182,9 +182,16 @@ target_link_libraries(pyopenvdb
ee76930
 )
ee76930
 
ee76930
 set_target_properties(pyopenvdb PROPERTIES
ee76930
-  PREFIX ""
ee76930
+  PREFIX ""  # no 'lib' prefix
ee76930
 )
ee76930
 
ee76930
+if(UNIX)
ee76930
+  # must be .so (not .dylib)
ee76930
+  set_target_properties(pyopenvdb PROPERTIES
ee76930
+    SUFFIX ".so"
ee76930
+  )
ee76930
+endif()
ee76930
+
ee76930
 if(OPENVDB_ENABLE_RPATH)
ee76930
   # @todo There is probably a better way to do this for imported targets
ee76930
   set(RPATHS "")
ee76930
diff --git a/openvdb/python/pyOpenVDBModule.cc b/openvdb/python/pyOpenVDBModule.cc
ee76930
index b41095bb..5f423176 100644
ee76930
--- a/openvdb/python/pyOpenVDBModule.cc
ee76930
+++ b/openvdb/python/pyOpenVDBModule.cc
ee76930
@@ -320,7 +320,11 @@ struct PointIndexConverter
ee76930
     /// @return nullptr if the given Python object is not convertible to the PointIndex.
ee76930
     static void* convertible(PyObject* obj)
ee76930
     {
ee76930
+#if PY_MAJOR_VERSION >= 3
ee76930
+        if (!PyLong_Check(obj)) return nullptr; // not a Python integer
ee76930
+#else
ee76930
         if (!PyInt_Check(obj)) return nullptr; // not a Python integer
ee76930
+#endif
ee76930
         return obj;
ee76930
     }
ee76930
 
ee76930
@@ -336,8 +340,11 @@ struct PointIndexConverter
ee76930
 
ee76930
         // Extract the PointIndex from the python integer
ee76930
         PointIndexT* index = static_cast<PointIndexT*>(storage);
ee76930
-
ee76930
+#if PY_MAJOR_VERSION >= 3
ee76930
+        *index = static_cast<IntType>(PyLong_AsLong(obj));
ee76930
+#else
ee76930
         *index = static_cast<IntType>(PyInt_AsLong(obj));
ee76930
+#endif
ee76930
     }
ee76930
 
ee76930
     /// Register both the PointIndex-to-integer and the integer-to-PointIndex converters.