comparison src/alloc.c @ 28411:ecba29fa0198

(xstrdup): Moved here from xfaces.c. (allocating_for_lisp): Variable removed. (lisp_malloc): Block input around the calls to malloc and mem_insert.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 30 Mar 2000 09:29:22 +0000
parents 451721e784a8
children f66f2b4d5eb7
comparison
equal deleted inserted replaced
28410:2812a333e746 28411:ecba29fa0198
167 #define SPARE_MEMORY (1 << 14) 167 #define SPARE_MEMORY (1 << 14)
168 168
169 /* Number of extra blocks malloc should get when it needs more core. */ 169 /* Number of extra blocks malloc should get when it needs more core. */
170 170
171 static int malloc_hysteresis; 171 static int malloc_hysteresis;
172
173 /* Nonzero when malloc is called for allocating Lisp object space.
174 Currently set but not used. */
175
176 int allocating_for_lisp;
177 172
178 /* Non-nil means defun should do purecopy on the function definition. */ 173 /* Non-nil means defun should do purecopy on the function definition. */
179 174
180 Lisp_Object Vpurify_flag; 175 Lisp_Object Vpurify_flag;
181 176
462 free (block); 457 free (block);
463 UNBLOCK_INPUT; 458 UNBLOCK_INPUT;
464 } 459 }
465 460
466 461
462 /* Like strdup, but uses xmalloc. */
463
464 char *
465 xstrdup (s)
466 char *s;
467 {
468 int len = strlen (s) + 1;
469 char *p = (char *) xmalloc (len);
470 bcopy (s, p, len);
471 return p;
472 }
473
474
467 /* Like malloc but used for allocating Lisp data. NBYTES is the 475 /* Like malloc but used for allocating Lisp data. NBYTES is the
468 number of bytes to allocate, TYPE describes the intended use of the 476 number of bytes to allocate, TYPE describes the intended use of the
469 allcated memory block (for strings, for conses, ...). */ 477 allcated memory block (for strings, for conses, ...). */
470 478
471 static void * 479 static void *
474 enum mem_type type; 482 enum mem_type type;
475 { 483 {
476 register void *val; 484 register void *val;
477 485
478 BLOCK_INPUT; 486 BLOCK_INPUT;
479 allocating_for_lisp++;
480 val = (void *) malloc (nbytes); 487 val = (void *) malloc (nbytes);
481 allocating_for_lisp--; 488
482 UNBLOCK_INPUT;
483
484 if (!val && nbytes)
485 memory_full ();
486
487 #if GC_MARK_STACK 489 #if GC_MARK_STACK
488 if (type != MEM_TYPE_NON_LISP) 490 if (val && type != MEM_TYPE_NON_LISP)
489 mem_insert (val, (char *) val + nbytes, type); 491 mem_insert (val, (char *) val + nbytes, type);
490 #endif 492 #endif
491 493
494 UNBLOCK_INPUT;
495 if (!val && nbytes)
496 memory_full ();
492 return val; 497 return val;
493 } 498 }
494 499
495 500
496 /* Return a new buffer structure allocated from the heap with 501 /* Return a new buffer structure allocated from the heap with
510 void 515 void
511 lisp_free (block) 516 lisp_free (block)
512 long *block; 517 long *block;
513 { 518 {
514 BLOCK_INPUT; 519 BLOCK_INPUT;
515 allocating_for_lisp++;
516 free (block); 520 free (block);
517 #if GC_MARK_STACK 521 #if GC_MARK_STACK
518 mem_delete (mem_find (block)); 522 mem_delete (mem_find (block));
519 #endif 523 #endif
520 allocating_for_lisp--;
521 UNBLOCK_INPUT; 524 UNBLOCK_INPUT;
522 } 525 }
523 526
524 527
525 /* Arranging to disable input signals while we're in malloc. 528 /* Arranging to disable input signals while we're in malloc.