diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 16 | ||||
-rw-r--r-- | src/alloc.c | 20 | ||||
-rw-r--r-- | src/dired.c | 4 | ||||
-rw-r--r-- | src/editfns.c | 4 | ||||
-rw-r--r-- | src/fileio.c | 4 | ||||
-rw-r--r-- | src/font.c | 2 | ||||
-rw-r--r-- | src/ftfont.c | 2 | ||||
-rw-r--r-- | src/gtkutil.c | 2 | ||||
-rw-r--r-- | src/keymap.c | 2 | ||||
-rw-r--r-- | src/lisp.h | 63 | ||||
-rw-r--r-- | src/lread.c | 2 | ||||
-rw-r--r-- | src/nsmenu.m | 2 | ||||
-rw-r--r-- | src/nsterm.m | 2 | ||||
-rw-r--r-- | src/xfns.c | 2 | ||||
-rw-r--r-- | src/xmenu.c | 10 | ||||
-rw-r--r-- | src/xselect.c | 2 |
16 files changed, 101 insertions, 38 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 316995bf20b..c85e0a789ea 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,21 @@ 2013-01-17 Dmitry Antipov <dmantipov@yandex.ru> + * lisp.h (toplevel): Add comment about using Lisp_Save_Value + objects, related functions and macros. + (make_save_value): Adjust prototype. + (make_save_pointer): New prototype. + (SAFE_NALLOCA): Fix indentation. Use make_save_pointer. + (SAFE_ALLOCA_LISP): Adjust make_save_value usage. + * alloc.c (format_save_value): Rename to make_save_value. + (make_save_pointer): New function. + (record_xmalloc): Use make_save_pointer. + * dired.c, editfns.c, fileio.c, font.c, gtkutil.c, lread.c: + * nsmenu.m, nsterm.m, xfns.c, xmenu.c, xselect.c, keymap.c: + Change users of make_save_value to make_save_pointer. + Likewise for format_save_value and make_save_value. + +2013-01-17 Dmitry Antipov <dmantipov@yandex.ru> + * buffer.h (NARROWED, BUF_NARROWED): Drop unused macros. (DECODE_POSITION, BUFFER_CHECK_INDIRECTION): Fix indentation. * buffer.c (toplevel, syms_of_buffer): Drop old commented-out diff --git a/src/alloc.c b/src/alloc.c index 7275a01bb73..a2e7282bb60 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -845,7 +845,7 @@ void * record_xmalloc (size_t size) { void *p = xmalloc (size); - record_unwind_protect (safe_alloca_unwind, make_save_value (p, 0)); + record_unwind_protect (safe_alloca_unwind, make_save_pointer (p)); return p; } @@ -3356,7 +3356,7 @@ free_misc (Lisp_Object misc) and `o' for Lisp_Object. Up to 4 objects can be specified. */ Lisp_Object -format_save_value (const char *fmt, ...) +make_save_value (const char *fmt, ...) { va_list ap; int len = strlen (fmt); @@ -3404,15 +3404,19 @@ format_save_value (const char *fmt, ...) return val; } -/* Return a Lisp_Save_Value object containing POINTER and INTEGER. - Most code should use this to package C integers and pointers - to call record_unwind_protect. The unwind function can get the - C values back using XSAVE_POINTER and XSAVE_INTEGER. */ +/* The most common task it to save just one C pointer. */ Lisp_Object -make_save_value (void *pointer, ptrdiff_t integer) +make_save_pointer (void *pointer) { - return format_save_value ("pi", pointer, integer); + Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); + struct Lisp_Save_Value *p = XSAVE_VALUE (val); + + p->area = 0; + p->type0 = SAVE_POINTER; + p->data[0].pointer = pointer; + p->type1 = p->type2 = p->type3 = SAVE_UNUSED; + return val; } /* Free a Lisp_Save_Value object. Do not use this function diff --git a/src/dired.c b/src/dired.c index 3dca9d24f67..a4c8621e9c0 100644 --- a/src/dired.c +++ b/src/dired.c @@ -152,7 +152,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, file-attributes on filenames, both of which can throw, so we must do a proper unwind-protect. */ record_unwind_protect (directory_files_internal_unwind, - make_save_value (d, 0)); + make_save_pointer (d)); #ifdef WINDOWSNT if (attrs) @@ -465,7 +465,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, report_file_error ("Opening directory", Fcons (dirname, Qnil)); record_unwind_protect (directory_files_internal_unwind, - make_save_value (d, 0)); + make_save_pointer (d)); /* Loop reading blocks */ /* (att3b compiler bug requires do a null comparison this way) */ diff --git a/src/editfns.c b/src/editfns.c index 8910b66e4d3..197950517b7 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -833,7 +833,7 @@ This function does not move point. */) Lisp_Object save_excursion_save (void) { - return format_save_value + return make_save_value ("oooo", Fpoint_marker (), /* Do not copy the mark if it points to nowhere. */ @@ -4249,7 +4249,7 @@ usage: (format STRING &rest OBJECTS) */) { buf = xmalloc (bufsize); sa_must_free = 1; - buf_save_value = make_save_value (buf, 0); + buf_save_value = make_save_pointer (buf); record_unwind_protect (safe_alloca_unwind, buf_save_value); memcpy (buf, initial_buffer, used); } diff --git a/src/fileio.c b/src/fileio.c index 87d945c1e5e..8d711e8e6bf 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4249,7 +4249,7 @@ by calling `format-decode', which see. */) to be signaled after decoding the text we read. */ nbytes = internal_condition_case_1 (read_non_regular, - format_save_value ("iii", (ptrdiff_t) fd, inserted, trytry), + make_save_value ("iii", (ptrdiff_t) fd, inserted, trytry), Qerror, read_non_regular_quit); if (NILP (nbytes)) @@ -5608,7 +5608,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) } record_unwind_protect (do_auto_save_unwind, - make_save_value (stream, 0)); + make_save_pointer (stream)); record_unwind_protect (do_auto_save_unwind_1, make_number (minibuffer_auto_raise)); minibuffer_auto_raise = 0; diff --git a/src/font.c b/src/font.c index 89931f6ec76..18caf751643 100644 --- a/src/font.c +++ b/src/font.c @@ -1861,7 +1861,7 @@ otf_open (Lisp_Object file) else { otf = STRINGP (file) ? OTF_open (SSDATA (file)) : NULL; - val = make_save_value (otf, 0); + val = make_save_pointer (otf); otf_list = Fcons (Fcons (file, val), otf_list); } return otf; diff --git a/src/ftfont.c b/src/ftfont.c index 5bf91832c7c..03e40bf2e46 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -393,7 +393,7 @@ ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for) cache_data = xmalloc (sizeof *cache_data); cache_data->ft_face = NULL; cache_data->fc_charset = NULL; - val = make_save_value (cache_data, 0); + val = make_save_value ("pi", cache_data, 0); cache = Fcons (Qnil, val); Fputhash (key, cache, ft_face_cache); } diff --git a/src/gtkutil.c b/src/gtkutil.c index f045deacd33..d5bc159c063 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1716,7 +1716,7 @@ xg_dialog_run (FRAME_PTR f, GtkWidget *w) g_signal_connect (G_OBJECT (w), "delete-event", G_CALLBACK (gtk_true), NULL); gtk_widget_show (w); - record_unwind_protect (pop_down_dialog, make_save_value (&dd, 0)); + record_unwind_protect (pop_down_dialog, make_save_pointer (&dd)); (void) xg_maybe_add_timer (&dd); g_main_loop_run (dd.loop); diff --git a/src/keymap.c b/src/keymap.c index a9266120e86..1e201e06dc3 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -610,7 +610,7 @@ map_keymap_internal (Lisp_Object map, } else if (CHAR_TABLE_P (binding)) map_char_table (map_keymap_char_table_item, Qnil, binding, - format_save_value ("ppo", fun, data, args)); + make_save_value ("ppo", fun, data, args)); } UNGCPRO; return tail; diff --git a/src/lisp.h b/src/lisp.h index 40e4821bc10..5c81bc5dd8a 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1388,7 +1388,50 @@ enum SAVE_OBJECT }; -/* Special object used to hold a different values for later use. */ +/* Special object used to hold a different values for later use. + + This is mostly used to package C integers and pointers to call + record_unwind_protect. Typical task is to pass just one C pointer + to unwind function. You should pack pointer with make_save_pointer + and then get it back with XSAVE_POINTER, e.g.: + + ... + struct my_data *md = get_my_data (); + record_unwind_protect (my_unwind, make_save_pointer (md)); + ... + + Lisp_Object my_unwind (Lisp_Object arg) + { + struct my_data *md = XSAVE_POINTER (arg, 0); + ... + } + + If yon need to pass more than just one C pointer, you should + use make_save_value. This function allows you to pack up to + 4 integers, pointers or Lisp_Objects and conveniently get them + back with XSAVE_POINTER, XSAVE_INTEGER and XSAVE_OBJECT macros: + + ... + struct my_data *md = get_my_data (); + ptrdiff_t my_offset = get_my_offset (); + Lisp_Object my_object = get_my_object (); + record_unwind_protect + (my_unwind, make_save_value ("pio", md, my_offset, my_object)); + ... + + Lisp_Object my_unwind (Lisp_Object arg) + { + struct my_data *md = XSAVE_POINTER (arg, 0); + ptrdiff_t my_offset = XSAVE_INTEGER (arg, 1); + Lisp_Object my_object = XSAVE_OBJECT (arg, 2); + ... + } + + If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the + saved objects and raise eassert if type of the saved object doesn't match + the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2) + or XSAVE_OBJECT (arg, 1) are wrong because integer was saved in slot 1 and + Lisp_Object was saved in slot 2 of ARG. */ struct Lisp_Save_Value { @@ -3018,8 +3061,8 @@ extern bool abort_on_gc; extern Lisp_Object make_float (double); extern void display_malloc_warning (void); extern ptrdiff_t inhibit_garbage_collection (void); -extern Lisp_Object format_save_value (const char *, ...); -extern Lisp_Object make_save_value (void *, ptrdiff_t); +extern Lisp_Object make_save_value (const char *, ...); +extern Lisp_Object make_save_pointer (void *); extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); extern void free_marker (Lisp_Object); extern void free_cons (struct Lisp_Cons *); @@ -3701,16 +3744,16 @@ extern void *record_xmalloc (size_t); NITEMS items, each of the same type as *BUF. MULTIPLIER must positive. The code is tuned for MULTIPLIER being a constant. */ -#define SAFE_NALLOCA(buf, multiplier, nitems) \ - do { \ - if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \ - (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \ - else \ +#define SAFE_NALLOCA(buf, multiplier, nitems) \ + do { \ + if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \ + (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \ + else \ { \ (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \ sa_must_free = 1; \ record_unwind_protect (safe_alloca_unwind, \ - make_save_value (buf, 0)); \ + make_save_pointer (buf)); \ } \ } while (0) @@ -3735,7 +3778,7 @@ extern void *record_xmalloc (size_t); { \ Lisp_Object arg_; \ buf = xmalloc ((nelt) * word_size); \ - arg_ = make_save_value (buf, nelt); \ + arg_ = make_save_value ("pi", buf, nelt); \ XSAVE_VALUE (arg_)->area = 1; \ sa_must_free = 1; \ record_unwind_protect (safe_alloca_unwind, arg_); \ diff --git a/src/lread.c b/src/lread.c index a01cf099b49..09eccb0fb30 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1298,7 +1298,7 @@ Return t if the file exists and loads successfully. */) message_with_string ("Loading %s...", file, 1); } - record_unwind_protect (load_unwind, make_save_value (stream, 0)); + record_unwind_protect (load_unwind, make_save_pointer (stream)); record_unwind_protect (load_descriptor_unwind, load_descriptor_list); specbind (Qload_file_name, found); specbind (Qinhibit_file_name_operation, Qnil); diff --git a/src/nsmenu.m b/src/nsmenu.m index b0369e76a27..6899e3575f5 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1440,7 +1440,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) unwind_data->pool = pool; unwind_data->dialog = dialog; - record_unwind_protect (pop_down_menu, make_save_value (unwind_data, 0)); + record_unwind_protect (pop_down_menu, make_save_pointer (unwind_data)); popup_activated_flag = 1; tem = [dialog runDialogAt: p]; unbind_to (specpdl_count, Qnil); /* calls pop_down_menu */ diff --git a/src/nsterm.m b/src/nsterm.m index 48efac3f70b..d346f05624b 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -3677,7 +3677,7 @@ ns_set_vertical_scroll_bar (struct window *window, } bar = [[EmacsScroller alloc] initFrame: r window: win]; - wset_vertical_scroll_bar (window, make_save_value (bar, 0)); + wset_vertical_scroll_bar (window, make_save_pointer (bar)); } else { diff --git a/src/xfns.c b/src/xfns.c index 65148d1c9e1..f01983fea4d 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -5416,7 +5416,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) XmStringFree (default_xmstring); } - record_unwind_protect (clean_up_file_dialog, make_save_value (dialog, 0)); + record_unwind_protect (clean_up_file_dialog, make_save_pointer (dialog)); /* Process events until the user presses Cancel or OK. */ x_menu_set_in_use (1); diff --git a/src/xmenu.c b/src/xmenu.c index 7f6914d26ac..958cd220393 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1477,7 +1477,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i, timestamp ? timestamp : gtk_get_current_event_time ()); - record_unwind_protect (pop_down_menu, make_save_value (menu, 0)); + record_unwind_protect (pop_down_menu, make_save_pointer (menu)); if (gtk_widget_get_mapped (menu)) { @@ -1826,7 +1826,7 @@ xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, /* Make sure to free the widget_value objects we used to specify the contents even with longjmp. */ record_unwind_protect (cleanup_widget_value_tree, - make_save_value (first_wv, 0)); + make_save_pointer (first_wv)); /* Actually create and show the menu until popped down. */ create_and_show_popup_menu (f, first_wv, x, y, for_click, timestamp); @@ -1925,7 +1925,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv) if (menu) { ptrdiff_t specpdl_count = SPECPDL_INDEX (); - record_unwind_protect (pop_down_menu, make_save_value (menu, 0)); + record_unwind_protect (pop_down_menu, make_save_pointer (menu)); /* Display the menu. */ gtk_widget_show_all (menu); @@ -2136,7 +2136,7 @@ xdialog_show (FRAME_PTR f, /* Make sure to free the widget_value objects we used to specify the contents even with longjmp. */ record_unwind_protect (cleanup_widget_value_tree, - make_save_value (first_wv, 0)); + make_save_pointer (first_wv)); /* Actually create and show the dialog. */ create_and_show_dialog (f, first_wv); @@ -2479,7 +2479,7 @@ xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, #endif record_unwind_protect (pop_down_menu, - format_save_value ("pp", f, menu)); + make_save_value ("pp", f, menu)); /* Help display under X won't work because XMenuActivate contains a loop that doesn't give Emacs a chance to process it. */ diff --git a/src/xselect.c b/src/xselect.c index b7cdf70ff77..37d2c753c5e 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -1141,7 +1141,7 @@ wait_for_property_change (struct prop_location *location) /* Make sure to do unexpect_property_change if we quit or err. */ record_unwind_protect (wait_for_property_change_unwind, - make_save_value (location, 0)); + make_save_pointer (location)); XSETCAR (property_change_reply, Qnil); property_change_reply_object = location; |