comparison src/alloc.c @ 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 141c2920ea48
children 1c2a4e4e81d9
comparison
equal deleted inserted replaced
3169:5bfedec8927e 3170:db0631f96757
229 xfree (tmp, void *); 229 xfree (tmp, void *);
230 } 230 }
231 } 231 }
232 #endif /* not MC_ALLOC */ 232 #endif /* not MC_ALLOC */
233 233
234 /* malloc calls this if it finds we are near exhausting storage */
235 void
236 malloc_warning (const char *str)
237 {
238 if (ignore_malloc_warnings)
239 return;
240
241 warn_when_safe
242 (Qmemory, Qemergency,
243 "%s\n"
244 "Killing some buffers may delay running out of memory.\n"
245 "However, certainly by the time you receive the 95%% warning,\n"
246 "you should clean up, kill this Emacs, and start a new one.",
247 str);
248 }
249
250 /* Called if malloc returns zero */ 234 /* Called if malloc returns zero */
251 DOESNT_RETURN 235 DOESNT_RETURN
252 memory_full (void) 236 memory_full (void)
253 { 237 {
254 fprintf (stderr, "##### M E M O R Y F U L L #####\n"); 238 fprintf (stderr, "##### M E M O R Y F U L L #####\n");
288 if ((char *) val < (char *) minimum_address_seen) 272 if ((char *) val < (char *) minimum_address_seen)
289 minimum_address_seen = (char *) val; 273 minimum_address_seen = (char *) val;
290 } 274 }
291 275
292 #ifdef ERROR_CHECK_MALLOC 276 #ifdef ERROR_CHECK_MALLOC
293 static int in_malloc; 277 static int in_malloc, in_malloc_warning;
294 extern int regex_malloc_disallowed; 278 extern int regex_malloc_disallowed;
295 279
296 #define MALLOC_BEGIN() \ 280 #define MALLOC_BEGIN() \
297 do \ 281 do \
298 { \ 282 { \
299 assert (!in_malloc); \ 283 assert (!in_malloc || in_malloc_warning); \
300 assert (!regex_malloc_disallowed); \ 284 assert (!regex_malloc_disallowed); \
301 in_malloc = 1; \ 285 in_malloc = 1; \
302 } \ 286 } \
303 while (0) 287 while (0)
288
289 #define MALLOC_WARNING_BEGIN() (++in_malloc_warning)
290 #define MALLOC_WARNING_END() (--in_malloc_warning)
304 291
305 #ifdef MC_ALLOC 292 #ifdef MC_ALLOC
306 #define FREE_OR_REALLOC_BEGIN(block) \ 293 #define FREE_OR_REALLOC_BEGIN(block) \
307 do \ 294 do \
308 { \ 295 { \
339 while (0) 326 while (0)
340 327
341 #else /* ERROR_CHECK_MALLOC */ 328 #else /* ERROR_CHECK_MALLOC */
342 329
343 #define MALLOC_BEGIN() 330 #define MALLOC_BEGIN()
331 #define MALLOC_WARNING_BEGIN()
332 #define MALLOC_WARNING_END()
344 #define FREE_OR_REALLOC_BEGIN(block) 333 #define FREE_OR_REALLOC_BEGIN(block)
345 #define MALLOC_END() 334 #define MALLOC_END()
346 335
347 #endif /* ERROR_CHECK_MALLOC */ 336 #endif /* ERROR_CHECK_MALLOC */
337
338 /* malloc calls this if it finds we are near exhausting storage */
339 void
340 malloc_warning (const char *str)
341 {
342 if (ignore_malloc_warnings)
343 return;
344
345 MALLOC_WARNING_BEGIN();
346
347 warn_when_safe
348 (Qmemory, Qemergency,
349 "%s\n"
350 "Killing some buffers may delay running out of memory.\n"
351 "However, certainly by the time you receive the 95%% warning,\n"
352 "you should clean up, kill this Emacs, and start a new one.\n"
353 "On Unix, look into your resource limits; ulimit -d, especially.",
354 str);
355
356 MALLOC_WARNING_END();
357 }
348 358
349 static void 359 static void
350 malloc_after (void *val, Bytecount size) 360 malloc_after (void *val, Bytecount size)
351 { 361 {
352 if (!val && size != 0) 362 if (!val && size != 0)