diff options
| author | Paul Eggert | 2016-01-30 14:20:57 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-01-30 15:26:07 -0800 |
| commit | e1a9f2099c2e683dffc4b898ce85ce935c4cb254 (patch) | |
| tree | 14f8b080fb8515b81111dc269e37aa01f73b16fc | |
| parent | 874c59a81b7ee12a739149c5229e6d3bbd463324 (diff) | |
| download | emacs-e1a9f2099c2e683dffc4b898ce85ce935c4cb254.tar.gz emacs-e1a9f2099c2e683dffc4b898ce85ce935c4cb254.zip | |
Pacify --enable-gcc-warnings when HYBRID_MALLOC
* src/buffer.c (init_buffer):
* src/emacs.c (main):
* src/xsmfns.c (smc_save_yourself_CB, x_session_initialize):
Use emacs_get_current_dir_name, not get_current_dir_name.
* src/conf_post.h (aligned_alloc) [HYBRID_MALLOC && emacs]: New macro.
(HYBRID_GET_CURRENT_DIR_NAME, get_current_dir_name): Remove.
* src/emacs.c: Include "sheap.h".
(report_sheap_usage): Remove decl.
(Fdump_emacs) [HYBRID_MALLOC]: Report usage directly.
Don't assume ptrdiff_t can be printed as int.
* src/gmalloc.c [HYBRID_MALLOC]:
Include "sheap.h" rather than declaring its contents by hand.
(get_current_dir_name, gget_current_dir_name)
(hybrid_get_current_dir_name): Remove.
(emacs_abort): Remove duplicate decl.
(aligned_alloc): Undef, like malloc etc.
(ALLOCATED_BEFORE_DUMPING): Now a static function, not a macro.
Make it a bit more efficient.
(malloc_find_object_address): Remove unused decl.
(enum mcheck_status, mcheck, mprobe, mtrace, muntrace, struct mstats)
(mstats, memory_warnings): Declare only if GC_MCHECK.
* src/lisp.h (emacs_get_current_dir_name):
New decl, replacing get_current_dir_name.
* src/sheap.c: Include sheap.h first.
(STATIC_HEAP_SIZE): Remove; now in sheap.h.
(debug_sheap): Now static.
(bss_sbrk_buffer_end): Remove; no longer used.
(bss_sbrk_ptr): Now static and private.
(bss_sbrk_did_unexec): Now bool.
(BLOCKSIZE): Remove, to avoid GCC warning about its not being used.
(bss_sbrk): Don't treat request_size 0 as special, since the code
works without this being a special case.
Avoid overflow if request size exceeds INT_MAX.
(report_sheap_usage): Remove; now done in emacs.c.
* src/sheap.h: New file.
* src/sysdep.c (get_current_dir_name): Remove macro.
Include "sheap.h".
(emacs_get_current_dir_name): Rename function from
get_current_dir_name. Handle HYBRID_MALLOC here;
this is simpler.
(Bug#22086)
| -rw-r--r-- | src/buffer.c | 2 | ||||
| -rw-r--r-- | src/conf_post.h | 5 | ||||
| -rw-r--r-- | src/emacs.c | 13 | ||||
| -rw-r--r-- | src/gmalloc.c | 51 | ||||
| -rw-r--r-- | src/lisp.h | 4 | ||||
| -rw-r--r-- | src/sheap.c | 83 | ||||
| -rw-r--r-- | src/sheap.h | 31 | ||||
| -rw-r--r-- | src/sysdep.c | 29 | ||||
| -rw-r--r-- | src/xsmfns.c | 4 |
9 files changed, 102 insertions, 120 deletions
diff --git a/src/buffer.c b/src/buffer.c index 0c52eaf41ba..3e410670c54 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -5277,7 +5277,7 @@ init_buffer (int initialized) | |||
| 5277 | if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) | 5277 | if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) |
| 5278 | Fset_buffer_multibyte (Qnil); | 5278 | Fset_buffer_multibyte (Qnil); |
| 5279 | 5279 | ||
| 5280 | pwd = get_current_dir_name (); | 5280 | pwd = emacs_get_current_dir_name (); |
| 5281 | 5281 | ||
| 5282 | if (!pwd) | 5282 | if (!pwd) |
| 5283 | { | 5283 | { |
diff --git a/src/conf_post.h b/src/conf_post.h index 5c332a05a5c..9f4becdfd7c 100644 --- a/src/conf_post.h +++ b/src/conf_post.h | |||
| @@ -100,11 +100,8 @@ typedef bool bool_bf; | |||
| 100 | #define malloc hybrid_malloc | 100 | #define malloc hybrid_malloc |
| 101 | #define realloc hybrid_realloc | 101 | #define realloc hybrid_realloc |
| 102 | #define calloc hybrid_calloc | 102 | #define calloc hybrid_calloc |
| 103 | #define aligned_alloc hybrid_aligned_alloc | ||
| 103 | #define free hybrid_free | 104 | #define free hybrid_free |
| 104 | #if defined HAVE_GET_CURRENT_DIR_NAME && !defined BROKEN_GET_CURRENT_DIR_NAME | ||
| 105 | #define HYBRID_GET_CURRENT_DIR_NAME 1 | ||
| 106 | #define get_current_dir_name hybrid_get_current_dir_name | ||
| 107 | #endif | ||
| 108 | #endif | 105 | #endif |
| 109 | #endif /* HYBRID_MALLOC */ | 106 | #endif /* HYBRID_MALLOC */ |
| 110 | 107 | ||
diff --git a/src/emacs.c b/src/emacs.c index 7ba5cfeb2e5..7cfc91ee9e0 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -79,6 +79,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 79 | #include "composite.h" | 79 | #include "composite.h" |
| 80 | #include "dispextern.h" | 80 | #include "dispextern.h" |
| 81 | #include "regex.h" | 81 | #include "regex.h" |
| 82 | #include "sheap.h" | ||
| 82 | #include "syntax.h" | 83 | #include "syntax.h" |
| 83 | #include "sysselect.h" | 84 | #include "sysselect.h" |
| 84 | #include "systime.h" | 85 | #include "systime.h" |
| @@ -134,7 +135,6 @@ extern void unexec_init_emacs_zone (void); | |||
| 134 | #endif | 135 | #endif |
| 135 | 136 | ||
| 136 | extern void malloc_enable_thread (void); | 137 | extern void malloc_enable_thread (void); |
| 137 | extern void report_sheap_usage (int); | ||
| 138 | 138 | ||
| 139 | /* If true, Emacs should not attempt to use a window-specific code, | 139 | /* If true, Emacs should not attempt to use a window-specific code, |
| 140 | but instead should use the virtual terminal under which it was started. */ | 140 | but instead should use the virtual terminal under which it was started. */ |
| @@ -775,7 +775,7 @@ main (int argc, char **argv) | |||
| 775 | filename_from_ansi (ch_to_dir, newdir); | 775 | filename_from_ansi (ch_to_dir, newdir); |
| 776 | ch_to_dir = newdir; | 776 | ch_to_dir = newdir; |
| 777 | #endif | 777 | #endif |
| 778 | original_pwd = get_current_dir_name (); | 778 | original_pwd = emacs_get_current_dir_name (); |
| 779 | if (chdir (ch_to_dir) != 0) | 779 | if (chdir (ch_to_dir) != 0) |
| 780 | { | 780 | { |
| 781 | fprintf (stderr, "%s: Can't chdir to %s: %s\n", | 781 | fprintf (stderr, "%s: Can't chdir to %s: %s\n", |
| @@ -2075,7 +2075,14 @@ You must run Emacs in batch mode in order to dump it. */) | |||
| 2075 | Vpurify_flag = Qnil; | 2075 | Vpurify_flag = Qnil; |
| 2076 | 2076 | ||
| 2077 | #ifdef HYBRID_MALLOC | 2077 | #ifdef HYBRID_MALLOC |
| 2078 | report_sheap_usage (1); | 2078 | { |
| 2079 | static char const fmt[] = "%d of %d static heap bytes used"; | ||
| 2080 | char buf[sizeof fmt + 2 * (INT_STRLEN_BOUND (int) - 2)]; | ||
| 2081 | int max_usage = max_bss_sbrk_ptr - bss_sbrk_buffer; | ||
| 2082 | sprintf (buf, fmt, max_usage, STATIC_HEAP_SIZE); | ||
| 2083 | /* Don't log messages, because at this point buffers cannot be created. */ | ||
| 2084 | message1_nolog (buf); | ||
| 2085 | } | ||
| 2079 | #endif | 2086 | #endif |
| 2080 | 2087 | ||
| 2081 | fflush (stdout); | 2088 | fflush (stdout); |
diff --git a/src/gmalloc.c b/src/gmalloc.c index 30e01319e0e..4fd324686ba 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -28,11 +28,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | #include <string.h> | 28 | #include <string.h> |
| 29 | #include <limits.h> | 29 | #include <limits.h> |
| 30 | #include <stdint.h> | 30 | #include <stdint.h> |
| 31 | |||
| 32 | #ifdef HYBRID_GET_CURRENT_DIR_NAME | ||
| 33 | #undef get_current_dir_name | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include <unistd.h> | 31 | #include <unistd.h> |
| 37 | 32 | ||
| 38 | #ifdef USE_PTHREAD | 33 | #ifdef USE_PTHREAD |
| @@ -43,10 +38,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 43 | #include <w32heap.h> /* for sbrk */ | 38 | #include <w32heap.h> /* for sbrk */ |
| 44 | #endif | 39 | #endif |
| 45 | 40 | ||
| 46 | #ifdef emacs | ||
| 47 | extern void emacs_abort (void); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | /* If HYBRID_MALLOC is defined, then temacs will use malloc, | 41 | /* If HYBRID_MALLOC is defined, then temacs will use malloc, |
| 51 | realloc... as defined in this file (and renamed gmalloc, | 42 | realloc... as defined in this file (and renamed gmalloc, |
| 52 | grealloc... via the macros that follow). The dumped emacs, | 43 | grealloc... via the macros that follow). The dumped emacs, |
| @@ -63,6 +54,7 @@ extern void emacs_abort (void); | |||
| 63 | #undef malloc | 54 | #undef malloc |
| 64 | #undef realloc | 55 | #undef realloc |
| 65 | #undef calloc | 56 | #undef calloc |
| 57 | #undef aligned_alloc | ||
| 66 | #undef free | 58 | #undef free |
| 67 | #define malloc gmalloc | 59 | #define malloc gmalloc |
| 68 | #define realloc grealloc | 60 | #define realloc grealloc |
| @@ -71,13 +63,13 @@ extern void emacs_abort (void); | |||
| 71 | #define free gfree | 63 | #define free gfree |
| 72 | 64 | ||
| 73 | #ifdef HYBRID_MALLOC | 65 | #ifdef HYBRID_MALLOC |
| 74 | extern void *bss_sbrk (ptrdiff_t size); | 66 | # include "sheap.h" |
| 75 | extern int bss_sbrk_did_unexec; | 67 | # define DUMPED bss_sbrk_did_unexec |
| 76 | extern char bss_sbrk_buffer[]; | 68 | static bool |
| 77 | extern void *bss_sbrk_buffer_end; | 69 | ALLOCATED_BEFORE_DUMPING (char *p) |
| 78 | #define DUMPED bss_sbrk_did_unexec | 70 | { |
| 79 | #define ALLOCATED_BEFORE_DUMPING(P) \ | 71 | return bss_sbrk_buffer <= p && p < bss_sbrk_buffer + STATIC_HEAP_SIZE; |
| 80 | ((P) < bss_sbrk_buffer_end && (P) >= (void *) bss_sbrk_buffer) | 72 | } |
| 81 | #endif | 73 | #endif |
| 82 | 74 | ||
| 83 | #ifdef __cplusplus | 75 | #ifdef __cplusplus |
| @@ -87,10 +79,6 @@ extern "C" | |||
| 87 | 79 | ||
| 88 | #include <stddef.h> | 80 | #include <stddef.h> |
| 89 | 81 | ||
| 90 | #ifdef emacs | ||
| 91 | extern void emacs_abort (void); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* Underlying allocation function; successive calls should | 82 | /* Underlying allocation function; successive calls should |
| 95 | return contiguous pieces of memory. */ | 83 | return contiguous pieces of memory. */ |
| 96 | extern void *(*__morecore) (ptrdiff_t size); | 84 | extern void *(*__morecore) (ptrdiff_t size); |
| @@ -255,10 +243,6 @@ extern int _malloc_thread_enabled_p; | |||
| 255 | #define UNLOCK_ALIGNED_BLOCKS() | 243 | #define UNLOCK_ALIGNED_BLOCKS() |
| 256 | #endif | 244 | #endif |
| 257 | 245 | ||
| 258 | /* Given an address in the middle of a malloc'd object, | ||
| 259 | return the address of the beginning of the object. */ | ||
| 260 | extern void *malloc_find_object_address (void *ptr); | ||
| 261 | |||
| 262 | /* If not NULL, this function is called after each time | 246 | /* If not NULL, this function is called after each time |
| 263 | `__morecore' is called to increase the data size. */ | 247 | `__morecore' is called to increase the data size. */ |
| 264 | extern void (*__after_morecore_hook) (void); | 248 | extern void (*__after_morecore_hook) (void); |
| @@ -279,6 +263,8 @@ extern void *(*__malloc_hook) (size_t size); | |||
| 279 | extern void *(*__realloc_hook) (void *ptr, size_t size); | 263 | extern void *(*__realloc_hook) (void *ptr, size_t size); |
| 280 | extern void *(*__memalign_hook) (size_t size, size_t alignment); | 264 | extern void *(*__memalign_hook) (size_t size, size_t alignment); |
| 281 | 265 | ||
| 266 | #ifdef GC_MCHECK | ||
| 267 | |||
| 282 | /* Return values for `mprobe': these are the kinds of inconsistencies that | 268 | /* Return values for `mprobe': these are the kinds of inconsistencies that |
| 283 | `mcheck' enables detection of. */ | 269 | `mcheck' enables detection of. */ |
| 284 | enum mcheck_status | 270 | enum mcheck_status |
| @@ -321,6 +307,8 @@ extern struct mstats mstats (void); | |||
| 321 | /* Call WARNFUN with a warning message when memory usage is high. */ | 307 | /* Call WARNFUN with a warning message when memory usage is high. */ |
| 322 | extern void memory_warnings (void *start, void (*warnfun) (const char *)); | 308 | extern void memory_warnings (void *start, void (*warnfun) (const char *)); |
| 323 | 309 | ||
| 310 | #endif | ||
| 311 | |||
| 324 | #undef extern | 312 | #undef extern |
| 325 | 313 | ||
| 326 | #ifdef __cplusplus | 314 | #ifdef __cplusplus |
| @@ -1797,7 +1785,7 @@ hybrid_aligned_alloc (size_t alignment, size_t size) | |||
| 1797 | #endif | 1785 | #endif |
| 1798 | } | 1786 | } |
| 1799 | #endif | 1787 | #endif |
| 1800 | 1788 | ||
| 1801 | void * | 1789 | void * |
| 1802 | hybrid_realloc (void *ptr, size_t size) | 1790 | hybrid_realloc (void *ptr, size_t size) |
| 1803 | { | 1791 | { |
| @@ -1825,19 +1813,6 @@ hybrid_realloc (void *ptr, size_t size) | |||
| 1825 | return result; | 1813 | return result; |
| 1826 | } | 1814 | } |
| 1827 | 1815 | ||
| 1828 | #ifdef HYBRID_GET_CURRENT_DIR_NAME | ||
| 1829 | /* Defined in sysdep.c. */ | ||
| 1830 | char *gget_current_dir_name (void); | ||
| 1831 | |||
| 1832 | char * | ||
| 1833 | hybrid_get_current_dir_name (void) | ||
| 1834 | { | ||
| 1835 | if (DUMPED) | ||
| 1836 | return get_current_dir_name (); | ||
| 1837 | return gget_current_dir_name (); | ||
| 1838 | } | ||
| 1839 | #endif | ||
| 1840 | |||
| 1841 | #else /* ! HYBRID_MALLOC */ | 1816 | #else /* ! HYBRID_MALLOC */ |
| 1842 | 1817 | ||
| 1843 | void * | 1818 | void * |
diff --git a/src/lisp.h b/src/lisp.h index 82cbca8e6ba..53f123df973 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4254,9 +4254,7 @@ struct tty_display_info; | |||
| 4254 | struct terminal; | 4254 | struct terminal; |
| 4255 | 4255 | ||
| 4256 | /* Defined in sysdep.c. */ | 4256 | /* Defined in sysdep.c. */ |
| 4257 | #ifndef HAVE_GET_CURRENT_DIR_NAME | 4257 | extern char *emacs_get_current_dir_name (void); |
| 4258 | extern char *get_current_dir_name (void); | ||
| 4259 | #endif | ||
| 4260 | extern void stuff_char (char c); | 4258 | extern void stuff_char (char c); |
| 4261 | extern void init_foreground_group (void); | 4259 | extern void init_foreground_group (void); |
| 4262 | extern void sys_subshell (void); | 4260 | extern void sys_subshell (void); |
diff --git a/src/sheap.c b/src/sheap.c index 1451eca8ce7..fe905ca0c02 100644 --- a/src/sheap.c +++ b/src/sheap.c | |||
| @@ -19,87 +19,62 @@ You should have received a copy of the GNU General Public License | |||
| 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | |||
| 23 | #include "sheap.h" | ||
| 24 | |||
| 22 | #include <stdio.h> | 25 | #include <stdio.h> |
| 23 | #include "lisp.h" | 26 | #include "lisp.h" |
| 24 | #include <unistd.h> | 27 | #include <unistd.h> |
| 25 | #include <stdlib.h> /* for exit */ | 28 | #include <stdlib.h> /* for exit */ |
| 26 | 29 | ||
| 27 | #ifdef ENABLE_CHECKING | 30 | static int debug_sheap; |
| 28 | #define STATIC_HEAP_SIZE (28 * 1024 * 1024) | ||
| 29 | #else | ||
| 30 | #define STATIC_HEAP_SIZE (19 * 1024 * 1024) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | int debug_sheap = 0; | ||
| 34 | |||
| 35 | #define BLOCKSIZE 4096 | ||
| 36 | 31 | ||
| 37 | char bss_sbrk_buffer[STATIC_HEAP_SIZE]; | 32 | char bss_sbrk_buffer[STATIC_HEAP_SIZE]; |
| 38 | /* The following is needed in gmalloc.c */ | ||
| 39 | void *bss_sbrk_buffer_end = bss_sbrk_buffer + STATIC_HEAP_SIZE; | ||
| 40 | char *bss_sbrk_ptr; | ||
| 41 | char *max_bss_sbrk_ptr; | 33 | char *max_bss_sbrk_ptr; |
| 42 | int bss_sbrk_did_unexec; | 34 | bool bss_sbrk_did_unexec; |
| 43 | 35 | ||
| 44 | void * | 36 | void * |
| 45 | bss_sbrk (ptrdiff_t request_size) | 37 | bss_sbrk (ptrdiff_t request_size) |
| 46 | { | 38 | { |
| 39 | static char *bss_sbrk_ptr; | ||
| 40 | |||
| 47 | if (!bss_sbrk_ptr) | 41 | if (!bss_sbrk_ptr) |
| 48 | { | 42 | { |
| 49 | max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer; | 43 | max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer; |
| 50 | #ifdef CYGWIN | 44 | #ifdef CYGWIN |
| 51 | sbrk (BLOCKSIZE); /* force space for fork to work */ | 45 | /* Force space for fork to work. */ |
| 46 | sbrk (4096); | ||
| 52 | #endif | 47 | #endif |
| 53 | } | 48 | } |
| 54 | 49 | ||
| 55 | if (!(int) request_size) | 50 | int used = bss_sbrk_ptr - bss_sbrk_buffer; |
| 56 | { | 51 | |
| 57 | return (bss_sbrk_ptr); | 52 | if (request_size < -used) |
| 58 | } | ||
| 59 | else if (bss_sbrk_ptr + (int) request_size < bss_sbrk_buffer) | ||
| 60 | { | 53 | { |
| 61 | printf | 54 | printf (("attempt to free too much: " |
| 62 | ("attempt to free too much: avail %d used %d failed request %d\n", | 55 | "avail %d used %d failed request %"pD"d\n"), |
| 63 | STATIC_HEAP_SIZE, bss_sbrk_ptr - bss_sbrk_buffer, | 56 | STATIC_HEAP_SIZE, used, request_size); |
| 64 | (int) request_size); | ||
| 65 | exit (-1); | 57 | exit (-1); |
| 66 | return 0; | 58 | return 0; |
| 67 | } | 59 | } |
| 68 | else if (bss_sbrk_ptr + (int) request_size > | 60 | else if (STATIC_HEAP_SIZE - used < request_size) |
| 69 | bss_sbrk_buffer + STATIC_HEAP_SIZE) | ||
| 70 | { | 61 | { |
| 71 | printf ("static heap exhausted: avail %d used %d failed request %d\n", | 62 | printf ("static heap exhausted: avail %d used %d failed request %"pD"d\n", |
| 72 | STATIC_HEAP_SIZE, | 63 | STATIC_HEAP_SIZE, used, request_size); |
| 73 | bss_sbrk_ptr - bss_sbrk_buffer, (int) request_size); | ||
| 74 | exit (-1); | 64 | exit (-1); |
| 75 | return 0; | 65 | return 0; |
| 76 | } | 66 | } |
| 77 | else if ((int) request_size < 0) | 67 | |
| 78 | { | 68 | void *ret = bss_sbrk_ptr; |
| 79 | bss_sbrk_ptr += (int) request_size; | 69 | bss_sbrk_ptr += request_size; |
| 80 | if (debug_sheap) | 70 | if (max_bss_sbrk_ptr < bss_sbrk_ptr) |
| 81 | printf ("freed size %d\n", request_size); | 71 | max_bss_sbrk_ptr = bss_sbrk_ptr; |
| 82 | return bss_sbrk_ptr; | 72 | if (debug_sheap) |
| 83 | } | ||
| 84 | else | ||
| 85 | { | 73 | { |
| 86 | char *ret = bss_sbrk_ptr; | 74 | if (request_size < 0) |
| 87 | if (debug_sheap) | 75 | printf ("freed size %"pD"d\n", request_size); |
| 88 | printf ("allocated 0x%08x size %d\n", ret, request_size); | 76 | else |
| 89 | bss_sbrk_ptr += (int) request_size; | 77 | printf ("allocated %p size %"pD"d\n", ret, request_size); |
| 90 | if (bss_sbrk_ptr > max_bss_sbrk_ptr) | ||
| 91 | max_bss_sbrk_ptr = bss_sbrk_ptr; | ||
| 92 | return ret; | ||
| 93 | } | 78 | } |
| 94 | } | 79 | return ret; |
| 95 | |||
| 96 | void | ||
| 97 | report_sheap_usage (int die_if_pure_storage_exceeded) | ||
| 98 | { | ||
| 99 | char buf[200]; | ||
| 100 | sprintf (buf, "Maximum static heap usage: %d of %d bytes", | ||
| 101 | max_bss_sbrk_ptr - bss_sbrk_buffer, STATIC_HEAP_SIZE); | ||
| 102 | /* Don't log messages, cause at this point, we're not allowed to create | ||
| 103 | buffers. */ | ||
| 104 | message1_nolog (buf); | ||
| 105 | } | 80 | } |
diff --git a/src/sheap.h b/src/sheap.h new file mode 100644 index 00000000000..4af3cf482b1 --- /dev/null +++ b/src/sheap.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* Static heap allocation for GNU Emacs. | ||
| 2 | |||
| 3 | Copyright 2016 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 3 of the License, or | ||
| 10 | (at your option) any later version. | ||
| 11 | |||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | #include <stddef.h> | ||
| 21 | |||
| 22 | #ifdef ENABLE_CHECKING | ||
| 23 | # define STATIC_HEAP_SIZE (28 * 1024 * 1024) | ||
| 24 | #else | ||
| 25 | # define STATIC_HEAP_SIZE (19 * 1024 * 1024) | ||
| 26 | #endif | ||
| 27 | |||
| 28 | extern char bss_sbrk_buffer[STATIC_HEAP_SIZE]; | ||
| 29 | extern char *max_bss_sbrk_ptr; | ||
| 30 | extern bool bss_sbrk_did_unexec; | ||
| 31 | extern void *bss_sbrk (ptrdiff_t); | ||
diff --git a/src/sysdep.c b/src/sysdep.c index 19a7212f7e2..418c50d5e78 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -19,14 +19,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 19 | 19 | ||
| 20 | #include <config.h> | 20 | #include <config.h> |
| 21 | 21 | ||
| 22 | /* If HYBRID_GET_CURRENT_DIR_NAME is defined in conf_post.h, then we | ||
| 23 | need the following before including unistd.h, in order to pick up | ||
| 24 | the right prototype for gget_current_dir_name. */ | ||
| 25 | #ifdef HYBRID_GET_CURRENT_DIR_NAME | ||
| 26 | #undef get_current_dir_name | ||
| 27 | #define get_current_dir_name gget_current_dir_name | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <execinfo.h> | 22 | #include <execinfo.h> |
| 31 | #include "sysstdio.h" | 23 | #include "sysstdio.h" |
| 32 | #ifdef HAVE_PWD_H | 24 | #ifdef HAVE_PWD_H |
| @@ -40,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 40 | #include <utimens.h> | 32 | #include <utimens.h> |
| 41 | 33 | ||
| 42 | #include "lisp.h" | 34 | #include "lisp.h" |
| 35 | #include "sheap.h" | ||
| 43 | #include "sysselect.h" | 36 | #include "sysselect.h" |
| 44 | #include "blockinput.h" | 37 | #include "blockinput.h" |
| 45 | 38 | ||
| @@ -137,14 +130,21 @@ static const int baud_convert[] = | |||
| 137 | 1800, 2400, 4800, 9600, 19200, 38400 | 130 | 1800, 2400, 4800, 9600, 19200, 38400 |
| 138 | }; | 131 | }; |
| 139 | 132 | ||
| 140 | #if !defined HAVE_GET_CURRENT_DIR_NAME || defined BROKEN_GET_CURRENT_DIR_NAME \ | 133 | /* Return the current working directory. The result should be freed |
| 141 | || (defined HYBRID_GET_CURRENT_DIR_NAME) | 134 | with 'free'. Return NULL on errors. */ |
| 142 | /* Return the current working directory. Returns NULL on errors. | ||
| 143 | Any other returned value must be freed with free. This is used | ||
| 144 | only when get_current_dir_name is not defined on the system. */ | ||
| 145 | char * | 135 | char * |
| 146 | get_current_dir_name (void) | 136 | emacs_get_current_dir_name (void) |
| 147 | { | 137 | { |
| 138 | # if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME | ||
| 139 | # ifdef HYBRID_MALLOC | ||
| 140 | bool use_libc = bss_sbrk_did_unexec; | ||
| 141 | # else | ||
| 142 | bool use_libc = true; | ||
| 143 | # endif | ||
| 144 | if (use_libc) | ||
| 145 | return get_current_dir_name (); | ||
| 146 | # endif | ||
| 147 | |||
| 148 | char *buf; | 148 | char *buf; |
| 149 | char *pwd = getenv ("PWD"); | 149 | char *pwd = getenv ("PWD"); |
| 150 | struct stat dotstat, pwdstat; | 150 | struct stat dotstat, pwdstat; |
| @@ -192,7 +192,6 @@ get_current_dir_name (void) | |||
| 192 | } | 192 | } |
| 193 | return buf; | 193 | return buf; |
| 194 | } | 194 | } |
| 195 | #endif | ||
| 196 | 195 | ||
| 197 | 196 | ||
| 198 | /* Discard pending input on all input descriptors. */ | 197 | /* Discard pending input on all input descriptors. */ |
diff --git a/src/xsmfns.c b/src/xsmfns.c index 76414496770..df5c46b0288 100644 --- a/src/xsmfns.c +++ b/src/xsmfns.c | |||
| @@ -204,7 +204,7 @@ smc_save_yourself_CB (SmcConn smcConn, | |||
| 204 | props[props_idx]->vals[0].value = SDATA (user_login_name); | 204 | props[props_idx]->vals[0].value = SDATA (user_login_name); |
| 205 | ++props_idx; | 205 | ++props_idx; |
| 206 | 206 | ||
| 207 | char *cwd = get_current_dir_name (); | 207 | char *cwd = emacs_get_current_dir_name (); |
| 208 | if (cwd) | 208 | if (cwd) |
| 209 | { | 209 | { |
| 210 | props[props_idx] = &prop_ptr[props_idx]; | 210 | props[props_idx] = &prop_ptr[props_idx]; |
| @@ -401,7 +401,7 @@ x_session_initialize (struct x_display_info *dpyinfo) | |||
| 401 | ptrdiff_t name_len = 0; | 401 | ptrdiff_t name_len = 0; |
| 402 | 402 | ||
| 403 | /* libSM seems to crash if pwd is missing - see bug#18851. */ | 403 | /* libSM seems to crash if pwd is missing - see bug#18851. */ |
| 404 | if (! get_current_dir_name ()) | 404 | if (! emacs_get_current_dir_name ()) |
| 405 | { | 405 | { |
| 406 | fprintf (stderr, "Disabling session management due to pwd error: %s\n", | 406 | fprintf (stderr, "Disabling session management due to pwd error: %s\n", |
| 407 | emacs_strerror (errno)); | 407 | emacs_strerror (errno)); |