Permalink
Browse files

Changed module interface (added function to free module)

  • Loading branch information...
1 parent 6e62786 commit 6170a3b5936d906c0370aff2bad04e045fde9678 @harmer harmer committed with paraboul May 24, 2010
Showing with 42 additions and 3 deletions.
  1. +22 −1 modules/libape-spidermonkey.c
  2. +2 −1 modules/plugins.h
  3. +2 −1 src/entry.c
  4. +14 −0 src/plugins.c
  5. +2 −0 src/plugins.h
@@ -2973,6 +2973,27 @@ static void init_module(acetables *g_ape) // Called when module is loaded
}
+static void free_module(acetables *g_ape) // Called when module is unloaded
+{
+ // TODO free other allocated objects
+
+ ape_sm_compiled *asc = ASMR->scripts;
+ ape_sm_compiled *prev_asc;
+
+ while (asc != NULL) {
+ free(asc->filename);
+ JS_DestroyContext(asc->cx);
+ prev_asc = asc;
+ asc = asc->next;
+ free(prev_asc);
+ }
+
+ JS_DestroyContext(ASMC);
+ JS_DestroyRuntime(ASMR->runtime);
+
+ free(ASMR);
+}
+
static USERS *ape_cb_add_user(USERS *allocated, acetables *g_ape)
{
jsval params[1];
@@ -3168,5 +3189,5 @@ static ace_callbacks callbacks = {
ape_cb_delsubuser
};
-APE_INIT_PLUGIN(MODULE_NAME, init_module, callbacks)
+APE_INIT_PLUGIN(MODULE_NAME, init_module, free_module, callbacks)
View
@@ -77,13 +77,14 @@ struct _plug_config
#define APE_PLUGIN_ENTRY_POINT
#endif
-#define APE_INIT_PLUGIN(modname, initfunc, modcallbacks) \
+#define APE_INIT_PLUGIN(modname, initfunc, freefunc, modcallbacks) \
APE_PLUGIN_ENTRY_POINT void ape_module_init(ace_plugins *module) \
{ \
infos_module.conf = NULL; \
module->cb = &modcallbacks; \
module->infos = &infos_module; \
module->loader = initfunc; \
+ module->unloader = freefunc; \
module->modulename = modname; \
}
View
@@ -334,7 +334,8 @@ int main(int argc, char **argv)
}
free(g_ape->co);
- free(g_ape->plugins);
+ free_all_plugins(g_ape);
+
free(g_ape);
return 0;
View
@@ -105,6 +105,20 @@ void findandloadplugin(acetables *g_ape)
}
+void free_all_plugins(acetables *g_ape)
+{
+ ace_plugins *prev;
+
+ while (g_ape->plugins != NULL) {
+ g_ape->plugins->unloader(g_ape);
+// dlclose(g_ape->plugins->hPlug);
+
+ prev = g_ape->plugins;
+ g_ape->plugins = g_ape->plugins->next;
+ free(g_ape->plugins);
+ }
+}
+
plug_config *plugin_parse_conf(const char *file)
{
char lines[2048], *tkn[2];
View
@@ -62,6 +62,7 @@ struct _ace_plugins
/* Module Handle */
void *hPlug;
void (*loader)(acetables *g_ape);
+ void (*unloader)(acetables *g_ape);
const char *modulename;
@@ -79,6 +80,7 @@ enum {
ace_plugins *loadplugin(char *file);
void findandloadplugin(acetables *g_ape);
+void free_all_plugins(acetables *g_ape);
struct _plug_config *plugin_parse_conf(const char *file);
void plugin_read_config(ace_plugins *plug, const char *path);
char *plugin_get_conf(struct _plug_config *conf, char *key);

0 comments on commit 6170a3b

Please sign in to comment.