Mercurial > hg > xemacs-beta
changeset 3170:db0631f96757
[xemacs-hg @ 2005-12-24 19:06:04 by aidan]
Allow the low-memory warning code to call malloc itself.
author | aidan |
---|---|
date | Sat, 24 Dec 2005 19:06:05 +0000 |
parents | 5bfedec8927e |
children | 4cad7ff4a200 |
files | src/ChangeLog src/alloc.c |
diffstat | 2 files changed, 40 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Sat Dec 24 17:33:34 2005 +0000 +++ b/src/ChangeLog Sat Dec 24 19:06:05 2005 +0000 @@ -1,3 +1,15 @@ +2005-12-24 Aidan Kehoe <kehoea@parhasard.net> + + * alloc.c (MALLOC_BEGIN): + Assert that we're either not in malloc, or warning about memory + being low. + * alloc.c (MALLOC_WARNING_BEGIN, MALLOC_WARNING_END): + Add two clauses to set and clear a flag that we're in a low-memory + warning situation. + * alloc.c (malloc_warning): + Move it after the definition of MALLOC_WARNING_BEGIN, + MALLOC_WARNING_END + 2005-12-24 Aidan Kehoe <kehoea@parhasard.net> * objects-gtk.c (MAX_FONT_COUNT):
--- a/src/alloc.c Sat Dec 24 17:33:34 2005 +0000 +++ b/src/alloc.c Sat Dec 24 19:06:05 2005 +0000 @@ -231,22 +231,6 @@ } #endif /* not MC_ALLOC */ -/* malloc calls this if it finds we are near exhausting storage */ -void -malloc_warning (const char *str) -{ - if (ignore_malloc_warnings) - return; - - warn_when_safe - (Qmemory, Qemergency, - "%s\n" - "Killing some buffers may delay running out of memory.\n" - "However, certainly by the time you receive the 95%% warning,\n" - "you should clean up, kill this Emacs, and start a new one.", - str); -} - /* Called if malloc returns zero */ DOESNT_RETURN memory_full (void) @@ -290,18 +274,21 @@ } #ifdef ERROR_CHECK_MALLOC -static int in_malloc; +static int in_malloc, in_malloc_warning; extern int regex_malloc_disallowed; #define MALLOC_BEGIN() \ do \ { \ - assert (!in_malloc); \ + assert (!in_malloc || in_malloc_warning); \ assert (!regex_malloc_disallowed); \ in_malloc = 1; \ } \ while (0) +#define MALLOC_WARNING_BEGIN() (++in_malloc_warning) +#define MALLOC_WARNING_END() (--in_malloc_warning) + #ifdef MC_ALLOC #define FREE_OR_REALLOC_BEGIN(block) \ do \ @@ -341,11 +328,34 @@ #else /* ERROR_CHECK_MALLOC */ #define MALLOC_BEGIN() +#define MALLOC_WARNING_BEGIN() +#define MALLOC_WARNING_END() #define FREE_OR_REALLOC_BEGIN(block) #define MALLOC_END() #endif /* ERROR_CHECK_MALLOC */ +/* malloc calls this if it finds we are near exhausting storage */ +void +malloc_warning (const char *str) +{ + if (ignore_malloc_warnings) + return; + + MALLOC_WARNING_BEGIN(); + + warn_when_safe + (Qmemory, Qemergency, + "%s\n" + "Killing some buffers may delay running out of memory.\n" + "However, certainly by the time you receive the 95%% warning,\n" + "you should clean up, kill this Emacs, and start a new one.\n" + "On Unix, look into your resource limits; ulimit -d, especially.", + str); + + MALLOC_WARNING_END(); +} + static void malloc_after (void *val, Bytecount size) {