aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--awk.h4
-rwxr-xr-xconfigure4
-rw-r--r--configure.ac4
-rw-r--r--eval.c2
-rw-r--r--ext.c70
-rw-r--r--extension/ChangeLog6
-rw-r--r--extension/bindarr.c10
-rw-r--r--extension/fileop.c70
-rw-r--r--extension/sparr.c13
-rwxr-xr-xextension/steps19
-rw-r--r--extension/testsparr.awk1
-rw-r--r--interpret.h17
-rw-r--r--msg.c3
14 files changed, 117 insertions, 118 deletions
diff --git a/ChangeLog b/ChangeLog
index bb60a06e..6cd9889d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-11-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awk.h (Node_old_ext_func, Op_old_ext_func): New enum values.
+ * configure.ac: Use -export-dynamic if supported for old extension
+ mechanism.
+ * eval.c (nodeytpes): Add Node_old_ext_func.
+ (optypetab): Add Op_old_ext_func.
+ * ext.c (make_old_ext_builtin): "New" function.
+ * interpret.h: Special case Op_old_ext_builtin. Add checks for
+ Node_old_ext_func.
+ * msg.c: Adjust placement of a comment.
+
2012-05-02 John Haque <j.eh@mchsi.com>
* str_array.c (str_copy): Initialize next pointer in the linked list
diff --git a/awk.h b/awk.h
index 67fb6acd..a01f28f8 100644
--- a/awk.h
+++ b/awk.h
@@ -294,6 +294,7 @@ typedef enum nodevals {
Node_param_list, /* lnode is a variable, rnode is more list */
Node_func, /* lnode is param. list, rnode is body */
Node_ext_func, /* extension function, code_ptr is builtin code */
+ Node_old_ext_func, /* extension function, code_ptr is builtin code */
Node_array_ref, /* array passed by ref as parameter */
Node_array_tree, /* Hashed array tree (HAT) */
@@ -628,6 +629,7 @@ typedef enum opcodeval {
Op_builtin,
Op_sub_builtin, /* sub, gsub and gensub */
Op_ext_builtin,
+ Op_old_ext_builtin, /* temporary */
Op_in_array, /* boolean test of membership in array */
/* function call instruction */
@@ -1284,7 +1286,7 @@ if (val++) \
if (--val) \
memcpy((char *) tag, (const char *) (stack), sizeof(jmp_buf))
-#define assoc_length(a) (*((a)->alength(a, NULL)))->table_size
+#define assoc_length(a) ((*((a)->alength(a, NULL)))->table_size)
#define assoc_empty(a) (assoc_length(a) == 0)
#define assoc_lookup(a, s) ((a)->alookup(a, s))
diff --git a/configure b/configure
index 0e1998e8..4834aae3 100755
--- a/configure
+++ b/configure
@@ -10086,6 +10086,10 @@ fi
$as_echo "#define DYNAMIC 1" >>confdefs.h
+ if uname | $EGREP -i 'linux|freebsd' > /dev/null
+ then
+ LDFLAGS="$LDFLAGS -export-dynamic"
+ fi
fi
fi
diff --git a/configure.ac b/configure.ac
index bda69198..8d82747e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -295,6 +295,10 @@ AC_CHECK_HEADER(dlfcn.h,
if test "$gawk_have_dlopen" = yes
then
AC_DEFINE([DYNAMIC], 1, [dynamic loading is possible])
+ if uname | $EGREP -i 'linux|freebsd' > /dev/null
+ then
+ LDFLAGS="$LDFLAGS -export-dynamic"
+ fi
fi
])
diff --git a/eval.c b/eval.c
index 2cf22129..e9b971d8 100644
--- a/eval.c
+++ b/eval.c
@@ -241,6 +241,7 @@ static const char *const nodetypes[] = {
"Node_param_list",
"Node_func",
"Node_ext_func",
+ "Node_old_ext_func",
"Node_array_ref",
"Node_array_tree",
"Node_array_leaf",
@@ -330,6 +331,7 @@ static struct optypetab {
{ "Op_builtin", NULL },
{ "Op_sub_builtin", NULL },
{ "Op_ext_builtin", NULL },
+ { "Op_old_ext_builtin", NULL }, /* temporary */
{ "Op_in_array", " in " },
{ "Op_func_call", NULL },
{ "Op_indirect_func_call", NULL },
diff --git a/ext.c b/ext.c
index d861b82a..54098e51 100644
--- a/ext.c
+++ b/ext.c
@@ -223,92 +223,56 @@ make_builtin(const awk_ext_func_t *funcinfo)
return true;
}
-#if 0
/* make_old_builtin --- register name to be called as func with a builtin body */
void
-make_old_builtin(const char *, NODE *(*)(int), int) /* temporary */
+make_old_builtin(const char *name, NODE *(*func)(int), int count) /* temporary */
{
- NODE *p, *symbol, *f;
- INSTRUCTION *b, *r;
+ NODE *symbol, *f;
+ INSTRUCTION *b;
const char *sp;
- char *pname;
- char **vnames = NULL;
- char c, buf[200];
- size_t space_needed;
- int i;
+ char c;
sp = name;
if (sp == NULL || *sp == '\0')
fatal(_("extension: missing function name"));
while ((c = *sp++) != '\0') {
- if ((sp == &name[1] && c != '_' && ! isalpha((unsigned char) c))
+ if ((sp == & name[1] && c != '_' && ! isalpha((unsigned char) c))
|| (sp > &name[1] && ! is_identchar((unsigned char) c)))
- fatal(_("make_old_builtin: illegal character `%c' in function name `%s'"), c, name);
+ fatal(_("extension: illegal character `%c' in function name `%s'"), c, name);
}
f = lookup(name);
if (f != NULL) {
if (f->type == Node_func) {
- INSTRUCTION *pc = f->code_ptr;
- if (pc->opcode != Op_ext_func) /* user-defined function */
- fatal(_("extension: can't redefine function `%s'"), name);
- else {
- /* multiple extension() calls etc. */
- if (do_lint)
- lintwarn(_("extension: function `%s' already defined"), name);
- return;
- }
+ /* user-defined function */
+ fatal(_("extension: can't redefine function `%s'"), name);
+ } else if (f->type == Node_ext_func) {
+ /* multiple extension() calls etc. */
+ if (do_lint)
+ lintwarn(_("extension: function `%s' already defined"), name);
+ return;
} else
/* variable name etc. */
fatal(_("extension: function name `%s' previously defined"), name);
} else if (check_special(name) >= 0)
fatal(_("extension: can't use gawk built-in `%s' as function name"), name);
- /* count parameters, create artificial list of param names */
if (count < 0)
fatal(_("make_builtin: negative argument count for function `%s'"),
- name);
-
- if (count > 0) {
- sprintf(buf, "p%d", count);
- space_needed = strlen(buf) + 1;
- emalloc(vnames, char **, count * sizeof(char *), "make_builtin");
- for (i = 0; i < count; i++) {
- emalloc(pname, char *, space_needed, "make_builtin");
- sprintf(pname, "p%d", i);
- vnames[i] = pname;
- }
- }
-
-
- getnode(p);
- p->type = Node_param_list;
- p->flags |= FUNC;
- /* get our own copy for name */
- p->param = estrdup(name, strlen(name));
- p->param_cnt = count;
+ name);
- /* actual source and line numbers set at runtime for these instructions */
- b = bcalloc(Op_builtin, 1, __LINE__);
+ b = bcalloc(Op_symbol, 1, 0);
b->builtin = func;
b->expr_count = count;
- b->nexti = bcalloc(Op_K_return, 1, __LINE__);
- r = bcalloc(Op_ext_func, 1, __LINE__);
- r->source_file = __FILE__;
- r->nexti = b;
/* NB: extension sub must return something */
- symbol = mk_symbol(Node_func, p);
- symbol->parmlist = vnames;
- symbol->code_ptr = r;
- r->func_body = symbol;
- (void) install_symbol(p->param, symbol);
+ symbol = install_symbol(estrdup(name, strlen(name)), Node_old_ext_func);
+ symbol->code_ptr = b;
}
-#endif
/* get_argument --- get the i'th argument of a dynamically linked function */
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 4089185e..932eb3a7 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2012-11-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * bindarr.c, fileop.c, sparr.c: Make them compile.
+ * steps: Reinstated and updated.
+ * testsparr.awk: Add call to extension().
+
2011-05-03 John Haque <j.eh@mchsi.com>
* fileop.c, record.awk, testrecord.sh: New files.
diff --git a/extension/bindarr.c b/extension/bindarr.c
index 9f8e090c..60959903 100644
--- a/extension/bindarr.c
+++ b/extension/bindarr.c
@@ -203,7 +203,7 @@ do_bind_array(int nargs)
array_t *aq;
char *aname;
- symbol = get_array_argument(0, FALSE);
+ symbol = get_array_argument(0, false);
if (symbol->array_funcs == bind_array_func)
fatal(_("bind_array: array `%s' already bound"), array_vname(symbol));
@@ -212,7 +212,7 @@ do_bind_array(int nargs)
emalloc(aq, array_t *, sizeof(array_t), "do_bind_array");
memset(aq, '\0', sizeof(array_t));
- t = get_array_argument(1, FALSE);
+ t = get_array_argument(1, false);
for (i = 0; i < sizeof(bfn)/sizeof(char *); i++) {
NODE *subs, *val, *f;
@@ -265,7 +265,7 @@ do_unbind_array(int nargs)
NODE *symbol, *xn, *td;
array_t *aq;
- symbol = get_array_argument(0, FALSE);
+ symbol = get_array_argument(0, false);
if (symbol->array_funcs != bind_array_func)
fatal(_("unbind_array: `%s' is not a bound array"), array_vname(symbol));
@@ -341,7 +341,7 @@ call_func(NODE *func, NODE **arg, int arg_count)
NODE *
dlload(NODE *obj, void *dl)
{
- make_builtin("bind_array", do_bind_array, 2);
- make_builtin("unbind_array", do_unbind_array, 1);
+ make_old_builtin("bind_array", do_bind_array, 2);
+ make_old_builtin("unbind_array", do_unbind_array, 1);
return make_number((AWKNUM) 0);
}
diff --git a/extension/fileop.c b/extension/fileop.c
index 947c683b..86f62576 100644
--- a/extension/fileop.c
+++ b/extension/fileop.c
@@ -49,16 +49,16 @@ do_fread(int nargs)
file_t *f;
char *rbuf;
- f = file_open("fread", nargs, TRUE);
+ f = file_open("fread", nargs, true);
- arg = get_scalar_argument(2, FALSE);
+ arg = get_scalar_argument(2, false);
force_number(arg);
rlen = get_number_ui(arg);
emalloc(rbuf, char *, rlen + 2, "do_fread");
if ((count = fread(rbuf, 1, rlen, f->fp)) < rlen) {
if (! feof(f->fp))
- update_ERRNO();
+ update_ERRNO_int(errno);
}
return make_str_node(rbuf, count, ALREADY_MALLOCED);
}
@@ -72,14 +72,14 @@ do_fwrite(int nargs)
file_t *f;
size_t count = 0;
- f = file_open("fwrite", nargs, TRUE);
+ f = file_open("fwrite", nargs, true);
- arg = get_scalar_argument(2, FALSE);
+ arg = get_scalar_argument(2, false);
force_string(arg);
if (arg->stlen > 0) {
count = fwrite(arg->stptr, 1, arg->stlen, f->fp);
if (count < arg->stlen)
- update_ERRNO();
+ update_ERRNO_int(errno);
}
return make_number(count);
}
@@ -94,13 +94,13 @@ do_fseek(int nargs)
file_t *f;
int whence = 0, ret = 0;
- f = file_open("fseek", nargs, TRUE);
+ f = file_open("fseek", nargs, true);
- arg = get_scalar_argument(2, FALSE);
+ arg = get_scalar_argument(2, false);
force_number(arg);
offset = get_number_si(arg);
- arg = get_scalar_argument(3, FALSE);
+ arg = get_scalar_argument(3, false);
force_string(arg);
if (strcasecmp(arg->stptr, "SEEK_SET") == 0)
whence = SEEK_SET;
@@ -113,7 +113,7 @@ do_fseek(int nargs)
(int) arg->stlen, arg->stptr);
if (fseek(f->fp, offset, whence) < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
ret = -1;
}
return make_number(ret);
@@ -129,12 +129,12 @@ do_ftruncate(int nargs)
off_t len;
int ret = 0;
- f = file_open("ftruncate", nargs, TRUE);
- arg = get_scalar_argument(2, FALSE);
+ f = file_open("ftruncate", nargs, true);
+ arg = get_scalar_argument(2, false);
force_number(arg);
len = (off_t) get_number_si(arg);
if (ftruncate(fileno(f->fp), len) < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
ret = -1;
}
return make_number(ret);
@@ -148,12 +148,12 @@ do_unlink(int nargs)
NODE *file;
int ret = 0;
- file = get_scalar_argument(0, FALSE);
+ file = get_scalar_argument(0, false);
force_string(file);
if (file->stlen == 0)
fatal(_("unlink: filename has empty string value"));
if (unlink(file->stptr) < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
ret = -1;
}
return make_number(ret);
@@ -167,11 +167,11 @@ do_flush(int nargs)
file_t *f;
int status = -1;
- f = file_open("flush", nargs, FALSE);
+ f = file_open("flush", nargs, false);
if (f != NULL) {
status = fflush(f->fp);
if (status != 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
}
return make_number(status);
}
@@ -184,11 +184,11 @@ do_fclose(int nargs)
file_t *f;
int status = -1;
- f = file_open("fclose", nargs, FALSE);
+ f = file_open("fclose", nargs, false);
if (f != NULL) {
status = fclose(f->fp);
if (status != 0)
- update_ERRNO();
+ update_ERRNO_int(errno);
assert(files == f);
files = f->next;
efree(f);
@@ -205,18 +205,18 @@ do_filesize(int nargs)
struct stat sbuf;
AWKNUM d = -1.0;
- file = get_scalar_argument(0, FALSE);
+ file = get_scalar_argument(0, false);
force_string(file);
if (file->stlen == 0)
fatal(_("filesize: filename has empty string value"));
if (stat(file->stptr, & sbuf) < 0) {
- update_ERRNO();
+ update_ERRNO_int(errno);
goto ferror;
}
if ((sbuf.st_mode & S_IFMT) != S_IFREG) {
errno = EINVAL;
- update_ERRNO();
+ update_ERRNO_int(errno);
goto ferror;
}
d = sbuf.st_size;
@@ -234,14 +234,14 @@ do_file_exists(int nargs)
struct stat sbuf;
int ret = 1;
- file = get_scalar_argument(0, FALSE);
+ file = get_scalar_argument(0, false);
force_string(file);
if (file->stlen == 0)
fatal(_("file_exists: filename has empty string value"));
if (stat(file->stptr, & sbuf) < 0) {
if (errno != ENOENT)
- update_ERRNO();
+ update_ERRNO_int(errno);
ret = 0;
}
return make_number(ret);
@@ -262,9 +262,9 @@ file_open(const char *builtin_name, int nargs, int do_open)
if (nargs < 2)
cant_happen();
- file = get_scalar_argument(0, FALSE);
+ file = get_scalar_argument(0, false);
force_string(file);
- mode = get_scalar_argument(1, TRUE);
+ mode = get_scalar_argument(1, true);
force_string(mode);
if (file->stlen == 0)
@@ -366,15 +366,15 @@ mode2flags(const char *mode)
NODE *
dlload(NODE *tree, void *dl)
{
- make_builtin("fseek", do_fseek, 4);
- make_builtin("fread", do_fread, 3);
- make_builtin("fwrite", do_fwrite, 3);
- make_builtin("flush", do_flush, 2);
- make_builtin("filesize", do_filesize, 1);
- make_builtin("file_exists", do_file_exists, 1);
- make_builtin("fclose", do_fclose, 2);
- make_builtin("ftruncate", do_ftruncate, 3);
- make_builtin("unlink", do_unlink, 1);
+ make_old_builtin("fseek", do_fseek, 4);
+ make_old_builtin("fread", do_fread, 3);
+ make_old_builtin("fwrite", do_fwrite, 3);
+ make_old_builtin("flush", do_flush, 2);
+ make_old_builtin("filesize", do_filesize, 1);
+ make_old_builtin("file_exists", do_file_exists, 1);
+ make_old_builtin("fclose", do_fclose, 2);
+ make_old_builtin("ftruncate", do_ftruncate, 3);
+ make_old_builtin("unlink", do_unlink, 1);
return make_number((AWKNUM) 0);
}
diff --git a/extension/sparr.c b/extension/sparr.c
index e986eb1e..a3d06e66 100644
--- a/extension/sparr.c
+++ b/extension/sparr.c
@@ -47,7 +47,7 @@ install_array(const char *name)
r = install_symbol(estrdup(name, strlen(name)), Node_var_array);
switch (r->type) {
case Node_var_new:
- r = force_array(r, FALSE);
+ r = force_array(r, false);
/* fall through */
case Node_var_array:
assoc_clear(r);
@@ -79,7 +79,7 @@ store_SYS(NODE *symbol, NODE *subs, NODE *val, void *data)
if (subs != NULL && val != NULL && val->type == Node_val) {
force_string(subs);
if (strcmp(subs->stptr, "readline") == 0) {
- sd->load_file = TRUE;
+ sd->load_file = true;
unref(sd->filename);
sd->filename = dupnode(val);
}
@@ -95,7 +95,8 @@ load_READLINE(NODE *symbol, void *data)
NODE *file, *tmp;
FILE *fp;
static char linebuf[BUFSIZ];
- int i, long_line = FALSE;
+ int i;
+ bool long_line = false;
if (! sd->load_file) /* non-existent SYS["readline"] or already loaded */
return;
@@ -122,7 +123,7 @@ load_READLINE(NODE *symbol, void *data)
linebuf[sz - 1] = '\0';
sz--;
if (long_line) {
- long_line = FALSE;
+ long_line = false;
i--;
continue;
}
@@ -133,7 +134,7 @@ load_READLINE(NODE *symbol, void *data)
if (do_lint)
lintwarn(_("file `%s' does not end in newline or line # `%d' is too long"),
file->stptr, i);
- long_line = TRUE;
+ long_line = true;
}
tmp = make_number(i);
@@ -143,7 +144,7 @@ load_READLINE(NODE *symbol, void *data)
*lhs = make_string(linebuf, sz);
}
fclose(fp);
- sd->load_file = FALSE; /* don't load this file again */
+ sd->load_file = false; /* don't load this file again */
}
/* dlload --- load this library */
diff --git a/extension/steps b/extension/steps
index 168ec39e..3e8070d6 100755
--- a/extension/steps
+++ b/extension/steps
@@ -1,15 +1,10 @@
# what to do under linux to make dl.so
-# Tue Nov 24 15:04:14 EST 1998
-# Sun Aug 26 16:03:58 IDT 2001
-# Sun Apr 28 15:59:57 IDT 2002
-# Mon Jun 21 17:03:37 IDT 2004
-# Fri May 15 15:48:45 IDT 2009
# Sun Nov 25 21:40:49 IST 2012
-gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. spec_array.c
-gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. sparr.c
-gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. bindarr.c
-gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. fileop.c
-ld -o sparr.so -shared sparr.o spec_array.o
-ld -o bindarr.so -shared bindarr.o
-ld -o fileop.so -shared fileop.o
+gcc -fPIC -shared -Wall -DGAWK -DHAVE_CONFIG_H -c -O -g -I.. spec_array.c
+gcc -fPIC -shared -Wall -DGAWK -DHAVE_CONFIG_H -c -O -g -I.. sparr.c
+gcc -fPIC -shared -Wall -DGAWK -DHAVE_CONFIG_H -c -O -g -I.. bindarr.c
+gcc -fPIC -shared -Wall -DGAWK -DHAVE_CONFIG_H -c -O -g -I.. fileop.c
+gcc -o sparr.so -shared sparr.o spec_array.o
+gcc -o bindarr.so -shared bindarr.o
+gcc -o fileop.so -shared fileop.o
diff --git a/extension/testsparr.awk b/extension/testsparr.awk
index b31409f2..648a21a2 100644
--- a/extension/testsparr.awk
+++ b/extension/testsparr.awk
@@ -1,5 +1,6 @@
# ../gawk -lsparr -f testsparr.awk
BEGIN {
+ extension("sparr")
print SYS["time"]
SYS["readline"] = "sparr.c";
printf("File %s has %d lines\n", SYS["readline"], length(READLINE))
diff --git a/interpret.h b/interpret.h
index 419fc2e3..0d1511ab 100644
--- a/interpret.h
+++ b/interpret.h
@@ -901,12 +901,16 @@ arrayfor:
break;
case Op_ext_builtin:
+ case Op_old_ext_builtin:
{
int arg_count = pc->expr_count;
awk_value_t result;
PUSH_CODE(pc);
- r = awk_value_to_node(pc->extfunc(arg_count, & result));
+ if (op == Op_ext_builtin)
+ r = awk_value_to_node(pc->extfunc(arg_count, & result));
+ else
+ r = pc->builtin(arg_count);
(void) POP_CODE();
while (arg_count-- > 0) {
t1 = POP();
@@ -1012,7 +1016,7 @@ match_re:
}
if (f == NULL || f->type != Node_func) {
- if (f->type == Node_ext_func)
+ if (f->type == Node_ext_func || f->type == Node_old_ext_func)
fatal(_("cannot (yet) call extension functions indirectly"));
else
fatal(_("function called indirectly through `%s' does not exist"),
@@ -1032,19 +1036,22 @@ match_re:
f = pc->func_body;
if (f == NULL) {
f = lookup(pc->func_name);
- if (f == NULL || (f->type != Node_func && f->type != Node_ext_func))
+ if (f == NULL || (f->type != Node_func && f->type != Node_ext_func && f->type != Node_old_ext_func))
fatal(_("function `%s' not defined"), pc->func_name);
pc->func_body = f; /* save for next call */
}
- if (f->type == Node_ext_func) {
+ if (f->type == Node_ext_func || f->type == Node_old_ext_func) {
INSTRUCTION *bc;
char *fname = pc->func_name;
int arg_count = (pc + 1)->expr_count;
bc = f->code_ptr;
assert(bc->opcode == Op_symbol);
- pc->opcode = Op_ext_builtin; /* self modifying code */
+ if (f->type == Node_ext_func)
+ pc->opcode = Op_ext_builtin; /* self modifying code */
+ else
+ pc->opcode = Op_old_ext_builtin; /* self modifying code */
pc->extfunc = bc->extfunc;
pc->expr_count = arg_count; /* actual argument count */
(pc + 1)->func_name = fname; /* name of the builtin */
diff --git a/msg.c b/msg.c
index 5427a963..c0bf38ae 100644
--- a/msg.c
+++ b/msg.c
@@ -162,7 +162,6 @@ gawk_exit(int status)
longjmp(fatal_tag, 1);
}
- /* we could close_io() here */
final_exit(status);
}
@@ -173,6 +172,8 @@ final_exit(int status)
{
/* run any extension exit handlers */
run_ext_exit_handlers(status);
+
+ /* we could close_io() here */
close_extensions();
exit(status);