[AC21.5] Handle leading + signs on bignums, etc.
Jerry James
james at xemacs.org
Tue Apr 13 11:37:44 EDT 2004
Hi Giacomo,
Thanks for the bug report!
giacomo boffi <giacomo.boffi at polimi.it> wrote:
> i built xemacs from cvs, and i enabled the new bignums support
>
> M-x gnus RET
>
> failed, please see the attached backtrace
>
> i tried building a new copy of xemacs, from the same sources, except
> disabling bignum support, and gnus worked as fine as usual
>
> i'm sending this bug report from the xemacs with bignums enabled
It looks like the GMP function mpz_set_str chokes when the first
character is +. In fact, mpq_set_str chokes also. Well, we can safely
skip such plus signs, so let's just do it in case other libraries have
this defect as well.
src/ChangeLog addition:
2004-04-13 Jerry James <james at 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.
xemacs-21.5 source patch:
Diff command: cvs -q diff -uN
Files affected: src/number.c src/lread.c src/data.c
Index: src/data.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/data.c,v
retrieving revision 1.54
diff -d -u -u -r1.54 data.c
--- src/data.c 2004/04/08 15:23:09 1.54
+++ src/data.c 2004/04/13 15:16:41
@@ -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);
Index: src/lread.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/lread.c,v
retrieving revision 1.67
diff -d -u -u -r1.67 lread.c
--- src/lread.c 2004/04/07 03:49:00 1.67
+++ src/lread.c 2004/04/13 15:16:43
@@ -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 */
Index: src/number.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/number.c,v
retrieving revision 1.4
diff -d -u -u -r1.4 number.c
--- src/number.c 2004/04/08 15:23:09 1.4
+++ src/number.c 2004/04/13 15:16:43
@@ -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
--
Jerry James
http://www.ittc.ku.edu/~james/
More information about the XEmacs-Beta
mailing list