[Freeswitch-svn] [commit] r5102 - in freeswitch/trunk/src/mod/languages: mod_python mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Tue May 8 11:44:44 EDT 2007


Author: anthm
Date: Tue May  8 11:44:44 2007
New Revision: 5102

Modified:
   freeswitch/trunk/src/mod/languages/mod_python/Makefile
   freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h

Log:
whatever

Modified: freeswitch/trunk/src/mod/languages/mod_python/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/Makefile	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/Makefile	Tue May  8 11:44:44 2007
@@ -3,8 +3,8 @@
 
 # and define these variables to impact your build
 
-LOCAL_CFLAGS=-I$(PREFIX)/include/python2.4/
-LOCAL_LDFLAGS=-lpython2.4 -L$(PREFIX)/lib/python2.4/config/  -lutil -lstdc++
+LOCAL_CFLAGS=-I$(PREFIX)/include/python2.5/
+LOCAL_LDFLAGS=-lpython2.5 -L$(PREFIX)/lib/python2.5/config/  -lutil -lstdc++
 LOCAL_OBJS=freeswitch_python.o mod_python_wrap.o
 include ../../../../build/modmake.rules
 
@@ -14,7 +14,7 @@
 SWIGIFILE=../../../switch_swig.i
 
 local_depend:
-	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install Python-2.4.3.tgz --prefix=$(PREFIX) --enable-threads CFLAGSFORSHARED="-fPIC"
+	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install Python-2.5.1.tgz --prefix=$(PREFIX) --enable-threads CFLAGSFORSHARED="-fPIC"
 
 reswig: 
 	swig -python -shadow -c++ -o mod_python_wrap.cpp mod_python.i
@@ -26,5 +26,5 @@
 	$(CC)  -w $(CFLAGS) -c $< -o $@
 
 local_install:
-	cp -f freeswitch.py $(PREFIX)/lib/python2.4/site-packages/
+	cp -f freeswitch.py $(PREFIX)/lib/python2.5/site-packages/
 

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python.c	Tue May  8 11:44:44 2007
@@ -57,7 +57,7 @@
 	char *argv[128] = {0};
 	int argc;
 	int lead = 0;
-	char *script = NULL;
+	char *script = NULL, *script_path = NULL, *path = NULL;
 
 	if (args) {
 		dupargs = strdup(args);
@@ -80,27 +80,47 @@
 		lead = 1;
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "running %s\n", script);
+	
+	if (switch_is_file_path(script)) {
+		script_path = script;
+		if ((script = strrchr(script_path, *SWITCH_PATH_SEPARATOR))) {
+			script++;
+		} else {
+			script = script_path;
+		}
+	} else if ((path = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR, script))) {
+		script_path = path;
+	}
+	if (script_path) {
+		if (!switch_file_exists(script_path, NULL) == SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_path);
+			goto done;
+		}
+	}
 
 
-	if ((pythonfile = fopen(script, "r"))) {
-		PyEval_AcquireLock();
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "running %s\n", script_path);
+
+
+	if ((pythonfile = fopen(script_path, "r"))) {
 		tstate = Py_NewInterpreter();
-		PyEval_ReleaseLock(); 
 
 		if (!tstate) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
 			goto done;
 		}
+		
 
-
+		PyThreadState_Clear(tstate);
 		init_freeswitch();
+		PyRun_SimpleString("from freeswitch import *");
+		
 		PySys_SetArgv(argc - lead, &argv[lead]);
-		PyRun_SimpleFile(pythonfile, "");
+		PyRun_SimpleFile(pythonfile, script);
 		Py_EndInterpreter(tstate);
 		
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error running %s\n", script);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error running %s\n", script_path);
 	}
 
 
@@ -111,6 +131,7 @@
 	}
 
 	switch_safe_free(dupargs);
+	switch_safe_free(path);
 }
 
 static void python_function(switch_core_session_t *session, char *data)
@@ -214,6 +235,9 @@
 
 	PyEval_ReleaseLock();	
 
+	eval_some_python(NULL, "init_python.py");
+	PyThreadState_Swap(NULL);
+
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	Tue May  8 11:44:44 2007
@@ -85,7 +85,7 @@
 		cptr = code + 1;
 		script = JS_CompileScript(cx, obj, cptr, strlen(cptr), "inline", 1);
 	} else {
-		if (*code == '/') {
+		if (switch_is_file_path(code)) {
 			script_name = code;
 		} else if ((path = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR, code))) {
 			script_name = path;



More information about the Freeswitch-svn mailing list