[Freeswitch-branches] [commit] r11410 - in freeswitch/branches/1.0/src: . include mod/languages/mod_spidermonkey

FreeSWITCH SVN mikej at freeswitch.org
Thu Jan 22 14:14:52 PST 2009


Author: mikej
Date: Thu Jan 22 16:14:52 2009
New Revision: 11410

Log:
mod_spidermonkey: fix loading of spidermonkey modules (r:11084-11085)

Modified:
   freeswitch/branches/1.0/src/include/switch_dso.h
   freeswitch/branches/1.0/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/1.0/src/switch_dso.c

Modified: freeswitch/branches/1.0/src/include/switch_dso.h
==============================================================================
--- freeswitch/branches/1.0/src/include/switch_dso.h	(original)
+++ freeswitch/branches/1.0/src/include/switch_dso.h	Thu Jan 22 16:14:52 2009
@@ -30,10 +30,10 @@
 
 typedef void * switch_dso_data_t;
 
-void switch_dso_destroy(switch_dso_lib_t *lib);
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err);
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err);
-void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err);
+SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib);
+SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err);
+SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err);
+SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err);
 
 
 #endif

Modified: freeswitch/branches/1.0/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/1.0/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Thu Jan 22 16:14:52 2009
@@ -42,7 +42,7 @@
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_spidermonkey_shutdown);
-SWITCH_MODULE_DEFINITION(mod_spidermonkey, mod_spidermonkey_load, mod_spidermonkey_shutdown, NULL);
+SWITCH_MODULE_DEFINITION_EX(mod_spidermonkey, mod_spidermonkey_load, mod_spidermonkey_shutdown, NULL, SMODF_GLOBAL_SYMBOLS);
 
 #define METHOD_SANITY_CHECK()  if (!jss || !jss->session) {				\
 		eval_some_js("~throw new Error(\"You must call the session.originate method before calling this method!\");", cx, obj, rval); \
@@ -882,50 +882,54 @@
 static switch_status_t sm_load_file(char *filename)
 {
 	sm_loadable_module_t *module = NULL;
-	switch_dso_handle_t *dso = NULL;
+	switch_dso_lib_t dso = NULL;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_dso_handle_sym_t function_handle = NULL;
+	switch_loadable_module_function_table_t *function_handle = NULL;
 	spidermonkey_init_t spidermonkey_init = NULL;
 	const sm_module_interface_t *module_interface = NULL, *mp;
-
-	int loading = 1;
+	char *derr = NULL;
 	const char *err = NULL;
-	char derr[512] = "";
 
 	switch_assert(filename != NULL);
 
-	status = switch_dso_load(&dso, filename, module_manager.pool);
+	if (!(dso = switch_dso_open(filename, 1, &derr))) {
+		status = SWITCH_STATUS_FALSE;
+	}
 
-	while (loading) {
-		if (status != SWITCH_STATUS_SUCCESS) {
-			switch_dso_error(dso, derr, sizeof(derr));
-			err = derr;
-			break;
-		}
+	if (derr || status != SWITCH_STATUS_SUCCESS) {
+		err = derr;
+		goto err;
+	}
 
-		status = switch_dso_sym(&function_handle, dso, "spidermonkey_init");
-		spidermonkey_init = (spidermonkey_init_t) (intptr_t) function_handle;
+	function_handle = switch_dso_data_sym(dso, "spidermonkey_init", &derr);
 
-		if (spidermonkey_init == NULL) {
-			err = "Cannot Load";
-			break;
-		}
+	if (!function_handle || derr) {
+		status = SWITCH_STATUS_FALSE;
+		err = derr;
+		goto err;
+	}
 
-		if (spidermonkey_init(&module_interface) != SWITCH_STATUS_SUCCESS) {
-			err = "Module load routine returned an error";
-			break;
-		}
+	spidermonkey_init = (spidermonkey_init_t) (intptr_t) function_handle;
 
-		if (!(module = (sm_loadable_module_t *) switch_core_permanent_alloc(sizeof(*module)))) {
-			err = "Could not allocate memory\n";
-			break;
-		}
+	if (spidermonkey_init == NULL) {
+		err = "Cannot Load";
+		goto err;
+	}
+
+	if (spidermonkey_init(&module_interface) != SWITCH_STATUS_SUCCESS) {
+		err = "Module load routine returned an error";
+		goto err;
+	}
 
-		loading = 0;
+	if (!(module = (sm_loadable_module_t *) switch_core_permanent_alloc(sizeof(*module)))) {
+		err = "Could not allocate memory\n";
 	}
 
-	if (err) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Loading module %s\n**%s**\n", filename, err);
+ err:
+
+	if (err || !module) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Loading module %s\n**%s**\n", filename, switch_str_nil(err));
+		switch_safe_free(derr);
 		return SWITCH_STATUS_GENERR;
 	}
 

Modified: freeswitch/branches/1.0/src/switch_dso.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_dso.c	(original)
+++ freeswitch/branches/1.0/src/switch_dso.c	Thu Jan 22 16:14:52 2009
@@ -24,14 +24,14 @@
 
 #ifdef WIN32
 
-void switch_dso_destroy(switch_dso_lib_t *lib) {
+SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {
 	if (lib && *lib) {
 		FreeLibrary(*lib);
 		*lib = NULL;
 	}
 }
 
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {
     HINSTANCE lib;
 	
 	lib = LoadLibraryEx(path, NULL, 0);
@@ -48,7 +48,7 @@
 	return lib;
 }
 
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
 	FARPROC func = GetProcAddress(lib, sym);
 	if (!func) {
 		DWORD error = GetLastError();
@@ -57,7 +57,7 @@
 	return (switch_dso_func_t)func;
 }
 
-void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
 	FARPROC addr = GetProcAddress(lib, sym);
 	if (!addr) {
 		DWORD error = GetLastError();



More information about the Freeswitch-branches mailing list