diff options
| author | Wolfgang Jenkner | 2015-12-26 12:12:02 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-12-26 12:12:43 -0800 |
| commit | 4b1436b702d56eedd27a0777fc7232cdfb7ac4f6 (patch) | |
| tree | 0a92fb0417ed2eac4f5b0ef7165def7d194b0df0 /src/gmalloc.c | |
| parent | 0191077d6a96d9ef8e43989fd5dc8a95e61806d5 (diff) | |
| download | emacs-4b1436b702d56eedd27a0777fc7232cdfb7ac4f6.tar.gz emacs-4b1436b702d56eedd27a0777fc7232cdfb7ac4f6.zip | |
Always define gmalloc etc. in src/gmalloc.c
This is a work-around to prevent the compiler from using semantic
knowledge about malloc for optimization purposes. E.g., gcc 5.2
with -O2 replaces most of calloc's definition by a call to calloc;
see Bug#22085.
* src/gmalloc.c [!HYBRID_MALLOC] (malloc, realloc, calloc)
(aligned_alloc, free): Do not undef. Instead, define these as
functions (perhaps renamed to gmalloc etc.) in terms of gmalloc etc.
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index a88f4ab75e0..90a52a1c728 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -60,7 +60,6 @@ extern void emacs_abort (void); | |||
| 60 | which HYBRID_MACRO is defined. Any other platform that wants to | 60 | which HYBRID_MACRO is defined. Any other platform that wants to |
| 61 | define it will have to define the macros DUMPED and | 61 | define it will have to define the macros DUMPED and |
| 62 | ALLOCATED_BEFORE_DUMPING, defined below for Cygwin. */ | 62 | ALLOCATED_BEFORE_DUMPING, defined below for Cygwin. */ |
| 63 | #ifdef HYBRID_MALLOC | ||
| 64 | #undef malloc | 63 | #undef malloc |
| 65 | #undef realloc | 64 | #undef realloc |
| 66 | #undef calloc | 65 | #undef calloc |
| @@ -70,7 +69,6 @@ extern void emacs_abort (void); | |||
| 70 | #define calloc gcalloc | 69 | #define calloc gcalloc |
| 71 | #define aligned_alloc galigned_alloc | 70 | #define aligned_alloc galigned_alloc |
| 72 | #define free gfree | 71 | #define free gfree |
| 73 | #endif /* HYBRID_MALLOC */ | ||
| 74 | 72 | ||
| 75 | #ifdef CYGWIN | 73 | #ifdef CYGWIN |
| 76 | extern void *bss_sbrk (ptrdiff_t size); | 74 | extern void *bss_sbrk (ptrdiff_t size); |
| @@ -1711,13 +1709,13 @@ valloc (size_t size) | |||
| 1711 | return aligned_alloc (pagesize, size); | 1709 | return aligned_alloc (pagesize, size); |
| 1712 | } | 1710 | } |
| 1713 | 1711 | ||
| 1714 | #ifdef HYBRID_MALLOC | ||
| 1715 | #undef malloc | 1712 | #undef malloc |
| 1716 | #undef realloc | 1713 | #undef realloc |
| 1717 | #undef calloc | 1714 | #undef calloc |
| 1718 | #undef aligned_alloc | 1715 | #undef aligned_alloc |
| 1719 | #undef free | 1716 | #undef free |
| 1720 | 1717 | ||
| 1718 | #ifdef HYBRID_MALLOC | ||
| 1721 | /* Declare system malloc and friends. */ | 1719 | /* Declare system malloc and friends. */ |
| 1722 | extern void *malloc (size_t size); | 1720 | extern void *malloc (size_t size); |
| 1723 | extern void *realloc (void *ptr, size_t size); | 1721 | extern void *realloc (void *ptr, size_t size); |
| @@ -1816,6 +1814,38 @@ hybrid_get_current_dir_name (void) | |||
| 1816 | } | 1814 | } |
| 1817 | #endif | 1815 | #endif |
| 1818 | 1816 | ||
| 1817 | #else /* ! HYBRID_MALLOC */ | ||
| 1818 | |||
| 1819 | void * | ||
| 1820 | malloc (size_t size) | ||
| 1821 | { | ||
| 1822 | return gmalloc (size); | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | void * | ||
| 1826 | calloc (size_t nmemb, size_t size) | ||
| 1827 | { | ||
| 1828 | return gcalloc (nmemb, size); | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | void | ||
| 1832 | free (void *ptr) | ||
| 1833 | { | ||
| 1834 | gfree (ptr); | ||
| 1835 | } | ||
| 1836 | |||
| 1837 | void * | ||
| 1838 | aligned_alloc (size_t alignment, size_t size) | ||
| 1839 | { | ||
| 1840 | return galigned_alloc (alignment, size); | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | void * | ||
| 1844 | realloc (void *ptr, size_t size) | ||
| 1845 | { | ||
| 1846 | return grealloc (ptr, size); | ||
| 1847 | } | ||
| 1848 | |||
| 1819 | #endif /* HYBRID_MALLOC */ | 1849 | #endif /* HYBRID_MALLOC */ |
| 1820 | 1850 | ||
| 1821 | #ifdef GC_MCHECK | 1851 | #ifdef GC_MCHECK |