Simplify and avoid signal-handling races.
[bpt/emacs.git] / src / xmenu.c
index ab79009..06d6cb0 100644 (file)
@@ -32,13 +32,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
-#if 0  /* Why was this included?  And without syssignal.h?  */
-/* On 4.3 this loses if it comes after xterm.h.  */
-#include <signal.h>
-#endif
-
 #include <stdio.h>
-#include <setjmp.h>
 
 #include "lisp.h"
 #include "keyboard.h"
@@ -169,9 +163,9 @@ mouse_position_for_popup (FRAME_PTR f, int *x, int *y)
   int dummy;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
-  BLOCK_INPUT;
+  block_input ();
 
   XQueryPointer (FRAME_X_DISPLAY (f),
                  DefaultRootWindow (FRAME_X_DISPLAY (f)),
@@ -192,7 +186,7 @@ mouse_position_for_popup (FRAME_PTR f, int *x, int *y)
                     we don't care.  */
                  (unsigned int *) &dummy);
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   /* xmenu_show expects window coordinates, not root window
      coordinates.  Translate.  */
@@ -334,9 +328,9 @@ for instance using the window manager, then this produces a quit and
     list_of_panes (Fcons (contents, Qnil));
 
     /* Display them in a dialog box.  */
-    BLOCK_INPUT;
+    block_input ();
     selection = xdialog_show (f, 0, title, header, &error_name);
-    UNBLOCK_INPUT;
+    unblock_input ();
 
     unbind_to (specpdl_count, Qnil);
     discard_menu_items ();
@@ -496,7 +490,7 @@ If FRAME is nil or not given, use the selected frame.  */)
   XEvent ev;
   FRAME_PTR f = check_x_frame (frame);
   Widget menubar;
-  BLOCK_INPUT;
+  block_input ();
 
   if (FRAME_EXTERNAL_MENU_BAR (f))
     set_frame_menubar (f, 0, 1);
@@ -554,7 +548,7 @@ If FRAME is nil or not given, use the selected frame.  */)
         }
     }
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   return Qnil;
 }
@@ -575,9 +569,9 @@ If FRAME is nil or not given, use the selected frame.  */)
   FRAME_PTR f;
 
   /* gcc 2.95 doesn't accept the FRAME_PTR declaration after
-     BLOCK_INPUT.  */
+     block_input ().  */
 
-  BLOCK_INPUT;
+  block_input ();
   f = check_x_frame (frame);
 
   if (FRAME_EXTERNAL_MENU_BAR (f))
@@ -596,7 +590,7 @@ If FRAME is nil or not given, use the selected frame.  */)
           g_list_free (children);
         }
     }
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   return Qnil;
 }
@@ -636,7 +630,7 @@ void
 x_activate_menubar (FRAME_PTR f)
 {
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   if (!f->output_data.x->saved_menu_event->type)
     return;
@@ -648,7 +642,7 @@ x_activate_menubar (FRAME_PTR f)
 #endif
 
   set_frame_menubar (f, 0, 1);
-  BLOCK_INPUT;
+  block_input ();
   popup_activated_flag = 1;
 #ifdef USE_GTK
   XPutBackEvent (f->output_data.x->display_info->display,
@@ -656,7 +650,7 @@ x_activate_menubar (FRAME_PTR f)
 #else
   XtDispatchEvent (f->output_data.x->saved_menu_event);
 #endif
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   /* Ignore this if we get it a second time.  */
   f->output_data.x->saved_menu_event->type = 0;
@@ -809,10 +803,10 @@ menubar_selection_callback (GtkWidget *widget, gpointer client_data)
      sit-for will exit at once if the focus event follows the menu selection
      event.  */
 
-  BLOCK_INPUT;
+  block_input ();
   while (gtk_events_pending ())
     gtk_main_iteration ();
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   find_and_call_menu_selection (cb_data->cl_data->f,
                                 cb_data->cl_data->menu_bar_items_used,
@@ -852,14 +846,14 @@ update_frame_menubar (FRAME_PTR f)
   int columns, rows;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   x = f->output_data.x;
 
   if (!x->menubar_widget || XtIsManaged (x->menubar_widget))
     return 0;
 
-  BLOCK_INPUT;
+  block_input ();
   /* Save the size of the frame because the pane widget doesn't accept
      to resize itself. So force it.  */
   columns = FRAME_COLS (f);
@@ -886,7 +880,7 @@ update_frame_menubar (FRAME_PTR f)
 
   /* Force the pane widget to resize itself with the right values.  */
   EmacsFrameSetCharSize (x->edit_widget, columns, rows);
-  UNBLOCK_INPUT;
+  unblock_input ();
 #endif
   return 1;
 }
@@ -940,7 +934,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
   int *submenu_top_level_items, *submenu_n_panes;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   menubar_widget = f->output_data.x->menubar_widget;
 
@@ -1008,7 +1002,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       if (! NILP (Vlucid_menu_bar_dirty_flag))
        call0 (Qrecompute_lucid_menubar);
       safe_run_hooks (Qmenu_bar_update_hook);
-      FSET (f, menu_bar_items, menu_bar_items (FRAME_MENU_BAR_ITEMS (f)));
+      fset_menu_bar_items (f, menu_bar_items (FRAME_MENU_BAR_ITEMS (f)));
 
       items = FRAME_MENU_BAR_ITEMS (f);
 
@@ -1100,7 +1094,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
        }
 
       /* The menu items are different, so store them in the frame.  */
-      FSET (f, menu_bar_vector, menu_items);
+      fset_menu_bar_vector (f, menu_items);
       f->menu_bar_items_used = menu_items_used;
 
       /* This undoes save_menu_items.  */
@@ -1170,7 +1164,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 
   /* Create or update the menu bar widget.  */
 
-  BLOCK_INPUT;
+  block_input ();
 
 #ifdef USE_GTK
   xg_crazy_callback_abort = 1;
@@ -1270,7 +1264,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
   xg_crazy_callback_abort = 0;
 #endif
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 }
 
 /* Called from Fx_create_frame to create the initial menubar of a frame
@@ -1283,7 +1277,7 @@ initialize_frame_menubar (FRAME_PTR f)
 {
   /* This function is called before the first chance to redisplay
      the frame.  It has to be, so the frame will have the right size.  */
-  FSET (f, menu_bar_items, menu_bar_items (FRAME_MENU_BAR_ITEMS (f)));
+  fset_menu_bar_items (f, menu_bar_items (FRAME_MENU_BAR_ITEMS (f)));
   set_frame_menubar (f, 1, 1);
 }
 
@@ -1299,7 +1293,7 @@ free_frame_menubar (FRAME_PTR f)
   Widget menubar_widget;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   menubar_widget = f->output_data.x->menubar_widget;
 
@@ -1319,7 +1313,7 @@ free_frame_menubar (FRAME_PTR f)
       Position x0, y0, x1, y1;
 #endif
 
-      BLOCK_INPUT;
+      block_input ();
 
 #ifdef USE_MOTIF
       if (f->output_data.x->widget)
@@ -1338,7 +1332,7 @@ free_frame_menubar (FRAME_PTR f)
 #endif
           x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
        }
-      UNBLOCK_INPUT;
+      unblock_input ();
     }
 }
 #endif /* not USE_GTK */
@@ -1423,9 +1417,9 @@ pop_down_menu (Lisp_Object arg)
   struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
 
   popup_activated_flag = 0;
-  BLOCK_INPUT;
+  block_input ();
   gtk_widget_destroy (GTK_WIDGET (p->pointer));
-  UNBLOCK_INPUT;
+  unblock_input ();
   return Qnil;
 }
 
@@ -1450,7 +1444,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
 #endif
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   xg_crazy_callback_abort = 1;
   menu = xg_create_widget ("popup", first_wv->name, f, first_wv,
@@ -1533,9 +1527,9 @@ pop_down_menu (Lisp_Object arg)
   LWLIB_ID id = (XINT (XCAR (arg)) << 4 * sizeof (LWLIB_ID)
                  | XINT (XCDR (arg)));
 
-  BLOCK_INPUT;
+  block_input ();
   lw_destroy_all_widgets (id);
-  UNBLOCK_INPUT;
+  unblock_input ();
   popup_activated_flag = 0;
 
   return Qnil;
@@ -1557,7 +1551,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
   Widget menu;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
 #ifdef USE_LUCID
   apply_systemfont_to_menu (f, f->output_data.x->widget);
@@ -1646,7 +1640,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   *error_name = NULL;
 
@@ -1792,7 +1786,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
          else if (EQ (type, QCradio))
            wv->button_type = BUTTON_TYPE_RADIO;
          else
-           abort ();
+           emacs_abort ();
 
          wv->selected = !NILP (selected);
 
@@ -1930,7 +1924,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
   GtkWidget *menu;
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   menu = xg_create_widget ("dialog", first_wv->name, f, first_wv,
                            G_CALLBACK (dialog_selection_callback),
@@ -1961,9 +1955,9 @@ dialog_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
   if ((intptr_t) client_data != -1)
     menu_item_selection = (Lisp_Object *) client_data;
 
-  BLOCK_INPUT;
+  block_input ();
   lw_destroy_all_widgets (id);
-  UNBLOCK_INPUT;
+  unblock_input ();
   popup_activated_flag = 0;
 }
 
@@ -1977,7 +1971,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
   LWLIB_ID dialog_id;
 
   if (!FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   dialog_id = widget_id_tick++;
 #ifdef USE_LUCID
@@ -2036,7 +2030,7 @@ xdialog_show (FRAME_PTR f,
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
 
   if (! FRAME_X_P (f))
-    abort ();
+    emacs_abort ();
 
   *error_name = NULL;
 
@@ -2257,7 +2251,7 @@ pop_down_menu (Lisp_Object arg)
   FRAME_PTR f = p1->pointer;
   XMenu *menu = p2->pointer;
 
-  BLOCK_INPUT;
+  block_input ();
 #ifndef MSDOS
   XUngrabPointer (FRAME_X_DISPLAY (f), CurrentTime);
   XUngrabKeyboard (FRAME_X_DISPLAY (f), CurrentTime);
@@ -2277,7 +2271,7 @@ pop_down_menu (Lisp_Object arg)
 
 #endif /* HAVE_X_WINDOWS */
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   return Qnil;
 }
@@ -2301,7 +2295,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
 
   if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
-    abort ();
+    emacs_abort ();
 
   *error_name = 0;
   if (menu_items_n_panes == 0)