diff options
| author | Dmitry Antipov | 2013-01-14 13:55:21 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2013-01-14 13:55:21 +0400 |
| commit | 73ebd38f16c4799b657e501f188e9f3a3eca7805 (patch) | |
| tree | 2584576d6931b14b336ac4ed3eb9eb513892da2c /src/alloc.c | |
| parent | d6d02e06ee135655b604a12b0c53987988277a16 (diff) | |
| download | emacs-73ebd38f16c4799b657e501f188e9f3a3eca7805.tar.gz emacs-73ebd38f16c4799b657e501f188e9f3a3eca7805.zip | |
Make Lisp_Save_Value more versatile storage for up to four objects.
* lisp.h (toplevel): Enumeration to describe types of saved objects.
(struct Lisp_Save_Value): New layout. Adjust comments.
(XSAVE_POINTER): New macro.
(XSAVE_INTEGER): Likewise.
(allocate_misc): Add prototype.
(free_misc): Likewise.
* alloc.c (allocate_misc): Now global.
(free_misc): Likewise. Adjust comment.
(make_save_value): Use new Lisp_Save_Value layout. Adjust comment.
(free_save_value): Likewise.
(mark_object): Likewise.
* editfns.c (save_excursion_save): Pack everything within
Lisp_Save_Value and so avoid xmalloc.
(save_excursion_restore): Adjust to match new layout. Use free_misc
because we do not allocate extra memory any more. Add eassert.
* print.c (print_object): New code to print Lisp_Save_Value. Do not
rely on valid_lisp_object_p if !GC_MARK_STACK. Adjust comments.
* dired.c, fileio.c, font.c, ftfont.c, gtkutil.c, keymap.c,
* lread.c, nsmenu.m, nsterm.h, xfns.c, xmenu.c, xselect.c:
Use XSAVE_POINTER and XSAVE_INTEGER where appropriate.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/alloc.c b/src/alloc.c index b147aa20723..c50bb0f32c7 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -219,7 +219,6 @@ static void refill_memory_reserve (void); | |||
| 219 | #endif | 219 | #endif |
| 220 | static void compact_small_strings (void); | 220 | static void compact_small_strings (void); |
| 221 | static void free_large_strings (void); | 221 | static void free_large_strings (void); |
| 222 | static void free_misc (Lisp_Object); | ||
| 223 | extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE; | 222 | extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE; |
| 224 | 223 | ||
| 225 | /* When scanning the C stack for live Lisp objects, Emacs keeps track of | 224 | /* When scanning the C stack for live Lisp objects, Emacs keeps track of |
| @@ -3303,7 +3302,7 @@ static union Lisp_Misc *marker_free_list; | |||
| 3303 | 3302 | ||
| 3304 | /* Return a newly allocated Lisp_Misc object of specified TYPE. */ | 3303 | /* Return a newly allocated Lisp_Misc object of specified TYPE. */ |
| 3305 | 3304 | ||
| 3306 | static Lisp_Object | 3305 | Lisp_Object |
| 3307 | allocate_misc (enum Lisp_Misc_Type type) | 3306 | allocate_misc (enum Lisp_Misc_Type type) |
| 3308 | { | 3307 | { |
| 3309 | Lisp_Object val; | 3308 | Lisp_Object val; |
| @@ -3339,9 +3338,9 @@ allocate_misc (enum Lisp_Misc_Type type) | |||
| 3339 | return val; | 3338 | return val; |
| 3340 | } | 3339 | } |
| 3341 | 3340 | ||
| 3342 | /* Free a Lisp_Misc object */ | 3341 | /* Free a Lisp_Misc object. */ |
| 3343 | 3342 | ||
| 3344 | static void | 3343 | void |
| 3345 | free_misc (Lisp_Object misc) | 3344 | free_misc (Lisp_Object misc) |
| 3346 | { | 3345 | { |
| 3347 | XMISCTYPE (misc) = Lisp_Misc_Free; | 3346 | XMISCTYPE (misc) = Lisp_Misc_Free; |
| @@ -3351,9 +3350,10 @@ free_misc (Lisp_Object misc) | |||
| 3351 | total_free_markers++; | 3350 | total_free_markers++; |
| 3352 | } | 3351 | } |
| 3353 | 3352 | ||
| 3354 | /* Return a Lisp_Misc_Save_Value object containing POINTER and | 3353 | /* Return a Lisp_Save_Value object containing POINTER and INTEGER. |
| 3355 | INTEGER. This is used to package C values to call record_unwind_protect. | 3354 | Most code should use this to package C integers and pointers |
| 3356 | The unwind function can get the C values back using XSAVE_VALUE. */ | 3355 | to call record_unwind_protect. The unwind function can get the |
| 3356 | C values back using XSAVE_POINTER and XSAVE_INTEGER. */ | ||
| 3357 | 3357 | ||
| 3358 | Lisp_Object | 3358 | Lisp_Object |
| 3359 | make_save_value (void *pointer, ptrdiff_t integer) | 3359 | make_save_value (void *pointer, ptrdiff_t integer) |
| @@ -3363,22 +3363,22 @@ make_save_value (void *pointer, ptrdiff_t integer) | |||
| 3363 | 3363 | ||
| 3364 | val = allocate_misc (Lisp_Misc_Save_Value); | 3364 | val = allocate_misc (Lisp_Misc_Save_Value); |
| 3365 | p = XSAVE_VALUE (val); | 3365 | p = XSAVE_VALUE (val); |
| 3366 | p->pointer = pointer; | 3366 | p->type0 = SAVE_POINTER; |
| 3367 | p->integer = integer; | 3367 | p->data[0].pointer = pointer; |
| 3368 | p->dogc = 0; | 3368 | p->type1 = SAVE_INTEGER; |
| 3369 | p->data[1].integer = integer; | ||
| 3370 | p->type2 = p->type3 = SAVE_UNUSED; | ||
| 3371 | p->area = 0; | ||
| 3369 | return val; | 3372 | return val; |
| 3370 | } | 3373 | } |
| 3371 | 3374 | ||
| 3372 | /* Free a Lisp_Misc_Save_Value object. */ | 3375 | /* Free a Lisp_Save_Value object. Do not use this function |
| 3376 | if SAVE contains pointer other than returned by xmalloc. */ | ||
| 3373 | 3377 | ||
| 3374 | void | 3378 | void |
| 3375 | free_save_value (Lisp_Object save) | 3379 | free_save_value (Lisp_Object save) |
| 3376 | { | 3380 | { |
| 3377 | register struct Lisp_Save_Value *p = XSAVE_VALUE (save); | 3381 | xfree (XSAVE_POINTER (save)); |
| 3378 | |||
| 3379 | p->dogc = 0; | ||
| 3380 | xfree (p->pointer); | ||
| 3381 | p->pointer = NULL; | ||
| 3382 | free_misc (save); | 3382 | free_misc (save); |
| 3383 | } | 3383 | } |
| 3384 | 3384 | ||
| @@ -5935,20 +5935,33 @@ mark_object (Lisp_Object arg) | |||
| 5935 | 5935 | ||
| 5936 | case Lisp_Misc_Save_Value: | 5936 | case Lisp_Misc_Save_Value: |
| 5937 | XMISCANY (obj)->gcmarkbit = 1; | 5937 | XMISCANY (obj)->gcmarkbit = 1; |
| 5938 | #if GC_MARK_STACK | ||
| 5939 | { | 5938 | { |
| 5940 | register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); | 5939 | register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); |
| 5941 | /* If DOGC is set, POINTER is the address of a memory | 5940 | /* If `area' is nonzero, `data[0].pointer' is the address |
| 5942 | area containing INTEGER potential Lisp_Objects. */ | 5941 | of a memory area containing `data[1].integer' potential |
| 5943 | if (ptr->dogc) | 5942 | Lisp_Objects. */ |
| 5943 | #if GC_MARK_STACK | ||
| 5944 | if (ptr->area) | ||
| 5944 | { | 5945 | { |
| 5945 | Lisp_Object *p = (Lisp_Object *) ptr->pointer; | 5946 | Lisp_Object *p = (Lisp_Object *) ptr->data[0].pointer; |
| 5946 | ptrdiff_t nelt; | 5947 | ptrdiff_t nelt; |
| 5947 | for (nelt = ptr->integer; nelt > 0; nelt--, p++) | 5948 | for (nelt = ptr->data[1].integer; nelt > 0; nelt--, p++) |
| 5948 | mark_maybe_object (*p); | 5949 | mark_maybe_object (*p); |
| 5949 | } | 5950 | } |
| 5951 | else | ||
| 5952 | #endif /* GC_MARK_STACK */ | ||
| 5953 | { | ||
| 5954 | /* Find Lisp_Objects in `data[N]' slots and mark them. */ | ||
| 5955 | if (ptr->type0 == SAVE_OBJECT) | ||
| 5956 | mark_object (ptr->data[0].object); | ||
| 5957 | if (ptr->type1 == SAVE_OBJECT) | ||
| 5958 | mark_object (ptr->data[1].object); | ||
| 5959 | if (ptr->type2 == SAVE_OBJECT) | ||
| 5960 | mark_object (ptr->data[2].object); | ||
| 5961 | if (ptr->type3 == SAVE_OBJECT) | ||
| 5962 | mark_object (ptr->data[3].object); | ||
| 5963 | } | ||
| 5950 | } | 5964 | } |
| 5951 | #endif | ||
| 5952 | break; | 5965 | break; |
| 5953 | 5966 | ||
| 5954 | case Lisp_Misc_Overlay: | 5967 | case Lisp_Misc_Overlay: |