diff options
| author | Paul Eggert | 2011-07-06 18:32:56 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-06 18:32:56 -0700 |
| commit | 0e926e561c259468174b16407dd7271c2c8fe904 (patch) | |
| tree | 6a226d2950e17e8e117874c6714fd054600ffba6 /src/gmalloc.c | |
| parent | 59361254a6ea5fcfc2f1ec344665aa719fbb936f (diff) | |
| download | emacs-0e926e561c259468174b16407dd7271c2c8fe904.tar.gz emacs-0e926e561c259468174b16407dd7271c2c8fe904.zip | |
Assume freestanding C89 headers, string.h, stdlib.h.
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 4f27ea3079a..fa4aa1fdf6a 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -41,28 +41,13 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 41 | #define USE_PTHREAD | 41 | #define USE_PTHREAD |
| 42 | #endif | 42 | #endif |
| 43 | 43 | ||
| 44 | #if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \ | ||
| 45 | || defined STDC_HEADERS || defined PROTOTYPES)) | ||
| 46 | #undef PP | 44 | #undef PP |
| 47 | #define PP(args) args | 45 | #define PP(args) args |
| 48 | #undef __ptr_t | 46 | #undef __ptr_t |
| 49 | #define __ptr_t void * | 47 | #define __ptr_t void * |
| 50 | #else /* Not C++ or ANSI C. */ | ||
| 51 | #undef PP | ||
| 52 | #define PP(args) () | ||
| 53 | #undef __ptr_t | ||
| 54 | #define __ptr_t char * | ||
| 55 | #endif /* C++ or ANSI C. */ | ||
| 56 | 48 | ||
| 57 | #include <string.h> | 49 | #include <string.h> |
| 58 | |||
| 59 | #ifdef HAVE_LIMITS_H | ||
| 60 | #include <limits.h> | 50 | #include <limits.h> |
| 61 | #endif | ||
| 62 | #ifndef CHAR_BIT | ||
| 63 | #define CHAR_BIT 8 | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include <unistd.h> | 51 | #include <unistd.h> |
| 67 | 52 | ||
| 68 | #ifdef USE_PTHREAD | 53 | #ifdef USE_PTHREAD |
| @@ -77,26 +62,9 @@ extern "C" | |||
| 77 | { | 62 | { |
| 78 | #endif | 63 | #endif |
| 79 | 64 | ||
| 80 | #ifdef STDC_HEADERS | ||
| 81 | #include <stddef.h> | 65 | #include <stddef.h> |
| 82 | #define __malloc_size_t size_t | 66 | #define __malloc_size_t size_t |
| 83 | #define __malloc_ptrdiff_t ptrdiff_t | 67 | #define __malloc_ptrdiff_t ptrdiff_t |
| 84 | #else | ||
| 85 | #ifdef __GNUC__ | ||
| 86 | #include <stddef.h> | ||
| 87 | #ifdef __SIZE_TYPE__ | ||
| 88 | #define __malloc_size_t __SIZE_TYPE__ | ||
| 89 | #endif | ||
| 90 | #endif | ||
| 91 | #ifndef __malloc_size_t | ||
| 92 | #define __malloc_size_t unsigned int | ||
| 93 | #endif | ||
| 94 | #define __malloc_ptrdiff_t int | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifndef NULL | ||
| 98 | #define NULL 0 | ||
| 99 | #endif | ||
| 100 | 68 | ||
| 101 | 69 | ||
| 102 | /* Allocate SIZE bytes of memory. */ | 70 | /* Allocate SIZE bytes of memory. */ |
| @@ -1881,22 +1849,6 @@ struct hdr | |||
| 1881 | unsigned long int magic; /* Magic number to check header integrity. */ | 1849 | unsigned long int magic; /* Magic number to check header integrity. */ |
| 1882 | }; | 1850 | }; |
| 1883 | 1851 | ||
| 1884 | #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) | ||
| 1885 | #define flood memset | ||
| 1886 | #else | ||
| 1887 | static void flood (__ptr_t, int, __malloc_size_t); | ||
| 1888 | static void | ||
| 1889 | flood (ptr, val, size) | ||
| 1890 | __ptr_t ptr; | ||
| 1891 | int val; | ||
| 1892 | __malloc_size_t size; | ||
| 1893 | { | ||
| 1894 | char *cp = ptr; | ||
| 1895 | while (size--) | ||
| 1896 | *cp++ = val; | ||
| 1897 | } | ||
| 1898 | #endif | ||
| 1899 | |||
| 1900 | static enum mcheck_status checkhdr (const struct hdr *); | 1852 | static enum mcheck_status checkhdr (const struct hdr *); |
| 1901 | static enum mcheck_status | 1853 | static enum mcheck_status |
| 1902 | checkhdr (hdr) | 1854 | checkhdr (hdr) |
| @@ -1935,7 +1887,7 @@ freehook (ptr) | |||
| 1935 | hdr = ((struct hdr *) ptr) - 1; | 1887 | hdr = ((struct hdr *) ptr) - 1; |
| 1936 | checkhdr (hdr); | 1888 | checkhdr (hdr); |
| 1937 | hdr->magic = MAGICFREE; | 1889 | hdr->magic = MAGICFREE; |
| 1938 | flood (ptr, FREEFLOOD, hdr->size); | 1890 | memset (ptr, FREEFLOOD, hdr->size); |
| 1939 | } | 1891 | } |
| 1940 | else | 1892 | else |
| 1941 | hdr = NULL; | 1893 | hdr = NULL; |
| @@ -1961,7 +1913,7 @@ mallochook (size) | |||
| 1961 | hdr->size = size; | 1913 | hdr->size = size; |
| 1962 | hdr->magic = MAGICWORD; | 1914 | hdr->magic = MAGICWORD; |
| 1963 | ((char *) &hdr[1])[size] = MAGICBYTE; | 1915 | ((char *) &hdr[1])[size] = MAGICBYTE; |
| 1964 | flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); | 1916 | memset ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); |
| 1965 | return (__ptr_t) (hdr + 1); | 1917 | return (__ptr_t) (hdr + 1); |
| 1966 | } | 1918 | } |
| 1967 | 1919 | ||
| @@ -1981,7 +1933,7 @@ reallochook (ptr, size) | |||
| 1981 | 1933 | ||
| 1982 | checkhdr (hdr); | 1934 | checkhdr (hdr); |
| 1983 | if (size < osize) | 1935 | if (size < osize) |
| 1984 | flood ((char *) ptr + size, FREEFLOOD, osize - size); | 1936 | memset ((char *) ptr + size, FREEFLOOD, osize - size); |
| 1985 | } | 1937 | } |
| 1986 | 1938 | ||
| 1987 | __free_hook = old_free_hook; | 1939 | __free_hook = old_free_hook; |
| @@ -1998,7 +1950,7 @@ reallochook (ptr, size) | |||
| 1998 | hdr->magic = MAGICWORD; | 1950 | hdr->magic = MAGICWORD; |
| 1999 | ((char *) &hdr[1])[size] = MAGICBYTE; | 1951 | ((char *) &hdr[1])[size] = MAGICBYTE; |
| 2000 | if (size > osize) | 1952 | if (size > osize) |
| 2001 | flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); | 1953 | memset ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); |
| 2002 | return (__ptr_t) (hdr + 1); | 1954 | return (__ptr_t) (hdr + 1); |
| 2003 | } | 1955 | } |
| 2004 | 1956 | ||