(LBAPR-1) load mod_lua with global symbols space so that sub modules are able to link to it properly. Broken in svn r9605.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10306 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-11-08 11:21:54 +00:00
parent bd79896c21
commit d3e7370885
4 changed files with 34 additions and 10 deletions

View File

@ -1355,7 +1355,7 @@ struct switch_network_list;
typedef struct switch_network_list switch_network_list_t;
#define SWITCH_API_VERSION 1
#define SWITCH_API_VERSION 2
#define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
#define SWITCH_MODULE_RUNTIME_ARGS (void)
#define SWITCH_MODULE_SHUTDOWN_ARGS (void)
@ -1366,22 +1366,32 @@ typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS;
#define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
#define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
typedef enum {
SMODF_NONE = 0,
SMODF_GLOBAL_SYMBOLS = (1 << 0)
} switch_module_flag_enum_t;
typedef uint32_t switch_module_flag_t;
typedef struct switch_loadable_module_function_table {
int switch_api_version;
switch_module_load_t load;
switch_module_shutdown_t shutdown;
switch_module_runtime_t runtime;
switch_module_flag_t flags;
} switch_loadable_module_function_table_t;
#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \
#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags) \
static const char modname[] = #name ; \
SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = { \
SWITCH_API_VERSION, \
load, \
shutdown, \
runtime \
runtime, \
flags \
}
#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \
SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE)
/* things we don't deserve to know about */
/*! \brief A channel */

View File

@ -52,7 +52,7 @@
#define SWIFT_FAILED(r) ((void *)(r) < (void *)0)
SWITCH_MODULE_LOAD_FUNCTION(mod_cepstral_load);
SWITCH_MODULE_DEFINITION(mod_cepstral, mod_cepstral_load, NULL, NULL);
SWITCH_MODULE_DEFINITION_EX(mod_cepstral, mod_cepstral_load, NULL, NULL, SMODF_GLOBAL_SYMBOLS);
static swift_engine *engine;

View File

@ -40,8 +40,7 @@ SWITCH_BEGIN_EXTERN_C
SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lua_shutdown);
SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, mod_lua_shutdown, NULL);
SWITCH_MODULE_DEFINITION_EX(mod_lua, mod_lua_load, mod_lua_shutdown, NULL, SMODF_GLOBAL_SYMBOLS);
static struct {
switch_memory_pool_t *pool;
char *xml_handler;

View File

@ -691,6 +691,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
char *derr = NULL;
const char *err = NULL;
switch_memory_pool_t *pool;
switch_bool_t load_global = global;
switch_assert(path != NULL);
@ -700,11 +701,11 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
struct_name = switch_core_sprintf(pool, "%s_module_interface", filename);
#ifdef WIN32
dso = switch_dso_open("FreeSwitch.dll", global, &derr);
dso = switch_dso_open("FreeSwitch.dll", load_global, &derr);
#elif defined (MACOSX) || defined(DARWIN)
dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", global, &derr);
dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", load_global, &derr);
#else
dso = switch_dso_open(NULL, global, &derr);
dso = switch_dso_open(NULL, load_global, &derr);
#endif
if (!derr && dso) {
interface_struct_handle = switch_dso_data_sym(dso, struct_name, &derr);
@ -713,7 +714,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
switch_safe_free(derr)
if (!interface_struct_handle) {
dso = switch_dso_open(path, global, &derr);
dso = switch_dso_open(path, load_global, &derr);
}
while (loading) {
@ -731,6 +732,20 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
break;
}
if (interface_struct_handle && interface_struct_handle->switch_api_version != SWITCH_API_VERSION) {
err = "Trying to load an out of date module, please rebuild the module.";
break;
}
if (!load_global && interface_struct_handle && switch_test_flag(interface_struct_handle, SMODF_GLOBAL_SYMBOLS)) {
load_global = SWITCH_TRUE;
switch_dso_destroy(&dso);
interface_struct_handle = NULL;
dso = switch_dso_open(path, load_global, &derr);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading module with global namespace at request of module\n");
continue;
}
if (interface_struct_handle) {
mod_interface_functions = interface_struct_handle;
load_func_ptr = mod_interface_functions->load;