[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, feature/assoc_set, updated. gawk-4.1.0-3
From: |
Andrew J. Schorr |
Subject: |
[gawk-diffs] [SCM] gawk branch, feature/assoc_set, updated. gawk-4.1.0-3599-g5812db7 |
Date: |
Tue, 15 Jan 2019 10:52:02 -0500 (EST) |
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, feature/assoc_set has been updated
via 5812db74483bce781281422953d359fde5be6a99 (commit)
from 69b4c6e0b70f92e829848e21c4d8983fac904f30 (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=5812db74483bce781281422953d359fde5be6a99
commit 5812db74483bce781281422953d359fde5be6a99
Author: Andrew J. Schorr <address@hidden>
Date: Tue Jan 15 10:51:40 2019 -0500
Fix location of assoc_set function in awk.h and start to use it.
diff --git a/ChangeLog b/ChangeLog
index f90a00f..ea1badb 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-15 Andrew J. Schorr <address@hidden>
+
+ * awk.h (assoc_set): Move the definition lower down because it
+ needs to be after unref is declared.
+ * builtin.c (do_match): Use assoc_set in 3 places.
+ (do_intdiv): Use assoc_set in 2 places.
+ (do_typeof): Use assoc_set in 2 places.
+
2019-01-14 Andrew J. Schorr <address@hidden>
* awk.h (assoc_set): Add new inline function to set an array element
diff --git a/awk.h b/awk.h
index 9b5d359..d14eae2 100644
--- a/awk.h
+++ b/awk.h
@@ -1362,20 +1362,6 @@ extern int fatal_tag_valid;
/* assoc_remove --- remove an index from symbol[] */
#define assoc_remove(a, s) ((a)->aremove(a, s) != NULL)
-/* assoc_set -- set an element in an array */
-
-static inline void
-assoc_set(NODE *array, NODE *sub, NODE *value)
-{
-
- NODE **lhs = assoc_lookup(array, sub);
- unref(*lhs);
- *lhs = value;
- if (array->astore != NULL)
- (*array->astore)(array, sub);
- unref(sub);
-}
-
/* ------------- Function prototypes or defs (as appropriate) ------------- */
/* array.c */
@@ -2038,6 +2024,20 @@ make_number_node(unsigned int flags)
return r;
}
+/* assoc_set -- set an element in an array */
+
+static inline void
+assoc_set(NODE *array, NODE *sub, NODE *value)
+{
+
+ NODE **lhs = assoc_lookup(array, sub);
+ unref(*lhs);
+ *lhs = value;
+ if (array->astore != NULL)
+ (*array->astore)(array, sub);
+ unref(sub);
+}
+
/*
* str_terminate_f, str_terminate, str_restore: function and macros to
* reduce chances of typos when terminating and restoring strings.
diff --git a/builtin.c b/builtin.c
index 9cf817a..de8e3f7 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2719,15 +2719,7 @@ do_match(int nargs)
it = make_string(start, len);
it->flags |= USER_INPUT;
-
- sub = make_number((AWKNUM) (ii));
- lhs = assoc_lookup(dest, sub);
- unref(*lhs);
- *lhs = it;
- /* execute post-assignment routine if
any */
- if (dest->astore != NULL)
- (*dest->astore)(dest, sub);
- unref(sub);
+ assoc_set(dest, make_number((AWKNUM)
(ii)), it);;
sprintf(buff, "%d", ii);
ilen = strlen(buff);
@@ -2745,14 +2737,7 @@ do_match(int nargs)
slen = ilen + subseplen + 5;
- it = make_number((AWKNUM) subpat_start
+ 1);
- sub = make_string(buf, slen);
- lhs = assoc_lookup(dest, sub);
- unref(*lhs);
- *lhs = it;
- if (dest->astore != NULL)
- (*dest->astore)(dest, sub);
- unref(sub);
+ assoc_set(dest, make_string(buf, slen),
make_number((AWKNUM) subpat_start + 1));
memcpy(buf, buff, ilen);
memcpy(buf + ilen, subsepstr,
subseplen);
@@ -2760,14 +2745,7 @@ do_match(int nargs)
slen = ilen + subseplen + 6;
- it = make_number((AWKNUM) subpat_len);
- sub = make_string(buf, slen);
- lhs = assoc_lookup(dest, sub);
- unref(*lhs);
- *lhs = it;
- if (dest->astore != NULL)
- (*dest->astore)(dest, sub);
- unref(sub);
+ assoc_set(dest, make_string(buf, slen),
make_number((AWKNUM) subpat_len));
}
}
@@ -4044,15 +4022,9 @@ do_intdiv(int nargs)
#endif /* ! HAVE_FMOD */
remainder = double_to_int(remainder);
- sub = make_string("quotient", 8);
- lhs = assoc_lookup(result, sub);
- unref(*lhs);
- *lhs = make_number((AWKNUM) quotient);
+ assoc_set(result, make_string("quotient", 8), make_number((AWKNUM)
quotient));
- sub = make_string("remainder", 9);
- lhs = assoc_lookup(result, sub);
- unref(*lhs);
- *lhs = make_number((AWKNUM) remainder);
+ assoc_set(result, make_string("remainder", 9), make_number((AWKNUM)
remainder));
DEREF(denominator);
DEREF(numerator);
@@ -4085,15 +4057,8 @@ do_typeof(int nargs)
/* Node_var_array is never UPREF'ed */
res = "array";
deref = false;
- if (dbg) {
- NODE *sub = make_string("array_type", 10);
- NODE **lhs = assoc_lookup(dbg, sub);
- unref(*lhs);
- *lhs = make_string(arg->array_funcs->name,
strlen(arg->array_funcs->name));
- if (dbg->astore != NULL)
- (*dbg->astore)(dbg, sub);
- unref(sub);
- }
+ if (dbg)
+ assoc_set(dbg, make_string("array_type", 10),
make_string(arg->array_funcs->name, strlen(arg->array_funcs->name)));
break;
case Node_val:
switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX))
{
@@ -4124,13 +4089,7 @@ do_typeof(int nargs)
}
if (dbg) {
const char *s = flags2str(arg->flags);
- NODE *sub = make_string("flags", 5);
- NODE **lhs = assoc_lookup(dbg, sub);
- unref(*lhs);
- *lhs = make_string(s, strlen(s));
- if (dbg->astore != NULL)
- (*dbg->astore)(dbg, sub);
- unref(sub);
+ assoc_set(dbg, make_string("flags", 5), make_string(s,
strlen(s)));
}
break;
case Node_var_new:
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 8 ++++++++
awk.h | 28 ++++++++++++++--------------
builtin.c | 57 ++++++++-------------------------------------------------
3 files changed, 30 insertions(+), 63 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/assoc_set, updated. gawk-4.1.0-3599-g5812db7,
Andrew J. Schorr <=