aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorBill Wohler2012-12-08 17:19:00 -0800
committerBill Wohler2012-12-08 17:19:00 -0800
commite1b489df7af8f7034f8c2ef275b786e93a39df31 (patch)
tree2edc9307185e2c77b98fe75f6d7eb0476c58c7e3 /src/alloc.c
parentce974958f93ffa2e1bd01b4dd85dcb8ec1395787 (diff)
parentc6c08d3f8fe4d2c9e588189e46d60a30ef3e8d20 (diff)
downloademacs-e1b489df7af8f7034f8c2ef275b786e93a39df31.tar.gz
emacs-e1b489df7af8f7034f8c2ef275b786e93a39df31.zip
Merge from trunk; up to 2012-12-09T01:04:43Z!rgm@gnu.org.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 28c9b51dab4..5a3ba465d81 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,
@@ -816,18 +820,22 @@ xstrdup (const char *s)
816 return p; 820 return p;
817} 821}
818 822
823/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
824 argument is a const pointer. */
825
826void
827xputenv (char const *string)
828{
829 if (putenv ((char *) string) != 0)
830 memory_full (0);
831}
819 832
820/* Unwind for SAFE_ALLOCA */ 833/* Unwind for SAFE_ALLOCA */
821 834
822Lisp_Object 835Lisp_Object
823safe_alloca_unwind (Lisp_Object arg) 836safe_alloca_unwind (Lisp_Object arg)
824{ 837{
825 register struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 838 free_save_value (arg);
826
827 p->dogc = 0;
828 xfree (p->pointer);
829 p->pointer = 0;
830 free_misc (arg);
831 return Qnil; 839 return Qnil;
832} 840}
833 841
@@ -3361,6 +3369,19 @@ make_save_value (void *pointer, ptrdiff_t integer)
3361 return val; 3369 return val;
3362} 3370}
3363 3371
3372/* Free a Lisp_Misc_Save_Value object. */
3373
3374void
3375free_save_value (Lisp_Object save)
3376{
3377 register struct Lisp_Save_Value *p = XSAVE_VALUE (save);
3378
3379 p->dogc = 0;
3380 xfree (p->pointer);
3381 p->pointer = NULL;
3382 free_misc (save);
3383}
3384
3364/* Return a Lisp_Misc_Overlay object with specified START, END and PLIST. */ 3385/* Return a Lisp_Misc_Overlay object with specified START, END and PLIST. */
3365 3386
3366Lisp_Object 3387Lisp_Object