bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] mem* modules patches to assume C89 or better


From: Paul Eggert
Subject: [Bug-gnulib] mem* modules patches to assume C89 or better
Date: 09 Sep 2003 15:24:35 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I installed this:

2003-09-09  Paul Eggert  <address@hidden>

        * lib/memchr.c (__ptr_t): Remove; all uses changed to void *.
        * lib/memcmp.c (__ptr_t): Likewise.
        * lib/memrchr.c (__ptr_t): Likewise.
        * lib/memchr.c, lib/memcmp.c, lib/memcoll.c, lib/memrchr.c:
        Include <string.h> unconditionally.
        * lib/memchr.c, lib/memrchr.c: Include <limits.h> unconditionally.
        * lib/memchr.c: Include <stdlib.h> unconditionally.
        * lib/memchr.c (LONG_MAX): Remove.
        * lib/memrchr.c (LONG_MAX): Likewise.
        * lib/memchr.c (__memchr): Define via a prototype.
        * lib/memrchr.c (__memrchr): Likewise.
        * lib/memcmp.c (__P): Remove, and remove all uses.
        (memcmp_bytes, memcmp_common_alignment, memcmp_not_common_alignment):
        Remove forward decls; no longer needed.
        * lib/memcpy.c, lib/memmove.c, lib/memset.c: Include <stddef.h>.
        Use types required by C89 in prototype.
        * m4/memrchr.m4 (jm_PREREQ_MEMCHR): Don't check for limits.h, stdlib.h.
        * m4/memcmp.m4 (gl_PREREQ_MEMCMP): Don't check for string.h.
        * m4/memcoll.m4 (gl_MEMCOLL): Likewise.
        * m4/memrchr.c (gl_PREREQ_MEMRCHR): Don't check for limits.h.

Index: lib/memchr.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memchr.c,v
retrieving revision 1.15
diff -p -u -r1.15 memchr.c
--- lib/memchr.c        28 Oct 2000 08:22:11 -0000      1.15
+++ lib/memchr.c        9 Sep 2003 22:20:09 -0000
@@ -1,4 +1,6 @@
-/* Copyright (C) 1991,93,96,97,99,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free
+   Software Foundation, Inc.
+
    Based on strlen implementation by Torbjorn Granlund (address@hidden),
    with help from Dan Sahlin (address@hidden) and
    commentary by Jim Blandy (address@hidden);
@@ -27,34 +29,19 @@ USA.  */
 # include <config.h>
 #endif
 
-#undef __ptr_t
-#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
-# define __ptr_t void *
-#else /* Not C++ or ANSI C.  */
-# define __ptr_t char *
-#endif /* C++ or ANSI C.  */
+#include <string.h>
 
 #if defined _LIBC
-# include <string.h>
 # include <memcopy.h>
 #else
 # define reg_char char
 #endif
 
-#if HAVE_STDLIB_H || defined _LIBC
-# include <stdlib.h>
-#endif
-
-#if HAVE_LIMITS_H || defined _LIBC
-# include <limits.h>
-#endif
+#include <limits.h>
+#include <stdlib.h>
 
 #define LONG_MAX_32_BITS 2147483647
 
-#ifndef LONG_MAX
-# define LONG_MAX LONG_MAX_32_BITS
-#endif
-
 #include <sys/types.h>
 #if HAVE_BP_SYM_H || defined _LIBC
 # include <bp-sym.h>
@@ -66,11 +53,8 @@ USA.  */
 #undef __memchr
 
 /* Search no more than N bytes of S for C.  */
-__ptr_t
-__memchr (s, c_in, n)
-     const __ptr_t s;
-     int c_in;
-     size_t n;
+void *
+__memchr (void const *s, int c_in, size_t n)
 {
   const unsigned char *char_ptr;
   const unsigned long int *longword_ptr;
@@ -86,7 +70,7 @@ __memchr (s, c_in, n)
                 & (sizeof (longword) - 1)) != 0;
        --n, ++char_ptr)
     if (*char_ptr == c)
-      return (__ptr_t) char_ptr;
+      return (void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to 8-byte longwords.  */
@@ -177,22 +161,22 @@ __memchr (s, c_in, n)
          const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
 
          if (cp[0] == c)
-           return (__ptr_t) cp;
+           return (void *) cp;
          if (cp[1] == c)
-           return (__ptr_t) &cp[1];
+           return (void *) &cp[1];
          if (cp[2] == c)
-           return (__ptr_t) &cp[2];
+           return (void *) &cp[2];
          if (cp[3] == c)
-           return (__ptr_t) &cp[3];
+           return (void *) &cp[3];
 #if LONG_MAX > 2147483647
          if (cp[4] == c)
-           return (__ptr_t) &cp[4];
+           return (void *) &cp[4];
          if (cp[5] == c)
-           return (__ptr_t) &cp[5];
+           return (void *) &cp[5];
          if (cp[6] == c)
-           return (__ptr_t) &cp[6];
+           return (void *) &cp[6];
          if (cp[7] == c)
-           return (__ptr_t) &cp[7];
+           return (void *) &cp[7];
 #endif
        }
 
@@ -204,7 +188,7 @@ __memchr (s, c_in, n)
   while (n-- > 0)
     {
       if (*char_ptr == c)
-       return (__ptr_t) char_ptr;
+       return (void *) char_ptr;
       else
        ++char_ptr;
     }
Index: lib/memcmp.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memcmp.c,v
retrieving revision 1.10
diff -p -u -r1.10 memcmp.c
--- lib/memcmp.c        28 Oct 2000 08:24:44 -0000      1.10
+++ lib/memcmp.c        9 Sep 2003 22:20:09 -0000
@@ -1,4 +1,6 @@
-/* Copyright (C) 1991, 1993, 1995, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1995, 1997, 1998, 2003 Free Software
+   Foundation, Inc.
+
    Contributed by Torbjorn Granlund (address@hidden).
 
    NOTE: The canonical source of this file is maintained with the GNU C 
Library.
@@ -23,26 +25,7 @@
 # include "config.h"
 #endif
 
-#undef __ptr_t
-#if defined __cplusplus || (defined __STDC__ && __STDC__)
-# define __ptr_t       void *
-#else /* Not C++ or ANSI C.  */
-# undef        const
-# define const
-# define __ptr_t       char *
-#endif /* C++ or ANSI C.  */
-
-#ifndef __P
-# if defined __GNUC__ || (defined __STDC__ && __STDC__)
-#  define __P(args) args
-# else
-#  define __P(args) ()
-# endif  /* GCC.  */
-#endif  /* Not __P.  */
-
-#if defined HAVE_STRING_H || defined _LIBC
-# include <string.h>
-#endif
+#include <string.h>
 
 #undef memcmp
 
@@ -103,8 +86,6 @@ typedef unsigned char byte;
    A and B are known to be different.
    This is needed only on little-endian machines.  */
 
-static int memcmp_bytes __P((op_t, op_t));
-
 # ifdef  __GNUC__
 __inline
 # endif
@@ -127,8 +108,6 @@ memcmp_bytes (long unsigned int a, long 
 }
 #endif
 
-static int memcmp_common_alignment __P((long, long, size_t));
-
 /* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t'
    objects (not LEN bytes!).  Both SRCP1 and SRCP2 should be aligned for
    memory operations on `op_t's.  */
@@ -213,8 +192,6 @@ memcmp_common_alignment (long int srcp1,
     return CMP_LT_OR_GT (a1, b1);
   return 0;
 }
-
-static int memcmp_not_common_alignment __P((long, long, size_t));
 
 /* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN
    `op_t' objects (not LEN bytes!).  SRCP2 should be aligned for memory
Index: lib/memcoll.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memcoll.c,v
retrieving revision 1.10
diff -p -u -r1.10 memcoll.c
--- lib/memcoll.c       18 Jul 2003 17:49:25 -0000      1.10
+++ lib/memcoll.c       9 Sep 2003 22:20:09 -0000
@@ -28,9 +28,7 @@
 extern int errno;
 #endif
 
-#if HAVE_STRING_H
-# include <string.h>
-#endif
+#include <string.h>
 
 /* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
    to the LC_COLLATE locale.  S1 and S2 do not overlap, and are not
Index: lib/memcpy.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memcpy.c,v
retrieving revision 1.8
diff -p -u -r1.8 memcpy.c
--- lib/memcpy.c        11 Jan 2000 14:05:28 -0000      1.8
+++ lib/memcpy.c        9 Sep 2003 22:20:09 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,16 +20,19 @@
 # include <config.h>
 #endif
 
+#include <stddef.h>
+
 /* Copy LEN bytes starting at SRCADDR to DESTADDR.  Result undefined
    if the source overlaps with the destination.
    Return DESTADDR. */
 
-char *
-memcpy (char *destaddr, const char *srcaddr, int len)
+void *
+memcpy (void *destaddr, void const *srcaddr, size_t len)
 {
   char *dest = destaddr;
+  char const *src = srcaddr;
 
   while (len-- > 0)
-    *destaddr++ = *srcaddr++;
-  return dest;
+    *dest++ = *src++;
+  return destaddr;
 }
Index: lib/memmove.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memmove.c,v
retrieving revision 1.7
diff -p -u -r1.7 memmove.c
--- lib/memmove.c       17 Oct 1996 03:05:09 -0000      1.7
+++ lib/memmove.c       9 Sep 2003 22:20:09 -0000
@@ -7,13 +7,13 @@
 # include <config.h>
 #endif
 
+#include <stddef.h>
+
 void *
-memmove (dest, source, length)
-     char *dest;
-     const char *source;
-     unsigned length;
+memmove (void *dest0, void const *source0, size_t length)
 {
-  char *d0 = dest;
+  char *dest = dest0;
+  char const *source = source0;
   if (source < dest)
     /* Moving from low mem to hi mem; start at end.  */
     for (source += length, dest += length; length; --length)
@@ -24,5 +24,5 @@ memmove (dest, source, length)
       for (; length; --length)
        *dest++ = *source++;
     }
-  return (void *) d0;
+  return dest0;
 }
Index: lib/memrchr.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memrchr.c,v
retrieving revision 1.3
diff -p -u -r1.3 memrchr.c
--- lib/memrchr.c       9 Jul 2003 22:48:53 -0000       1.3
+++ lib/memrchr.c       9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,8 @@
 /* memrchr -- find the last occurrence of a byte in a memory block
-   Copyright (C) 1991, 93, 96, 97, 99, 2000 Free Software Foundation, Inc.
+
+   Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free
+   Software Foundation, Inc.
+
    Based on strlen implementation by Torbjorn Granlund (address@hidden),
    with help from Dan Sahlin (address@hidden) and
    commentary by Jim Blandy (address@hidden);
@@ -25,31 +28,18 @@
 #endif
 
 #include <stdlib.h>
-
-#undef __ptr_t
-#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
-# define __ptr_t void *
-#else /* Not C++ or ANSI C.  */
-# define __ptr_t char *
-#endif /* C++ or ANSI C.  */
+#include <string.h>
 
 #if defined (_LIBC)
-# include <string.h>
 # include <memcopy.h>
 #else
 # define reg_char char
 #endif
 
-#if defined (HAVE_LIMITS_H) || defined (_LIBC)
-# include <limits.h>
-#endif
+#include <limits.h>
 
 #define LONG_MAX_32_BITS 2147483647
 
-#ifndef LONG_MAX
-# define LONG_MAX LONG_MAX_32_BITS
-#endif
-
 #include <sys/types.h>
 
 #undef __memrchr
@@ -60,11 +50,8 @@
 #endif
 
 /* Search no more than N bytes of S for C.  */
-__ptr_t
-__memrchr (s, c_in, n)
-     const __ptr_t s;
-     int c_in;
-     size_t n;
+void *
+__memrchr (void const *s, int c_in, size_t n)
 {
   const unsigned char *char_ptr;
   const unsigned long int *longword_ptr;
@@ -80,7 +67,7 @@ __memrchr (s, c_in, n)
                 & (sizeof (longword) - 1)) != 0;
        --n)
     if (*--char_ptr == c)
-      return (__ptr_t) char_ptr;
+      return (void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to 8-byte longwords.  */
@@ -172,22 +159,22 @@ __memrchr (s, c_in, n)
 
 #if LONG_MAX > 2147483647
          if (cp[7] == c)
-           return (__ptr_t) &cp[7];
+           return (void *) &cp[7];
          if (cp[6] == c)
-           return (__ptr_t) &cp[6];
+           return (void *) &cp[6];
          if (cp[5] == c)
-           return (__ptr_t) &cp[5];
+           return (void *) &cp[5];
          if (cp[4] == c)
-           return (__ptr_t) &cp[4];
+           return (void *) &cp[4];
 #endif
          if (cp[3] == c)
-           return (__ptr_t) &cp[3];
+           return (void *) &cp[3];
          if (cp[2] == c)
-           return (__ptr_t) &cp[2];
+           return (void *) &cp[2];
          if (cp[1] == c)
-           return (__ptr_t) &cp[1];
+           return (void *) &cp[1];
          if (cp[0] == c)
-           return (__ptr_t) cp;
+           return (void *) cp;
        }
 
       n -= sizeof (longword);
@@ -198,7 +185,7 @@ __memrchr (s, c_in, n)
   while (n-- > 0)
     {
       if (*--char_ptr == c)
-       return (__ptr_t) char_ptr;
+       return (void *) char_ptr;
     }
 
   return 0;
Index: lib/memset.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/memset.c,v
retrieving revision 1.5
diff -p -u -r1.5 memset.c
--- lib/memset.c        7 Aug 2000 15:48:18 -0000       1.5
+++ lib/memset.c        9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,5 @@
 /* memset.c -- set an area of memory to a given value
-   Copyright (C) 1991 Free Software Foundation, Inc.
+   Copyright (C) 1991, 2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,8 +15,10 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-char *
-memset (char *str, int c, unsigned int len)
+#include <stddef.h>
+
+void *
+memset (void *str, int c, size_t len)
 {
   register char *st = str;
 
Index: m4/memchr.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/memchr.m4,v
retrieving revision 1.1
diff -p -u -r1.1 memchr.m4
--- m4/memchr.m4        31 Dec 2002 13:42:07 -0000      1.1
+++ m4/memchr.m4        9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,5 @@
-# memchr.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memchr.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -16,6 +16,5 @@ AC_DEFUN([gl_FUNC_MEMCHR],
 
 # Prerequisites of lib/memchr.c.
 AC_DEFUN([jm_PREREQ_MEMCHR], [
-  AC_CHECK_HEADERS_ONCE(limits.h stdlib.h)
   AC_CHECK_HEADERS(bp-sym.h)
 ])
Index: m4/memcmp.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/memcmp.m4,v
retrieving revision 1.11
diff -p -u -r1.11 memcmp.m4
--- m4/memcmp.m4        31 Dec 2002 13:43:06 -0000      1.11
+++ m4/memcmp.m4        9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,5 @@
-# memcmp.m4 serial 8
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memcmp.m4 serial 9
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -17,6 +17,4 @@ AC_DEFUN([jm_FUNC_MEMCMP],
 ])
 
 # Prerequisites of lib/memcmp.c.
-AC_DEFUN([gl_PREREQ_MEMCMP], [
-  AC_CHECK_HEADERS_ONCE(string.h)
-])
+AC_DEFUN([gl_PREREQ_MEMCMP], [:])
Index: m4/memcoll.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/memcoll.m4,v
retrieving revision 1.2
diff -p -u -r1.2 memcoll.m4
--- m4/memcoll.m4       31 Dec 2002 22:11:51 -0000      1.2
+++ m4/memcoll.m4       9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,5 @@
-# memcoll.m4 serial 2
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memcoll.m4 serial 3
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -10,6 +10,5 @@ AC_DEFUN([gl_MEMCOLL],
 [
   dnl Prerequisites of lib/memcoll.c.
   AC_REQUIRE([AC_FUNC_MEMCMP])
-  AC_CHECK_HEADERS_ONCE(string.h)
   AC_FUNC_STRCOLL
 ])
Index: m4/memrchr.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/memrchr.m4,v
retrieving revision 1.1
diff -p -u -r1.1 memrchr.m4
--- m4/memrchr.m4       31 Dec 2002 13:42:07 -0000      1.1
+++ m4/memrchr.m4       9 Sep 2003 22:20:09 -0000
@@ -1,5 +1,5 @@
-# memrchr.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memrchr.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -18,6 +18,4 @@ AC_DEFUN([gl_FUNC_MEMRCHR],
 ])
 
 # Prerequisites of lib/memrchr.c.
-AC_DEFUN([gl_PREREQ_MEMRCHR], [
-  AC_CHECK_HEADERS_ONCE(limits.h)
-])
+AC_DEFUN([gl_PREREQ_MEMRCHR], [:])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]