changeset 2010:a9cdbfb4716e

[xemacs-hg @ 2004-04-13 15:38:30 by james] Handle leading + signs on numbers correctly.
author james
date Tue, 13 Apr 2004 15:38:42 +0000
parents 1388c8b3e663
children d3aba8b8f77e
files src/ChangeLog src/data.c src/lread.c src/number.c
diffstat 4 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Apr 13 04:23:50 2004 +0000
+++ b/src/ChangeLog	Tue Apr 13 15:38:42 2004 +0000
@@ -1,3 +1,11 @@
+2004-04-13  Jerry James  <james@xemacs.org>
+
+	* data.c (Fstring_to_number): Skip leading + sign to avoid
+	triggering random GMP behavior.
+	* lread.c (read_atom): Ditto.
+	* lread.c (isratio_string): Recognize ratio with leading + sign.
+	* number.c (string_to_bignum): Skip leading + sign.
+
 2004-01-30  Glynn Clements  <glynn.clements@virgin.net>
 
 	* device-x.c (x_error_handler): Don't call stderr_out
--- a/src/data.c	Tue Apr 13 04:23:50 2004 +0000
+++ b/src/data.c	Tue Apr 13 15:38:42 2004 +0000
@@ -1271,6 +1271,9 @@
 #ifdef HAVE_BIGFLOAT
       else
 	{
+	  /* GMP bigfloat_set_string returns random values with initial + */
+	  if (*p == '+')
+	    p++;
 	  bigfloat_set_prec (scratch_bigfloat, bigfloat_get_default_prec ());
 	  bigfloat_set_string (scratch_bigfloat, (const char *) p, b);
 	  return make_bigfloat_bf (scratch_bigfloat);
@@ -1281,12 +1284,19 @@
 #ifdef HAVE_RATIO
   if (qxestrchr (p, '/') != NULL)
     {
+      /* GMP ratio_set_string returns random values with initial + sign */
+      if (*p == '+')
+	p++;
       ratio_set_string (scratch_ratio, (const char *) p, b);
       return make_ratio_rt (scratch_ratio);
     }
 #endif /* HAVE_RATIO */
 
 #ifdef HAVE_BIGNUM
+  /* GMP bignum_set_string returns random values when the string starts with a
+     plus sign */
+  if (*p == '+')
+    p++;
   /* GMP bignum_set_string returns random values when fed an empty string */
   if (*p == '\0')
     return make_int (0);
--- a/src/lread.c	Tue Apr 13 04:23:50 2004 +0000
+++ b/src/lread.c	Tue Apr 13 15:38:42 2004 +0000
@@ -1851,6 +1851,9 @@
 #ifdef HAVE_RATIO
       if (isratio_string (read_ptr))
 	{
+	  /* GMP ratio_set_string returns random values with initial + sign */
+	  if (*read_ptr == '+')
+	    read_ptr++;
 	  ratio_set_string (scratch_ratio, read_ptr, 0);
 	  ratio_canonicalize (scratch_ratio);
 	  return Fcanonicalize_number (make_ratio_rt (scratch_ratio));
@@ -2673,8 +2676,8 @@
 int
 isratio_string (const char *cp)
 {
-  /* Possible minus sign */
-  if (*cp == '-')
+  /* Possible minus/plus sign */
+  if (*cp == '-' || *cp == '+')
     cp++;
 
   /* Numerator */
--- a/src/number.c	Tue Apr 13 04:23:50 2004 +0000
+++ b/src/number.c	Tue Apr 13 15:38:42 2004 +0000
@@ -82,9 +82,15 @@
 			       bignum_hash, bignum_description, Lisp_Bignum);
 
 Lisp_Object
-string_to_bignum(const Ibyte *str, Bytecount len, int base)
+string_to_bignum (const Ibyte *str, Bytecount len, int base)
 {
   Lisp_Object b = make_bignum (0L);
+  /* GMP bignum_set_string returns random values with initial + sign */
+  if (*str == '+')
+    str++;
+  /* GMP bignum_set_string returns random values when fed an empty string */
+  if (*str == '\0')
+    return make_int (0);
   return (bignum_set_string (XBIGNUM_DATA (b), (const char *) str, base) < 0)
     ? Fsignal (Qinvalid_read_syntax,
 	       list3 (build_msg_string