diff options
| author | Paul Eggert | 2011-07-04 22:27:49 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-04 22:27:49 -0700 |
| commit | 9cfdb3ec08672f13088ebd133bbc794c04a66b05 (patch) | |
| tree | 0e0b851de11b990831c7a0fc39ff97f00edfad93 /src | |
| parent | 6089c5670b18a02fc2caca3e665d2bb7799dc4c8 (diff) | |
| download | emacs-9cfdb3ec08672f13088ebd133bbc794c04a66b05.tar.gz emacs-9cfdb3ec08672f13088ebd133bbc794c04a66b05.zip | |
[ChangeLog]
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.
[lib-src/ChangeLog]
Assume support for memcmp, memcpy, memmove, memset.
* etags.c (absolute_filename): Assume memmove exists.
[src/ChangeLog]
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/gmalloc.c | 102 | ||||
| -rw-r--r-- | src/lisp.h | 12 | ||||
| -rw-r--r-- | src/regex.c | 13 | ||||
| -rw-r--r-- | src/sysdep.c | 53 |
5 files changed, 9 insertions, 179 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e4702b4316b..22d70bf54eb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2011-07-05 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-07-05 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Assume support for memcmp, memcpy, memmove, memset. | ||
| 4 | * lisp.h, sysdep.c (memcmp, memcpy, memmove, memset): | ||
| 5 | * regex.c (memcmp, memcpy): | ||
| 6 | Remove; we assume C89 now. | ||
| 7 | |||
| 8 | * gmalloc.c (memcpy, memset, memmove): Remove; we assume C89 now. | ||
| 9 | (__malloc_safe_bcopy): Remove; no longer needed. | ||
| 10 | |||
| 3 | * lisp.h (struct vectorlike_header, struct Lisp_Subr): Signed sizes. | 11 | * lisp.h (struct vectorlike_header, struct Lisp_Subr): Signed sizes. |
| 4 | Use EMACS_INT, not EMACS_UINT, for sizes. The code works equally | 12 | Use EMACS_INT, not EMACS_UINT, for sizes. The code works equally |
| 5 | well either way, and we prefer signed to unsigned. | 13 | well either way, and we prefer signed to unsigned. |
diff --git a/src/gmalloc.c b/src/gmalloc.c index a023d2d78e5..4f27ea3079a 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -54,16 +54,7 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 54 | #define __ptr_t char * | 54 | #define __ptr_t char * |
| 55 | #endif /* C++ or ANSI C. */ | 55 | #endif /* C++ or ANSI C. */ |
| 56 | 56 | ||
| 57 | #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) | ||
| 58 | #include <string.h> | 57 | #include <string.h> |
| 59 | #else | ||
| 60 | #ifndef memset | ||
| 61 | #define memset(s, zero, n) bzero ((s), (n)) | ||
| 62 | #endif | ||
| 63 | #ifndef memcpy | ||
| 64 | #define memcpy(d, s, n) bcopy ((s), (d), (n)) | ||
| 65 | #endif | ||
| 66 | #endif | ||
| 67 | 58 | ||
| 68 | #ifdef HAVE_LIMITS_H | 59 | #ifdef HAVE_LIMITS_H |
| 69 | #include <limits.h> | 60 | #include <limits.h> |
| @@ -1069,20 +1060,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 1069 | #endif | 1060 | #endif |
| 1070 | 1061 | ||
| 1071 | 1062 | ||
| 1072 | /* Cope with systems lacking `memmove'. */ | ||
| 1073 | #ifndef memmove | ||
| 1074 | #if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | ||
| 1075 | #ifdef emacs | ||
| 1076 | #undef __malloc_safe_bcopy | ||
| 1077 | #define __malloc_safe_bcopy safe_bcopy | ||
| 1078 | #endif | ||
| 1079 | /* This function is defined in realloc.c. */ | ||
| 1080 | extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); | ||
| 1081 | #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) | ||
| 1082 | #endif | ||
| 1083 | #endif | ||
| 1084 | |||
| 1085 | |||
| 1086 | /* Debugging hook for free. */ | 1063 | /* Debugging hook for free. */ |
| 1087 | void (*__free_hook) PP ((__ptr_t __ptr)); | 1064 | void (*__free_hook) PP ((__ptr_t __ptr)); |
| 1088 | 1065 | ||
| @@ -1402,85 +1379,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 1402 | #endif | 1379 | #endif |
| 1403 | 1380 | ||
| 1404 | 1381 | ||
| 1405 | |||
| 1406 | /* Cope with systems lacking `memmove'. */ | ||
| 1407 | #if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | ||
| 1408 | |||
| 1409 | #ifdef emacs | ||
| 1410 | #undef __malloc_safe_bcopy | ||
| 1411 | #define __malloc_safe_bcopy safe_bcopy | ||
| 1412 | #else | ||
| 1413 | |||
| 1414 | /* Snarfed directly from Emacs src/dispnew.c: | ||
| 1415 | XXX Should use system bcopy if it handles overlap. */ | ||
| 1416 | |||
| 1417 | /* Like bcopy except never gets confused by overlap. */ | ||
| 1418 | |||
| 1419 | void | ||
| 1420 | __malloc_safe_bcopy (afrom, ato, size) | ||
| 1421 | __ptr_t afrom; | ||
| 1422 | __ptr_t ato; | ||
| 1423 | __malloc_size_t size; | ||
| 1424 | { | ||
| 1425 | char *from = afrom, *to = ato; | ||
| 1426 | |||
| 1427 | if (size <= 0 || from == to) | ||
| 1428 | return; | ||
| 1429 | |||
| 1430 | /* If the source and destination don't overlap, then bcopy can | ||
| 1431 | handle it. If they do overlap, but the destination is lower in | ||
| 1432 | memory than the source, we'll assume bcopy can handle that. */ | ||
| 1433 | if (to < from || from + size <= to) | ||
| 1434 | bcopy (from, to, size); | ||
| 1435 | |||
| 1436 | /* Otherwise, we'll copy from the end. */ | ||
| 1437 | else | ||
| 1438 | { | ||
| 1439 | register char *endf = from + size; | ||
| 1440 | register char *endt = to + size; | ||
| 1441 | |||
| 1442 | /* If TO - FROM is large, then we should break the copy into | ||
| 1443 | nonoverlapping chunks of TO - FROM bytes each. However, if | ||
| 1444 | TO - FROM is small, then the bcopy function call overhead | ||
| 1445 | makes this not worth it. The crossover point could be about | ||
| 1446 | anywhere. Since I don't think the obvious copy loop is too | ||
| 1447 | bad, I'm trying to err in its favor. */ | ||
| 1448 | if (to - from < 64) | ||
| 1449 | { | ||
| 1450 | do | ||
| 1451 | *--endt = *--endf; | ||
| 1452 | while (endf != from); | ||
| 1453 | } | ||
| 1454 | else | ||
| 1455 | { | ||
| 1456 | for (;;) | ||
| 1457 | { | ||
| 1458 | endt -= (to - from); | ||
| 1459 | endf -= (to - from); | ||
| 1460 | |||
| 1461 | if (endt < to) | ||
| 1462 | break; | ||
| 1463 | |||
| 1464 | bcopy (endf, endt, to - from); | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | /* If SIZE wasn't a multiple of TO - FROM, there will be a | ||
| 1468 | little left over. The amount left over is | ||
| 1469 | (endt + (to - from)) - to, which is endt - from. */ | ||
| 1470 | bcopy (from, to, endt - from); | ||
| 1471 | } | ||
| 1472 | } | ||
| 1473 | } | ||
| 1474 | #endif /* emacs */ | ||
| 1475 | |||
| 1476 | #ifndef memmove | ||
| 1477 | extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); | ||
| 1478 | #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) | ||
| 1479 | #endif | ||
| 1480 | |||
| 1481 | #endif | ||
| 1482 | |||
| 1483 | |||
| 1484 | #define min(A, B) ((A) < (B) ? (A) : (B)) | 1382 | #define min(A, B) ((A) < (B) ? (A) : (B)) |
| 1485 | 1383 | ||
| 1486 | /* Debugging hook for realloc. */ | 1384 | /* Debugging hook for realloc. */ |
diff --git a/src/lisp.h b/src/lisp.h index 2835302947f..cd3cfd316a5 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3429,18 +3429,6 @@ extern EMACS_INT emacs_read (int, char *, EMACS_INT); | |||
| 3429 | extern EMACS_INT emacs_write (int, const char *, EMACS_INT); | 3429 | extern EMACS_INT emacs_write (int, const char *, EMACS_INT); |
| 3430 | enum { READLINK_BUFSIZE = 1024 }; | 3430 | enum { READLINK_BUFSIZE = 1024 }; |
| 3431 | extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); | 3431 | extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); |
| 3432 | #ifndef HAVE_MEMSET | ||
| 3433 | extern void *memset (void *, int, size_t); | ||
| 3434 | #endif | ||
| 3435 | #ifndef HAVE_MEMCPY | ||
| 3436 | extern void *memcpy (void *, void *, size_t); | ||
| 3437 | #endif | ||
| 3438 | #ifndef HAVE_MEMMOVE | ||
| 3439 | extern void *memmove (void *, void *, size_t); | ||
| 3440 | #endif | ||
| 3441 | #ifndef HAVE_MEMCMP | ||
| 3442 | extern int memcmp (void *, void *, size_t); | ||
| 3443 | #endif | ||
| 3444 | 3432 | ||
| 3445 | EXFUN (Funlock_buffer, 0); | 3433 | EXFUN (Funlock_buffer, 0); |
| 3446 | extern void unlock_all_files (void); | 3434 | extern void unlock_all_files (void); |
diff --git a/src/regex.c b/src/regex.c index 479239897bc..f514b603488 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -238,18 +238,7 @@ xrealloc (void *block, size_t size) | |||
| 238 | # endif | 238 | # endif |
| 239 | # define realloc xrealloc | 239 | # define realloc xrealloc |
| 240 | 240 | ||
| 241 | /* This is the normal way of making sure we have memcpy, memcmp and memset. */ | 241 | # include <string.h> |
| 242 | # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC | ||
| 243 | # include <string.h> | ||
| 244 | # else | ||
| 245 | # include <strings.h> | ||
| 246 | # ifndef memcmp | ||
| 247 | # define memcmp(s1, s2, n) bcmp (s1, s2, n) | ||
| 248 | # endif | ||
| 249 | # ifndef memcpy | ||
| 250 | # define memcpy(d, s, n) (bcopy (s, d, n), (d)) | ||
| 251 | # endif | ||
| 252 | # endif | ||
| 253 | 242 | ||
| 254 | /* Define the syntax stuff for \<, \>, etc. */ | 243 | /* Define the syntax stuff for \<, \>, etc. */ |
| 255 | 244 | ||
diff --git a/src/sysdep.c b/src/sysdep.c index 8b6939b91fe..f157baf3e76 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2216,59 +2216,6 @@ rmdir (char *dpath) | |||
| 2216 | #endif /* !HAVE_RMDIR */ | 2216 | #endif /* !HAVE_RMDIR */ |
| 2217 | 2217 | ||
| 2218 | 2218 | ||
| 2219 | #ifndef HAVE_MEMSET | ||
| 2220 | void * | ||
| 2221 | memset (void *b, int n, size_t length) | ||
| 2222 | { | ||
| 2223 | unsigned char *p = b; | ||
| 2224 | while (length-- > 0) | ||
| 2225 | *p++ = n; | ||
| 2226 | return b; | ||
| 2227 | } | ||
| 2228 | #endif /* !HAVE_MEMSET */ | ||
| 2229 | |||
| 2230 | #ifndef HAVE_MEMCPY | ||
| 2231 | void * | ||
| 2232 | memcpy (void *b1, void *b2, size_t length) | ||
| 2233 | { | ||
| 2234 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2235 | while (length-- > 0) | ||
| 2236 | *p1++ = *p2++; | ||
| 2237 | return b1; | ||
| 2238 | } | ||
| 2239 | #endif /* !HAVE_MEMCPY */ | ||
| 2240 | |||
| 2241 | #ifndef HAVE_MEMMOVE | ||
| 2242 | void * | ||
| 2243 | memmove (void *b1, void *b2, size_t length) | ||
| 2244 | { | ||
| 2245 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2246 | if (p1 < p2 || p1 >= p2 + length) | ||
| 2247 | while (length-- > 0) | ||
| 2248 | *p1++ = *p2++; | ||
| 2249 | else | ||
| 2250 | { | ||
| 2251 | p1 += length; | ||
| 2252 | p2 += length; | ||
| 2253 | while (length-- > 0) | ||
| 2254 | *--p1 = *--p2; | ||
| 2255 | } | ||
| 2256 | return b1; | ||
| 2257 | } | ||
| 2258 | #endif /* !HAVE_MEMCPY */ | ||
| 2259 | |||
| 2260 | #ifndef HAVE_MEMCMP | ||
| 2261 | int | ||
| 2262 | memcmp (void *b1, void *b2, size_t length) | ||
| 2263 | { | ||
| 2264 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2265 | while (length-- > 0) | ||
| 2266 | if (*p1++ != *p2++) | ||
| 2267 | return p1[-1] < p2[-1] ? -1 : 1; | ||
| 2268 | return 0; | ||
| 2269 | } | ||
| 2270 | #endif /* !HAVE_MEMCMP */ | ||
| 2271 | |||
| 2272 | #ifndef HAVE_STRSIGNAL | 2219 | #ifndef HAVE_STRSIGNAL |
| 2273 | char * | 2220 | char * |
| 2274 | strsignal (int code) | 2221 | strsignal (int code) |