diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2012-05-24 15:34:17 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2012-05-24 15:34:17 -0400 |
commit | 577c3fc31a2718461fba2e599d162de96fe838fa (patch) | |
tree | 1f45346053a5ae9db3c62761ef214a8a94095d30 /ext.c | |
parent | c62b9d773bc064bc1dd5d8db35207fd4e6d42f1e (diff) | |
download | egawk-577c3fc31a2718461fba2e599d162de96fe838fa.tar.gz egawk-577c3fc31a2718461fba2e599d162de96fe838fa.tar.bz2 egawk-577c3fc31a2718461fba2e599d162de96fe838fa.zip |
First working version of new API mechanism (probably has memory leaks).
Diffstat (limited to 'ext.c')
-rw-r--r-- | ext.c | 38 |
1 files changed, 18 insertions, 20 deletions
@@ -42,12 +42,12 @@ do_ext(int nargs) SRCFILE *s; extern SRCFILE *srcfiles; - fun = POP_STRING(); - obj = POP_STRING(); + fun = POP_STRING(); /* name of initialization function */ + obj = POP_STRING(); /* name of shared object */ s = add_srcfile(SRC_EXTLIB, obj->stptr, srcfiles, NULL, NULL); if (s != NULL) - ret = load_ext(s->fullpath, fun->stptr, obj); + ret = load_ext(s->fullpath, fun->stptr); DEREF(obj); DEREF(fun); if (ret == NULL) @@ -58,10 +58,9 @@ do_ext(int nargs) /* load_ext --- load an external library */ NODE * -load_ext(const char *lib_name, const char *init_func, NODE *obj) +load_ext(const char *lib_name, const char *init_func) { - NODE *tmp = NULL; - NODE *(*func)(NODE *, void *); + int (*func)(const gawk_api_t *const, awk_ext_id_t); void *dl; int flags = RTLD_LAZY; int *gpl_compat; @@ -85,33 +84,31 @@ load_ext(const char *lib_name, const char *init_func, NODE *obj) if (gpl_compat == NULL) fatal(_("extension: library `%s': does not define `plugin_is_GPL_compatible' (%s)\n"), lib_name, dlerror()); - func = (NODE *(*)(NODE *, void *)) dlsym(dl, init_func); + func = (int (*)(const gawk_api_t *const, awk_ext_id_t)) dlsym(dl, init_func); if (func == NULL) fatal(_("extension: library `%s': cannot call function `%s' (%s)\n"), lib_name, init_func, dlerror()); - if (obj == NULL) { - obj = make_string(lib_name, strlen(lib_name)); - tmp = (*func)(obj, dl); - unref(tmp); - unref(obj); - return NULL; + if ((*func)(& api_impl, NULL /* ext_id */) == 0) { + warning(_("extension: library `%s' initialization routine `%s' failed\n"), + lib_name, init_func); + return make_number(-1); } - - tmp = (*func)(obj, dl); - return tmp; + return make_number(0); } /* make_builtin --- register name to be called as func with a builtin body */ -void -make_builtin(const char *name, NODE *(*func)(int), int count) +awk_bool_t +make_builtin(const awk_ext_func_t *funcinfo) { NODE *symbol, *f; INSTRUCTION *b; const char *sp; char c; + const char *name = funcinfo->name; + int count = funcinfo->num_args_expected; sp = name; if (sp == NULL || *sp == '\0') @@ -133,7 +130,7 @@ make_builtin(const char *name, NODE *(*func)(int), int count) /* multiple extension() calls etc. */ if (do_lint) lintwarn(_("extension: function `%s' already defined"), name); - return; + return false; } else /* variable name etc. */ fatal(_("extension: function name `%s' previously defined"), name); @@ -145,13 +142,14 @@ make_builtin(const char *name, NODE *(*func)(int), int count) name); b = bcalloc(Op_symbol, 1, 0); - b->builtin = func; + b->extfunc = funcinfo->function; b->expr_count = count; /* NB: extension sub must return something */ symbol = install_symbol(estrdup(name, strlen(name)), Node_ext_func); symbol->code_ptr = b; + return true; } |