From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: memcmp, memcpy, memmove, memset Date: Tue, 05 Jul 2011 00:52:30 -0700 Organization: UCLA Computer Science Department Message-ID: <4E12C2BE.1050609@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1309853803 20713 80.91.229.12 (5 Jul 2011 08:16:43 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 5 Jul 2011 08:16:43 +0000 (UTC) To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 05 10:16:40 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qe0o9-000839-Ek for ged-emacs-devel@m.gmane.org; Tue, 05 Jul 2011 10:16:38 +0200 Original-Received: from localhost ([::1]:34745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qe0o7-0005mU-8v for ged-emacs-devel@m.gmane.org; Tue, 05 Jul 2011 04:16:35 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:58123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qe0R0-0001Zi-VC for emacs-devel@gnu.org; Tue, 05 Jul 2011 03:52:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qe0Qz-00086M-3B for emacs-devel@gnu.org; Tue, 05 Jul 2011 03:52:42 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:52219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qe0Qx-00086B-UK for emacs-devel@gnu.org; Tue, 05 Jul 2011 03:52:40 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 5FB7639E810F for ; Tue, 5 Jul 2011 00:52:37 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sOn4Q2fDOzOM for ; Tue, 5 Jul 2011 00:52:36 -0700 (PDT) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 7641B39E80F8 for ; Tue, 5 Jul 2011 00:52:36 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:141575 Archived-At: 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 + + 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 * 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 + + Assume support for memcmp, memcpy, memmove, memset. + * etags.c (absolute_filename): Assume memmove exists. + 2011-07-02 Jason Rumney * 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 + 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 -#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 @@ -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 -# else -# include -# 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 /* 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 */ -#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 */ - #ifndef HAVE_STRSIGNAL char * strsignal (int code)