Browse Source

explicit calls instead of PyRun_SimpleString

David Rose 16 years ago
parent
commit
15175c727d
1 changed files with 18 additions and 6 deletions
  1. 18 6
      direct/src/plugin/p3dPythonRun.cxx

+ 18 - 6
direct/src/plugin/p3dPythonRun.cxx

@@ -137,11 +137,23 @@ run_python() {
     return false;
     return false;
   }
   }
 
 
-  string startup;
-  startup = "import imp; imp.load_dynamic('libpandaexpress', \"";
-  startup += libpandaexpress.to_os_specific();
-  startup += "\");";
-  PyRun_SimpleString(startup.c_str());
+  // We need the "imp" built-in module for that.
+  PyObject *imp_module = PyImport_ImportModule("imp");
+  if (imp_module == NULL) {
+    PyErr_Print();
+    return false;
+  }
+
+  string os_specific = libpandaexpress.to_os_specific();
+  PyObject *result = PyObject_CallMethod
+    (imp_module, (char *)"load_dynamic", (char *)"ss", 
+     "libpandaexpress", os_specific.c_str());
+  if (result == NULL) {
+    PyErr_Print();
+    return false;
+  }
+  Py_DECREF(result);
+  Py_DECREF(imp_module);
 
 
   // Now we can load _vfsimporter.pyd.  Since this is a magic frozen
   // Now we can load _vfsimporter.pyd.  Since this is a magic frozen
   // pyd, importing it automatically makes all of its frozen contents
   // pyd, importing it automatically makes all of its frozen contents
@@ -161,7 +173,7 @@ run_python() {
   }
   }
 
 
   // And register the VFSImporter.
   // And register the VFSImporter.
-  PyObject *result = PyObject_CallMethod(vfsimporter_module, (char *)"register", (char *)"");
+  result = PyObject_CallMethod(vfsimporter_module, (char *)"register", (char *)"");
   if (result == NULL) {
   if (result == NULL) {
     PyErr_Print();
     PyErr_Print();
     return false;
     return false;