diff options
| author | Dmitry Antipov | 2013-01-15 12:38:07 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2013-01-15 12:38:07 +0400 |
| commit | 1b971ac155006504b6b1c2688199747f976723af (patch) | |
| tree | 0e5f4dc8243cec3591ce8ee659b5babc0a6639f9 /src | |
| parent | cb9c0a53bc4a6d67f10d4674472b2884a71852c8 (diff) | |
| download | emacs-1b971ac155006504b6b1c2688199747f976723af.tar.gz emacs-1b971ac155006504b6b1c2688199747f976723af.zip | |
Some convenient bits to deal with Lisp_Save_Values.
* lisp.h (XSAVE_OBJECT): New macro to extract saved objects.
(allocate_misc): Remove prototype.
(format_save_value): New prototype.
* alloc.c (allocate_misc): Revert back to static.
(format_save_value): New function to build Lisp_Save_Value
object with the specified internal structure.
(make_save_value): Reimplement using format_save_value.
* editfns.c (save_excursion_save): Use format_save_value.
(save_excursion_restore): Use XSAVE_OBJECT.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/alloc.c | 68 | ||||
| -rw-r--r-- | src/editfns.c | 51 | ||||
| -rw-r--r-- | src/lisp.h | 8 |
4 files changed, 91 insertions, 49 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 80f5875ef16..34c137a35c6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2013-01-15 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Some convenient bits to deal with Lisp_Save_Values. | ||
| 4 | * lisp.h (XSAVE_OBJECT): New macro to extract saved objects. | ||
| 5 | (allocate_misc): Remove prototype. | ||
| 6 | (format_save_value): New prototype. | ||
| 7 | * alloc.c (allocate_misc): Revert back to static. | ||
| 8 | (format_save_value): New function to build Lisp_Save_Value | ||
| 9 | object with the specified internal structure. | ||
| 10 | (make_save_value): Reimplement using format_save_value. | ||
| 11 | * editfns.c (save_excursion_save): Use format_save_value. | ||
| 12 | (save_excursion_restore): Use XSAVE_OBJECT. | ||
| 13 | |||
| 1 | 2013-01-14 Paul Eggert <eggert@cs.ucla.edu> | 14 | 2013-01-14 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 15 | ||
| 3 | Avoid needless casts with XSAVE_POINTER. | 16 | Avoid needless casts with XSAVE_POINTER. |
diff --git a/src/alloc.c b/src/alloc.c index 3f1ccc82a58..e1cb97163ce 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3302,7 +3302,7 @@ static union Lisp_Misc *marker_free_list; | |||
| 3302 | 3302 | ||
| 3303 | /* Return a newly allocated Lisp_Misc object of specified TYPE. */ | 3303 | /* Return a newly allocated Lisp_Misc object of specified TYPE. */ |
| 3304 | 3304 | ||
| 3305 | Lisp_Object | 3305 | static Lisp_Object |
| 3306 | allocate_misc (enum Lisp_Misc_Type type) | 3306 | allocate_misc (enum Lisp_Misc_Type type) |
| 3307 | { | 3307 | { |
| 3308 | Lisp_Object val; | 3308 | Lisp_Object val; |
| @@ -3350,6 +3350,59 @@ free_misc (Lisp_Object misc) | |||
| 3350 | total_free_markers++; | 3350 | total_free_markers++; |
| 3351 | } | 3351 | } |
| 3352 | 3352 | ||
| 3353 | /* Return a Lisp_Save_Value object with the data saved according to | ||
| 3354 | FMT. Format specifiers are `i' for an integer, `p' for a pointer | ||
| 3355 | and `o' for Lisp_Object. Up to 4 objects can be specified. */ | ||
| 3356 | |||
| 3357 | Lisp_Object | ||
| 3358 | format_save_value (const char *fmt, ...) | ||
| 3359 | { | ||
| 3360 | va_list ap; | ||
| 3361 | int len = strlen (fmt); | ||
| 3362 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); | ||
| 3363 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); | ||
| 3364 | |||
| 3365 | eassert (0 < len && len < 5); | ||
| 3366 | va_start (ap, fmt); | ||
| 3367 | |||
| 3368 | #define INITX(index) \ | ||
| 3369 | do { \ | ||
| 3370 | if (len <= index) \ | ||
| 3371 | p->type ## index = SAVE_UNUSED; \ | ||
| 3372 | else \ | ||
| 3373 | { \ | ||
| 3374 | if (fmt[index] == 'i') \ | ||
| 3375 | { \ | ||
| 3376 | p->type ## index = SAVE_INTEGER; \ | ||
| 3377 | p->data[index].integer = va_arg (ap, ptrdiff_t); \ | ||
| 3378 | } \ | ||
| 3379 | else if (fmt[index] == 'p') \ | ||
| 3380 | { \ | ||
| 3381 | p->type ## index = SAVE_POINTER; \ | ||
| 3382 | p->data[index].pointer = va_arg (ap, void *); \ | ||
| 3383 | } \ | ||
| 3384 | else if (fmt[index] == 'o') \ | ||
| 3385 | { \ | ||
| 3386 | p->type ## index = SAVE_OBJECT; \ | ||
| 3387 | p->data[index].object = va_arg (ap, Lisp_Object); \ | ||
| 3388 | } \ | ||
| 3389 | else \ | ||
| 3390 | emacs_abort (); \ | ||
| 3391 | } \ | ||
| 3392 | } while (0) | ||
| 3393 | |||
| 3394 | INITX (0); | ||
| 3395 | INITX (1); | ||
| 3396 | INITX (2); | ||
| 3397 | INITX (3); | ||
| 3398 | |||
| 3399 | #undef INITX | ||
| 3400 | |||
| 3401 | va_end (ap); | ||
| 3402 | p->area = 0; | ||
| 3403 | return val; | ||
| 3404 | } | ||
| 3405 | |||
| 3353 | /* Return a Lisp_Save_Value object containing POINTER and INTEGER. | 3406 | /* Return a Lisp_Save_Value object containing POINTER and INTEGER. |
| 3354 | Most code should use this to package C integers and pointers | 3407 | Most code should use this to package C integers and pointers |
| 3355 | to call record_unwind_protect. The unwind function can get the | 3408 | to call record_unwind_protect. The unwind function can get the |
| @@ -3358,18 +3411,7 @@ free_misc (Lisp_Object misc) | |||
| 3358 | Lisp_Object | 3411 | Lisp_Object |
| 3359 | make_save_value (void *pointer, ptrdiff_t integer) | 3412 | make_save_value (void *pointer, ptrdiff_t integer) |
| 3360 | { | 3413 | { |
| 3361 | register Lisp_Object val; | 3414 | return format_save_value ("pi", pointer, integer); |
| 3362 | register struct Lisp_Save_Value *p; | ||
| 3363 | |||
| 3364 | val = allocate_misc (Lisp_Misc_Save_Value); | ||
| 3365 | p = XSAVE_VALUE (val); | ||
| 3366 | p->type0 = SAVE_POINTER; | ||
| 3367 | p->data[0].pointer = pointer; | ||
| 3368 | p->type1 = SAVE_INTEGER; | ||
| 3369 | p->data[1].integer = integer; | ||
| 3370 | p->type2 = p->type3 = SAVE_UNUSED; | ||
| 3371 | p->area = 0; | ||
| 3372 | return val; | ||
| 3373 | } | 3415 | } |
| 3374 | 3416 | ||
| 3375 | /* Free a Lisp_Save_Value object. Do not use this function | 3417 | /* Free a Lisp_Save_Value object. Do not use this function |
diff --git a/src/editfns.c b/src/editfns.c index feac17f64b8..3fe085caac8 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -833,31 +833,17 @@ This function does not move point. */) | |||
| 833 | Lisp_Object | 833 | Lisp_Object |
| 834 | save_excursion_save (void) | 834 | save_excursion_save (void) |
| 835 | { | 835 | { |
| 836 | Lisp_Object save = allocate_misc (Lisp_Misc_Save_Value); | 836 | return format_save_value |
| 837 | register struct Lisp_Save_Value *v = XSAVE_VALUE (save); | 837 | ("oooo", |
| 838 | 838 | Fpoint_marker (), | |
| 839 | /* Do not allocate extra space and pack everything in SAVE. */ | 839 | /* Do not copy the mark if it points to nowhere. */ |
| 840 | v->area = 0; | 840 | (XMARKER (BVAR (current_buffer, mark))->buffer |
| 841 | 841 | ? Fcopy_marker (BVAR (current_buffer, mark), Qnil) | |
| 842 | v->type0 = SAVE_OBJECT; | 842 | : Qnil), |
| 843 | v->data[0].object = Fpoint_marker (); | 843 | /* Selected window if current buffer is shown in it, nil otherwise. */ |
| 844 | 844 | ((XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer) | |
| 845 | /* Do not copy the mark if it points to nowhere. */ | 845 | ? selected_window : Qnil), |
| 846 | v->type1 = SAVE_OBJECT; | 846 | BVAR (current_buffer, mark_active)); |
| 847 | v->data[1].object = (XMARKER (BVAR (current_buffer, mark))->buffer | ||
| 848 | ? Fcopy_marker (BVAR (current_buffer, mark), Qnil) | ||
| 849 | : Qnil); | ||
| 850 | |||
| 851 | /* Selected window if current buffer is shown in it, nil otherwise. */ | ||
| 852 | v->type2 = SAVE_OBJECT; | ||
| 853 | v->data[2].object | ||
| 854 | = ((XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer) | ||
| 855 | ? selected_window : Qnil); | ||
| 856 | |||
| 857 | v->type3 = SAVE_OBJECT; | ||
| 858 | v->data[3].object = BVAR (current_buffer, mark_active); | ||
| 859 | |||
| 860 | return save; | ||
| 861 | } | 847 | } |
| 862 | 848 | ||
| 863 | /* Restore saved buffer before leaving `save-excursion' special form. */ | 849 | /* Restore saved buffer before leaving `save-excursion' special form. */ |
| @@ -867,13 +853,8 @@ save_excursion_restore (Lisp_Object info) | |||
| 867 | { | 853 | { |
| 868 | Lisp_Object tem, tem1, omark, nmark; | 854 | Lisp_Object tem, tem1, omark, nmark; |
| 869 | struct gcpro gcpro1, gcpro2, gcpro3; | 855 | struct gcpro gcpro1, gcpro2, gcpro3; |
| 870 | register struct Lisp_Save_Value *v = XSAVE_VALUE (info); | ||
| 871 | |||
| 872 | /* Paranoid. */ | ||
| 873 | eassert (v->type0 == SAVE_OBJECT && v->type1 == SAVE_OBJECT | ||
| 874 | && v->type2 == SAVE_OBJECT && v->type3 == SAVE_OBJECT); | ||
| 875 | 856 | ||
| 876 | tem = Fmarker_buffer (v->data[0].object); | 857 | tem = Fmarker_buffer (XSAVE_OBJECT (info, 0)); |
| 877 | /* If we're unwinding to top level, saved buffer may be deleted. This | 858 | /* If we're unwinding to top level, saved buffer may be deleted. This |
| 878 | means that all of its markers are unchained and so tem is nil. */ | 859 | means that all of its markers are unchained and so tem is nil. */ |
| 879 | if (NILP (tem)) | 860 | if (NILP (tem)) |
| @@ -885,12 +866,12 @@ save_excursion_restore (Lisp_Object info) | |||
| 885 | Fset_buffer (tem); | 866 | Fset_buffer (tem); |
| 886 | 867 | ||
| 887 | /* Point marker. */ | 868 | /* Point marker. */ |
| 888 | tem = v->data[0].object; | 869 | tem = XSAVE_OBJECT (info, 0); |
| 889 | Fgoto_char (tem); | 870 | Fgoto_char (tem); |
| 890 | unchain_marker (XMARKER (tem)); | 871 | unchain_marker (XMARKER (tem)); |
| 891 | 872 | ||
| 892 | /* Mark marker. */ | 873 | /* Mark marker. */ |
| 893 | tem = v->data[1].object; | 874 | tem = XSAVE_OBJECT (info, 1); |
| 894 | omark = Fmarker_position (BVAR (current_buffer, mark)); | 875 | omark = Fmarker_position (BVAR (current_buffer, mark)); |
| 895 | if (NILP (tem)) | 876 | if (NILP (tem)) |
| 896 | unchain_marker (XMARKER (BVAR (current_buffer, mark))); | 877 | unchain_marker (XMARKER (BVAR (current_buffer, mark))); |
| @@ -902,7 +883,7 @@ save_excursion_restore (Lisp_Object info) | |||
| 902 | } | 883 | } |
| 903 | 884 | ||
| 904 | /* Mark active. */ | 885 | /* Mark active. */ |
| 905 | tem = v->data[3].object; | 886 | tem = XSAVE_OBJECT (info, 3); |
| 906 | tem1 = BVAR (current_buffer, mark_active); | 887 | tem1 = BVAR (current_buffer, mark_active); |
| 907 | bset_mark_active (current_buffer, tem); | 888 | bset_mark_active (current_buffer, tem); |
| 908 | 889 | ||
| @@ -926,7 +907,7 @@ save_excursion_restore (Lisp_Object info) | |||
| 926 | /* If buffer was visible in a window, and a different window was | 907 | /* If buffer was visible in a window, and a different window was |
| 927 | selected, and the old selected window is still showing this | 908 | selected, and the old selected window is still showing this |
| 928 | buffer, restore point in that window. */ | 909 | buffer, restore point in that window. */ |
| 929 | tem = v->data[2].object; | 910 | tem = XSAVE_OBJECT (info, 2); |
| 930 | if (WINDOWP (tem) | 911 | if (WINDOWP (tem) |
| 931 | && !EQ (tem, selected_window) | 912 | && !EQ (tem, selected_window) |
| 932 | && (tem1 = XWINDOW (tem)->buffer, | 913 | && (tem1 = XWINDOW (tem)->buffer, |
diff --git a/src/lisp.h b/src/lisp.h index 7decd54c9d1..ac7346c5386 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -1421,6 +1421,12 @@ struct Lisp_Save_Value | |||
| 1421 | 1421 | ||
| 1422 | #define XSAVE_INTEGER(obj) XSAVE_VALUE (obj)->data[1].integer | 1422 | #define XSAVE_INTEGER(obj) XSAVE_VALUE (obj)->data[1].integer |
| 1423 | 1423 | ||
| 1424 | /* Macro to extract Nth saved object. */ | ||
| 1425 | |||
| 1426 | #define XSAVE_OBJECT(obj, n) \ | ||
| 1427 | (eassert (XSAVE_VALUE (obj)->type ## n == SAVE_OBJECT), \ | ||
| 1428 | XSAVE_VALUE (obj)->data[n].object) | ||
| 1429 | |||
| 1424 | /* A miscellaneous object, when it's on the free list. */ | 1430 | /* A miscellaneous object, when it's on the free list. */ |
| 1425 | struct Lisp_Free | 1431 | struct Lisp_Free |
| 1426 | { | 1432 | { |
| @@ -2921,7 +2927,6 @@ extern void memory_warnings (void *, void (*warnfun) (const char *)); | |||
| 2921 | 2927 | ||
| 2922 | /* Defined in alloc.c. */ | 2928 | /* Defined in alloc.c. */ |
| 2923 | extern void check_pure_size (void); | 2929 | extern void check_pure_size (void); |
| 2924 | extern Lisp_Object allocate_misc (enum Lisp_Misc_Type); | ||
| 2925 | extern void free_misc (Lisp_Object); | 2930 | extern void free_misc (Lisp_Object); |
| 2926 | extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT); | 2931 | extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT); |
| 2927 | extern void malloc_warning (const char *); | 2932 | extern void malloc_warning (const char *); |
| @@ -3007,6 +3012,7 @@ extern bool abort_on_gc; | |||
| 3007 | extern Lisp_Object make_float (double); | 3012 | extern Lisp_Object make_float (double); |
| 3008 | extern void display_malloc_warning (void); | 3013 | extern void display_malloc_warning (void); |
| 3009 | extern ptrdiff_t inhibit_garbage_collection (void); | 3014 | extern ptrdiff_t inhibit_garbage_collection (void); |
| 3015 | extern Lisp_Object format_save_value (const char *, ...); | ||
| 3010 | extern Lisp_Object make_save_value (void *, ptrdiff_t); | 3016 | extern Lisp_Object make_save_value (void *, ptrdiff_t); |
| 3011 | extern void free_save_value (Lisp_Object); | 3017 | extern void free_save_value (Lisp_Object); |
| 3012 | extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); | 3018 | extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); |