diff options
| author | Bill Wohler | 2012-12-08 17:19:00 -0800 |
|---|---|---|
| committer | Bill Wohler | 2012-12-08 17:19:00 -0800 |
| commit | e1b489df7af8f7034f8c2ef275b786e93a39df31 (patch) | |
| tree | 2edc9307185e2c77b98fe75f6d7eb0476c58c7e3 /src/alloc.c | |
| parent | ce974958f93ffa2e1bd01b4dd85dcb8ec1395787 (diff) | |
| parent | c6c08d3f8fe4d2c9e588189e46d60a30ef3e8d20 (diff) | |
| download | emacs-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.c | 41 |
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 | ||
| 772 | void * | 776 | void * |
| 773 | xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, | 777 | xpalloc (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 | |||
| 826 | void | ||
| 827 | xputenv (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 | ||
| 822 | Lisp_Object | 835 | Lisp_Object |
| 823 | safe_alloca_unwind (Lisp_Object arg) | 836 | safe_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 | |||
| 3374 | void | ||
| 3375 | free_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 | ||
| 3366 | Lisp_Object | 3387 | Lisp_Object |