* 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.
This commit is contained in:
Dmitry Antipov 2013-01-17 10:29:40 +04:00
parent 0e70695aa4
commit 468afbacea
16 changed files with 101 additions and 38 deletions

View file

@ -1,3 +1,19 @@
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.

View file

@ -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

View file

@ -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) */

View file

@ -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);
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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_); \

View file

@ -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);

View file

@ -1440,7 +1440,7 @@ - (NSRect) frame
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 */

View file

@ -3677,7 +3677,7 @@ overwriting cursor (usually when cursor on a tab) */
}
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
{

View file

@ -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);

View file

@ -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. */

View file

@ -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;