use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / xmenu.c
index 0f2e9f2..92f293b 100644 (file)
@@ -750,7 +750,7 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
 
       struct buffer *prev = current_buffer;
       Lisp_Object buffer;
-      ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+      dynwind_begin ();
       int previous_menu_items_used = f->menu_bar_items_used;
       Lisp_Object *previous_items
        = alloca (previous_menu_items_used * sizeof *previous_items);
@@ -867,7 +867,7 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
             the menus in any form, since it would be a no-op.  */
          free_menubar_widget_value_tree (first_wv);
          discard_menu_items ();
-         unbind_to (specpdl_count, Qnil);
+         dynwind_end ();
          return;
        }
 
@@ -876,7 +876,7 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
       f->menu_bar_items_used = menu_items_used;
 
       /* This undoes save_menu_items.  */
-      unbind_to (specpdl_count, Qnil);
+      dynwind_end ();
 
       /* Now GC cannot happen during the lifetime of the widget_value,
         so it's safe to store data from a Lisp_String.  */
@@ -1201,7 +1201,7 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
   GtkWidget *menu;
   GtkMenuPositionFunc pos_func = 0;  /* Pop up at pointer.  */
   struct next_popup_x_y popup_x_y;
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  dynwind_begin ();
   bool use_pos_func = ! for_click;
 
 #ifdef HAVE_GTK3
@@ -1261,7 +1261,7 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
       popup_widget_loop (1, menu);
     }
 
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
   /* Must reset this manually because the button release event is not passed
      to Emacs event loop. */
@@ -1363,7 +1363,7 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
 
   {
     int fact = 4 * sizeof (LWLIB_ID);
-    ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+    dynwind_begin ();
     record_unwind_protect (pop_down_menu,
                            Fcons (make_number (menu_id >> (fact)),
                                   make_number (menu_id & ~(-1 << (fact)))));
@@ -1371,7 +1371,7 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
     /* Process events that apply to the menu.  */
     popup_get_selection (0, FRAME_DISPLAY_INFO (f), menu_id, 1);
 
-    unbind_to (specpdl_count, Qnil);
+    dynwind_end ();
   }
 }
 
@@ -1397,7 +1397,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
 
   int first_pane;
 
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   eassert (FRAME_X_P (f));
 
@@ -1406,6 +1406,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
   if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
     {
       *error_name = "Empty menu";
+      dynwind_end ();
       return Qnil;
     }
 
@@ -1579,7 +1580,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
   create_and_show_popup_menu (f, first_wv, x, y,
                              menuflags & MENU_FOR_CLICK);
 
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
   /* Find the selected item, and its pane, to return
      the proper value.  */
@@ -1676,7 +1677,7 @@ create_and_show_dialog (struct frame *f, widget_value *first_wv)
 
   if (menu)
     {
-      ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+      dynwind_begin ();
       record_unwind_protect_ptr (pop_down_menu, menu);
 
       /* Display the menu.  */
@@ -1685,7 +1686,7 @@ create_and_show_dialog (struct frame *f, widget_value *first_wv)
       /* Process events that apply to the menu.  */
       popup_widget_loop (1, menu);
 
-      unbind_to (specpdl_count, Qnil);
+      dynwind_end ();
     }
 }
 
@@ -1731,7 +1732,7 @@ create_and_show_dialog (struct frame *f, widget_value *first_wv)
   /* Process events that apply to the dialog box.
      Also handle timers.  */
   {
-    ptrdiff_t count = SPECPDL_INDEX ();
+    dynwind_begin ();
     int fact = 4 * sizeof (LWLIB_ID);
 
     /* xdialog_show_unwind is responsible for popping the dialog box down.  */
@@ -1741,7 +1742,7 @@ create_and_show_dialog (struct frame *f, widget_value *first_wv)
 
     popup_get_selection (0, FRAME_DISPLAY_INFO (f), dialog_id, 1);
 
-    unbind_to (count, Qnil);
+    dynwind_end ();
   }
 }
 
@@ -1765,7 +1766,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
   /* 1 means we've seen the boundary between left-hand elts and right-hand.  */
   int boundary_seen = 0;
 
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   eassert (FRAME_X_P (f));
 
@@ -1774,6 +1775,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
   if (menu_items_n_panes > 1)
     {
       *error_name = "Multiple panes in dialog box";
+      dynwind_end ();
       return Qnil;
     }
 
@@ -1804,6 +1806,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
          {
            free_menubar_widget_value_tree (first_wv);
            *error_name = "Submenu in dialog items";
+           dynwind_end ();
            return Qnil;
          }
        if (EQ (item_name, Qquote))
@@ -1818,6 +1821,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
          {
            free_menubar_widget_value_tree (first_wv);
            *error_name = "Too many dialog items";
+           dynwind_end ();
            return Qnil;
          }
 
@@ -1875,7 +1879,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
   /* Actually create and show the dialog.  */
   create_and_show_dialog (f, first_wv);
 
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
   /* Find the selected item, and its pane, to return
      the proper value.  */
@@ -2030,17 +2034,20 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
   int maxwidth;
   int dummy_int;
   unsigned int dummy_uint;
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   eassert (FRAME_X_P (f) || FRAME_MSDOS_P (f));
 
   *error_name = 0;
-  if (menu_items_n_panes == 0)
+  if (menu_items_n_panes == 0) {
+    dynwind_end ();
     return Qnil;
+  }
 
   if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
     {
       *error_name = "Empty menu";
+      dynwind_end ();
       return Qnil;
     }
 
@@ -2057,6 +2064,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
     {
       *error_name = "Can't create menu";
       unblock_input ();
+      dynwind_end ();
       return Qnil;
     }
 
@@ -2096,6 +2104,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
              XMenuDestroy (FRAME_X_DISPLAY (f), menu);
              *error_name = "Can't create pane";
              unblock_input ();
+             dynwind_end ();
              return Qnil;
            }
          i += MENU_ITEMS_PANE_LENGTH;
@@ -2161,6 +2170,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
              XMenuDestroy (FRAME_X_DISPLAY (f), menu);
              *error_name = "Can't add selection to menu";
              unblock_input ();
+             dynwind_end ();
              return Qnil;
            }
          i += MENU_ITEMS_ITEM_LENGTH;
@@ -2295,7 +2305,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
     }
 
   unblock_input ();
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
   return entry;
 }