aboutsummaryrefslogtreecommitdiffstats
path: root/src/bignum.c
diff options
context:
space:
mode:
authorPaul Eggert2018-10-10 23:17:18 -0700
committerPaul Eggert2018-10-10 23:19:42 -0700
commit5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d (patch)
treec51b2a470f62679f5e5c3f6f55d90aa0082d0133 /src/bignum.c
parentfd3a48fcd8bb212ec12b9b10a79de0ae605ee93b (diff)
downloademacs-5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d.tar.gz
emacs-5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d.zip
Fix mishandling of symbols that look like numbers
* src/bignum.c (make_neg_biguint): New function. * src/lread.c (read1): Do not mishandle an unquoted symbol with name equal to something like "1\0x", i.e., a string of numeric form followed by a NUL byte. Formerly these symbols were misread as numbers. (string_to_number): Change last argument from an integer flag to a pointer to the length. This lets the caller figure out how much of the prefix was used. All callers changed. Add a fast path if the integer (sans sign) fits in uintmax_t. Update comments and simplify now that bignums are present. * src/print.c (print_object): Fix quoting of symbols that look like numbers, by relying on string_to_number for the tricky cases rather than trying to redo its logic, incorrectly. For example, (read (prin1-to-string '\1e+NaN)) formerly returned "1e+NaN", which was wrong: a backslash is needed in the output to prevent it from being read as a NaN. Escape NO_BREAK_SPACE too, since lread.c treats it like SPACE. * test/src/print-tests.el (print-read-roundtrip): Add tests illustrating the abovementioned bugs.
Diffstat (limited to 'src/bignum.c')
-rw-r--r--src/bignum.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/bignum.c b/src/bignum.c
index 0ab8de3ab7a..e3db0377a53 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -117,6 +117,16 @@ make_biguint (uintmax_t n)
117 return make_bignum (); 117 return make_bignum ();
118} 118}
119 119
120/* Return a Lisp integer equal to -N, which must not be in fixnum range. */
121Lisp_Object
122make_neg_biguint (uintmax_t n)
123{
124 eassert (-MOST_NEGATIVE_FIXNUM < n);
125 mpz_set_uintmax (mpz[0], n);
126 mpz_neg (mpz[0], mpz[0]);
127 return make_bignum ();
128}
129
120/* Return a Lisp integer with value taken from mpz[0]. 130/* Return a Lisp integer with value taken from mpz[0].
121 Set mpz[0] to a junk value. */ 131 Set mpz[0] to a junk value. */
122Lisp_Object 132Lisp_Object