Mercurial > hg > xemacs-beta
comparison src/gmalloc.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | b8cc9ab3f761 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
22 Therefore, there is no need to consult the abominable STDC_HEADERS flag. | 22 Therefore, there is no need to consult the abominable STDC_HEADERS flag. |
23 -- jwz | 23 -- jwz |
24 */ | 24 */ |
25 # define STDC_HEADERS | 25 # define STDC_HEADERS |
26 #endif | 26 #endif |
27 | |
28 #define __const const | |
27 | 29 |
28 | 30 |
29 /* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */ | 31 /* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */ |
30 /* Bwaa-haa-haa! Not a chance that this is actually true! */ | 32 /* Bwaa-haa-haa! Not a chance that this is actually true! */ |
31 | 33 |
269 /* Pick up the current statistics. */ | 271 /* Pick up the current statistics. */ |
270 extern struct mstats mstats __P ((void)); | 272 extern struct mstats mstats __P ((void)); |
271 | 273 |
272 /* Call WARNFUN with a warning message when memory usage is high. */ | 274 /* Call WARNFUN with a warning message when memory usage is high. */ |
273 extern void memory_warnings __P ((__ptr_t __start, | 275 extern void memory_warnings __P ((__ptr_t __start, |
274 void (*__warnfun) __P ((const char *)))); | 276 void (*__warnfun) __P ((__const char *)))); |
275 | 277 |
276 | 278 |
277 #if 0 /* unused in this file, and conflicting prototypes anyway */ | 279 #if 0 /* unused in this file, and conflicting prototypes anyway */ |
278 /* Relocating allocator. */ | 280 /* Relocating allocator. */ |
279 | 281 |
365 #define _MALLOC_INTERNAL | 367 #define _MALLOC_INTERNAL |
366 #include <malloc.h> | 368 #include <malloc.h> |
367 #endif | 369 #endif |
368 | 370 |
369 /* How to really get more memory. */ | 371 /* How to really get more memory. */ |
370 #if defined (HEAP_IN_DATA) && !defined(PDUMP) | 372 #ifdef HEAP_IN_DATA |
371 /* once dumped, free() & realloc() on static heap space will fail */ | 373 /* once dumped, free() & realloc() on static heap space will fail */ |
372 #define PURE_DATA(x) \ | 374 #define PURE_DATA(x) \ |
373 ((static_heap_dumped && (char*)x >= static_heap_base \ | 375 ((static_heap_dumped && (char*)x >= static_heap_base \ |
374 && (char*)x <= (static_heap_base + static_heap_size) ) ? 1 : 0) | 376 && (char*)x <= (static_heap_base + static_heap_size) ) ? 1 : 0) |
375 extern int initialized; | 377 extern int initialized; |
444 /* Set everything up and remember that we have. */ | 446 /* Set everything up and remember that we have. */ |
445 static int initialize __P ((void)); | 447 static int initialize __P ((void)); |
446 static int | 448 static int |
447 initialize () | 449 initialize () |
448 { | 450 { |
449 #if defined (HEAP_IN_DATA) && !defined(PDUMP) | 451 #ifdef HEAP_IN_DATA |
450 if (static_heap_dumped && __morecore == more_static_core) | 452 if (static_heap_dumped && __morecore == more_static_core) |
451 { | 453 { |
452 __morecore = __default_morecore; | 454 __morecore = __default_morecore; |
453 } | 455 } |
454 #endif | 456 #endif |
1014 #ifndef _MALLOC_INTERNAL | 1016 #ifndef _MALLOC_INTERNAL |
1015 #define _MALLOC_INTERNAL | 1017 #define _MALLOC_INTERNAL |
1016 #include <malloc.h> | 1018 #include <malloc.h> |
1017 #endif | 1019 #endif |
1018 | 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 | |
1019 #ifndef min | 1094 #ifndef min |
1020 #define min(A, B) ((A) < (B) ? (A) : (B)) | 1095 #define min(A, B) ((A) < (B) ? (A) : (B)) |
1021 #endif | 1096 #endif |
1022 | 1097 |
1023 /* Debugging hook for realloc. */ | 1098 /* Debugging hook for realloc. */ |
1034 { | 1109 { |
1035 __ptr_t result; | 1110 __ptr_t result; |
1036 int type; | 1111 int type; |
1037 __malloc_size_t block, blocks, oldlimit; | 1112 __malloc_size_t block, blocks, oldlimit; |
1038 | 1113 |
1039 if (PURE_DATA (ptr)) | 1114 if (PURE_DATA(ptr)) |
1040 { | 1115 { |
1041 result = malloc (size); | 1116 result = malloc (size); |
1042 memcpy(result, ptr, size); | 1117 memcpy(result, ptr, size); |
1043 return result; | 1118 return result; |
1044 } | 1119 } |