changeset 25:7648f3f2fa14

cleaned up vampy preloading, no functional change. tried python preload, did not work.
author fazekasgy
date Tue, 18 Aug 2009 08:32:45 +0000
parents 7d28bed0864e
children ba3686eb697c
files Makefile PyPlugScanner.cpp pyvamp-main.cpp
diffstat 3 files changed, 30 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Aug 17 15:22:06 2009 +0000
+++ b/Makefile	Tue Aug 18 08:32:45 2009 +0000
@@ -1,5 +1,6 @@
 
-CXXFLAGS	:= -I../vamp-plugin-sdk -O2 -Wall -I/usr/include/python2.5 -fvisibility=hidden
+CXXFLAGS	:= -I../vamp-plugin-sdk -O2 -Wall -I/usr/include/python2.5 
+#-fvisibility=hidden
 
 vampy.dylib:	PyPlugin.o PyPlugScanner.o pyvamp-main.o Mutex.o
 	g++ -shared $^ -o $@ -L../vamp-plugin-sdk/vamp-sdk -lvamp-sdk -dynamiclib -lpython2.5 -lpthread
@@ -16,7 +17,7 @@
 	mkdir -p $(INSTALL_DIR)
 	rm -f $(INSTALL_DIR)/$(PLUGIN_NAME)$(PLUGIN_EXT)
 	cp $(PLUGIN_NAME)$(PLUGIN_EXT) $(INSTALL_DIR)/$(PLUGIN_NAME)$(PLUGIN_EXT)	
-	cp $(PYEXAMPLE_DIR)/*.py $(INSTALL_DIR)
+	#cp $(PYEXAMPLE_DIR)/*.py $(INSTALL_DIR)
 	
 installplug : install
 cleanplug : clean
--- a/PyPlugScanner.cpp	Mon Aug 17 15:22:06 2009 +0000
+++ b/PyPlugScanner.cpp	Tue Aug 18 08:32:45 2009 +0000
@@ -109,7 +109,7 @@
 
 	//Add plugin path to active Python Path 
 	string pyCmd = "import sys\nsys.path.append('" + path + "')\n";
-	PyRun_SimpleString(pyCmd.c_str());				
+	PyRun_SimpleString(pyCmd.c_str());
 
 	//Assign an object to the source code
 	PyObject *pySource = PyString_FromString(classname.c_str());
--- a/pyvamp-main.cpp	Mon Aug 17 15:22:06 2009 +0000
+++ b/pyvamp-main.cpp	Tue Aug 18 08:32:45 2009 +0000
@@ -141,7 +141,25 @@
         
     return false;
 }
-    
+
+/* This doesn't work: don't try it again.
+static bool initPython()
+{
+	// preloadPython();
+	Py_Initialize();
+#ifndef _WIN32
+	//set dlopen flags form Python 
+	string pyCmd = "from sys import setdlopenflags\nimport dl\nsetdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)\n";
+	if (PyRun_SimpleString(pyCmd.c_str()) == -1) 
+	{   
+	    cerr << "Warning: Could not set dlopen flasgs. Dynamic loading in scripts will fail." << endl;
+		return false;
+	}
+#endif	
+	PyEval_InitThreads();			
+	return Py_IsInitialized();
+}    
+*/
 
 const VampPluginDescriptor 
 *vampGetPluginDescriptor(unsigned int version,unsigned int index)
@@ -154,33 +172,15 @@
 
 	if (!haveScannedPlugins) {
 
-		if (!isPythonInitialized) {
+		if (!isPythonInitialized){
 
-			if (!preloadPython()) {
-                            cerr << "Warning: Could not preload Python." 
-                                 << " Dynamic loading in scripts will fail." << endl;
-                        }
+			if (!preloadPython())
+				cerr << "Warning: Could not preload Python. Dynamic loading in scripts will fail." << endl;
+			Py_Initialize();
+		    cerr << "# isPythonInitialized after initialize: " << Py_IsInitialized() << endl;
+			// PyEval_InitThreads(); //not sure why this was needed
+		}
 
-/*
-			void *pylib = 0; 
-			
-			cerr << "Loading Python Interpreter at: " << pythonPath << endl;
-			//Preloading the binary allows the load of shared libs 
-			//TODO: check how to do RTLD_NOW on Windows
-#ifdef _WIN32
-			pylib = LoadLibrary(pythonPath.c_str());
-#else			
-			pylib = dlopen(pythonPath.c_str(), RTLD_NOW|RTLD_GLOBAL);
-#endif			
-			if (!pylib) cerr << "Warning: Could not preload Python." 
-						<< " Dynamic loading in scripts will fail." << endl;
-*/
-			Py_Initialize();
-                        cerr << "# isPythonInitialized after initialize: " << Py_IsInitialized() << endl;
-	 		PyEval_InitThreads();			
-		} else {
-			//Py_InitializeEx(1);
-		}
 
 		vector<string> pyPlugs;
 		vector<string> pyPath;