[RFA] s/char/void/g in floatformat.[ch]

Mark Kettenis mark.kettenis@xs4all.nl
Mon Aug 15 14:52:00 GMT 2005


The fact that the floatformat_xxx functions use `char *' for byte
buffers used to store floating-point numbers doesn't help with GCC 4's
`unsigned char' vs. '(signed) char' "madness".  GDB now uses
`gdb_byte' instead of '(unsigned) char', but we obviously cannot use
that in libiberty.  Therefore I propose we take the easy way out and
use `void *' for the byte buffers.  That should remove the need for
nasty casts in all code that uses the floatformat stuff.

Mark

P.S. I still think this code should be removed from libiberty/ and
     moved back into gdb/.  Or does newlib still use it?

Index: include/ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* floatformat.h (struct floatformat): Change type of large
	argument for is_valid member to `const void *'.
	(floatformat_to_double): Change type of second argument to `const
	void *'.
	(floatformat_from_double): Change type of last argument to `void
	*'.
	(floatformat_is_valid): Change type of last argument to `const
	void *'.

Index: include/floatformat.h
===================================================================
RCS file: /cvs/src/src/include/floatformat.h,v
retrieving revision 1.11
diff -u -p -r1.11 floatformat.h
--- include/floatformat.h 10 May 2005 10:21:08 -0000 1.11
+++ include/floatformat.h 15 Aug 2005 14:05:37 -0000
@@ -1,5 +1,6 @@
 /* IEEE floating point support declarations, for GDB, the GNU Debugger.
-   Copyright 1991, 1994, 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
+   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -82,7 +83,7 @@ struct floatformat
   const char *name;
 
   /* Validator method.  */
-  int (*is_valid) (const struct floatformat *fmt, const char *from);
+  int (*is_valid) (const struct floatformat *fmt, const void *from);
 };
 
 /* floatformats for IEEE single and double, big and little endian.  */
@@ -116,17 +117,17 @@ extern const struct floatformat floatfor
    Store the double in *TO.  */
 
 extern void
-floatformat_to_double (const struct floatformat *, const char *, double *);
+floatformat_to_double (const struct floatformat *, const void *, double *);
 
 /* The converse: convert the double *FROM to FMT
    and store where TO points.  */
 
 extern void
-floatformat_from_double (const struct floatformat *, const double *, char *);
+floatformat_from_double (const struct floatformat *, const double *, void *);
 
 /* Return non-zero iff the data at FROM is a valid number in format FMT.  */
 
 extern int
-floatformat_is_valid (const struct floatformat *fmt, const char *from);
+floatformat_is_valid (const struct floatformat *fmt, const void *from);
 
 #endif	/* defined (FLOATFORMAT_H) */
Index: libiberty/ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* floatformat.c (floatformat_always_valid): Change type of last
	argument to `void *'.
	(floatformat_i387_ext_is_valid): Likewise.
	(floatformat_to_double): Change type of second argument to `const
	void *'.
	(floatformat_from_double): Change type of last argument to `void
	*'.
	(floatformat_is_valid): Change type of last argument to `const
	void *'.
	(ieee_test): Remove redundant casts.

Index: libiberty/floatformat.c
===================================================================
RCS file: /cvs/src/src/libiberty/floatformat.c,v
retrieving revision 1.15
diff -u -p -r1.15 floatformat.c
--- libiberty/floatformat.c 12 Jul 2005 10:35:00 -0000 1.15
+++ libiberty/floatformat.c 15 Aug 2005 14:05:39 -0000
@@ -1,5 +1,6 @@
 /* IEEE floating point support routines, for GDB, the GNU Debugger.
-   Copyright (C) 1991, 1994, 1999, 2000, 2003 Free Software Foundation, Inc.
+   Copyright 1991, 1994, 1999, 2000, 2003, 2005
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -52,11 +53,11 @@ static unsigned long get_field (const un
                                 unsigned int,
                                 unsigned int);
 static int floatformat_always_valid (const struct floatformat *fmt,
-                                     const char *from);
+                                     const void *from);
 
 static int
 floatformat_always_valid (const struct floatformat *fmt ATTRIBUTE_UNUSED,
-                          const char *from ATTRIBUTE_UNUSED)
+                          const void *from ATTRIBUTE_UNUSED)
 {
   return 1;
 }
@@ -107,23 +108,24 @@ const struct floatformat floatformat_iee
   floatformat_always_valid
 };
 
-static int floatformat_i387_ext_is_valid (const struct floatformat *fmt, const char *from);
+static int floatformat_i387_ext_is_valid (const struct floatformat *fmt,
+					  const void *from);
 
 static int
-floatformat_i387_ext_is_valid (const struct floatformat *fmt, const char *from)
+floatformat_i387_ext_is_valid (const struct floatformat *fmt, const void *from)
 {
   /* In the i387 double-extended format, if the exponent is all ones,
      then the integer bit must be set.  If the exponent is neither 0
      nor ~0, the intbit must also be set.  Only if the exponent is
      zero can it be zero, and then it must be zero.  */
   unsigned long exponent, int_bit;
-  const unsigned char *ufrom = (const unsigned char *) from;
-  
+  const unsigned char *ufrom = from;
+
   exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
 			fmt->exp_start, fmt->exp_len);
   int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
 		       fmt->man_start, 1);
-  
+
   if ((exponent == 0) != (int_bit == 0))
     return 0;
   else
@@ -267,9 +269,9 @@ get_field (const unsigned char *data, en
 
 void
 floatformat_to_double (const struct floatformat *fmt,
-                       const char *from, double *to)
+                       const void *from, double *to)
 {
-  const unsigned char *ufrom = (const unsigned char *)from;
+  const unsigned char *ufrom = from;
   double dto;
   long exponent;
   unsigned long mant;
@@ -438,14 +440,14 @@ put_field (unsigned char *data, enum flo
 
 void
 floatformat_from_double (const struct floatformat *fmt,
-                         const double *from, char *to)
+                         const double *from, void *to)
 {
   double dfrom;
   int exponent;
   double mant;
   unsigned int mant_bits, mant_off;
   int mant_bits_left;
-  unsigned char *uto = (unsigned char *)to;
+  unsigned char *uto = to;
 
   dfrom = *from;
   memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
@@ -533,7 +535,7 @@ floatformat_from_double (const struct fl
 /* Return non-zero iff the data at FROM is a valid number in format FMT.  */
 
 int
-floatformat_is_valid (const struct floatformat *fmt, const char *from)
+floatformat_is_valid (const struct floatformat *fmt, const void *from)
 {
   return fmt->is_valid (fmt, from);
 }
@@ -550,15 +552,13 @@ ieee_test (double n)
 {
   double result;
 
-  floatformat_to_double (&floatformat_ieee_double_little, (char *) &n,
-			 &result);
+  floatformat_to_double (&floatformat_ieee_double_little, &n, &result);
   if ((n != result && (! isnan (n) || ! isnan (result)))
       || (n < 0 && result >= 0)
       || (n >= 0 && result < 0))
     printf ("Differ(to): %.20g -> %.20g\n", n, result);
 
-  floatformat_from_double (&floatformat_ieee_double_little, &n,
-			   (char *) &result);
+  floatformat_from_double (&floatformat_ieee_double_little, &n, &result);
   if ((n != result && (! isnan (n) || ! isnan (result)))
       || (n < 0 && result >= 0)
       || (n >= 0 && result < 0))



More information about the Gdb-patches mailing list