diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2020-07-07 17:47:32 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2020-07-07 17:47:32 +0300 |
commit | 328708c8205cbd211ca1523d6f56bd64fd1389f9 (patch) | |
tree | 4720a8263e7d053a8bd02c39e8977820ab5245d8 | |
parent | 6f919b67d12616168c5e1bbfca509359fed9143d (diff) | |
parent | 54483c688b659b96cc930000444d5b34ee11d11c (diff) | |
download | egawk-328708c8205cbd211ca1523d6f56bd64fd1389f9.tar.gz egawk-328708c8205cbd211ca1523d6f56bd64fd1389f9.tar.bz2 egawk-328708c8205cbd211ca1523d6f56bd64fd1389f9.zip |
Merge branch 'gawk-5.1-stable'
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | awk.h | 204 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | node.c | 15 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/Makefile.in | 2 |
7 files changed, 124 insertions, 115 deletions
@@ -1,3 +1,12 @@ +2020-07-07 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h: Turn all the flag defines into enums. GDB can then show + the bit maps directly. + +2020-07-07 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * node.c (r_dupnode): Sanitize the code, particularly for MPFR. + 2020-07-05 Arnold D. Robbins <arnold@skeeve.com> Bug fixes in MPFR, reported by Hyunho Cho<mug896@naver.com>. @@ -363,9 +363,10 @@ typedef struct exp_node { size_t reserved; struct exp_node *rn; unsigned long cnt; - unsigned long reflags; -# define CONSTANT 1 -# define FS_DFLT 2 + enum reflagvals { + CONSTANT = 1, + FS_DFLT = 2, + } reflags; } nodep; struct { @@ -390,79 +391,79 @@ typedef struct exp_node { } val; } sub; NODETYPE type; - unsigned int flags; - -/* type = Node_val */ - /* - * STRING and NUMBER are mutually exclusive, except for the special - * case of an uninitialized value, represented internally by - * Nnull_string. They represent the type of a value as assigned. - * Nnull_string has both STRING and NUMBER attributes, but all other - * scalar values should have precisely one of these bits set. - * - * STRCUR and NUMCUR are not mutually exclusive. They represent that - * the particular type of value is up to date. For example, - * - * a = 5 # NUMBER | NUMCUR - * b = a "" # Adds STRCUR to a, since a string value - * # is now available. But the type hasn't changed! - * - * a = "42" # STRING | STRCUR - * b = a + 0 # Adds NUMCUR to a, since numeric value - * # is now available. But the type hasn't changed! - * - * USER_INPUT is the joker. When STRING|USER_INPUT is set, it means - * "this is string data, but the user may have really wanted it to be a - * number. If we have to guess, like in a comparison, turn it into a - * number if the string is indeed numeric." - * For example, gawk -v a=42 .... - * Here, `a' gets STRING|STRCUR|USER_INPUT and then when used where - * a number is needed, it gets turned into a NUMBER and STRING - * is cleared. In that case, we leave the USER_INPUT in place, so - * the combination NUMBER|USER_INPUT means it is a strnum a.k.a. a - * "numeric string". - * - * WSTRCUR is for efficiency. If in a multibyte locale, and we - * need to do something character based (substr, length, etc.) - * we create the corresponding wide character string and store it, - * and add WSTRCUR to the flags so that we don't have to do the - * conversion more than once. - * - * The NUMINT flag may be used with a value of any type -- NUMBER, - * STRING, or STRNUM. It indicates that the string representation - * equals the result of sprintf("%ld", <numeric value>). So, for - * example, NUMINT should NOT be set if it's a strnum or string value - * where the string is " 1" or "01" or "+1" or "1.0" or "0.1E1". This - * is a hint to indicate that an integer array optimization may be - * used when this value appears as a subscript. - * - * We hope that the rest of the flags are self-explanatory. :-) - */ -# define MALLOC 0x0001 /* stptr can be free'd, i.e. not a field node pointing into a shared buffer */ -# define STRING 0x0002 /* assigned as string */ -# define STRCUR 0x0004 /* string value is current */ -# define NUMCUR 0x0008 /* numeric value is current */ -# define NUMBER 0x0010 /* assigned as number */ -# define USER_INPUT 0x0020 /* user input: if NUMERIC then - * a NUMBER */ -# define INTLSTR 0x0040 /* use localized version */ -# define NUMINT 0x0080 /* numeric value is an integer */ -# define INTIND 0x0100 /* integral value is array index; - * lazy conversion to string. - */ -# define WSTRCUR 0x0200 /* wide str value is current */ -# define MPFN 0x0400 /* arbitrary-precision floating-point number */ -# define MPZN 0x0800 /* arbitrary-precision integer */ -# define NO_EXT_SET 0x1000 /* extension cannot set a value for this variable */ -# define NULL_FIELD 0x2000 /* this is the null field */ - -/* type = Node_var_array */ -# define ARRAYMAXED 0x4000 /* array is at max size */ -# define HALFHAT 0x8000 /* half-capacity Hashed Array Tree; - * See cint_array.c */ -# define XARRAY 0x10000 -# define NUMCONSTSTR 0x20000 /* have string value for numeric constant */ -# define REGEX 0x40000 /* this is a typed regex */ + enum flagvals { + /* type = Node_val */ + /* + * STRING and NUMBER are mutually exclusive, except for the special + * case of an uninitialized value, represented internally by + * Nnull_string. They represent the type of a value as assigned. + * Nnull_string has both STRING and NUMBER attributes, but all other + * scalar values should have precisely one of these bits set. + * + * STRCUR and NUMCUR are not mutually exclusive. They represent that + * the particular type of value is up to date. For example, + * + * a = 5 # NUMBER | NUMCUR + * b = a "" # Adds STRCUR to a, since a string value + * # is now available. But the type hasn't changed! + * + * a = "42" # STRING | STRCUR + * b = a + 0 # Adds NUMCUR to a, since numeric value + * # is now available. But the type hasn't changed! + * + * USER_INPUT is the joker. When STRING|USER_INPUT is set, it means + * "this is string data, but the user may have really wanted it to be a + * number. If we have to guess, like in a comparison, turn it into a + * number if the string is indeed numeric." + * For example, gawk -v a=42 .... + * Here, `a' gets STRING|STRCUR|USER_INPUT and then when used where + * a number is needed, it gets turned into a NUMBER and STRING + * is cleared. In that case, we leave the USER_INPUT in place, so + * the combination NUMBER|USER_INPUT means it is a strnum a.k.a. a + * "numeric string". + * + * WSTRCUR is for efficiency. If in a multibyte locale, and we + * need to do something character based (substr, length, etc.) + * we create the corresponding wide character string and store it, + * and add WSTRCUR to the flags so that we don't have to do the + * conversion more than once. + * + * The NUMINT flag may be used with a value of any type -- NUMBER, + * STRING, or STRNUM. It indicates that the string representation + * equals the result of sprintf("%ld", <numeric value>). So, for + * example, NUMINT should NOT be set if it's a strnum or string value + * where the string is " 1" or "01" or "+1" or "1.0" or "0.1E1". This + * is a hint to indicate that an integer array optimization may be + * used when this value appears as a subscript. + * + * We hope that the rest of the flags are self-explanatory. :-) + */ + MALLOC = 0x0001, /* stptr can be free'd, i.e. not a field node pointing into a shared buffer */ + STRING = 0x0002, /* assigned as string */ + STRCUR = 0x0004, /* string value is current */ + NUMCUR = 0x0008, /* numeric value is current */ + NUMBER = 0x0010, /* assigned as number */ + USER_INPUT = 0x0020, /* user input: if NUMERIC then + * a NUMBER */ + INTLSTR = 0x0040, /* use localized version */ + NUMINT = 0x0080, /* numeric value is an integer */ + INTIND = 0x0100, /* integral value is array index; + * lazy conversion to string. + */ + WSTRCUR = 0x0200, /* wide str value is current */ + MPFN = 0x0400, /* arbitrary-precision floating-point number */ + MPZN = 0x0800, /* arbitrary-precision integer */ + NO_EXT_SET = 0x1000, /* extension cannot set a value for this variable */ + NULL_FIELD = 0x2000, /* this is the null field */ + + /* type = Node_var_array */ + ARRAYMAXED = 0x4000, /* array is at max size */ + HALFHAT = 0x8000, /* half-capacity Hashed Array Tree; + * See cint_array.c */ + XARRAY = 0x10000, + NUMCONSTSTR = 0x20000, /* have string value for numeric constant */ + REGEX = 0x40000, /* this is a typed regex */ + } flags; } NODE; #define vname sub.nodep.name @@ -944,30 +945,32 @@ typedef struct iobuf { bool valid; int errcode; - int flag; -# define IOP_IS_TTY 1 -# define IOP_AT_EOF 2 -# define IOP_CLOSED 4 -# define IOP_AT_START 8 + enum iobuf_flags { + IOP_IS_TTY = 1, + IOP_AT_EOF = 2, + IOP_CLOSED = 4, + IOP_AT_START = 8, + } flag; } IOBUF; typedef void (*Func_ptr)(void); /* structure used to dynamically maintain a linked-list of open files/pipes */ struct redirect { - unsigned int flag; -# define RED_FILE 1 -# define RED_PIPE 2 -# define RED_READ 4 -# define RED_WRITE 8 -# define RED_APPEND 16 -# define RED_NOBUF 32 -# define RED_USED 64 /* closed temporarily to reuse fd */ -# define RED_EOF 128 -# define RED_TWOWAY 256 -# define RED_PTY 512 -# define RED_SOCKET 1024 -# define RED_TCP 2048 + enum redirect_flags { + RED_FILE = 1, + RED_PIPE = 2, + RED_READ = 4, + RED_WRITE = 8, + RED_APPEND = 16, + RED_NOBUF = 32, + RED_USED = 64, /* closed temporarily to reuse fd */ + RED_EOF = 128, + RED_TWOWAY = 256, + RED_PTY = 512, + RED_SOCKET = 1024, + RED_TCP = 2048, + } flag; char *value; FILE *ifp; /* input fp, needed for PIPES_SIMULATED */ IOBUF *iop; @@ -982,10 +985,10 @@ struct redirect { /* values for BINMODE, used as bit flags */ enum binmode_values { - TEXT_TRANSLATE = 0, /* usual \r\n ---> \n translation */ - BINMODE_INPUT = 1, /* no translation for input files */ - BINMODE_OUTPUT = 2, /* no translation for output files */ - BINMODE_BOTH = 3 /* no translation for either */ + TEXT_TRANSLATE = 0, /* usual \r\n ---> \n translation */ + BINMODE_INPUT = 1, /* no translation for input files */ + BINMODE_OUTPUT = 2, /* no translation for output files */ + BINMODE_BOTH = 3 /* no translation for either */ }; /* @@ -1139,12 +1142,11 @@ extern NODE *success_node; extern struct block_header nextfree[]; extern bool field0_valid; -extern int do_flags; extern bool do_itrace; /* separate so can poke from a debugger */ extern SRCFILE *srcfiles; /* source files */ -enum do_flag_values { +extern enum do_flag_values { DO_LINT_INVALID = 0x00001, /* only warn about invalid */ DO_LINT_EXTENSIONS = 0x00002, /* warn about gawk extensions */ DO_LINT_ALL = 0x00004, /* warn about all things */ @@ -1161,7 +1163,7 @@ enum do_flag_values { DO_PROFILE = 0x02000, /* profile the program */ DO_DEBUG = 0x04000, /* debug the program */ DO_MPFR = 0x08000, /* arbitrary-precision floating-point math */ -}; +} do_flags; #define do_traditional (do_flags & DO_TRADITIONAL) #define do_posix (do_flags & DO_POSIX) @@ -145,7 +145,7 @@ static void parse_args(int argc, char **argv); static void set_locale_stuff(void); static bool stopped_early = false; -int do_flags = false; +enum do_flag_values do_flags = 0; bool do_itrace = false; /* provide simple instruction trace */ bool do_optimize = true; /* apply default optimizations */ static int do_nostalgia = false; /* provide a blast from the past */ @@ -310,24 +310,17 @@ r_dupnode(NODE *n) return n; } #endif + getnode(r); + *r = *n; #ifdef HAVE_MPFR if ((n->flags & MPZN) != 0) { - r = mpg_integer(); + mpz_init(r->mpg_i); mpz_set(r->mpg_i, n->mpg_i); - r->flags = n->flags; - r->strndmode = MPFR_round_mode; } else if ((n->flags & MPFN) != 0) { - r = mpg_float(); + mpfr_init(r->mpg_numbr); int tval = mpfr_set(r->mpg_numbr, n->mpg_numbr, ROUND_MODE); IEEE_FMT(r->mpg_numbr, tval); - r->flags = n->flags; - r->strndmode = MPFR_round_mode; - } else { -#endif - getnode(r); - *r = *n; -#ifdef HAVE_MPFR } #endif diff --git a/test/ChangeLog b/test/ChangeLog index d70282a8..9a9922f2 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2020-07-06 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am (AWK): Append $(GAWK_TEST_ARGS) to enable running + tests with -M enabled for MPFR debugging. + 2020-07-05 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): New tests, mpfrcase, mpfrnonum. diff --git a/test/Makefile.am b/test/Makefile.am index 7a1b4491..b7e3240f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1580,7 +1580,7 @@ VALGRIND = # # And we set AWKLIBPATH to find the extension libraries we built. LOCALES = LANGUAGE= LC_ALL=$${GAWKLOCALE:-C} LANG=$${GAWKLOCALE:-C} -AWK = $(LOCALES) AWKLIBPATH=../extension/.libs $(VALGRIND) $(AWKPROG) +AWK = $(LOCALES) AWKLIBPATH=../extension/.libs $(VALGRIND) $(AWKPROG) $(GAWK_TEST_ARGS) # Message stuff is to make it a little easier to follow. # Make the pass-fail last and dependent on others to avoid diff --git a/test/Makefile.in b/test/Makefile.in index dc691adb..afa233fb 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -161,7 +161,7 @@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ -AWK = $(LOCALES) AWKLIBPATH=../extension/.libs $(VALGRIND) $(AWKPROG) +AWK = $(LOCALES) AWKLIBPATH=../extension/.libs $(VALGRIND) $(AWKPROG) $(GAWK_TEST_ARGS) CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ |