]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug #15933 with crashes in file-notify-tests on MS-Windows.
authorEli Zaretskii <eliz@gnu.org>
Thu, 28 Nov 2013 19:40:15 +0000 (21:40 +0200)
committerEli Zaretskii <eliz@gnu.org>
Thu, 28 Nov 2013 19:40:15 +0000 (21:40 +0200)
 Support w32 file notifications in batch mode.
 src/w32proc.c (sys_select): Don't wait on interrupt_handle if it is
 invalid (which happens in batch mode).  If non-interactive, call
 handle_file_notifications to store file notification events in the
 input queue.
 src/w32notify.c (send_notifications): Handle FRAME_INITIAL frames as
 well.
 src/w32inevt.c (handle_file_notifications): Now external, not
 static.
 src/w32term.h (handle_file_notifications): Provide prototype.
 src/emacs.c (main) [HAVE_W32NOTIFY]: When non-interactive, call
 init_crit, since init_display, which does that otherwise, is not
 called.

src/ChangeLog
src/emacs.c
src/w32inevt.c
src/w32notify.c
src/w32proc.c
src/w32term.h

index 78dd23620186b05b358fbd58d83cd82f0eb5fedb..f3cbf4e1f145697463bddc4eeeb34e015a0e5bc9 100644 (file)
@@ -1,3 +1,23 @@
+2013-11-28  Eli Zaretskii  <eliz@gnu.org>
+
+       Support w32 file notifications in batch mode.
+       * w32proc.c (sys_select): Don't wait on interrupt_handle if it is
+       invalid (which happens in batch mode).  If non-interactive, call
+       handle_file_notifications to store file notification events in the
+       input queue.  (Bug#15933)
+
+       * w32notify.c (send_notifications): Handle FRAME_INITIAL frames as
+       well.
+
+       * w32inevt.c (handle_file_notifications): Now external, not
+       static.
+
+       * w32term.h (handle_file_notifications): Provide prototype.
+
+       * emacs.c (main) [HAVE_W32NOTIFY]: When non-interactive, call
+       init_crit, since init_display, which does that otherwise, is not
+       called.
+
 2013-11-27  Glenn Morris  <rgm@gnu.org>
 
        * Makefile.in ($(lispsource)/international/charprop.el): New.
index 75082ecef7df26155abda0b9392a7b3d2b850a71..159b0d5040d516b7b348c3185f2c4b02d56d14f7 100644 (file)
@@ -1517,6 +1517,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
   init_keyboard ();    /* This too must precede init_sys_modes.  */
   if (!noninteractive)
     init_display ();   /* Determine terminal type.  Calls init_sys_modes.  */
+#if HAVE_W32NOTIFY
+  else
+    init_crit ();      /* w32notify.c needs this in batch mode.  */
+#endif /* HAVE_W32NOTIFY */
   init_xdisp ();
 #ifdef HAVE_WINDOW_SYSTEM
   init_fringe ();
index dc587de11832cf67e96b468fa830e32532728a1b..a157cb5c1df4f7e38f627a4f55345a08d78232b1 100644 (file)
@@ -608,7 +608,7 @@ maybe_generate_resize_event (void)
 }
 
 #if HAVE_W32NOTIFY
-static int
+int
 handle_file_notifications (struct input_event *hold_quit)
 {
   BYTE *p = file_notifications;
@@ -676,7 +676,7 @@ handle_file_notifications (struct input_event *hold_quit)
   return nevents;
 }
 #else  /* !HAVE_W32NOTIFY */
-static int
+int
 handle_file_notifications (struct input_event *hold_quit)
 {
   return 0;
index 1f2ef83b2fdd863a5191c5d2f3be554d9b41c704..373e20e8e92394fc8b3019a3d0d17b88503cec5a 100644 (file)
@@ -163,7 +163,12 @@ send_notifications (BYTE *info, DWORD info_size, void *desc,
               && PostThreadMessage (dwMainThreadId, WM_EMACS_FILENOTIFY, 0, 0))
              || (FRAME_W32_P (f)
                  && PostMessage (FRAME_W32_WINDOW (f),
-                                 WM_EMACS_FILENOTIFY, 0, 0)))
+                                 WM_EMACS_FILENOTIFY, 0, 0))
+             /* When we are running in batch mode, there's no one to
+                send a message, so we just signal the data is
+                available and hope sys_select will be called soon and
+                will read the data.  */
+             || (FRAME_INITIAL_P (f) && noninteractive))
            notification_buffer_in_use = 1;
          done = 1;
        }
index ea16f26a0ee4fcc4aaeefaf09a29e70d6c2256b7..3e0081cd802ea3b0d706d7ec3db14b14d34db077 100644 (file)
@@ -1960,12 +1960,17 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
   FD_ZERO (rfds);
   nr = 0;
 
-  /* Always wait on interrupt_handle, to detect C-g (quit).  */
-  wait_hnd[0] = interrupt_handle;
-  fdindex[0] = -1;
+  /* If interrupt_handle is available and valid, always wait on it, to
+     detect C-g (quit).  */
+  nh = 0;
+  if (interrupt_handle && interrupt_handle != INVALID_HANDLE_VALUE)
+    {
+      wait_hnd[0] = interrupt_handle;
+      fdindex[0] = -1;
+      nh++;
+    }
 
   /* Build a list of pipe handles to wait on.  */
-  nh = 1;
   for (i = 0; i < nfds; i++)
     if (FD_ISSET (i, &orfds))
       {
@@ -1986,6 +1991,11 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
                FD_SET (i, rfds);
                return 1;
              }
+           else if (noninteractive)
+             {
+               if (handle_file_notifications (NULL))
+                 return 1;
+             }
          }
        else
          {
@@ -2086,6 +2096,11 @@ count_children:
     {
       if (timeout)
        Sleep (timeout_ms);
+      if (noninteractive)
+       {
+         if (handle_file_notifications (NULL))
+           return 1;
+       }
       return 0;
     }
 
@@ -2112,6 +2127,11 @@ count_children:
     }
   else if (active == WAIT_TIMEOUT)
     {
+      if (noninteractive)
+       {
+         if (handle_file_notifications (NULL))
+           return 1;
+       }
       return 0;
     }
   else if (active >= WAIT_OBJECT_0
@@ -2218,6 +2238,12 @@ count_children:
          break;
     } while (active < nh + nc);
 
+  if (noninteractive)
+    {
+      if (handle_file_notifications (NULL))
+       nr++;
+    }
+
   /* If no input has arrived and timeout hasn't expired, wait again.  */
   if (nr == 0)
     {
index b3c0cf56c7b8001b6ee60e58d6fcf95669d3b699..6825e3cd546430e555ad08c060cb99b2c2099bc0 100644 (file)
@@ -680,6 +680,7 @@ extern DWORD notifications_size;
 extern void *notifications_desc;
 extern Lisp_Object w32_get_watch_object (void *);
 extern Lisp_Object lispy_file_action (DWORD);
+extern int handle_file_notifications (struct input_event *);
 
 extern void w32_initialize_display_info (Lisp_Object);
 extern void initialize_w32_display (struct terminal *, int *, int *);