unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* memcmp, memcpy, memmove, memset
@ 2011-07-05  7:52 Paul Eggert
  2011-07-07  1:41 ` Paul Eggert
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Eggert @ 2011-07-05  7:52 UTC (permalink / raw)
  To: Emacs Development

While looking into low-level integer overflow and signedness
issues I ran into some old code that's no longer needed
and that I'd like to remove (so I don't have to worry about
it when looking for problems with unsigned integers).

This old code provides implementations of the functions memcmp, memcpy,
memmove, and memset.  These functions are now present everywhere,
so this stuff is never compiled and its presence in Emacs
merely slows 'configure' down now.

Here's the patch I'd like to install after a bit more testing.

I don't think this affects the Windows port, as Windows has these
functions too.

=== modified file 'ChangeLog'
--- ChangeLog	2011-07-01 17:53:59 +0000
+++ ChangeLog	2011-07-05 05:27:49 +0000
@@ -1,3 +1,11 @@
+2011-07-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Assume support for memcmp, memcpy, memmove, memset.
+	This simplifies the code a bit.  All current platforms have these,
+	as they are required for C89.  If this turns into a problem we
+	can add the gnulib modules for these (a 1-line change to Makefile.in).
+	* configure.in: Don't check for memcmp, memcpy, memmove, memset.
+
 2011-07-01  Glenn Morris  <rgm@gnu.org>
 
 	* configure.in (SETTINGS_CFLAGS, SETTINGS_LIBS) [HAVE_GCONF]: Fix typo.

=== modified file 'configure.in'
--- configure.in	2011-07-01 17:53:59 +0000
+++ configure.in	2011-07-05 05:27:49 +0000
@@ -2704,8 +2704,8 @@
 utimes getrlimit setrlimit setpgid getcwd getwd shutdown getaddrinfo \
 __fpending mblen mbrlen mbsinit strsignal setitimer ualarm strchr strrchr \
 sendto recvfrom getsockopt setsockopt getsockname getpeername \
-gai_strerror mkstemp getline getdelim mremap memmove fsync sync \
-memset memcmp difftime memcpy mempcpy mblen mbrlen posix_memalign \
+gai_strerror mkstemp getline getdelim mremap fsync sync \
+difftime mempcpy mblen mbrlen posix_memalign \
 cfmakeraw cfsetspeed isnan copysign __executable_start)
 
 dnl Cannot use AC_CHECK_FUNCS
@@ -3109,8 +3109,6 @@
 dnl    AC_DEFINE(HAVE_TCATTR, 1, [Define to 1 if you have tcgetattr and tcsetattr.])
 dnl fi
 
-dnl Fixme: Use AC_FUNC_MEMCMP since memcmp is used.  (Needs libobj replacement.)
-
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"

=== modified file 'lib-src/ChangeLog'
--- lib-src/ChangeLog	2011-07-02 15:07:57 +0000
+++ lib-src/ChangeLog	2011-07-05 05:27:49 +0000
@@ -1,3 +1,8 @@
+2011-07-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Assume support for memcmp, memcpy, memmove, memset.
+	* etags.c (absolute_filename): Assume memmove exists.
+
 2011-07-02  Jason Rumney  <jasonr@gnu.org>
 
 	* emacsclient.c (decode_options) [WINDOWSNT]: Avoid tty mode on

=== modified file 'lib-src/etags.c'
--- lib-src/etags.c	2011-05-28 22:39:39 +0000
+++ lib-src/etags.c	2011-07-05 05:27:49 +0000
@@ -6567,22 +6567,13 @@
 	      else if (cp[0] != '/')
 		cp = slashp;
 #endif
-#ifdef HAVE_MEMMOVE
               memmove (cp, slashp + 3, strlen (slashp + 2));
-#else
-              /* Overlapping copy isn't really okay */
-	      strcpy (cp, slashp + 3);
-#endif
 	      slashp = cp;
 	      continue;
 	    }
 	  else if (slashp[2] == '/' || slashp[2] == '\0')
 	    {
-#ifdef HAVE_MEMMOVE
 	      memmove (slashp, slashp + 2, strlen (slashp + 1));
-#else
-              strcpy (slashp, slashp + 2);
-#endif
 	      continue;
 	    }
 	}

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-07-05 03:09:36 +0000
+++ src/ChangeLog	2011-07-05 05:27:49 +0000
@@ -1,5 +1,13 @@
 2011-07-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Assume support for memcmp, memcpy, memmove, memset.
+	* lisp.h, sysdep.c (memcmp, memcpy, memmove, memset):
+	* regex.c (memcmp, memcpy):
+	Remove; we assume C89 now.
+
+	* gmalloc.c (memcpy, memset, memmove): Remove; we assume C89 now.
+	(__malloc_safe_bcopy): Remove; no longer needed.
+
 	* lisp.h (struct vectorlike_header, struct Lisp_Subr):  Signed sizes.
 	Use EMACS_INT, not EMACS_UINT, for sizes.  The code works equally
 	well either way, and we prefer signed to unsigned.

=== modified file 'src/gmalloc.c'
--- src/gmalloc.c	2011-05-28 22:39:39 +0000
+++ src/gmalloc.c	2011-07-05 05:27:49 +0000
@@ -54,16 +54,7 @@
 #define	__ptr_t		char *
 #endif /* C++ or ANSI C.  */
 
-#if	defined(_LIBC) || defined(STDC_HEADERS) || defined(USG)
 #include <string.h>
-#else
-#ifndef memset
-#define	memset(s, zero, n)	bzero ((s), (n))
-#endif
-#ifndef memcpy
-#define	memcpy(d, s, n)		bcopy ((s), (d), (n))
-#endif
-#endif
 
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
@@ -1069,20 +1060,6 @@
 #endif
 
 
-/* Cope with systems lacking `memmove'.    */
-#ifndef memmove
-#if  (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG))
-#ifdef emacs
-#undef	__malloc_safe_bcopy
-#define __malloc_safe_bcopy safe_bcopy
-#endif
-/* This function is defined in realloc.c.  */
-extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t));
-#define memmove(to, from, size)	__malloc_safe_bcopy ((from), (to), (size))
-#endif
-#endif
-
-
 /* Debugging hook for free.  */
 void (*__free_hook) PP ((__ptr_t __ptr));
 
@@ -1402,85 +1379,6 @@
 #endif
 
 
-
-/* Cope with systems lacking `memmove'.    */
-#if  (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG))
-
-#ifdef emacs
-#undef	__malloc_safe_bcopy
-#define __malloc_safe_bcopy safe_bcopy
-#else
-
-/* Snarfed directly from Emacs src/dispnew.c:
-   XXX Should use system bcopy if it handles overlap.  */
-
-/* Like bcopy except never gets confused by overlap.  */
-
-void
-__malloc_safe_bcopy (afrom, ato, size)
-     __ptr_t afrom;
-     __ptr_t ato;
-     __malloc_size_t size;
-{
-  char *from = afrom, *to = ato;
-
-  if (size <= 0 || from == to)
-    return;
-
-  /* If the source and destination don't overlap, then bcopy can
-     handle it.  If they do overlap, but the destination is lower in
-     memory than the source, we'll assume bcopy can handle that.  */
-  if (to < from || from + size <= to)
-    bcopy (from, to, size);
-
-  /* Otherwise, we'll copy from the end.  */
-  else
-    {
-      register char *endf = from + size;
-      register char *endt = to + size;
-
-      /* If TO - FROM is large, then we should break the copy into
-	 nonoverlapping chunks of TO - FROM bytes each.  However, if
-	 TO - FROM is small, then the bcopy function call overhead
-	 makes this not worth it.  The crossover point could be about
-	 anywhere.  Since I don't think the obvious copy loop is too
-	 bad, I'm trying to err in its favor.  */
-      if (to - from < 64)
-	{
-	  do
-	    *--endt = *--endf;
-	  while (endf != from);
-	}
-      else
-	{
-	  for (;;)
-	    {
-	      endt -= (to - from);
-	      endf -= (to - from);
-
-	      if (endt < to)
-		break;
-
-	      bcopy (endf, endt, to - from);
-	    }
-
-	  /* If SIZE wasn't a multiple of TO - FROM, there will be a
-	     little left over.  The amount left over is
-	     (endt + (to - from)) - to, which is endt - from.  */
-	  bcopy (from, to, endt - from);
-	}
-    }
-}
-#endif /* emacs */
-
-#ifndef memmove
-extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t));
-#define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size))
-#endif
-
-#endif
-
-
 #define min(A, B) ((A) < (B) ? (A) : (B))
 
 /* Debugging hook for realloc.  */

=== modified file 'src/lisp.h'
--- src/lisp.h	2011-07-05 03:09:36 +0000
+++ src/lisp.h	2011-07-05 05:27:49 +0000
@@ -3429,18 +3429,6 @@
 extern EMACS_INT emacs_write (int, const char *, EMACS_INT);
 enum { READLINK_BUFSIZE = 1024 };
 extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
-#ifndef HAVE_MEMSET
-extern void *memset (void *, int, size_t);
-#endif
-#ifndef HAVE_MEMCPY
-extern void *memcpy (void *, void *, size_t);
-#endif
-#ifndef HAVE_MEMMOVE
-extern void *memmove (void *, void *, size_t);
-#endif
-#ifndef HAVE_MEMCMP
-extern int memcmp (void *, void *, size_t);
-#endif
 
 EXFUN (Funlock_buffer, 0);
 extern void unlock_all_files (void);

=== modified file 'src/regex.c'
--- src/regex.c	2011-04-16 18:26:30 +0000
+++ src/regex.c	2011-07-05 05:27:49 +0000
@@ -238,18 +238,7 @@
 # endif
 # define realloc xrealloc
 
-/* This is the normal way of making sure we have memcpy, memcmp and memset.  */
-# if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC
-#  include <string.h>
-# else
-#  include <strings.h>
-#  ifndef memcmp
-#   define memcmp(s1, s2, n)	bcmp (s1, s2, n)
-#  endif
-#  ifndef memcpy
-#   define memcpy(d, s, n)	(bcopy (s, d, n), (d))
-#  endif
-# endif
+# include <string.h>
 
 /* Define the syntax stuff for \<, \>, etc.  */
 

=== modified file 'src/sysdep.c'
--- src/sysdep.c	2011-07-05 02:51:15 +0000
+++ src/sysdep.c	2011-07-05 05:27:49 +0000
@@ -2216,59 +2216,6 @@
 #endif /* !HAVE_RMDIR */
 
 \f
-#ifndef HAVE_MEMSET
-void *
-memset (void *b, int n, size_t length)
-{
-  unsigned char *p = b;
-  while (length-- > 0)
-    *p++ = n;
-  return b;
-}
-#endif /* !HAVE_MEMSET */
-
-#ifndef HAVE_MEMCPY
-void *
-memcpy (void *b1, void *b2, size_t length)
-{
-  unsigned char *p1 = b1, *p2 = b2;
-  while (length-- > 0)
-    *p1++ = *p2++;
-  return b1;
-}
-#endif /* !HAVE_MEMCPY */
-
-#ifndef HAVE_MEMMOVE
-void *
-memmove (void *b1, void *b2, size_t length)
-{
-  unsigned char *p1 = b1, *p2 = b2;
-  if (p1 < p2 || p1 >= p2 + length)
-    while (length-- > 0)
-      *p1++ = *p2++;
-  else
-    {
-      p1 += length;
-      p2 += length;
-      while (length-- > 0)
-	*--p1 = *--p2;
-    }
-  return b1;
-}
-#endif /* !HAVE_MEMCPY */
-
-#ifndef HAVE_MEMCMP
-int
-memcmp (void *b1, void *b2, size_t length)
-{
-  unsigned char *p1 = b1, *p2 = b2;
-  while (length-- > 0)
-    if (*p1++ != *p2++)
-      return p1[-1] < p2[-1] ? -1 : 1;
-  return 0;
-}
-#endif /* !HAVE_MEMCMP */
-\f
 #ifndef HAVE_STRSIGNAL
 char *
 strsignal (int code)




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: memcmp, memcpy, memmove, memset
  2011-07-05  7:52 memcmp, memcpy, memmove, memset Paul Eggert
@ 2011-07-07  1:41 ` Paul Eggert
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Eggert @ 2011-07-07  1:41 UTC (permalink / raw)
  To: Emacs Development

While I'm on the subject of cleaning out old
pre-C89 cruft that complicates maintenance a bit,
I thought I'd also remove the old replacements for
string.h, stdlib.h, stddef.h, limits.h, and float.h,
as all plausible Emacs porting targets have supported
these for many years.  So I'd like to install the following
patch after a bit more testing.

This removes several lines from the Windows port,
but in a way that I expect will be safe.

=== modified file 'ChangeLog'
--- ChangeLog	2011-07-06 23:34:39 +0000
+++ ChangeLog	2011-07-07 01:32:56 +0000
@@ -1,3 +1,12 @@
+2011-07-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Assume freestanding C89 headers, string.h, stdlib.h.
+	Again, this simplifies the code, and all current platforms have these.
+	* configure.in (AC_CHECK_HEADERS): Don't check for limits.h.
+	(AC_HEADER_STDC): Remove.
+	(AC_CHECK_FUNCS): No need to check for strchr, strrchr.
+	(strchr, strrchr): Remove fallback macros.
+
 2011-07-06  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Assume support for memcmp, memcpy, memmove, memset.

=== modified file 'configure.in'
--- configure.in	2011-07-06 23:34:39 +0000
+++ configure.in	2011-07-07 01:32:56 +0000
@@ -1211,7 +1211,7 @@
 
 dnl checks for header files
 AC_CHECK_HEADERS(sys/select.h sys/time.h unistd.h utime.h \
-  linux/version.h sys/systeminfo.h limits.h \
+  linux/version.h sys/systeminfo.h \
   stdio_ext.h fcntl.h coff.h pty.h sys/mman.h \
   sys/vlimit.h sys/resource.h locale.h sys/_mbstate_t.h \
   sys/utsname.h pwd.h utmp.h dirent.h util.h)
@@ -1230,7 +1230,6 @@
 dnl On Solaris 8 there's a compilation warning for term.h because
 dnl it doesn't define `bool'.
 AC_CHECK_HEADERS(term.h, , , -)
-AC_HEADER_STDC
 AC_HEADER_TIME
 AC_CHECK_DECLS([sys_siglist])
 if test $ac_cv_have_decl_sys_siglist != yes; then
@@ -2702,7 +2701,7 @@
 random lrand48 logb frexp fmod rint cbrt ftime setsid \
 strerror fpathconf select euidaccess getpagesize tzset setlocale \
 utimes getrlimit setrlimit setpgid getcwd getwd shutdown getaddrinfo \
-__fpending mblen mbrlen mbsinit strsignal setitimer ualarm strchr strrchr \
+__fpending mblen mbrlen mbsinit strsignal setitimer ualarm \
 sendto recvfrom getsockopt setsockopt getsockname getpeername \
 gai_strerror mkstemp getline getdelim mremap fsync sync \
 difftime mempcpy mblen mbrlen posix_memalign \
@@ -3582,14 +3581,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifndef HAVE_STRCHR
-#define strchr(a, b) index (a, b)
-#endif
-
-#ifndef HAVE_STRRCHR
-#define strrchr(a, b) rindex (a, b)
-#endif
-
 #if defined __GNUC__ && (__GNUC__ > 2 \
                          || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
 #define NO_RETURN	__attribute__ ((__noreturn__))

=== modified file 'lib-src/ChangeLog'
--- lib-src/ChangeLog	2011-07-06 23:34:39 +0000
+++ lib-src/ChangeLog	2011-07-07 01:32:56 +0000
@@ -1,5 +1,13 @@
 2011-07-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Assume freestanding C89 headers, string.h, stdlib.h.
+	* ebrowse.c: Include stdlib.h unconditionally.
+	* etags.c, update-game-score.c:
+	Include string.h and stdlib.h unconditionally.
+	* makefile.w32-in (LOCAL_CFLAGS): Don't define STDC_HEADERS.
+	* movemail.c, pop.c: Include string.h unconditionally.
+	* update-game-score.c: No need to include stdarg.h; not used.
+
 	Assume support for memcmp, memcpy, memmove, memset.
 	* etags.c (absolute_filename): Assume memmove exists.
 

=== modified file 'lib-src/ebrowse.c'
--- lib-src/ebrowse.c	2011-03-21 18:03:15 +0000
+++ lib-src/ebrowse.c	2011-07-07 01:32:56 +0000
@@ -20,11 +20,7 @@
 
 #include <config.h>
 #include <stdio.h>
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
 #include <string.h>
 #include <ctype.h>
 #include <assert.h>

=== modified file 'lib-src/etags.c'
--- lib-src/etags.c	2011-07-05 05:27:49 +0000
+++ lib-src/etags.c	2011-07-07 01:32:56 +0000
@@ -138,9 +138,7 @@
 #endif /* MSDOS */
 
 #ifdef WINDOWSNT
-# include <stdlib.h>
 # include <fcntl.h>
-# include <string.h>
 # include <direct.h>
 # include <io.h>
 # define MAXPATHLEN _MAX_PATH
@@ -151,27 +149,6 @@
 #   define HAVE_GETCWD
 # endif /* undef HAVE_GETCWD */
 #else /* not WINDOWSNT */
-# ifdef STDC_HEADERS
-#  include <stdlib.h>
-#  include <string.h>
-# else /* no standard C headers */
-   extern char *getenv (const char *);
-   extern char *strcpy (char *, const char *);
-   extern char *strncpy (char *, const char *, unsigned long);
-   extern char *strcat (char *, const char *);
-   extern char *strncat (char *, const char *, unsigned long);
-   extern int strcmp (const char *, const char *);
-   extern int strncmp (const char *, const char *, unsigned long);
-   extern int system (const char *);
-   extern unsigned long strlen (const char *);
-   extern void *malloc (unsigned long);
-   extern void *realloc (void *, unsigned long);
-   extern void exit (int);
-   extern void free (void *);
-   extern void *memmove (void *, const void *, unsigned long);
-#  define EXIT_SUCCESS	0
-#  define EXIT_FAILURE	1
-# endif
 #endif /* !WINDOWSNT */
 
 #include <unistd.h>
@@ -181,6 +158,8 @@
 # endif
 #endif /* HAVE_UNISTD_H */
 
+#include <stdlib.h>
+#include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>

=== modified file 'lib-src/makefile.w32-in'
--- lib-src/makefile.w32-in	2011-05-19 06:04:16 +0000
+++ lib-src/makefile.w32-in	2011-07-07 01:32:56 +0000
@@ -21,7 +21,7 @@
 
 .PHONY: $(ALL)
 
-LOCAL_FLAGS	= -DWINDOWSNT -DDOS_NT -DSTDC_HEADERS=1 -DNO_LDAV=1 \
+LOCAL_FLAGS	= -DWINDOWSNT -DDOS_NT -DNO_LDAV=1 \
 		  -DNO_ARCHIVES=1 -DHAVE_CONFIG_H=1 -I../lib \
 		  -I../nt/inc -I../src
 

=== modified file 'lib-src/movemail.c'
--- lib-src/movemail.c	2011-06-10 17:50:07 +0000
+++ lib-src/movemail.c	2011-07-07 01:32:56 +0000
@@ -68,9 +68,7 @@
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
 #include "syswait.h"
 #ifdef MAIL_USE_POP
 #include "pop.h"

=== modified file 'lib-src/pop.c'
--- lib-src/pop.c	2011-04-16 22:32:35 +0000
+++ lib-src/pop.c	2011-07-07 01:32:56 +0000
@@ -65,9 +65,7 @@
 #include <netdb.h>
 #include <errno.h>
 #include <stdio.h>
-#ifdef STDC_HEADERS
 #include <string.h>
-#endif
 #include <unistd.h>
 
 #ifdef KERBEROS

=== modified file 'lib-src/update-game-score.c'
--- lib-src/update-game-score.c	2011-03-21 07:46:53 +0000
+++ lib-src/update-game-score.c	2011-07-07 01:32:56 +0000
@@ -35,12 +35,8 @@
 
 #include <unistd.h>
 #include <errno.h>
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
 #include <stdio.h>
 #include <time.h>
 #include <pwd.h>
@@ -48,9 +44,6 @@
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
-#ifdef STDC_HEADERS
-#include <stdarg.h>
-#endif
 #include <sys/stat.h>
 
 /* Needed for SunOS4, for instance.  */

=== modified file 'nt/ChangeLog'
--- nt/ChangeLog	2011-06-07 12:35:48 +0000
+++ nt/ChangeLog	2011-07-07 01:32:56 +0000
@@ -1,3 +1,10 @@
+2011-07-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Assume freestanding C89 headers, string.h, stdlib.h.
+	* config.nt (HAVE_LIMITS_H, HAVE_STRING_H, HAVE_STDLIB_H)
+	(STDC_HEADERS): Remove.
+	Iinclude string.h, stdlib.h unconditionally.
+
 2011-06-07  Eli Zaretskii  <eliz@gnu.org>
 
 	* inc/stdint.h (INT32_MAX, INT64_MAX, INTPTR_MAX, PTRDIFF_MAX)

=== modified file 'nt/config.nt'
--- nt/config.nt	2011-05-28 22:39:39 +0000
+++ nt/config.nt	2011-07-07 01:32:56 +0000
@@ -131,12 +131,8 @@
 #undef HAVE_LINUX_VERSION_H
 #undef HAVE_SYS_SYSTEMINFO_H
 #undef HAVE_TERMIOS_H
-#undef HAVE_LIMITS_H
-#undef HAVE_STRING_H
 #undef HAVE_STRINGS_H
-#undef HAVE_STDLIB_H
 #undef HAVE_PWD_H
-#undef STDC_HEADERS
 
 #undef HAVE_LIBDNET
 #undef HAVE_LIBPTHREADS
@@ -506,15 +502,11 @@
 #define PROTOTYPES 1
 #endif
 
-#ifdef HAVE_STRING_H
 #include "string.h"
-#endif
 #ifdef HAVE_STRINGS_H
 #include "strings.h"
 #endif
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
 
 #ifndef NO_RETURN
 #if defined __GNUC__ && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR >= 5))

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-07-06 23:34:39 +0000
+++ src/ChangeLog	2011-07-07 01:32:56 +0000
@@ -1,3 +1,17 @@
+2011-07-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Assume freestanding C89 headers, string.h, stdlib.h.
+	* data.c, doprnt.c, floatfns.c, print.c:
+	Include float.h unconditionally.
+	* gmalloc.c: Assume C89-at-least behavior for preprocessor,
+	limits.h, stddef.h, string.h.  Use memset instead of 'flood'.
+	* regex.c: Likewise for stddef.h, string.h.
+	(ISASCII): Remove; can assume it returns 1 now.  All uses removed.
+	* s/aix4-2.h (HAVE_STRING_H): Remove obsolete undef.
+	* s/ms-w32.h (HAVE_LIMITS_H, HAVE_STRING_H, HAVE_STDLIB_H)
+	(STDC_HEADERS): Remove obsolete defines.
+	* sysdep.c: Include limits.h unconditionally.
+
 2011-07-06  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Assume support for memcmp, memcpy, memmove, memset.

=== modified file 'src/data.c'
--- src/data.c	2011-06-19 18:44:58 +0000
+++ src/data.c	2011-07-07 01:32:56 +0000
@@ -35,10 +35,7 @@
 #include "termhooks.h"  /* For FRAME_KBOARD reference in y-or-n-p.  */
 #include "font.h"
 
-#ifdef STDC_HEADERS
 #include <float.h>
-#endif
-
 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*.  */
 #ifndef IEEE_FLOATING_POINT
 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \

=== modified file 'src/doprnt.c'
--- src/doprnt.c	2011-06-14 20:09:52 +0000
+++ src/doprnt.c	2011-07-07 01:32:56 +0000
@@ -102,13 +102,8 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <setjmp.h>
-
-#ifdef STDC_HEADERS
 #include <float.h>
-#endif
-
 #include <unistd.h>
-
 #include <limits.h>
 
 #include "lisp.h"

=== modified file 'src/floatfns.c'
--- src/floatfns.c	2011-06-13 02:27:16 +0000
+++ src/floatfns.c	2011-07-07 01:32:56 +0000
@@ -53,10 +53,7 @@
 #include "lisp.h"
 #include "syssignal.h"
 
-#if STDC_HEADERS
 #include <float.h>
-#endif
-
 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
 #ifndef IEEE_FLOATING_POINT
 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \

=== modified file 'src/gmalloc.c'
--- src/gmalloc.c	2011-07-05 05:27:49 +0000
+++ src/gmalloc.c	2011-07-07 01:32:56 +0000
@@ -41,28 +41,13 @@
 #define USE_PTHREAD
 #endif
 
-#if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \
-      || defined STDC_HEADERS || defined PROTOTYPES))
 #undef	PP
 #define	PP(args)	args
 #undef	__ptr_t
 #define	__ptr_t		void *
-#else /* Not C++ or ANSI C.  */
-#undef	PP
-#define	PP(args)	()
-#undef	__ptr_t
-#define	__ptr_t		char *
-#endif /* C++ or ANSI C.  */
 
 #include <string.h>
-
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif
-#ifndef CHAR_BIT
-#define	CHAR_BIT	8
-#endif
-
 #include <unistd.h>
 
 #ifdef USE_PTHREAD
@@ -77,26 +62,9 @@
 {
 #endif
 
-#ifdef STDC_HEADERS
 #include <stddef.h>
 #define	__malloc_size_t		size_t
 #define	__malloc_ptrdiff_t	ptrdiff_t
-#else
-#ifdef __GNUC__
-#include <stddef.h>
-#ifdef __SIZE_TYPE__
-#define	__malloc_size_t		__SIZE_TYPE__
-#endif
-#endif
-#ifndef __malloc_size_t
-#define	__malloc_size_t		unsigned int
-#endif
-#define	__malloc_ptrdiff_t	int
-#endif
-
-#ifndef	NULL
-#define	NULL	0
-#endif
 
 
 /* Allocate SIZE bytes of memory.  */
@@ -1881,22 +1849,6 @@
     unsigned long int magic;	/* Magic number to check header integrity.  */
   };
 
-#if	defined(_LIBC) || defined(STDC_HEADERS) || defined(USG)
-#define flood memset
-#else
-static void flood (__ptr_t, int, __malloc_size_t);
-static void
-flood (ptr, val, size)
-     __ptr_t ptr;
-     int val;
-     __malloc_size_t size;
-{
-  char *cp = ptr;
-  while (size--)
-    *cp++ = val;
-}
-#endif
-
 static enum mcheck_status checkhdr (const struct hdr *);
 static enum mcheck_status
 checkhdr (hdr)
@@ -1935,7 +1887,7 @@
       hdr = ((struct hdr *) ptr) - 1;
       checkhdr (hdr);
       hdr->magic = MAGICFREE;
-      flood (ptr, FREEFLOOD, hdr->size);
+      memset (ptr, FREEFLOOD, hdr->size);
     }
   else
     hdr = NULL;
@@ -1961,7 +1913,7 @@
   hdr->size = size;
   hdr->magic = MAGICWORD;
   ((char *) &hdr[1])[size] = MAGICBYTE;
-  flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size);
+  memset ((__ptr_t) (hdr + 1), MALLOCFLOOD, size);
   return (__ptr_t) (hdr + 1);
 }
 
@@ -1981,7 +1933,7 @@
 
       checkhdr (hdr);
       if (size < osize)
-	flood ((char *) ptr + size, FREEFLOOD, osize - size);
+	memset ((char *) ptr + size, FREEFLOOD, osize - size);
     }
 
   __free_hook = old_free_hook;
@@ -1998,7 +1950,7 @@
   hdr->magic = MAGICWORD;
   ((char *) &hdr[1])[size] = MAGICBYTE;
   if (size > osize)
-    flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize);
+    memset ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize);
   return (__ptr_t) (hdr + 1);
 }
 

=== modified file 'src/print.c'
--- src/print.c	2011-06-24 21:25:22 +0000
+++ src/print.c	2011-07-07 01:32:56 +0000
@@ -46,10 +46,7 @@
 static Lisp_Object Qfloat_output_format;
 
 #include <math.h>
-
-#if STDC_HEADERS
 #include <float.h>
-#endif
 #include <ftoastr.h>
 
 /* Default to values appropriate for IEEE floating point.  */

=== modified file 'src/regex.c'
--- src/regex.c	2011-07-05 05:27:49 +0000
+++ src/regex.c	2011-07-07 01:32:56 +0000
@@ -37,9 +37,9 @@
 # include <config.h>
 #endif
 
-#if defined STDC_HEADERS && !defined emacs
-# include <stddef.h>
-#else
+#include <stddef.h>
+
+#ifdef emacs
 /* We need this for `regex.h', and perhaps for the Emacs include files.  */
 # include <sys/types.h>
 #endif
@@ -346,25 +346,6 @@
 
 #else /* not emacs */
 
-/* Jim Meyering writes:
-
-   "... Some ctype macros are valid only for character codes that
-   isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
-   using /bin/cc or gcc but without giving an ansi option).  So, all
-   ctype uses should be through macros like ISPRINT...  If
-   STDC_HEADERS is defined, then autoconf has verified that the ctype
-   macros don't need to be guarded with references to isascii. ...
-   Defining isascii to 1 should let any compiler worth its salt
-   eliminate the && through constant folding."
-   Solaris defines some of these symbols so we must undefine them first.  */
-
-# undef ISASCII
-# if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
-#  define ISASCII(c) 1
-# else
-#  define ISASCII(c) isascii(c)
-# endif
-
 /* 1 if C is an ASCII character.  */
 # define IS_REAL_ASCII(c) ((c) < 0200)
 
@@ -372,27 +353,28 @@
 # define ISUNIBYTE(c) 1
 
 # ifdef isblank
-#  define ISBLANK(c) (ISASCII (c) && isblank (c))
+#  define ISBLANK(c) isblank (c)
 # else
 #  define ISBLANK(c) ((c) == ' ' || (c) == '\t')
 # endif
 # ifdef isgraph
-#  define ISGRAPH(c) (ISASCII (c) && isgraph (c))
+#  define ISGRAPH(c) isgraph (c)
 # else
-#  define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
+#  define ISGRAPH(c) (isprint (c) && !isspace (c))
 # endif
 
+/* Solaris defines ISPRINT so we must undefine it first.  */
 # undef ISPRINT
-# define ISPRINT(c) (ISASCII (c) && isprint (c))
-# define ISDIGIT(c) (ISASCII (c) && isdigit (c))
-# define ISALNUM(c) (ISASCII (c) && isalnum (c))
-# define ISALPHA(c) (ISASCII (c) && isalpha (c))
-# define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
-# define ISLOWER(c) (ISASCII (c) && islower (c))
-# define ISPUNCT(c) (ISASCII (c) && ispunct (c))
-# define ISSPACE(c) (ISASCII (c) && isspace (c))
-# define ISUPPER(c) (ISASCII (c) && isupper (c))
-# define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
+# define ISPRINT(c) isprint (c)
+# define ISDIGIT(c) isdigit (c)
+# define ISALNUM(c) isalnum (c)
+# define ISALPHA(c) isalpha (c)
+# define ISCNTRL(c) iscntrl (c)
+# define ISLOWER(c) islower (c)
+# define ISPUNCT(c) ispunct (c)
+# define ISSPACE(c) isspace (c)
+# define ISUPPER(c) isupper (c)
+# define ISXDIGIT(c) isxdigit (c)
 
 # define ISWORD(c) ISALPHA(c)
 
@@ -439,10 +421,6 @@
 
 #endif /* not emacs */
 \f
-#ifndef NULL
-# define NULL (void *)0
-#endif
-
 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
    since ours (we hope) works properly with all combinations of
    machines, compilers, `char' and `unsigned char' argument types.

=== modified file 'src/s/aix4-2.h'
--- src/s/aix4-2.h	2011-03-17 05:15:08 +0000
+++ src/s/aix4-2.h	2011-07-07 01:32:56 +0000
@@ -47,11 +47,6 @@
 /* AIX doesn't define this.  */
 #define unix 1
 
-/* string.h defines rindex as a macro, at least with native cc, so we
-   lose declaring char * rindex without this.
-   It is just a guess which versions of AIX need this definition.  */
-#undef HAVE_STRING_H
-
 /* Perry Smith <pedz@ddivt1.austin.ibm.com> says these are correct.  */
 #define SIGNALS_VIA_CHARACTERS
 #define CLASH_DETECTION

=== modified file 'src/s/ms-w32.h'
--- src/s/ms-w32.h	2011-04-23 03:07:16 +0000
+++ src/s/ms-w32.h	2011-07-07 01:32:56 +0000
@@ -111,11 +111,7 @@
 #undef  HAVE_UTIME_H
 #undef  HAVE_LINUX_VERSION_H
 #undef  HAVE_SYS_SYSTEMINFO_H
-#define HAVE_LIMITS_H 1
-#define HAVE_STRING_H 1
-#define HAVE_STDLIB_H 1
 #define HAVE_PWD_H 1
-#define STDC_HEADERS 1
 #define TIME_WITH_SYS_TIME 1
 
 #define HAVE_GETTIMEOFDAY 1
@@ -386,4 +382,3 @@
 
 
 /* ============================================================ */
-

=== modified file 'src/sysdep.c'
--- src/sysdep.c	2011-07-05 05:27:49 +0000
+++ src/sysdep.c	2011-07-07 01:32:56 +0000
@@ -26,9 +26,7 @@
 #include <pwd.h>
 #include <grp.h>
 #endif /* HAVE_PWD_H */
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif /* HAVE_LIMITS_H */
 #include <unistd.h>
 
 #include <allocator.h>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-07  1:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-05  7:52 memcmp, memcpy, memmove, memset Paul Eggert
2011-07-07  1:41 ` Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).