emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111541: * lisp.h (toplevel): Add com


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111541: * lisp.h (toplevel): Add comment about using Lisp_Save_Value
Date: Thu, 17 Jan 2013 10:29:40 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111541
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Thu 2013-01-17 10:29:40 +0400
message:
  * 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.
modified:
  src/ChangeLog
  src/alloc.c
  src/dired.c
  src/editfns.c
  src/fileio.c
  src/font.c
  src/ftfont.c
  src/gtkutil.c
  src/keymap.c
  src/lisp.h
  src/lread.c
  src/nsmenu.m
  src/nsterm.m
  src/xfns.c
  src/xmenu.c
  src/xselect.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-01-17 05:52:13 +0000
+++ b/src/ChangeLog     2013-01-17 06:29:40 +0000
@@ -1,5 +1,21 @@
 2013-01-17  Dmitry Antipov  <address@hidden>
 
+       * 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  <address@hidden>
+
        * 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

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2013-01-15 21:38:58 +0000
+++ b/src/alloc.c       2013-01-17 06:29:40 +0000
@@ -845,7 +845,7 @@
 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 @@
    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 @@
   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

=== modified file 'src/dired.c'
--- a/src/dired.c       2013-01-15 09:22:25 +0000
+++ b/src/dired.c       2013-01-17 06:29:40 +0000
@@ -152,7 +152,7 @@
      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 @@
     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) */

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2013-01-15 09:22:25 +0000
+++ b/src/editfns.c     2013-01-17 06:29:40 +0000
@@ -833,7 +833,7 @@
 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 @@
          {
            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);
          }

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2013-01-15 10:14:31 +0000
+++ b/src/fileio.c      2013-01-17 06:29:40 +0000
@@ -4249,7 +4249,7 @@
               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 @@
     }
 
   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;

=== modified file 'src/font.c'
--- a/src/font.c        2013-01-15 09:22:25 +0000
+++ b/src/font.c        2013-01-17 06:29:40 +0000
@@ -1861,7 +1861,7 @@
   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;

=== modified file 'src/ftfont.c'
--- a/src/ftfont.c      2013-01-15 09:22:25 +0000
+++ b/src/ftfont.c      2013-01-17 06:29:40 +0000
@@ -393,7 +393,7 @@
       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);
     }

=== modified file 'src/gtkutil.c'
--- a/src/gtkutil.c     2013-01-15 09:22:25 +0000
+++ b/src/gtkutil.c     2013-01-17 06:29:40 +0000
@@ -1716,7 +1716,7 @@
   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);

=== modified file 'src/keymap.c'
--- a/src/keymap.c      2013-01-15 10:14:31 +0000
+++ b/src/keymap.c      2013-01-17 06:29:40 +0000
@@ -610,7 +610,7 @@
        }
       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;

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-01-15 21:38:58 +0000
+++ b/src/lisp.h        2013-01-17 06:29:40 +0000
@@ -1388,7 +1388,50 @@
     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 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 @@
    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 @@
       {                                                               \
        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_);      \

=== modified file 'src/lread.c'
--- a/src/lread.c       2013-01-15 09:22:25 +0000
+++ b/src/lread.c       2013-01-17 06:29:40 +0000
@@ -1298,7 +1298,7 @@
        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);

=== modified file 'src/nsmenu.m'
--- a/src/nsmenu.m      2013-01-15 09:22:25 +0000
+++ b/src/nsmenu.m      2013-01-17 06:29:40 +0000
@@ -1440,7 +1440,7 @@
     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 */

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2013-01-13 12:08:31 +0000
+++ b/src/nsterm.m      2013-01-17 06:29:40 +0000
@@ -3677,7 +3677,7 @@
         }
 
       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
     {

=== modified file 'src/xfns.c'
--- a/src/xfns.c        2013-01-15 09:22:25 +0000
+++ b/src/xfns.c        2013-01-17 06:29:40 +0000
@@ -5416,7 +5416,7 @@
       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);

=== modified file 'src/xmenu.c'
--- a/src/xmenu.c       2013-01-15 10:14:31 +0000
+++ b/src/xmenu.c       2013-01-17 06:29:40 +0000
@@ -1477,7 +1477,7 @@
   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 @@
   /* 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 @@
   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 @@
   /* 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 @@
 #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.  */

=== modified file 'src/xselect.c'
--- a/src/xselect.c     2013-01-15 09:22:25 +0000
+++ b/src/xselect.c     2013-01-17 06:29:40 +0000
@@ -1141,7 +1141,7 @@
 
   /* 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;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]