summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-05-25 15:18:43 +0300
committerArnold D. Robbins <arnold@skeeve.com>2012-05-25 15:18:43 +0300
commiteec7101174a3b2807fb282272f75cc13d4b953c3 (patch)
tree2748f77fb510d32f6090fc3e3e02829682336e15
parent577c3fc31a2718461fba2e599d162de96fe838fa (diff)
downloadgawk-eec7101174a3b2807fb282272f75cc13d4b953c3.tar.gz
Additional changes / some cleanups.
-rw-r--r--ChangeLog9
-rw-r--r--awk.h1
-rwxr-xr-xbootstrap.sh4
-rw-r--r--extension/ChangeLog5
-rw-r--r--extension/filefuncs.c2
-rw-r--r--gawkapi.c6
-rw-r--r--gawkapi.h5
-rw-r--r--main.c21
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am2
-rw-r--r--test/Makefile.in2
11 files changed, 57 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 8814c36f..abdcf131 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-05-25 Arnold D. Robbins <arnold@skeeve.com>
+
+ * main.c (is_off_limits_var): New function to check if a variable
+ is one that an extension function may not change.
+ * awk.h (is_off_limits_var): Declare it.
+ * gawkapi.c (api_sym_lookup): Use it.
+
+ * bootstrap.h: Touch various files in the extension directory also.
+
2012-05-24 Andrew J. Schorr <aschorr@telemetry-investments.com>
* gawkapi.h (awk_param_type_t): Remove (use awk_valtype_t instead).
diff --git a/awk.h b/awk.h
index 0ac59582..ea4819ed 100644
--- a/awk.h
+++ b/awk.h
@@ -1565,6 +1565,7 @@ extern int nextfile(IOBUF **curfile, bool skipping);
/* main.c */
extern int arg_assign(char *arg, bool initing);
extern int is_std_var(const char *var);
+extern int is_off_limits_var(const char *var);
extern char *estrdup(const char *str, size_t len);
extern void update_global_values();
extern long getenv_long(const char *name);
diff --git a/bootstrap.sh b/bootstrap.sh
index 54a97108..67faf76a 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -37,3 +37,7 @@ touch po/stamp-po
touch awkgram.c
touch command.c
touch version.c
+
+touch extension/configure
+sleep 2
+touch extension/configh.in
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 11c9f4d3..4fa1a7f5 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-25 Arnold D. Robbins <arnold@skeeve.com>
+
+ * filefuncs.c (array_set_numeric): Don't return a value from
+ a void function.
+
2012-05-24 Andrew J. Schorr <aschorr@telemetry-investments.com>
* Makefile.am (AM_CPPFLAGS): Use $(srcdir) to work properly when
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index 74a086a9..fb19f2b3 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -230,7 +230,7 @@ static void
array_set_numeric(awk_array_t array, const char *sub, double num)
{
awk_value_t tmp;
- return array_set(array, sub, make_number(num, & tmp));
+ array_set(array, sub, make_number(num, & tmp));
}
/* do_stat --- provide a stat() function for gawk */
diff --git a/gawkapi.c b/gawkapi.c
index dbaa730e..a25a8905 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -255,13 +255,17 @@ node_to_awk_value(NODE *node, awk_value_t *val)
/*
* Lookup a variable, return its value. No messing with the value
* returned. Return value is NULL if the variable doesn't exist.
+ * Built-in variables (except PROCINFO) may not be changed by an extension.
*/
static awk_value_t *
api_sym_lookup(awk_ext_id_t id, const char *name, awk_value_t *result)
{
NODE *node;
- if (name == NULL || (node = lookup(name)) == NULL)
+ if ( name == NULL
+ || *name == '\0'
+ || is_off_limits_var(name) /* most built-in vars not allowed */
+ || (node = lookup(name)) == NULL)
return NULL;
return node_to_awk_value(node, result);
diff --git a/gawkapi.h b/gawkapi.h
index 3b52bff1..54122cab 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -149,6 +149,11 @@ typedef struct awk_element {
* A record describing an extension function. Upon being
* loaded, the extension should pass in one of these for
* each C function.
+ *
+ * Each called function must fill in the result with eiher a number
+ * or string. Gawk takes ownership of any string memory.
+ *
+ * The called function should return the value of `result'.
*/
typedef struct {
const char *name;
diff --git a/main.c b/main.c
index 844052f1..e8f087c1 100644
--- a/main.c
+++ b/main.c
@@ -950,6 +950,7 @@ struct varinit {
int flags;
#define NO_INSTALL 0x01
#define NON_STANDARD 0x02
+#define NOT_OFF_LIMITS 0x04 /* may be accessed by extension function */
};
static const struct varinit varinit[] = {
@@ -973,7 +974,7 @@ static const struct varinit varinit[] = {
{&OFMT_node, "OFMT", "%.6g", 0, NULL, set_OFMT, true, 0 },
{&OFS_node, "OFS", " ", 0, NULL, set_OFS, true, 0 },
{&ORS_node, "ORS", "\n", 0, NULL, set_ORS, true, 0 },
-{NULL, "PROCINFO", NULL, 0, NULL, NULL, false, NO_INSTALL | NON_STANDARD },
+{NULL, "PROCINFO", NULL, 0, NULL, NULL, false, NO_INSTALL | NON_STANDARD | NOT_OFF_LIMITS },
{&RLENGTH_node, "RLENGTH", NULL, 0, NULL, NULL, false, 0 },
{&ROUNDMODE_node, "ROUNDMODE", DEFAULT_ROUNDMODE, 0, NULL, set_ROUNDMODE, false, NON_STANDARD },
{&RS_node, "RS", "\n", 0, NULL, set_RS, true, 0 },
@@ -1190,6 +1191,24 @@ is_std_var(const char *var)
return false;
}
+/*
+ * is_off_limits_var --- return true if a variable is off limits
+ * to extension functions
+ */
+
+int
+is_off_limits_var(const char *var)
+{
+ const struct varinit *vp;
+
+ for (vp = varinit; vp->name != NULL; vp++) {
+ if ( (vp->flags & NOT_OFF_LIMITS) != 0
+ && strcmp(vp->name, var) == 0)
+ return false;
+ }
+
+ return true;
+}
/* get_spec_varname --- return the name of a special variable
with the given assign or update routine.
diff --git a/test/ChangeLog b/test/ChangeLog
index 72c7b9e8..563f8e05 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-25 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (readfile): Don't copy the Makefile over readfile.ok
+ if there's a problem.
+
2012-05-24 Andrew J. Schorr <aschorr@telemetry-investments.com>
* Makefile.am (fmtspcl, include2, incdupe, incdup2, incdupe3): Fix
diff --git a/test/Makefile.am b/test/Makefile.am
index 2af0e38b..ea7e9a9e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1555,7 +1555,7 @@ ordchr2::
readfile::
@echo $@
@$(AWK) -l readfile 'BEGIN {printf "%s", readfile("Makefile")}' >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
- @-$(CMP) Makefile _$@ && rm -f _$@ || cp -p Makefile $@.ok
+ @-$(CMP) Makefile _$@ && rm -f _$@
include2::
@echo $@
diff --git a/test/Makefile.in b/test/Makefile.in
index 0c990912..34b7e930 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1936,7 +1936,7 @@ ordchr2::
readfile::
@echo $@
@$(AWK) -l readfile 'BEGIN {printf "%s", readfile("Makefile")}' >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
- @-$(CMP) Makefile _$@ && rm -f _$@ || cp -p Makefile $@.ok
+ @-$(CMP) Makefile _$@ && rm -f _$@
include2::
@echo $@