diff options
| author | Joakim Verona | 2012-12-04 01:46:34 +0100 |
|---|---|---|
| committer | Joakim Verona | 2012-12-04 01:46:34 +0100 |
| commit | d28fde00abbbf26b7c80700b1c9bc18b5079a30e (patch) | |
| tree | 3bf606901b01f67d6b2eed3998ac6fae9f4518a8 /src/alloc.c | |
| parent | fa8510a9aabe34d367d935b960eab0abbf060e18 (diff) | |
| parent | c38a186c2e06e0a351d166c5ef06d7307e145f45 (diff) | |
| download | emacs-d28fde00abbbf26b7c80700b1c9bc18b5079a30e.tar.gz emacs-d28fde00abbbf26b7c80700b1c9bc18b5079a30e.zip | |
auto upstream
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 32 |
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 | ||
| 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, |
| @@ -822,12 +826,7 @@ xstrdup (const char *s) | |||
| 822 | Lisp_Object | 826 | Lisp_Object |
| 823 | safe_alloca_unwind (Lisp_Object arg) | 827 | safe_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 | |||
| 3365 | void | ||
| 3366 | free_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 | ||
| 3366 | Lisp_Object | 3378 | Lisp_Object |