gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, extgawk, updated. 64fecd1d7a14c23fbbd693


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 64fecd1d7a14c23fbbd6938e237c66a31fabb04f
Date: Wed, 11 Jul 2012 19:23:07 +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, extgawk has been updated
       via  64fecd1d7a14c23fbbd6938e237c66a31fabb04f (commit)
      from  73533707616e119778993fe18540098239ecbb2e (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=64fecd1d7a14c23fbbd6938e237c66a31fabb04f

commit 64fecd1d7a14c23fbbd6938e237c66a31fabb04f
Author: Andrew J. Schorr <address@hidden>
Date:   Wed Jul 11 15:22:39 2012 -0400

    API array functions now accept any scalar value for an array subscript.

diff --git a/ChangeLog b/ChangeLog
index 8305718..44793ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-07-11         Andrew J. Schorr     <address@hidden>
+
+       * gawkapi.c (awk_value_to_node): Change to a switch statement
+       so AWK_SCALAR or other invalid type is handled properly.
+       (valid_subscript_type): Test whether a value type is acceptable
+       for use as an array subscript (any scalar value will do).
+       (api_get_array_element, api_set_array_element, api_del_array_element):
+       Use new valid_subscript_type instead of restricting to string values.
+
 2012-07-11         Arnold D. Robbins     <address@hidden>
 
        Lots of API work.
diff --git a/gawkapi.c b/gawkapi.c
index c5f8953..9e4f731 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -132,16 +132,23 @@ awk_value_to_node(const awk_value_t *retval)
        if (retval == NULL)
                fatal(_("awk_value_to_node: received null retval"));
 
-       ext_ret_val = NULL;
-       if (retval->val_type == AWK_ARRAY) {
+       switch (retval->val_type) {
+       case AWK_ARRAY:
                ext_ret_val = (NODE *) retval->array_cookie;
-       } else if (retval->val_type == AWK_UNDEFINED) {
+               break;
+       case AWK_UNDEFINED:
                ext_ret_val = dupnode(Nnull_string);
-       } else if (retval->val_type == AWK_NUMBER) {
+               break;
+       case AWK_NUMBER:
                ext_ret_val = make_number(retval->num_value);
-       } else {
+               break;
+       case AWK_STRING:
                ext_ret_val = make_str_node(retval->str_value.str,
                                retval->str_value.len, ALREADY_MALLOCED);
+               break;
+       default:        /* AWK_SCALAR or any invalid type */
+               ext_ret_val = NULL;
+               break;
        }
 
        return ext_ret_val;
@@ -532,6 +539,24 @@ api_sym_update_scalar(awk_ext_id_t id,
        return true;
 }
 
+/*
+ * Test if a type is allowed for an array subscript.  A string or numeric
+ * value is fine, and undefined is equivalent to "", so those are OK.
+ * We reject AWK_ARRAY and AWK_SCALAR.
+ */
+static inline int
+valid_subscript_type(awk_valtype_t valtype)
+{
+       switch (valtype) {
+       case AWK_UNDEFINED:
+       case AWK_NUMBER:
+       case AWK_STRING:
+               return true;
+       default:
+               return false;
+       }
+}
+
 /* Array management */
 /*
  * Return the value of an element - read only!
@@ -553,8 +578,7 @@ api_get_array_element(awk_ext_id_t id,
            || array->type != Node_var_array
            || result == NULL
            || index == NULL
-           || index->val_type != AWK_STRING
-           || index->str_value.str == NULL)
+           || ! valid_subscript_type(index->val_type))
                return false;
 
        subscript = awk_value_to_node(index);
@@ -596,10 +620,10 @@ api_set_array_element(awk_ext_id_t id, awk_array_t 
a_cookie,
            || array->type != Node_var_array
            || index == NULL
            || value == NULL
-           || index->str_value.str == NULL)
+           || ! valid_subscript_type(index->val_type))
                return false;
 
-       tmp = make_string(index->str_value.str, index->str_value.len);
+       tmp = awk_value_to_node(index);
        aptr = assoc_lookup(array, tmp);
        unref(tmp);
        unref(*aptr);
@@ -654,7 +678,7 @@ api_del_array_element(awk_ext_id_t id,
        if (   array == NULL
            || array->type != Node_var_array
            || index == NULL
-           || index->val_type != AWK_STRING)
+           || ! valid_subscript_type(index->val_type))
                return false;
 
        sub = awk_value_to_node(index);

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog |    9 +++++++++
 gawkapi.c |   44 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 43 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]