X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/2a64315a111fb4da67e9c40c9b69045c4f63d619..0d8f2df7c41d8904df693e4046849751adebd8ab:/src/gmalloc.c diff --git a/src/gmalloc.c b/src/gmalloc.c index a3f533bd5e..fa4aa1fdf6 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -41,40 +41,14 @@ Fifth Floor, Boston, MA 02110-1301, USA. #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. */ -#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 -#endif -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif - -#ifdef HAVE_UNISTD_H #include -#endif #ifdef USE_PTHREAD #include @@ -88,26 +62,9 @@ extern "C" { #endif -#ifdef STDC_HEADERS #include #define __malloc_size_t size_t #define __malloc_ptrdiff_t ptrdiff_t -#else -#ifdef __GNUC__ -#include -#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. */ @@ -554,12 +511,8 @@ get_contiguous_space (size, position) /* This is called when `_heapinfo' and `heapsize' have just been set to describe a new info table. Set up the table to describe itself and account for it in the statistics. */ -static void register_heapinfo PP ((void)); -#ifdef __GNUC__ -__inline__ -#endif -static void -register_heapinfo () +static inline void +register_heapinfo (void) { __malloc_size_t block, blocks; @@ -1075,20 +1028,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. #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)); @@ -1408,85 +1347,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. #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. */ @@ -1969,12 +1829,12 @@ Fifth Floor, Boston, MA 02110-1301, USA. #endif /* Old hook values. */ -static void (*old_free_hook) __P ((__ptr_t ptr)); -static __ptr_t (*old_malloc_hook) __P ((__malloc_size_t size)); -static __ptr_t (*old_realloc_hook) __P ((__ptr_t ptr, __malloc_size_t size)); +static void (*old_free_hook) (__ptr_t ptr); +static __ptr_t (*old_malloc_hook) (__malloc_size_t size); +static __ptr_t (*old_realloc_hook) (__ptr_t ptr, __malloc_size_t size); /* Function to call when something awful happens. */ -static void (*abortfunc) __P ((enum mcheck_status)); +static void (*abortfunc) (enum mcheck_status); /* Arbitrary magical numbers. */ #define MAGICWORD 0xfedabeeb @@ -1989,23 +1849,7 @@ struct hdr 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 __P ((__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 __P ((const struct hdr *)); +static enum mcheck_status checkhdr (const struct hdr *); static enum mcheck_status checkhdr (hdr) const struct hdr *hdr; @@ -2031,7 +1875,7 @@ checkhdr (hdr) return status; } -static void freehook __P ((__ptr_t)); +static void freehook (__ptr_t); static void freehook (ptr) __ptr_t ptr; @@ -2043,7 +1887,7 @@ freehook (ptr) hdr = ((struct hdr *) ptr) - 1; checkhdr (hdr); hdr->magic = MAGICFREE; - flood (ptr, FREEFLOOD, hdr->size); + memset (ptr, FREEFLOOD, hdr->size); } else hdr = NULL; @@ -2053,7 +1897,7 @@ freehook (ptr) __free_hook = freehook; } -static __ptr_t mallochook __P ((__malloc_size_t)); +static __ptr_t mallochook (__malloc_size_t); static __ptr_t mallochook (size) __malloc_size_t size; @@ -2069,11 +1913,11 @@ mallochook (size) 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); } -static __ptr_t reallochook __P ((__ptr_t, __malloc_size_t)); +static __ptr_t reallochook (__ptr_t, __malloc_size_t); static __ptr_t reallochook (ptr, size) __ptr_t ptr; @@ -2089,7 +1933,7 @@ reallochook (ptr, size) checkhdr (hdr); if (size < osize) - flood ((char *) ptr + size, FREEFLOOD, osize - size); + memset ((char *) ptr + size, FREEFLOOD, osize - size); } __free_hook = old_free_hook; @@ -2106,7 +1950,7 @@ reallochook (ptr, size) 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); } @@ -2146,7 +1990,7 @@ static int mcheck_used = 0; int mcheck (func) - void (*func) __P ((enum mcheck_status)); + void (*func) (enum mcheck_status); { abortfunc = (func != NULL) ? func : &mabort; @@ -2172,6 +2016,3 @@ mprobe (__ptr_t ptr) } #endif /* GC_MCHECK */ - -/* arch-tag: 93dce5c0-f49a-41b5-86b1-f91c4169c02e - (do not change this comment) */