gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, feature/bool, updated. gawk-4.1.0-4273-g2c53d83


From: Arnold Robbins
Subject: [SCM] gawk branch, feature/bool, updated. gawk-4.1.0-4273-g2c53d83
Date: Tue, 30 Mar 2021 10:14:30 -0400 (EDT)

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/bool has been updated
       via  2c53d8349f3e5abdbbcd8168ac284c5989b4f444 (commit)
       via  5887e22adfed809e482da3a6f5b2f37901915aff (commit)
      from  4561382e8ee7cb0ca0f03e817467973d428260b3 (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=2c53d8349f3e5abdbbcd8168ac284c5989b4f444

commit 2c53d8349f3e5abdbbcd8168ac284c5989b4f444
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Tue Mar 30 17:14:06 2021 +0300

    Update rwarray extension for bool values, and also test code.

diff --git a/extension/ChangeLog b/extension/ChangeLog
index cf58064..986a835 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-30         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * rwarray.c (write_value): Add support for writing boolean values.
+       (read_value): Ditto.
+
 2021-03-29         Arnold D. Robbins     <arnold@skeeve.com>
 
        * testext.c (var_test): Fix a comment. Update copyright year.
diff --git a/extension/rwarray.c b/extension/rwarray.c
index 45f9c73..a534a5a 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -8,7 +8,7 @@
  */
 
 /*
- * Copyright (C) 2009-2014, 2017, 2018, 2020 the Free Software Foundation, Inc.
+ * Copyright (C) 2009-2014, 2017, 2018, 2020, 2021 the Free Software 
Foundation, Inc.
  *
  * This file is part of GAWK, the GNU implementation of the
  * AWK Programming Language.
@@ -36,6 +36,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -249,6 +250,9 @@ write_value(FILE *fp, awk_value_t *val)
                case AWK_UNDEFINED:
                        code = htonl(5);
                        break;
+               case AWK_BOOL:
+                       code = htonl(6);
+                       break;
                default:
                        /* XXX can this happen? */
                        code = htonl(0);
@@ -258,13 +262,25 @@ write_value(FILE *fp, awk_value_t *val)
                if (fwrite(& code, 1, sizeof(code), fp) != sizeof(code))
                        return awk_false;
 
-               len = htonl(val->str_value.len);
-               if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
-                       return awk_false;
+               if (code == ntohl(6)) {
+                       len = (val->bool_value == awk_true ? 4 : 5);
+                       len = htonl(len);
+                       const char *s = (val->bool_value == awk_true ? "TRUE" : 
"FALSE");
 
-               if (fwrite(val->str_value.str, 1, val->str_value.len, fp)
-                               != (ssize_t) val->str_value.len)
-                       return awk_false;
+                       if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
+                               return awk_false;
+
+                       if (fwrite(s, 1, strlen(s), fp) != (ssize_t) strlen(s))
+                               return awk_false;
+               } else {
+                       len = htonl(val->str_value.len);
+                       if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
+                               return awk_false;
+
+                       if (fwrite(val->str_value.str, 1, val->str_value.len, 
fp)
+                                       != (ssize_t) val->str_value.len)
+                               return awk_false;
+               }
        }
 
        return awk_true;
@@ -484,6 +500,9 @@ read_value(FILE *fp, awk_value_t *value)
                case 5:
                        value->val_type = AWK_UNDEFINED;
                        break;
+               case 6:
+                       value->val_type = AWK_BOOL;
+                       break;
                default:
                        /* this cannot happen! */
                        warning(ext_id, _("treating recovered value with 
unknown type code %d as a string"), code);
@@ -498,6 +517,13 @@ read_value(FILE *fp, awk_value_t *value)
                        return awk_false;
                }
                value->str_value.str[len] = '\0';
+               value->str_value.len = len;
+               if (code == 6) {
+                       /* bool type */
+                       bool val = (strcmp(value->str_value.str, "TRUE") == 0);
+                       gawk_free(value->str_value.str);
+                       value->bool_value = val ? awk_true : awk_false;
+               }
        }
 
        return awk_true;
diff --git a/test/ChangeLog b/test/ChangeLog
index 0212e1f..a65ff61 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -2,6 +2,7 @@
 
        * Makefile.am (EXTRA_DIST): asortbool, new test.
        * asortbool.awk, asortbool.ok: New files.
+       * rwarray.awk: Add test of saving/restoring bool values.
 
 2021-03-08         Arnold D. Robbins     <arnold@skeeve.com>
 
diff --git a/test/rwarray.awk b/test/rwarray.awk
index 86a4b58..831f17c 100644
--- a/test/rwarray.awk
+++ b/test/rwarray.awk
@@ -11,6 +11,9 @@ BEGIN {
        split("-2.4", f)
        dict[strnum_sub] = f[1]
 
+       bool_sub = "bool-sub"
+       dict[bool_sub] = bool(1)
+
        n = asorti(dict, dictindices)
        for (i = 1; i <= n; i++)
                printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) 
> "orig.out"
@@ -51,4 +54,12 @@ BEGIN {
        if (typeof(dict[strnum_sub]) != "strnum")
                printf("dict[\"%s\"] should be strnum, is %s\n",
                        strnum_sub, typeof(dict[strnum_sub]));
+
+       if (typeof(dict[bool_sub]) != "bool")
+               printf("dict[\"%s\"] should be bool, is %s\n",
+                       bool_sub, typeof(dict[bool_sub]));
+
+       if ((dict[bool_sub] "") != "TRUE")
+               printf("dict[\"%s\"] should be TRUE, is %s\n",
+                       bool_sub, dict[bool_sub]);
 }

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=5887e22adfed809e482da3a6f5b2f37901915aff

commit 5887e22adfed809e482da3a6f5b2f37901915aff
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Tue Mar 30 16:40:34 2021 +0300

    Finish updating API code for bool.

diff --git a/ChangeLog b/ChangeLog
index 3682123..e4843cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-03-30         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * gawk_api.h (gawk_api_minor_version): Increase to 2.
+       * gawk_api.c (+assign_bool): New function.
+       (node_to_awk_value): Finish updating for bool types and values.
+
 2021-03-22         Arnold D. Robbins     <arnold@skeeve.com>
 
        * gawkapi.h (make_bool): New inline function.
diff --git a/gawkapi.c b/gawkapi.c
index 929c36b..e8a9c31 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -535,6 +535,16 @@ assign_regex(NODE *node, awk_value_t *val)
        val->val_type = AWK_REGEX;
 }
 
+/* assign_bool --- return a bool node */
+
+static inline void
+assign_bool(NODE *node, awk_value_t *val)
+{
+       assert((node->flags & BOOL) != 0);
+       val->val_type = AWK_BOOL;
+       val->bool_value = get_number_si(node) != 0 ? awk_true : awk_false;
+}
+
 /* node_to_awk_value --- convert a node into a value for an extension */
 
 static awk_bool_t
@@ -572,18 +582,15 @@ node_to_awk_value(NODE *node, awk_value_t *val, 
awk_valtype_t wanted)
                switch (wanted) {
                case AWK_BOOL:
                        if ((node->flags & BOOL) != 0) {
-                               val->val_type = AWK_BOOL;
-                               val->bool_value = (get_number_si(node) ? 
awk_true : awk_false);
+                               assign_bool(node, val);
                                ret = awk_true;
-                       } else {
+                       } else
                                ret = awk_false;
-                       }
                        break;
+
                case AWK_NUMBER:
                        if ((node->flags & REGEX) != 0)
                                val->val_type = AWK_REGEX;
-                       else if ((node->flags & BOOL) != 0)
-                               val->val_type = AWK_BOOL;
                        else {
                                (void) force_number(node);
                                assign_number(node, val);
@@ -693,8 +700,7 @@ node_to_awk_value(NODE *node, awk_value_t *val, 
awk_valtype_t wanted)
                        /* return true and actual type for request of undefined 
*/
                        switch (fixtype(node)->flags & 
(STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
                        case BOOL:
-                               val->val_type = AWK_BOOL;
-                               val->bool_value = (get_number_si(node) ? 
awk_true : awk_false);
+                               assign_bool(node, val);
                                ret = awk_true;
                                break;
                        case STRING:
diff --git a/gawkapi.h b/gawkapi.h
index 6923360..9967aa2 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -297,7 +297,7 @@ typedef struct awk_two_way_processor {
 } awk_two_way_processor_t;
 
 #define gawk_api_major_version 3
-#define gawk_api_minor_version 1
+#define gawk_api_minor_version 2
 
 /* Current version of the API. */
 enum {

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

Summary of changes:
 ChangeLog           |  6 ++++++
 extension/ChangeLog |  5 +++++
 extension/rwarray.c | 40 +++++++++++++++++++++++++++++++++-------
 gawkapi.c           | 22 ++++++++++++++--------
 gawkapi.h           |  2 +-
 test/ChangeLog      |  1 +
 test/rwarray.awk    | 11 +++++++++++
 7 files changed, 71 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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