Mercurial > hg > xemacs-beta
comparison src/gmalloc.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | 3ecd8885ac67 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
1016 #ifndef _MALLOC_INTERNAL | 1016 #ifndef _MALLOC_INTERNAL |
1017 #define _MALLOC_INTERNAL | 1017 #define _MALLOC_INTERNAL |
1018 #include <malloc.h> | 1018 #include <malloc.h> |
1019 #endif | 1019 #endif |
1020 | 1020 |
1021 #if 0 /* FSFmacs */ | |
1022 /* XEmacs requires an ANSI compiler, and memmove() is part of the ANSI- | |
1023 mandated functions. For losing systems like SunOS 4, we provide | |
1024 our own memmove(). */ | |
1025 | |
1026 #if (defined (MEMMOVE_MISSING) || \ | |
1027 !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | |
1028 | |
1029 /* Snarfed directly from Emacs src/dispnew.c: | |
1030 XXX Should use system bcopy if it handles overlap. */ | |
1031 #ifndef emacs | |
1032 | |
1033 /* Like bcopy except never gets confused by overlap. */ | |
1034 | |
1035 static void | |
1036 safe_bcopy (char *from, char *to, int size) | |
1037 { | |
1038 if (size <= 0 || from == to) | |
1039 return; | |
1040 | |
1041 /* If the source and destination don't overlap, then bcopy can | |
1042 handle it. If they do overlap, but the destination is lower in | |
1043 memory than the source, we'll assume bcopy can handle that. */ | |
1044 if (to < from || from + size <= to) | |
1045 bcopy (from, to, size); | |
1046 | |
1047 /* Otherwise, we'll copy from the end. */ | |
1048 else | |
1049 { | |
1050 char *endf = from + size; | |
1051 char *endt = to + size; | |
1052 | |
1053 /* If TO - FROM is large, then we should break the copy into | |
1054 nonoverlapping chunks of TO - FROM bytes each. However, if | |
1055 TO - FROM is small, then the bcopy function call overhead | |
1056 makes this not worth it. The crossover point could be about | |
1057 anywhere. Since I don't think the obvious copy loop is too | |
1058 bad, I'm trying to err in its favor. */ | |
1059 if (to - from < 64) | |
1060 { | |
1061 do | |
1062 *--endt = *--endf; | |
1063 while (endf != from); | |
1064 } | |
1065 else | |
1066 { | |
1067 for (;;) | |
1068 { | |
1069 endt -= (to - from); | |
1070 endf -= (to - from); | |
1071 | |
1072 if (endt < to) | |
1073 break; | |
1074 | |
1075 bcopy (endf, endt, to - from); | |
1076 } | |
1077 | |
1078 /* If SIZE wasn't a multiple of TO - FROM, there will be a | |
1079 little left over. The amount left over is | |
1080 (endt + (to - from)) - to, which is endt - from. */ | |
1081 bcopy (from, to, endt - from); | |
1082 } | |
1083 } | |
1084 } | |
1085 #endif /* Not emacs. */ | |
1086 | |
1087 #define memmove(to, from, size) safe_bcopy ((from), (to), (size)) | |
1088 | |
1089 #endif | |
1090 | |
1091 #endif /* FSFmacs */ | |
1092 | |
1093 | |
1094 #ifndef min | 1021 #ifndef min |
1095 #define min(A, B) ((A) < (B) ? (A) : (B)) | 1022 #define min(A, B) ((A) < (B) ? (A) : (B)) |
1096 #endif | 1023 #endif |
1097 | 1024 |
1098 /* Debugging hook for realloc. */ | 1025 /* Debugging hook for realloc. */ |