diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-12-10 11:58:56 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-12-10 11:58:56 +0200 |
commit | c85634612d741e496eea8619bf75d40a68f2a53b (patch) | |
tree | b8d3f97601ce22e6d509228543bcd8f5045fb239 | |
parent | d6404b8adac3d44272d0725786d5d45c291ee04d (diff) | |
parent | cfa3ac1c6a0fcbe794df853f25c757e4acd5fcc0 (diff) | |
download | egawk-c85634612d741e496eea8619bf75d40a68f2a53b.tar.gz egawk-c85634612d741e496eea8619bf75d40a68f2a53b.tar.bz2 egawk-c85634612d741e496eea8619bf75d40a68f2a53b.zip |
Merge branch 'gawk-5.1-stable'
-rw-r--r-- | extension/ChangeLog | 12 | ||||
-rw-r--r-- | extension/rwarray.c | 26 | ||||
-rw-r--r-- | test/ChangeLog | 7 | ||||
-rw-r--r-- | test/iolint.awk | 2 | ||||
-rw-r--r-- | test/iolint.ok | 2 |
5 files changed, 47 insertions, 2 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 90defbfc..5ce63c68 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,15 @@ +2021-12-10 Arnold D. Robbins <arnold@skeeve.com> + + * rwarray.c (write_number, read_number): Reformat comments a bit. + +2021-12-08 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * rwarray.c (write_number): Since mpfr_fpif_export is experimental + and not available in older versions of mpfr, add an ifdef to + use mpfr_out_str instead. + (read_number): Similarly, use mpfr_inp_str instead of + mpfr_fpif_import. + 2021-11-18 Arnold D. Robbins <arnold@skeeve.com> * rwarray.c: Add support for writing/reading GMP and MPFR values. diff --git a/extension/rwarray.c b/extension/rwarray.c index 9a8c1e4a..532a8da1 100644 --- a/extension/rwarray.c +++ b/extension/rwarray.c @@ -330,7 +330,26 @@ write_number(FILE *fp, awk_value_t *val) if (fwrite(& code, 1, sizeof(code), fp) != sizeof(code)) return awk_false; +#ifdef USE_MPFR_FPIF + /* + * This would be preferable, but it is not available + * on older platforms with mpfr 3.x. It's also marked + * experimental in mpfr 4.1, so perhaps not ready for + * production use yet. + */ if (mpfr_fpif_export(fp, val->num_ptr) != 0) +#else +#define MPFR_STR_BASE 62 /* maximize base to minimize string len */ +#define MPFR_STR_ROUND MPFR_RNDN + /* + * XXX does the choice of MPFR_RNDN matter, given + * that the precision is 0, so we should be rendering + * in full precision? + */ + // We need to write a terminating space, since + // mpfr_inp_str reads until it hits a space or EOF + if ((mpfr_out_str(fp, MPFR_STR_BASE, 0, val->num_ptr, MPFR_STR_ROUND) == 0) || (putc(' ', fp) == EOF)) +#endif return awk_false; } else { code = htonl(VT_GMP); @@ -624,7 +643,14 @@ read_number(FILE *fp, awk_value_t *value, uint32_t code) mpfr_t mpfr_val; mpfr_init(mpfr_val); +#ifdef USE_MPFR_FPIF + /* preferable if widely available and stable */ if (mpfr_fpif_import(mpfr_val, fp) != 0) +#else + // N.B. need to consume the terminating space we wrote + // after mpfr_out_str + if ((mpfr_inp_str(mpfr_val, fp, MPFR_STR_BASE, MPFR_STR_ROUND) == 0) || (getc(fp) != ' ')) +#endif return awk_false; value = make_number_mpfr(& mpfr_val, value); diff --git a/test/ChangeLog b/test/ChangeLog index 1a7b9175..034cc63b 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,10 @@ +2021-12-07 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * iolint.awk, iolint.ok: Reorder "cat" pipe/output file test to reduce + the likelihood of a race condition, since close operates on the + most-recently-used item. Thanks to Miguel Pineiro Jr., + <mpj@pineiro.cc>, for suggesting the fix. + 2021-11-21 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): stupid5, new test. diff --git a/test/iolint.awk b/test/iolint.awk index 042f743b..3ebaf436 100644 --- a/test/iolint.awk +++ b/test/iolint.awk @@ -49,8 +49,8 @@ BEGIN { # `%.*s' used for output pipe and two-way pipe # Not doing |& due to race condition and signals. sigh cat = "cat" - print "hello" | "cat" print "/bin/cat \"$@\"" > "cat" + print "hello" | "cat" print close("cat") print close("cat") fflush() diff --git a/test/iolint.ok b/test/iolint.ok index 7a165aa9..860bcfbf 100644 --- a/test/iolint.ok +++ b/test/iolint.ok @@ -20,9 +20,9 @@ gawk: iolint.awk:42: warning: `echo hello' used for input pipe and output file 0 0 gawk: iolint.awk:53: warning: `cat' used for output file and output pipe -0 hello 0 +0 gawk: iolint.awk:67: warning: `eval $CMD_TO_RUN' used for input pipe and output pipe 0 0 |