diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-12-04 16:50:50 -0500 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-12-04 16:50:50 -0500 |
commit | 16761af5b3cec40f1e341cb33787af33cb2b45c2 (patch) | |
tree | d29bc360a9c234bed55a2922d8fcca3fbe89f2a8 | |
parent | 4a20341b487c17b49fc455ba37df84946eda38a7 (diff) | |
download | egawk-16761af5b3cec40f1e341cb33787af33cb2b45c2.tar.gz egawk-16761af5b3cec40f1e341cb33787af33cb2b45c2.tar.bz2 egawk-16761af5b3cec40f1e341cb33787af33cb2b45c2.zip |
Improve API regex support.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | doc/ChangeLog | 5 | ||||
-rw-r--r-- | doc/gawktexi.in | 10 | ||||
-rw-r--r-- | gawkapi.c | 6 | ||||
-rw-r--r-- | gawkapi.h | 4 |
5 files changed, 30 insertions, 3 deletions
@@ -1,5 +1,13 @@ 2016-12-04 Andrew J. Schorr <aschorr@telemetry-investments.com> + * gawkapi.c (assign_regex): Do not call assign_string, since we + know that a REGEX value is not an unterminated field string. + * gawkapi.h (make_regex): Delete macro. + (make_const_regex, make_malloced_regex): Add new macros to replace + make_regex with necessary memory management support. + +2016-12-04 Andrew J. Schorr <aschorr@telemetry-investments.com> + * awk.h (fixtype): Remove conditional checking if the node type is Node_val. This is already covered by the assert, and if it's not true, we have serious bugs. diff --git a/doc/ChangeLog b/doc/ChangeLog index 2e08deff..ddf454f0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,10 @@ 2016-12-04 Andrew J. Schorr <aschorr@telemetry-investments.com> + * gawktexi.in: Remove make_regex and replace it with make_const_regex + and make_malloced_regex. + +2016-12-04 Andrew J. Schorr <aschorr@telemetry-investments.com> + * gawktexi.in: Document new flatten_array_typed API function, and indicate that the old flatten_array function has been superseded. diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 17206bce..1450d09d 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -31796,9 +31796,17 @@ 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 * -@itemx make_regex(const char *string, size_t length, awk_value_t *result); +@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}. + +@item static inline awk_value_t * +@itemx make_malloced_regex(const char *string, size_t length, awk_value_t *result); This function creates a strongly typed regexp value. @code{string} is the regular expression of length @code{len}. +It expects @code{string} to be a @samp{char *} +value pointing to data previously obtained from @code{gawk_malloc()}, @code{gawk_calloc()}, or @code{gawk_realloc()}. + @end table @node Registration Functions @@ -449,7 +449,11 @@ assign_string(NODE *node, awk_value_t *val) static inline void assign_regex(NODE *node, awk_value_t *val) { - assign_string(node, val); + /* a REGEX node cannot be an unterminated field string */ + assert((node->flags & MALLOC) != 0); + assert(node->stptr[node->stlen] == '\0'); + val->str_value.str = node->stptr; + val->str_value.len = node->stlen; val->val_type = AWK_REGEX; } @@ -891,7 +891,9 @@ r_make_string(const gawk_api_t *api, /* needed for emalloc */ #define make_const_string(str, len, result) r_make_string(api, ext_id, str, len, 1, result) #define make_malloced_string(str, len, result) r_make_string(api, ext_id, str, len, 0, result) -#define make_regex(str, len, result) r_make_string_type(api, ext_id, str, len, 1, result, AWK_REGEX) + +#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) /* make_null_string --- make a null string value */ |