From 133125e373eebdd96cfe5ed54951d2770c01ef7d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 4 Jul 2013 11:58:14 +0300 Subject: Force array indices to be strings in flatten_array API. --- ChangeLog | 10 ++++++++++ gawkapi.c | 11 ++++++++--- gawkapi.h | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6a32d6d..750b7f06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2013-07-04 Andrew J. Schorr + + * gawkapi.h (awk_element_t): Add comment indicating that the array + element index will always be a string! + * gawkapi.c (api_flatten_array): When converting the index to an awk + value, request a string conversion, since we want the indices to + appear as strings to the extensions. This makes the call to + force_string redundant, since node_to_awk_value does that internally + when we request a string. + 2013-07-04 Arnold D. Robbins * builtin.c (format_tree): Fixes for %c with multibyte characters diff --git a/gawkapi.c b/gawkapi.c index 61f91e8c..9936d530 100644 --- a/gawkapi.c +++ b/gawkapi.c @@ -934,12 +934,17 @@ api_flatten_array(awk_ext_id_t id, for (i = j = 0; i < 2 * array->table_size; i += 2, j++) { NODE *index, *value; - index = force_string(list[i]); + index = list[i]; value = list[i + 1]; /* number or string or subarray */ - /* convert index and value to ext types */ + /* + * Convert index and value to ext types. Force the + * index to be a string, since indices are always + * conceptually strings, regardless of internal optimizations + * to treat them as integers in some cases. + */ if (! node_to_awk_value(index, - & (*data)->elements[j].index, AWK_UNDEFINED)) { + & (*data)->elements[j].index, AWK_STRING)) { fatal(_("api_flatten_array: could not convert index %d\n"), (int) i); } diff --git a/gawkapi.h b/gawkapi.h index cc50bba3..b26ee24c 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -343,7 +343,7 @@ typedef struct awk_element { AWK_ELEMENT_DELETE = 1 /* set by extension if should be deleted */ } flags; - awk_value_t index; + awk_value_t index; /* guaranteed to be a string! */ awk_value_t value; } awk_element_t; -- cgit v1.2.3