aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 28c9b51dab4..0f105f87207 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -761,13 +761,17 @@ xnrealloc (void *pa, ptrdiff_t nitems, ptrdiff_t item_size)
761 infinity. 761 infinity.
762 762
763 If PA is null, then allocate a new array instead of reallocating 763 If PA is null, then allocate a new array instead of reallocating
764 the old one. Thus, to grow an array A without saving its old 764 the old one.
765 contents, invoke xfree (A) immediately followed by xgrowalloc (0,
766 &NITEMS, ...).
767 765
768 Block interrupt input as needed. If memory exhaustion occurs, set 766 Block interrupt input as needed. If memory exhaustion occurs, set
769 *NITEMS to zero if PA is null, and signal an error (i.e., do not 767 *NITEMS to zero if PA is null, and signal an error (i.e., do not
770 return). */ 768 return).
769
770 Thus, to grow an array A without saving its old contents, do
771 { xfree (A); A = NULL; A = xpalloc (NULL, &AITEMS, ...); }.
772 The A = NULL avoids a dangling pointer if xpalloc exhausts memory
773 and signals an error, and later this code is reexecuted and
774 attempts to free A. */
771 775
772void * 776void *
773xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, 777xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
@@ -822,12 +826,7 @@ xstrdup (const char *s)
822Lisp_Object 826Lisp_Object
823safe_alloca_unwind (Lisp_Object arg) 827safe_alloca_unwind (Lisp_Object arg)
824{ 828{
825 register struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 829 free_save_value (arg);
826
827 p->dogc = 0;
828 xfree (p->pointer);
829 p->pointer = 0;
830 free_misc (arg);
831 return Qnil; 830 return Qnil;
832} 831}
833 832
@@ -3361,6 +3360,19 @@ make_save_value (void *pointer, ptrdiff_t integer)
3361 return val; 3360 return val;
3362} 3361}
3363 3362
3363/* Free a Lisp_Misc_Save_Value object. */
3364
3365void
3366free_save_value (Lisp_Object save)
3367{
3368 register struct Lisp_Save_Value *p = XSAVE_VALUE (save);
3369
3370 p->dogc = 0;
3371 xfree (p->pointer);
3372 p->pointer = NULL;
3373 free_misc (save);
3374}
3375
3364/* Return a Lisp_Misc_Overlay object with specified START, END and PLIST. */ 3376/* Return a Lisp_Misc_Overlay object with specified START, END and PLIST. */
3365 3377
3366Lisp_Object 3378Lisp_Object