37
37
static unsigned long long dummy; /* fake out gcc for dynamic loading? */
40
/* do_ext --- load an extension */
40
/* do_ext --- load an extension at run-time: interface to load_ext */
45
NODE *obj, *fun, *ret = NULL;
47
extern SRCFILE *srcfiles;
52
s = add_srcfile(SRC_EXTLIB, obj->stptr, srcfiles, NULL, NULL);
54
ret = load_ext(s->fullpath, fun->stptr, obj);
58
ret = dupnode(Nnull_string);
62
/* load_ext --- load an external library */
65
load_ext(const char *lib_name, const char *init_func, NODE *obj)
48
68
NODE *(*func)(NODE *, void *);
50
70
int flags = RTLD_LAZY;
51
int fatal_error = FALSE;
61
80
fatal(_("extensions are not allowed in sandbox mode"));
63
82
if (do_traditional || do_posix)
64
error(_("`extension' is a gawk extension"));
83
fatal(_("`extension' is a gawk extension"));
70
86
flags |= RTLD_GLOBAL;
72
if ((dl = dlopen(obj->stptr, flags)) == NULL) {
73
/* fatal needs `obj', and we need to deallocate it! */
74
msg(_("fatal: extension: cannot open `%s' (%s)\n"), obj->stptr,
89
if ((dl = dlopen(lib_name, flags)) == NULL)
90
fatal(_("extension: cannot open library `%s' (%s)\n"), lib_name,
80
93
/* Per the GNU Coding standards */
81
94
gpl_compat = (int *) dlsym(dl, "plugin_is_GPL_compatible");
82
if (gpl_compat == NULL) {
83
msg(_("fatal: extension: library `%s': does not define `plugin_is_GPL_compatible' (%s)\n"),
84
obj->stptr, dlerror());
89
func = (NODE *(*)(NODE *, void *)) dlsym(dl, fun->stptr);
91
msg(_("fatal: extension: library `%s': cannot call function `%s' (%s)\n"),
92
obj->stptr, fun->stptr, dlerror());
95
if (gpl_compat == NULL)
96
fatal(_("extension: library `%s': does not define `plugin_is_GPL_compatible' (%s)\n"),
99
func = (NODE *(*)(NODE *, void *)) dlsym(dl, init_func);
101
fatal(_("extension: library `%s': cannot call function `%s' (%s)\n"),
102
lib_name, init_func, dlerror());
105
obj = make_string(lib_name, strlen(lib_name));
106
tmp = (*func)(obj, dl);
97
112
tmp = (*func)(obj, dl);
99
tmp = dupnode(Nnull_string);
104
gawk_exit(EXIT_FATAL);
174
182
if (i < 0 || i >= pcount || i >= arg_count)
185
t = PEEK(arg_count - i);
186
if (t->type == Node_param_list)
187
t = GET_PARAM(t->param_cnt);
178
189
if (t->type == Node_array_ref)
179
190
t = t->orig_array;
180
191
if (t->type == Node_var) /* See Case Node_var in setup_frame(), eval.c */
247
258
ERRNO_node->var_value = make_string(emsg, strlen(emsg));
248
259
return make_number((AWKNUM) -1);
262
/* load_ext --- dummy version if extensions not available */
265
load_ext(const char *lib_name, const char *init_func, NODE *obj)
267
fatal(_("dynamic loading of library not supported"));