aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorStefan Monnier2009-08-27 21:10:17 +0000
committerStefan Monnier2009-08-27 21:10:17 +0000
commit155a6764a38bef2f32d6fd532a2a59f008a87760 (patch)
treee6a4821d05eb868375e853e5b617b023cae3decc /src/lread.c
parent81cc988b4417219c5e9a0782359f1dad59e894ea (diff)
downloademacs-155a6764a38bef2f32d6fd532a2a59f008a87760.tar.gz
emacs-155a6764a38bef2f32d6fd532a2a59f008a87760.zip
(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/lread.c')
-rw-r--r--src/lread.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/lread.c b/src/lread.c
index 193bd6ae668..ee4659ffd47 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2258,7 +2258,8 @@ read_integer (readcharfun, radix)
2258 int radix; 2258 int radix;
2259{ 2259{
2260 int ndigits = 0, invalid_p, c, sign = 0; 2260 int ndigits = 0, invalid_p, c, sign = 0;
2261 EMACS_INT number = 0; 2261 /* We use a floating point number because */
2262 double number = 0;
2262 2263
2263 if (radix < 2 || radix > 36) 2264 if (radix < 2 || radix > 36)
2264 invalid_p = 1; 2265 invalid_p = 1;
@@ -2308,7 +2309,7 @@ read_integer (readcharfun, radix)
2308 invalid_syntax (buf, 0); 2309 invalid_syntax (buf, 0);
2309 } 2310 }
2310 2311
2311 return make_number (sign * number); 2312 return make_fixnum_or_float (sign * number);
2312} 2313}
2313 2314
2314 2315
@@ -2372,7 +2373,6 @@ read1 (readcharfun, pch, first_in_list)
2372 Lisp_Object ht; 2373 Lisp_Object ht;
2373 Lisp_Object key = Qnil; 2374 Lisp_Object key = Qnil;
2374 int param_count = 0; 2375 int param_count = 0;
2375 int i;
2376 2376
2377 if (!EQ (head, Qhash_table)) 2377 if (!EQ (head, Qhash_table))
2378 error ("Invalid extended read marker at head of #s list " 2378 error ("Invalid extended read marker at head of #s list "
@@ -3002,7 +3002,6 @@ read1 (readcharfun, pch, first_in_list)
3002 if (!quoted && !uninterned_symbol) 3002 if (!quoted && !uninterned_symbol)
3003 { 3003 {
3004 register char *p1; 3004 register char *p1;
3005 register Lisp_Object val;
3006 p1 = read_buffer; 3005 p1 = read_buffer;
3007 if (*p1 == '+' || *p1 == '-') p1++; 3006 if (*p1 == '+' || *p1 == '-') p1++;
3008 /* Is it an integer? */ 3007 /* Is it an integer? */
@@ -3016,15 +3015,21 @@ read1 (readcharfun, pch, first_in_list)
3016 { 3015 {
3017 if (p1[-1] == '.') 3016 if (p1[-1] == '.')
3018 p1[-1] = '\0'; 3017 p1[-1] = '\0';
3019 /* Fixme: if we have strtol, use that, and check 3018 {
3020 for overflow. */ 3019 /* EMACS_INT n = atol (read_buffer); */
3021 if (sizeof (int) == sizeof (EMACS_INT)) 3020 char *endptr = NULL;
3022 XSETINT (val, atoi (read_buffer)); 3021 EMACS_INT n = (errno = 0,
3023 else if (sizeof (long) == sizeof (EMACS_INT)) 3022 strtol (read_buffer, &endptr, 10));
3024 XSETINT (val, atol (read_buffer)); 3023 if (errno == ERANGE && endptr)
3025 else 3024 {
3026 abort (); 3025 Lisp_Object args
3027 return val; 3026 = Fcons (make_string (read_buffer,
3027 endptr - read_buffer),
3028 Qnil);
3029 xsignal (Qoverflow_error, args);
3030 }
3031 return make_fixnum_or_float (n);
3032 }
3028 } 3033 }
3029 } 3034 }
3030 if (isfloat_string (read_buffer)) 3035 if (isfloat_string (read_buffer))