[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, feature/andy, updated. gawk-4.1.0-2364-g
From: |
Andrew J. Schorr |
Subject: |
[gawk-diffs] [SCM] gawk branch, feature/andy, updated. gawk-4.1.0-2364-g352af50 |
Date: |
Mon, 5 Dec 2016 19:48:29 +0000 (UTC) |
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/andy has been updated
via 352af50d54071be81f6be1c4d93bfd791f473755 (commit)
from 16761af5b3cec40f1e341cb33787af33cb2b45c2 (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=352af50d54071be81f6be1c4d93bfd791f473755
commit 352af50d54071be81f6be1c4d93bfd791f473755
Author: Andrew J. Schorr <address@hidden>
Date: Mon Dec 5 14:47:51 2016 -0500
Add strnum support to API. Update rwarray extension and test.
diff --git a/ChangeLog b/ChangeLog
index 298ad7c..5c085f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2016-12-05 Andrew J. Schorr <address@hidden>
+
+ Add API support for strnum values.
+ * gawkapi.c (awk_value_to_node): Add AWK_STRNUM.
+ (assign_string): Add a type argument so we can use this for AWK_STRING
+ or AWK_STRNUM.
+ (node_to_awk_value): When AWK_NUMBER is requested, a regex value
+ should return false, as per the header file documentation.
+ Add support for AWK_STRNUM requests. When AWK_REGEX is requested,
+ implement the cases properly instead of always returning true.
+ Fix AWK_SCALAR logic. For AWK_UNDEFINED, rewrite using a switch
+ and support AWK_STRNUM.
+ (api_sym_update): Add AWK_STRNUM.
+ (api_sym_update_scalar): Add optimized support for updating AWK_STRNUM.
+ (valid_subscript_type): Add AWK_STRNUM.
+ (api_create_value): Add AWK_STRNUM.
+ * gawkapi.h (awk_valtype_t): Add AWK_STRNUM.
+ (strnum_value): New macro.
+ (Value fetching table): Updated.
+
2016-12-04 Andrew J. Schorr <address@hidden>
* gawkapi.c (assign_regex): Do not call assign_string, since we
diff --git a/doc/ChangeLog b/doc/ChangeLog
index ddf454f..cafced8 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-05 Andrew J. Schorr <address@hidden>
+
+ * gawktexi.in: Document strnum changes as relates to API.
+ Still stuff left to do -- tables for type conversions need
+ to be updated to show new strnum and regex rows and columns.
+
2016-12-04 Andrew J. Schorr <address@hidden>
* gawktexi.in: Remove make_regex and replace it with make_const_regex
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 1450d09..fc43c52 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -31572,7 +31572,8 @@ multibyte encoding.
@itemx @ @ @ @ AWK_ARRAY,
@itemx @ @ @ @ AWK_SCALAR,@ @ @ @ @ @ @ @ @ /* opaque access to a variable */
@itemx @ @ @ @ AWK_VALUE_COOKIE,@ @ @ /* for updating a previously created
value */
address@hidden @ @ @ @ AWK_REGEX
address@hidden @ @ @ @ AWK_REGEX,
address@hidden @ @ @ @ AWK_STRNUM
@itemx @} awk_valtype_t;
This @code{enum} indicates the type of a value.
It is used in the following @code{struct}.
@@ -31592,6 +31593,7 @@ The @code{val_type} member indicates what kind of value
the
@code{union} holds, and each member is of the appropriate type.
@item #define str_value@ @ @ @ @ @ u.s
address@hidden #define strnum_value@ @ @ @ str_value
@itemx #define regex_value@ @ @ @ str_value
@itemx #define num_value@ @ @ @ @ @ u.d
@itemx #define array_cookie@ @ @ u.a
@@ -31613,7 +31615,7 @@ and in more detail in @ref{Cached values}.
@end table
-Scalar values in @command{awk} are numbers, strings, or typed regexps. The
+Scalar values in @command{awk} are numbers, strings, strnums, or typed
regexps. The
@code{awk_value_t} struct represents values. The @code{val_type} member
indicates what is in the @code{union}.
@@ -31622,6 +31624,12 @@ require more work. Because @command{gawk} allows
embedded @sc{nul} bytes
in string values, a string must be represented as a pair containing a
data pointer and length. This is the @code{awk_string_t} type.
+A strnum (numeric string) value is represented as a string and consists
+of user input data that appears to be numeric.
+When an extension attempts to create a strnum value, a string flagged
+as user input is created. Subsequent parsing will determine whether it
+looks like a number and should be treated as a strnum or a regular string.
+
Typed regexp values (@pxref{Strong Regexp Constants}) are not of
much use to extension functions. Extension functions can tell that
they've received them, and create them for scalar values. Otherwise,
@@ -31796,6 +31804,18 @@ This function simply creates a numeric value in the
@code{awk_value_t} variable
pointed to by @code{result}.
@item static inline awk_value_t *
address@hidden make_const_user_input(const char *string, size_t length,
awk_value_t *result);
+This function is identical to @code{make_const_string}, but the string is
+flagged as user input that should be treated as a strnum value if the contents
+of the string are numeric.
+
address@hidden static inline awk_value_t *
address@hidden make_malloced_user_input(const char *string, size_t length,
awk_value_t *result);
+This function is identical to @code{make_malloced_string}, but the string is
+flagged as user input that should be treated as a strnum value if the contents
+of the string are numeric.
+
address@hidden static inline awk_value_t *
@itemx make_const_regex(const char *string, size_t length, awk_value_t
*result);
This function creates a strongly typed regexp value by allocating a copy of
the string.
@code{string} is the regular expression of length @code{len}.
@@ -32532,29 +32552,28 @@ value type, as appropriate. This behavior is
summarized in
@end ifnotplaintext
@ifplaintext
@example
-
+-------------------------------------------------------------+
- | Type of Actual Value:
|
-
+------------+------------+-----------+-----------+-----------+
- | String | Number | Regex | Array |
Undefined |
-+-----------+-----------+------------+------------+-----------+-----------+-----------+
-| | String | String | String | String | false |
false |
-|
+-----------+------------+------------+-----------+-----------+-----------+
-| | Number | Number if | Number | false | false |
false |
-| | | can be | | | |
|
-| | | converted, | | | |
|
-| | | else false | | | |
|
-|
+-----------+------------+------------+-----------+-----------+-----------+
-| | Regex | false | false | Regex | false |
false |
-|
+-----------+------------+------------+-----------+-----------+-----------+
-| Type | Array | false | false | false | Array |
false |
-| Requested
+-----------+------------+------------+-----------+-----------+-----------+
-| | Scalar | Scalar | Scalar | Scalar | false |
false |
-|
+-----------+------------+------------+-----------+-----------+-----------+
-| | Undefined | String | Number | Regex | Array |
Undefined |
-|
+-----------+------------+------------+-----------+-----------+-----------+
-| | Value | false | false | false | false |
false |
-| | Cookie | | | | |
|
-+-----------+-----------+------------+------------+-----------+-----------+-----------+
+
+-------------------------------------------------------+
+ | Type of Actual Value:
|
+
+--------+--------+--------+--------+-------+-----------+
+ | String | Strnum | Number | Regex | Array |
Undefined |
++-----------+-----------+--------+--------+--------+--------+-------+-----------+
+| | String | String | String | String | String | false | false
|
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Strnum | false | Strnum | Strnum | false | false | false
|
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Number | Number | Number | Number | false | false | false
|
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Regex | false | false | false | Regex | false | false
|
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| Type | Array | false | false | false | false | Array | false
|
+| Requested
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Scalar | Scalar | Scalar | Scalar | Scalar | false | false
|
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Undefined | String | Strnum | Number | Regex | Array |
Undefined |
+|
+-----------+--------+--------+--------+--------+-------+-----------+
+| | Value | false | false | false | false | false | false
|
+| | Cookie | | | | | |
|
++-----------+-----------+--------+--------+--------+--------+-------+-----------+
@end example
@end ifplaintext
@end float
@@ -32661,7 +32680,7 @@ Return false if the value cannot be retrieved.
@item awk_bool_t sym_update_scalar(awk_scalar_t cookie, awk_value_t *value);
Update the value associated with a scalar cookie. Return false if
-the new value is not of type @code{AWK_STRING}, @code{AWK_REGEX}, or
@code{AWK_NUMBER}.
+the new value is not of type @code{AWK_STRING}, @code{AWK_STRNUM},
@code{AWK_REGEX}, or @code{AWK_NUMBER}.
Here too, the predefined variables may not be updated.
@end table
@@ -32782,7 +32801,7 @@ is what the routines in this @value{SECTION} let you
do. The functions are as f
@table @code
@item awk_bool_t create_value(awk_value_t *value, awk_value_cookie_t *result);
Create a cached string or numeric value from @code{value} for
-efficient later assignment. Only values of type @code{AWK_NUMBER},
@code{AWK_REGEX},
+efficient later assignment. Only values of type @code{AWK_NUMBER},
@code{AWK_REGEX}, @code{AWK_STRNUM},
and @code{AWK_STRING} are allowed. Any other type is rejected.
@code{AWK_UNDEFINED} could be allowed, but doing so would result in
inferior performance.
diff --git a/extension/ChangeLog b/extension/ChangeLog
index dc0373f..f826e54 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,10 @@
+2016-12-05 Andrew J. Schorr <address@hidden>
+
+ * rwarray.c: Adjust to read and write strnum values.
+ (write_value): When writing a string value, code should use htonl.
+ There are now 3 string types: string, strnum, and regex.
+ (read_value): Support 3 string types: string, strnum, and regex.
+
2016-11-30 Arnold D. Robbins <address@hidden>
* rwarray.c: Restore read comparion of major and minor versions
diff --git a/extension/rwarray.c b/extension/rwarray.c
index ad77b68..5b9fd5d 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -84,7 +84,7 @@ static awk_bool_t read_value(FILE *fp, awk_value_t *value);
* For each element:
* Length of index val: 4 bytes - network order
* Index val as characters (N bytes)
- * Value type 4 bytes (0 = string, 1 = number, 2 = array, 3 = regex)
+ * Value type 4 bytes (0 = string, 1 = number, 2 = array, 3 = regex,
4 = strnum)
* IF string:
* Length of value 4 bytes
* Value as characters (N bytes)
@@ -213,7 +213,7 @@ write_elem(FILE *fp, awk_element_t *element)
return write_value(fp, & element->value);
}
-/* write_value --- write a number or a string or a regex or an array */
+/* write_value --- write a number or a string or a strnum or a regex or an
array */
static awk_bool_t
write_value(FILE *fp, awk_value_t *val)
@@ -235,7 +235,22 @@ write_value(FILE *fp, awk_value_t *val)
if (fwrite(& val->num_value, 1, sizeof(val->num_value), fp) !=
sizeof(val->num_value))
return awk_false;
} else {
- code = (val->val_type == AWK_STRING ? 0 : 3);
+ switch (val->val_type) {
+ case AWK_STRING:
+ code = htonl(0);
+ break;
+ case AWK_STRNUM:
+ code = htonl(4);
+ break;
+ case AWK_REGEX:
+ code = htonl(3);
+ break;
+ default:
+ /* XXX can this happen? */
+ code = htonl(0);
+ warning(ext_id, _("array value has unknown type %d"),
val->val_type);
+ break;
+ }
if (fwrite(& code, 1, sizeof(code), fp) != sizeof(code))
return awk_false;
@@ -455,7 +470,22 @@ read_value(FILE *fp, awk_value_t *value)
return awk_false;
}
len = ntohl(len);
- value->val_type = (code == 0 ? AWK_STRING : AWK_REGEX);
+ switch (code) {
+ case 0:
+ value->val_type = AWK_STRING;
+ break;
+ case 3:
+ value->val_type = AWK_REGEX;
+ break;
+ case 4:
+ value->val_type = AWK_STRNUM;
+ break;
+ default:
+ /* this cannot happen! */
+ warning(ext_id, _("treating recovered value with
unknown type code %d as a string"), code);
+ value->val_type = AWK_STRING;
+ break;
+ }
value->str_value.len = len;
value->str_value.str = gawk_malloc(len + 1);
memset(value->str_value.str, '\0', len + 1);
diff --git a/gawkapi.c b/gawkapi.c
index 8fe57fc..aaac24a 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -164,6 +164,11 @@ awk_value_to_node(const awk_value_t *retval)
ext_ret_val = make_str_node(retval->str_value.str,
retval->str_value.len, ALREADY_MALLOCED);
break;
+ case AWK_STRNUM:
+ ext_ret_val = make_str_node(retval->str_value.str,
+ retval->str_value.len, ALREADY_MALLOCED);
+ ext_ret_val->flags |= USER_INPUT;
+ break;
case AWK_REGEX:
ext_ret_val = make_typed_regex(retval->str_value.str,
retval->str_value.len);
@@ -415,9 +420,9 @@ free_api_string_copies()
/* assign_string --- return a string node with NUL termination */
static inline void
-assign_string(NODE *node, awk_value_t *val)
+assign_string(NODE *node, awk_value_t *val, awk_valtype_t val_type)
{
- val->val_type = AWK_STRING;
+ val->val_type = val_type;
if (node->stptr[node->stlen] != '\0') {
/*
* This is an unterminated field string, so make a copy.
@@ -493,55 +498,139 @@ node_to_awk_value(NODE *node, awk_value_t *val,
awk_valtype_t wanted)
/* a scalar value */
switch (wanted) {
case AWK_NUMBER:
- val->val_type = AWK_NUMBER;
+ if (node->flags & REGEX)
+ val->val_type = AWK_REGEX;
+ else {
+ val->val_type = AWK_NUMBER;
+ (void) force_number(node);
+ val->num_value = get_number_d(node);
+ ret = awk_true;
+ }
+ break;
- (void) force_number(node);
- val->num_value = get_number_d(node);
- ret = awk_true;
+ case AWK_STRNUM:
+ switch (fixtype(node)->flags &
(STRING|NUMBER|USER_INPUT|REGEX)) {
+ case STRING:
+ val->val_type = AWK_STRING;
+ break;
+ case NUMBER:
+ (void) force_string(node);
+ assign_string(node, val, AWK_STRNUM);
+ ret = awk_true;
+ break;
+ case NUMBER|USER_INPUT:
+ assign_string(node, val, AWK_STRNUM);
+ ret = awk_true;
+ break;
+ case REGEX:
+ val->val_type = AWK_REGEX;
+ break;
+ case NUMBER|STRING:
+ if (node == Nnull_string) {
+ val->val_type = AWK_UNDEFINED;
+ break;
+ }
+ /* fall through */
+ default:
+ warning(_("node_to_awk_value detected invalid
flags combination `%s'; please file a bug report."), flags2str(node->flags));
+ val->val_type = AWK_UNDEFINED;
+ break;
+ }
break;
case AWK_STRING:
(void) force_string(node);
- assign_string(node, val);
+ assign_string(node, val, AWK_STRING);
ret = awk_true;
break;
case AWK_REGEX:
- assign_regex(node, val);
- ret = awk_true;
+ switch (fixtype(node)->flags &
(STRING|NUMBER|USER_INPUT|REGEX)) {
+ case STRING:
+ val->val_type = AWK_STRING;
+ break;
+ case NUMBER:
+ val->val_type = AWK_NUMBER;
+ break;
+ case NUMBER|USER_INPUT:
+ val->val_type = AWK_STRNUM;
+ break;
+ case REGEX:
+ assign_regex(node, val);
+ ret = awk_true;
+ break;
+ case NUMBER|STRING:
+ if (node == Nnull_string) {
+ val->val_type = AWK_UNDEFINED;
+ break;
+ }
+ /* fall through */
+ default:
+ warning(_("node_to_awk_value detected invalid
flags combination `%s'; please file a bug report."), flags2str(node->flags));
+ val->val_type = AWK_UNDEFINED;
+ break;
+ }
break;
case AWK_SCALAR:
- fixtype(node);
- if ((node->flags & NUMBER) != 0) {
- val->val_type = AWK_NUMBER;
- } else if ((node->flags & STRING) != 0) {
+ switch (fixtype(node)->flags &
(STRING|NUMBER|USER_INPUT|REGEX)) {
+ case STRING:
val->val_type = AWK_STRING;
- } else if ((node->flags & REGEX) != 0) {
+ break;
+ case NUMBER:
+ val->val_type = AWK_NUMBER;
+ break;
+ case NUMBER|USER_INPUT:
+ val->val_type = AWK_STRNUM;
+ break;
+ case REGEX:
val->val_type = AWK_REGEX;
- } else
+ break;
+ case NUMBER|STRING:
+ if (node == Nnull_string) {
+ val->val_type = AWK_UNDEFINED;
+ break;
+ }
+ /* fall through */
+ default:
+ warning(_("node_to_awk_value detected invalid
flags combination `%s'; please file a bug report."), flags2str(node->flags));
val->val_type = AWK_UNDEFINED;
- ret = awk_false;
+ break;
+ }
break;
case AWK_UNDEFINED:
/* return true and actual type for request of undefined
*/
- fixtype(node);
- if (node == Nnull_string) {
- val->val_type = AWK_UNDEFINED;
+ switch (fixtype(node)->flags &
(STRING|NUMBER|USER_INPUT|REGEX)) {
+ case STRING:
+ assign_string(node, val, AWK_STRING);
ret = awk_true;
- } else if ((node->flags & NUMBER) != 0) {
+ break;
+ case NUMBER:
val->val_type = AWK_NUMBER;
val->num_value = get_number_d(node);
ret = awk_true;
- } else if ((node->flags & STRING) != 0) {
- assign_string(node, val);
+ break;
+ case NUMBER|USER_INPUT:
+ assign_string(node, val, AWK_STRNUM);
ret = awk_true;
- } else if ((node->flags & REGEX) != 0) {
+ break;
+ case REGEX:
assign_regex(node, val);
ret = awk_true;
- } else
+ break;
+ case NUMBER|STRING:
+ if (node == Nnull_string) {
+ val->val_type = AWK_UNDEFINED;
+ ret = awk_true;
+ break;
+ }
+ /* fall through */
+ default:
+ warning(_("node_to_awk_value detected invalid
flags combination `%s'; please file a bug report."), flags2str(node->flags));
val->val_type = AWK_UNDEFINED;
+ break;
+ }
break;
case AWK_ARRAY:
@@ -644,6 +733,7 @@ api_sym_update(awk_ext_id_t id,
switch (value->val_type) {
case AWK_NUMBER:
+ case AWK_STRNUM:
case AWK_STRING:
case AWK_REGEX:
case AWK_UNDEFINED:
@@ -745,6 +835,7 @@ api_sym_update_scalar(awk_ext_id_t id,
break;
case AWK_STRING:
+ case AWK_STRNUM:
if (node->var_value->valref == 1) {
NODE *r = node->var_value;
@@ -758,6 +849,8 @@ api_sym_update_scalar(awk_ext_id_t id,
/* make_str_node(s, l, ALREADY_MALLOCED): */
r->numbr = 0;
r->flags = (MALLOC|STRING|STRCUR);
+ if (value->val_type == AWK_STRNUM)
+ r->flags |= USER_INPUT;
r->stfmt = STFMT_UNUSED;
r->stptr = value->str_value.str;
r->stlen = value->str_value.len;
@@ -794,6 +887,7 @@ valid_subscript_type(awk_valtype_t valtype)
switch (valtype) {
case AWK_UNDEFINED:
case AWK_NUMBER:
+ case AWK_STRNUM:
case AWK_STRING:
case AWK_REGEX:
case AWK_SCALAR:
@@ -1114,6 +1208,7 @@ api_create_value(awk_ext_id_t id, awk_value_t *value,
switch (value->val_type) {
case AWK_NUMBER:
+ case AWK_STRNUM:
case AWK_STRING:
case AWK_REGEX:
break;
diff --git a/gawkapi.h b/gawkapi.h
index 4ae3649..51d4b42 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -309,7 +309,8 @@ typedef enum {
AWK_ARRAY,
AWK_SCALAR, /* opaque access to a variable */
AWK_VALUE_COOKIE, /* for updating a previously created value */
- AWK_REGEX /* last for binary compatibility */
+ AWK_REGEX,
+ AWK_STRNUM
} awk_valtype_t;
/*
@@ -326,6 +327,7 @@ typedef struct awk_value {
awk_value_cookie_t vc;
} u;
#define str_value u.s
+#define strnum_value str_value
#define regex_value str_value
#define num_value u.d
#define array_cookie u.a
@@ -479,29 +481,28 @@ typedef struct gawk_api {
Table entry is type returned:
-
+-------------------------------------------------------------+
- | Type of Actual Value:
|
-
+------------+------------+-----------+-----------+-----------+
- | String | Number | Regex | Array
| Undefined |
-
+-----------+-----------+------------+------------+-----------+-----------+-----------+
- | | String | String | String | String | false
| false |
- |
+-----------+------------+------------+-----------+-----------+-----------+
- | | Number | Number if | Number | false | false
| false |
- | | | can be | | |
| |
- | | | converted, | | |
| |
- | | | else false | | |
| |
- |
+-----------+------------+------------+-----------+-----------+-----------+
- | | Regex | false | false | Regex | false
| false |
- |
+-----------+------------+------------+-----------+-----------+-----------+
- | Type | Array | false | false | false | Array
| false |
- | Requested
+-----------+------------+------------+-----------+-----------+-----------+
- | | Scalar | Scalar | Scalar | Scalar | false
| false |
- |
+-----------+------------+------------+-----------+-----------+-----------+
- | | Undefined | String | Number | Regex | Array
| Undefined |
- |
+-----------+------------+------------+-----------+-----------+-----------+
- | | Value | false | false | false | false
| false |
- | | Cookie | | | |
| |
-
+-----------+-----------+------------+------------+-----------+-----------+-----------+
+
+-------------------------------------------------------+
+ | Type of Actual Value:
|
+
+--------+--------+--------+--------+-------+-----------+
+ | String | Strnum | Number | Regex | Array |
Undefined |
+
+-----------+-----------+--------+--------+--------+--------+-------+-----------+
+ | | String | String | String | String | String | false |
false |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Strnum | false | Strnum | Strnum | false | false |
false |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Number | Number | Number | Number | false | false |
false |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Regex | false | false | false | Regex | false |
false |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | Type | Array | false | false | false | false | Array |
false |
+ | Requested
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Scalar | Scalar | Scalar | Scalar | Scalar | false |
false |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Undefined | String | Strnum | Number | Regex | Array |
Undefined |
+ |
+-----------+--------+--------+--------+--------+-------+-----------+
+ | | Value | false | false | false | false | false |
false |
+ | | Cookie | | | | | |
|
+
+-----------+-----------+--------+--------+--------+--------+-------+-----------+
*/
/* Functions to handle parameters passed to the extension. */
@@ -846,7 +847,7 @@ typedef struct gawk_api {
/* Constructor functions */
-/* r_make_string_type --- make a string or regexp value in result from the
passed-in string */
+/* r_make_string_type --- make a string or strnum or regexp value in result
from the passed-in string */
static inline awk_value_t *
r_make_string_type(const gawk_api_t *api, /* needed for emalloc */
@@ -895,6 +896,14 @@ r_make_string(const gawk_api_t *api, /* needed for
emalloc */
#define make_const_regex(str, len, result) r_make_string_type(api, ext_id,
str, len, 1, result, AWK_REGEX)
#define make_malloced_regex(str, len, result) r_make_string_type(api, ext_id,
str, len, 0, result, AWK_REGEX)
+/*
+ * Note: The caller may not create a Strnum, but it can create a string that is
+ * flagged as user input that MAY be a Strnum. Gawk will decide whether it's a
+ * Strnum or a String by checking whether the string is numeric.
+ */
+#define make_const_user_input(str, len, result) r_make_string_type(api,
ext_id, str, len, 1, result, AWK_STRNUM)
+#define make_malloced_user_input(str, len, result) r_make_string_type(api,
ext_id, str, len, 0, result, AWK_STRNUM)
+
/* make_null_string --- make a null string value */
static inline awk_value_t *
diff --git a/test/ChangeLog b/test/ChangeLog
index a2dbdc5..d2b0cf7 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2016-12-05 Andrew J. Schorr <address@hidden>
+
+ * rwarray.awk: Check that strnum is recreated correctly.
+
2016-11-30 Arnold D. Robbins <address@hidden>
* rwarray.awk: Use typeof() to verify that typed regex is
diff --git a/test/rwarray.awk b/test/rwarray.awk
index 70809b6..86a4b58 100644
--- a/test/rwarray.awk
+++ b/test/rwarray.awk
@@ -7,6 +7,10 @@ BEGIN {
re_sub = "/typed-regex/"
dict[re_sub] = @/search me/
+ strnum_sub = "strnum-sub"
+ split("-2.4", f)
+ dict[strnum_sub] = f[1]
+
n = asorti(dict, dictindices)
for (i = 1; i <= n; i++)
printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]])
> "orig.out"
@@ -43,4 +47,8 @@ BEGIN {
if (typeof(dict[re_sub]) != "regexp")
printf("dict[\"%s\"] should be regexp, is %s\n",
re_sub, typeof(dict[re_sub]));
+
+ if (typeof(dict[strnum_sub]) != "strnum")
+ printf("dict[\"%s\"] should be strnum, is %s\n",
+ strnum_sub, typeof(dict[strnum_sub]));
}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 20 +++++++
doc/ChangeLog | 6 +++
doc/gawktexi.in | 73 ++++++++++++++++----------
extension/ChangeLog | 7 +++
extension/rwarray.c | 38 ++++++++++++--
gawkapi.c | 143 ++++++++++++++++++++++++++++++++++++++++++---------
gawkapi.h | 59 ++++++++++++---------
test/ChangeLog | 4 ++
test/rwarray.awk | 8 +++
9 files changed, 278 insertions(+), 80 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/andy, updated. gawk-4.1.0-2364-g352af50,
Andrew J. Schorr <=