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>
+
+ * 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.
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;
}
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);
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
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)
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) */
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. */
{
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);
}
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))
}
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;
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;
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);
}
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);
}
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;
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
{
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 *);
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)
{ \
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_); \
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);
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 */
}
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
{
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);
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))
{
/* 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);
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);
/* 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);
#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. */
/* 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;