aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2009-08-27 21:10:17 +0000
committerStefan Monnier <[email protected]>2009-08-27 21:10:17 +0000
commit155a6764a38bef2f32d6fd532a2a59f008a87760 (patch)
treee6a4821d05eb868375e853e5b617b023cae3decc /src
parent81cc988b4417219c5e9a0782359f1dad59e894ea (diff)
(read_integer): Use doubles (and potentially return a float
number) as we do in string-to-number. (read1): Use strtol to read integers, signal errors on strtol's overflow and use floats if strtol's output is too large for Elisp integers.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/lread.c31
2 files changed, 26 insertions, 13 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5b1874a7a9..bf112e0824 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2009-08-27 Stefan Monnier <[email protected]>
+
+ * lread.c (read_integer): Use doubles (and potentially return a float
+ number) as we do in string-to-number.
+ (read1): Use strtol to read integers, signal errors on strtol's
+ overflow and use floats if strtol's output is too large for
+ Elisp integers.
+
2009-08-27 Eli Zaretskii <[email protected]>
* makefile.w32-in ($(SRC)/buildobj.h, make-buildobj-CMD)
diff --git a/src/lread.c b/src/lread.c
index 193bd6ae66..ee4659ffd4 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2258,7 +2258,8 @@ read_integer (readcharfun, radix)
int radix;
{
int ndigits = 0, invalid_p, c, sign = 0;
- EMACS_INT number = 0;
+ /* We use a floating point number because */
+ double number = 0;
if (radix < 2 || radix > 36)
invalid_p = 1;
@@ -2308,7 +2309,7 @@ read_integer (readcharfun, radix)
invalid_syntax (buf, 0);
}
- return make_number (sign * number);
+ return make_fixnum_or_float (sign * number);
}
@@ -2372,7 +2373,6 @@ read1 (readcharfun, pch, first_in_list)
Lisp_Object ht;
Lisp_Object key = Qnil;
int param_count = 0;
- int i;
if (!EQ (head, Qhash_table))
error ("Invalid extended read marker at head of #s list "
@@ -3002,7 +3002,6 @@ read1 (readcharfun, pch, first_in_list)
if (!quoted && !uninterned_symbol)
{
register char *p1;
- register Lisp_Object val;
p1 = read_buffer;
if (*p1 == '+' || *p1 == '-') p1++;
/* Is it an integer? */
@@ -3016,15 +3015,21 @@ read1 (readcharfun, pch, first_in_list)
{
if (p1[-1] == '.')
p1[-1] = '\0';
- /* Fixme: if we have strtol, use that, and check
- for overflow. */
- if (sizeof (int) == sizeof (EMACS_INT))
- XSETINT (val, atoi (read_buffer));
- else if (sizeof (long) == sizeof (EMACS_INT))
- XSETINT (val, atol (read_buffer));
- else
- abort ();
- return val;
+ {
+ /* EMACS_INT n = atol (read_buffer); */
+ char *endptr = NULL;
+ EMACS_INT n = (errno = 0,
+ strtol (read_buffer, &endptr, 10));
+ if (errno == ERANGE && endptr)
+ {
+ Lisp_Object args
+ = Fcons (make_string (read_buffer,
+ endptr - read_buffer),
+ Qnil);
+ xsignal (Qoverflow_error, args);
+ }
+ return make_fixnum_or_float (n);
+ }
}
}
if (isfloat_string (read_buffer))