[Bf-blender-cvs] [be7571a5e4c] blender-v2.82-release: Fluid: Refactored Mantaflow <-> Blender pointer exchange once more

Sebastián Barschkis noreply at git.blender.org
Wed Jan 22 16:46:08 CET 2020


Commit: be7571a5e4c3b00b9df843b85b5820d880550824
Author: Sebastián Barschkis
Date:   Wed Jan 22 16:45:42 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBbe7571a5e4c3b00b9df843b85b5820d880550824

Fluid: Refactored Mantaflow <-> Blender pointer exchange once more

===================================================================

M	intern/mantaflow/intern/MANTA_main.cpp

===================================================================

diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 05e6999c193..20233353698 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -2051,20 +2051,24 @@ static PyObject *callPythonFunction(std::string varName,
   return (!isAttribute) ? returnedValue : func;
 }
 
-static char *pyObjectToString(PyObject *inputObject)
+static void *pyObjectToPointer(PyObject *inputObject)
 {
   PyGILState_STATE gilstate = PyGILState_Ensure();
 
   PyObject *encoded = PyUnicode_AsUTF8String(inputObject);
   char *result = PyBytes_AsString(encoded);
 
-  /* Do not decref (i.e. Py_DECREF(encoded)) of string 'encoded' PyObject.
-   * Otherwise those objects will be invalidated too early (see T72894).
-   * Reference count of those Python objects will be decreased with 'del' in Python scripts. */
   Py_DECREF(inputObject);
 
+  std::string str(result);
+  std::istringstream in(str);
+  void *dataPointer = nullptr;
+  in >> dataPointer;
+
+  Py_DECREF(encoded);
   PyGILState_Release(gilstate);
-  return result;
+
+  return dataPointer;
 }
 
 static double pyObjectToDouble(PyObject *inputObject)
@@ -2079,15 +2083,6 @@ static long pyObjectToLong(PyObject *inputObject)
   return PyLong_AsLong(inputObject);
 }
 
-static void *stringToPointer(char *inputString)
-{
-  std::string str(inputString);
-  std::istringstream in(str);
-  void *dataPointer = nullptr;
-  in >> dataPointer;
-  return dataPointer;
-}
-
 int MANTA::getFrame()
 {
   if (with_debug)
@@ -2527,158 +2522,108 @@ void MANTA::updatePointers()
   std::string mesh_ext2 = "_" + mesh2;
   std::string noise_ext = "_" + noise;
 
-  mObstacle = (int *)stringToPointer(
-      pyObjectToString(callPythonFunction("flags" + solver_ext, func)));
-  mPhiIn = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("phiIn" + solver_ext, func)));
-  mVelocityX = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("x_vel" + solver_ext, func)));
-  mVelocityY = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("y_vel" + solver_ext, func)));
-  mVelocityZ = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("z_vel" + solver_ext, func)));
-  mForceX = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("x_force" + solver_ext, func)));
-  mForceY = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("y_force" + solver_ext, func)));
-  mForceZ = (float *)stringToPointer(
-      pyObjectToString(callPythonFunction("z_force" + solver_ext, func)));
+  mObstacle = (int *)pyObjectToPointer(callPythonFunction("flags" + solver_ext, func));
+  mPhiIn = (float *)pyObjectToPointer(callPythonFunction("phiIn" + solver_ext, func));
+  mVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_vel" + solver_ext, func));
+  mVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_vel" + solver_ext, func));
+  mVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_vel" + solver_ext, func));
+  mForceX = (float *)pyObjectToPointer(callPythonFunction("x_force" + solver_ext, func));
+  mForceY = (float *)pyObjectToPointer(callPythonFunction("y_force" + solver_ext, func));
+  mForceZ = (float *)pyObjectToPointer(callPythonFunction("z_force" + solver_ext, func));
 
   if (mUsingOutflow) {
-    mPhiOutIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("phiOutIn" + solver_ext, func)));
+    mPhiOutIn = (float *)pyObjectToPointer(callPythonFunction("phiOutIn" + solver_ext, func));
   }
   if (mUsingObstacle) {
-    mPhiObsIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("phiObsIn" + solver_ext, func)));
-    mObVelocityX = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("x_obvel" + solver_ext, func)));
-    mObVelocityY = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("y_obvel" + solver_ext, func)));
-    mObVelocityZ = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("z_obvel" + solver_ext, func)));
-    mNumObstacle = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("numObs" + solver_ext, func)));
+    mPhiObsIn = (float *)pyObjectToPointer(callPythonFunction("phiObsIn" + solver_ext, func));
+    mObVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_obvel" + solver_ext, func));
+    mObVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_obvel" + solver_ext, func));
+    mObVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_obvel" + solver_ext, func));
+    mNumObstacle = (float *)pyObjectToPointer(callPythonFunction("numObs" + solver_ext, func));
   }
   if (mUsingGuiding) {
-    mPhiGuideIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("phiGuideIn" + solver_ext, func)));
-    mGuideVelocityX = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("x_guidevel" + solver_ext, func)));
-    mGuideVelocityY = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("y_guidevel" + solver_ext, func)));
-    mGuideVelocityZ = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("z_guidevel" + solver_ext, func)));
-    mNumGuide = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("numGuides" + solver_ext, func)));
+    mPhiGuideIn = (float *)pyObjectToPointer(callPythonFunction("phiGuideIn" + solver_ext, func));
+    mGuideVelocityX = (float *)pyObjectToPointer(
+        callPythonFunction("x_guidevel" + solver_ext, func));
+    mGuideVelocityY = (float *)pyObjectToPointer(
+        callPythonFunction("y_guidevel" + solver_ext, func));
+    mGuideVelocityZ = (float *)pyObjectToPointer(
+        callPythonFunction("z_guidevel" + solver_ext, func));
+    mNumGuide = (float *)pyObjectToPointer(callPythonFunction("numGuides" + solver_ext, func));
   }
   if (mUsingInvel) {
-    mInVelocityX = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("x_invel" + solver_ext, func)));
-    mInVelocityY = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("y_invel" + solver_ext, func)));
-    mInVelocityZ = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("z_invel" + solver_ext, func)));
+    mInVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_invel" + solver_ext, func));
+    mInVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_invel" + solver_ext, func));
+    mInVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_invel" + solver_ext, func));
   }
   if (mUsingSmoke) {
-    mDensity = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("density" + solver_ext, func)));
-    mDensityIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("densityIn" + solver_ext, func)));
-    mShadow = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("shadow" + solver_ext, func)));
-    mEmissionIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("emissionIn" + solver_ext, func)));
+    mDensity = (float *)pyObjectToPointer(callPythonFunction("density" + solver_ext, func));
+    mDensityIn = (float *)pyObjectToPointer(callPythonFunction("densityIn" + solver_ext, func));
+    mShadow = (float *)pyObjectToPointer(callPythonFunction("shadow" + solver_ext, func));
+    mEmissionIn = (float *)pyObjectToPointer(callPythonFunction("emissionIn" + solver_ext, func));
   }
   if (mUsingSmoke && mUsingHeat) {
-    mHeat = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("heat" + solver_ext, func)));
-    mHeatIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("heatIn" + solver_ext, func)));
+    mHeat = (float *)pyObjectToPointer(callPythonFunction("heat" + solver_ext, func));
+    mHeatIn = (float *)pyObjectToPointer(callPythonFunction("heatIn" + solver_ext, func));
   }
   if (mUsingSmoke && mUsingFire) {
-    mFlame = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("flame" + solver_ext, func)));
-    mFuel = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("fuel" + solver_ext, func)));
-    mReact = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("react" + solver_ext, func)));
-    mFuelIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("fuelIn" + solver_ext, func)));
-    mReactIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("reactIn" + solver_ext, func)));
+    mFlame = (float *)pyObjectToPointer(callPythonFunction("flame" + solver_ext, func));
+    mFuel = (float *)pyObjectToPointer(callPythonFunction("fuel" + solver_ext, func));
+    mReact = (float *)pyObjectToPointer(callPythonFunction("react" + solver_ext, func));
+    mFuelIn = (float *)pyObjectToPointer(callPythonFunction("fuelIn" + solver_ext, func));
+    mReactIn = (float *)pyObjectToPointer(callPythonFunction("reactIn" + solver_ext, func));
   }
   if (mUsingSmoke && mUsingColors) {
-    mColorR = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_r" + solver_ext, func)));
-    mColorG = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_g" + solver_ext, func)));
-    mColorB = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_b" + solver_ext, func)));
-    mColorRIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_r_in" + solver_ext, func)));
-    mColorGIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_g_in" + solver_ext, func)));
-    mColorBIn = (float *)stringToPointer(
-        pyObjectToString(callPythonFunction("color_b_in" + solver_ext, func)));
+    mColorR = (float *)pyObjectToPointer(callPythonFunction("color_r" + solver_ext, func));
+    mColorG = (float *)pyObjectToPointer(callPythonFunction("color_g" + solver_ext, func));
+    mColorB = (float *)pyObjectToPointer(callPythonFunction("color_b" + solver_ext, func));
+    mColorRIn = (float *)pyObjectToPointer(callPythonFunction("color_r_in" + solver_ext, func));
+    mColorGIn = (float *)pyObjectToPointer(callPythonFunction(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list