[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, select, updated. gawk-4.1.0-1067-g9121c3
From: |
Andrew J. Schorr |
Subject: |
[gawk-diffs] [SCM] gawk branch, select, updated. gawk-4.1.0-1067-g9121c30 |
Date: |
Tue, 06 Jan 2015 19:20:43 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, select has been updated
via 9121c3059288f36e004108e02ed4d826b84604e7 (commit)
from cb5838c3c261f9a775fae45adfa70e1514e8bfe0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=9121c3059288f36e004108e02ed4d826b84604e7
commit 9121c3059288f36e004108e02ed4d826b84604e7
Author: Andrew J. Schorr <address@hidden>
Date: Tue Jan 6 14:20:19 2015 -0500
Fix bug so that extensions can create deferred arrays PROCINFO and ENVIRON
properly.
diff --git a/ChangeLog b/ChangeLog
index f0c3dc4..098031a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2015-01-06 Andrew J. Schorr <address@hidden>
+
+ * awk.h (variable_create): Declare new function.
+ * awkgram.y (variable_create): New function to create a variable
+ taking the deferred variable list into consideration.
+ (variable): Call new function variable_create if the variable is
+ not found.
+ * gawkapi.c (api_sym_update): If an array is being created, then
+ call new function variable_create instead of install_symbol. If this
+ is the first reference to a deferred variable, than the new array
+ may contain elements that must be merged into the array provided by
+ the extension.
+
2015-01-05 Andrew J. Schorr <address@hidden>
* io.c (wait_any): If the `interesting' argument is non-zero, then we
diff --git a/awk.h b/awk.h
index bb63f65..5ecc13f 100644
--- a/awk.h
+++ b/awk.h
@@ -1318,6 +1318,7 @@ extern NODE *do_asorti(int nargs);
extern unsigned long (*hash)(const char *s, size_t len, unsigned long hsize,
size_t *code);
extern void init_env_array(NODE *env_node);
/* awkgram.c */
+extern NODE *variable_create(char *name, NODETYPE type);
extern NODE *variable(int location, char *name, NODETYPE type);
extern int parse_program(INSTRUCTION **pcode);
extern void track_ext_func(const char *name);
diff --git a/awkgram.c b/awkgram.c
index adb31d9..2257ee3 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -7052,6 +7052,20 @@ is_deferred_variable(const char *name)
return false;
}
+/* variable_create --- create a new variable */
+NODE *
+variable_create(char *name, NODETYPE type)
+{
+ struct deferred_variable *dv;
+
+ for (dv = deferred_variables; dv != NULL; dv = dv->next) {
+ if (strcmp(name, dv->name) == 0) {
+ efree(name);
+ return (*dv->load_func)();
+ }
+ }
+ return install_symbol(name, type);
+}
/* variable --- make sure NAME is in the symbol table */
@@ -7066,25 +7080,11 @@ variable(int location, char *name, NODETYPE type)
r->vname);
if (r == symbol_table)
symtab_used = true;
- } else {
- /* not found */
- struct deferred_variable *dv;
-
- for (dv = deferred_variables; true; dv = dv->next) {
- if (dv == NULL) {
- /*
- * This is the only case in which we may not
free the string.
- */
- return install_symbol(name, type);
- }
- if (strcmp(name, dv->name) == 0) {
- r = (*dv->load_func)();
- break;
- }
- }
+ efree(name);
+ return r;
}
- efree(name);
- return r;
+ /* not found */
+ return variable_create(name, type);
}
/* process_deferred --- if the program uses SYMTAB, load deferred variables */
diff --git a/awkgram.y b/awkgram.y
index 52284af..6575e0f 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -4714,6 +4714,20 @@ is_deferred_variable(const char *name)
return false;
}
+/* variable_create --- create a new variable */
+NODE *
+variable_create(char *name, NODETYPE type)
+{
+ struct deferred_variable *dv;
+
+ for (dv = deferred_variables; dv != NULL; dv = dv->next) {
+ if (strcmp(name, dv->name) == 0) {
+ efree(name);
+ return (*dv->load_func)();
+ }
+ }
+ return install_symbol(name, type);
+}
/* variable --- make sure NAME is in the symbol table */
@@ -4728,25 +4742,11 @@ variable(int location, char *name, NODETYPE type)
r->vname);
if (r == symbol_table)
symtab_used = true;
- } else {
- /* not found */
- struct deferred_variable *dv;
-
- for (dv = deferred_variables; true; dv = dv->next) {
- if (dv == NULL) {
- /*
- * This is the only case in which we may not
free the string.
- */
- return install_symbol(name, type);
- }
- if (strcmp(name, dv->name) == 0) {
- r = (*dv->load_func)();
- break;
- }
- }
+ efree(name);
+ return r;
}
- efree(name);
- return r;
+ /* not found */
+ return variable_create(name, type);
}
/* process_deferred --- if the program uses SYMTAB, load deferred variables */
diff --git a/gawkapi.c b/gawkapi.c
index a693621..5630185 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -579,10 +579,34 @@ api_sym_update(awk_ext_id_t id,
if (node == NULL) {
/* new value to be installed */
if (value->val_type == AWK_ARRAY) {
+ unsigned long nel;
+
array_node = awk_value_to_node(value);
- node = install_symbol(estrdup((char *) name,
strlen(name)),
- Node_var_array);
+ /*
+ * use variable_create instead of install_symbol in
+ * case this is a deferred variable such as PROCINFO
+ * or ENVIRON
+ */
+ node = variable_create(estrdup((char *) name,
strlen(name)), Node_var_array);
array_node->vname = node->vname;
+ if ((nel = assoc_length(node)) > 0) {
+ /* merge the 2 arrays */
+ NODE **list;
+ NODE akind;
+ unsigned long i;
+
+ akind.flags = (AINDEX|AVALUE);
+ list = node->alist(node, & akind);
+ for (i = 0; i < nel; i++) {
+ NODE **aptr;
+ aptr = assoc_lookup(array_node,
list[2*i]);
+ unref(*aptr);
+ unref(list[2*i]); /* alist duped it */
+ *aptr = dupnode(list[2*i+1]);
+ }
+ efree(list);
+ assoc_clear(node);
+ }
*node = *array_node;
freenode(array_node);
value->array_cookie = node; /* pass new cookie back
to extension */
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 13 +++++++++++++
awk.h | 1 +
awkgram.c | 36 ++++++++++++++++++------------------
awkgram.y | 36 ++++++++++++++++++------------------
gawkapi.c | 28 ++++++++++++++++++++++++++--
5 files changed, 76 insertions(+), 38 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, select, updated. gawk-4.1.0-1067-g9121c30,
Andrew J. Schorr <=