This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use ANSI_PROTOTYPES in libiberty


The following clean-up to the libiberty directory was suggested by
Kaveh.  Many ANSI C compilers don't define (or don't always define) the
macro __STDC__ even though they provide all the appropriate ANSI header
files.  The libiberty header <ansidecl.h> recognizes these compilers
and then appropriately defines ANSI_PROTOTYPES whether __STDC__ is
defined or not.  For this reason ANSI_PROTOTYPES is preferred over
__STDC__ when deciding whether to include a standard system header.
The patch below standardizes libiberty to follow this practice.

Unfortunately, some of the modified libiberty source files contained
compiler warnings that I took the opporunity to fix whilst I was there.

[1] GCC complains about the use of DEFUN to generate ISO C function
declarations as libiberty is compiled with the -traditional flag.  This
is fixed by switching to old-style function declarations in the six
affected source files.

[2] The implementations of memcpy and memmove refer to bcopy without
a function prototype.  For these files, its easy enough to provide the
prototype expected by the code below.


The following patch has been tested by compiling each of the affected
files with "make foo.o" without compilation warnings on i686-pc-cygwin.

Ok for mainline?



2003-04-14  Roger Sayle  <roger at eyesopen dot com>

	* argv.c: Use ANSI_PROTOTYPES instead of __STDC__.
	* memchr.c: Likewise.
	* strcasecmp.c: Likewise.
	* strncasecmp.c: Likewise.
	* strncmp.c: Likewise.
	* xatexit.c: Likewise.
	* xmalloc.c: Likewise.

	* copysign.c: Use traditional function declaration instead of DEFUN.
	* sigsetmask.c: Likewise.

	* memcmp.c: Both of the above, ANSI_PROTOTYPES and DEFUN.
	* memset.c: Likewise.

	* memcpy.c: ANSI_PROTOTYPES, DEFUN and prototype bcopy.
	* memmove.c: Likewise.


Index: argv.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/argv.c,v
retrieving revision 1.11
diff -c -3 -p -r1.11 argv.c
*** argv.c	17 Oct 2001 21:15:40 -0000	1.11
--- argv.c	15 Apr 2003 02:46:20 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 29,35 ****

  /*  Routines imported from standard C runtime libraries. */

! #ifdef __STDC__

  #include <stddef.h>
  #include <string.h>
--- 29,35 ----

  /*  Routines imported from standard C runtime libraries. */

! #ifdef ANSI_PROTOTYPES

  #include <stddef.h>
  #include <string.h>
Index: copysign.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/copysign.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 copysign.c
*** copysign.c	22 Jan 2002 20:03:29 -0000	1.3
--- copysign.c	15 Apr 2003 02:46:20 -0000
*************** typedef union
*** 131,137 ****

  #if defined(__IEEE_BIG_ENDIAN) || defined(__IEEE_LITTLE_ENDIAN)

! double DEFUN(copysign, (x, y), double x AND double y)
  {
    __ieee_double_shape_type a,b;
    b.value = y;
--- 131,139 ----

  #if defined(__IEEE_BIG_ENDIAN) || defined(__IEEE_LITTLE_ENDIAN)

! double
! copysign (x, y)
!      double x, y;
  {
    __ieee_double_shape_type a,b;
    b.value = y;
*************** double DEFUN(copysign, (x, y), double x
*** 142,148 ****

  #else

! double DEFUN(copysign, (x, y), double x AND double y)
  {
    if ((x < 0 && y > 0) || (x > 0 && y < 0))
      return -x;
--- 144,152 ----

  #else

! double
! copysign (x, y)
!      double x, y;
  {
    if ((x < 0 && y > 0) || (x > 0 && y < 0))
      return -x;
Index: memchr.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/memchr.c,v
retrieving revision 1.6
diff -c -3 -p -r1.6 memchr.c
*** memchr.c	7 Oct 2001 21:53:31 -0000	1.6
--- memchr.c	15 Apr 2003 02:46:20 -0000
*************** returned.
*** 15,21 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 15,21 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
Index: memcmp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/memcmp.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 memcmp.c
*** memcmp.c	26 Sep 2001 18:16:17 -0000	1.4
--- memcmp.c	15 Apr 2003 02:46:20 -0000
*************** as if comparing unsigned char arrays.
*** 16,30 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  int
! DEFUN(memcmp, (str1, str2, count),
!       const PTR str1 AND const PTR str2 AND size_t count)
  {
    register const unsigned char *s1 = (const unsigned char*)str1;
    register const unsigned char *s2 = (const unsigned char*)str2;
--- 16,32 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  int
! memcmp (str1, str2, count)
!      const PTR str1;
!      const PTR str2;
!      size_t count;
  {
    register const unsigned char *s1 = (const unsigned char*)str1;
    register const unsigned char *s2 = (const unsigned char*)str2;
Index: memcpy.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/memcpy.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 memcpy.c
*** memcpy.c	26 Sep 2001 18:16:17 -0000	1.4
--- memcpy.c	15 Apr 2003 02:46:20 -0000
*************** Copies @var{length} bytes from memory re
*** 13,26 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  PTR
! DEFUN(memcpy, (out, in, length), PTR out AND const PTR in AND size_t length)
  {
      bcopy(in, out, length);
      return out;
--- 13,31 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

+ void bcopy PARAMS((const void*, void*, size_t));
+
  PTR
! memcpy (out, in, length)
!      PTR out;
!      const PTR in;
!      size_t length;
  {
      bcopy(in, out, length);
      return out;
Index: memmove.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/memmove.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 memmove.c
*** memmove.c	26 Sep 2001 18:16:17 -0000	1.4
--- memmove.c	15 Apr 2003 02:46:20 -0000
*************** Copies @var{count} bytes from memory are
*** 13,23 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  PTR
  memmove (s1, s2, n)
--- 13,25 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif
+
+ void bcopy PARAMS ((const void*, void*, size_t));

  PTR
  memmove (s1, s2, n)
Index: memset.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/memset.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 memset.c
*** memset.c	26 Sep 2001 18:16:17 -0000	1.3
--- memset.c	15 Apr 2003 02:46:20 -0000
*************** Sets the first @var{count} bytes of @var
*** 13,27 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  PTR
! DEFUN(memset, (dest, val, len),
!       PTR dest AND register int val AND register size_t len)
  {
    register unsigned char *ptr = (unsigned char*)dest;
    while (len-- > 0)
--- 13,29 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
  #endif

  PTR
! memset (dest, val, len)
!      PTR dest;
!      register int val;
!      register size_t len;
  {
    register unsigned char *ptr = (unsigned char*)dest;
    while (len-- > 0)
Index: sigsetmask.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/sigsetmask.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 sigsetmask.c
*** sigsetmask.c	26 Sep 2001 18:16:17 -0000	1.4
--- sigsetmask.c	15 Apr 2003 02:46:20 -0000
*************** extern void abort PARAMS ((void)) ATTRIB
*** 25,32 ****

  #ifdef SIG_SETMASK
  int
! DEFUN(sigsetmask,(set),
!       int set)
  {
      sigset_t new;
      sigset_t old;
--- 25,32 ----

  #ifdef SIG_SETMASK
  int
! sigsetmask (set)
!       int set;
  {
      sigset_t new;
      sigset_t old;
Index: strcasecmp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/strcasecmp.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 strcasecmp.c
*** strcasecmp.c	7 Oct 2001 14:45:04 -0000	1.4
--- strcasecmp.c	15 Apr 2003 02:46:20 -0000
*************** static char sccsid[] = "@(#)strcasecmp.c
*** 25,31 ****
  #endif /* LIBC_SCCS and not lint */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 25,31 ----
  #endif /* LIBC_SCCS and not lint */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
Index: strncasecmp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/strncasecmp.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 strncasecmp.c
*** strncasecmp.c	7 Oct 2001 14:45:04 -0000	1.4
--- strncasecmp.c	15 Apr 2003 02:46:20 -0000
*************** static char sccsid[] = "@(#)strcasecmp.c
*** 25,31 ****
  #endif /* LIBC_SCCS and not lint */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 25,31 ----
  #endif /* LIBC_SCCS and not lint */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
Index: strncmp.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/strncmp.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 strncmp.c
*** strncmp.c	26 Sep 2001 18:16:17 -0000	1.2
--- strncmp.c	15 Apr 2003 02:46:20 -0000
*************** Compares the first @var{n} bytes of two
*** 13,19 ****
  */

  #include <ansidecl.h>
! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 13,19 ----
  */

  #include <ansidecl.h>
! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
Index: xatexit.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xatexit.c,v
retrieving revision 1.6
diff -c -3 -p -r1.6 xatexit.c
*** xatexit.c	11 Mar 2002 12:47:53 -0000	1.6
--- xatexit.c	15 Apr 2003 02:46:20 -0000
*************** failure.  If you use @code{xatexit} to r
*** 27,33 ****

  #include <stdio.h>

! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 27,33 ----

  #include <stdio.h>

! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long
Index: xmalloc.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xmalloc.c,v
retrieving revision 1.15
diff -c -3 -p -r1.15 xmalloc.c
*** xmalloc.c	4 Mar 2002 21:22:52 -0000	1.15
--- xmalloc.c	15 Apr 2003 02:46:21 -0000
*************** function will be called to print an erro
*** 68,74 ****

  #include <stdio.h>

! #ifdef __STDC__
  #include <stddef.h>
  #else
  #define size_t unsigned long
--- 68,74 ----

  #include <stdio.h>

! #ifdef ANSI_PROTOTYPES
  #include <stddef.h>
  #else
  #define size_t unsigned long


Roger
--
Roger Sayle,                         E-mail: roger at eyesopen dot com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]