From 4f0800ec2ffdfee7b56062aeac263e5071cf8868 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 12 Oct 2012 12:20:15 +0200 Subject: [PATCH] Some cleanups: 1. If fill_queue returns -1, but there were file notifications, return 0. 2. Move invariant code out of the loop in queue_notifications and handle_file_notifications. --- src/w32inevt.c | 42 +++++++++++++++++++++++------------------- src/w32term.c | 31 +++++++++++++++---------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/w32inevt.c b/src/w32inevt.c index 9b63d0c24b6..7d60c06d78d 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -576,7 +576,7 @@ maybe_generate_resize_event (void) 0, 0, 0); } -static void +static int handle_file_notifications (struct input_event *hold_quit) { BYTE *p = file_notifications; @@ -584,26 +584,32 @@ handle_file_notifications (struct input_event *hold_quit) const DWORD min_size = offsetof (FILE_NOTIFY_INFORMATION, FileName) + sizeof(wchar_t); struct input_event inev; + int nevents = 0; /* We cannot process notification before Emacs is fully initialized, since we need the UTF-16LE coding-system to be set up. */ if (!initialized) { notification_buffer_in_use = 0; - return; + return nevents; } enter_crit (); if (notification_buffer_in_use) { DWORD info_size = notifications_size; + Lisp_Object cs = intern ("utf-16le"); + Lisp_Object obj = get_watch_object (make_number (notifications_desc)); /* notifications_size could be zero when the buffer of notifications overflowed on the OS level, or when the directory being watched was itself deleted. Do nothing in that case. */ - if (info_size) + if (info_size + && !NILP (obj) && CONSP (obj)) { + Lisp_Object callback = XCDR (obj); + EVENT_INIT (inev); while (info_size >= min_size) @@ -614,22 +620,16 @@ handle_file_notifications (struct input_event *hold_quit) /* Note: mule-conf is preloaded, so utf-16le must already be defined at this point. */ Lisp_Object fname - = code_convert_string_norecord (utf_16_fn, - intern ("utf-16le"), 0); + = code_convert_string_norecord (utf_16_fn, cs, 0); Lisp_Object action = lispy_file_action (fni->Action); - Lisp_Object obj; - obj = get_watch_object (make_number (notifications_desc)); - if (!NILP (obj) && CONSP (obj)) - { - inev.kind = FILE_NOTIFY_EVENT; - inev.code = (ptrdiff_t)notifications_desc; - inev.timestamp = GetTickCount (); - inev.modifiers = 0; - inev.frame_or_window = XCDR (obj); - inev.arg = Fcons (action, fname); - kbd_buffer_store_event_hold (&inev, hold_quit); - } + inev.kind = FILE_NOTIFY_EVENT; + inev.code = (ptrdiff_t)notifications_desc; + inev.timestamp = GetTickCount (); + inev.modifiers = 0; + inev.frame_or_window = callback; + inev.arg = Fcons (action, fname); + kbd_buffer_store_event_hold (&inev, hold_quit); if (!fni->NextEntryOffset) break; @@ -641,6 +641,7 @@ handle_file_notifications (struct input_event *hold_quit) notification_buffer_in_use = 0; } leave_crit (); + return nevents; } int @@ -654,13 +655,16 @@ w32_console_read_socket (struct terminal *terminal, for (;;) { - handle_file_notifications (hold_quit); + int nfnotify = handle_file_notifications (hold_quit); + nev = fill_queue (0); if (nev <= 0) { /* If nev == -1, there was some kind of error - If nev == 0 then waitp must be zero and no events were available + If nev == 0 then no events were available so return. */ + if (nfnotify) + nev = 0; break; } diff --git a/src/w32term.c b/src/w32term.c index e1a2fbbf824..6d19d9a93ce 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -3281,13 +3281,18 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f, if (notification_buffer_in_use) { DWORD info_size = notifications_size; + Lisp_Object cs = intern ("utf-16le"); + Lisp_Object obj = get_watch_object (make_number (notifications_desc)); /* notifications_size could be zero when the buffer of notifications overflowed on the OS level, or when the directory being watched was itself deleted. Do nothing in that case. */ - if (info_size) + if (info_size + && !NILP (obj) && CONSP (obj)) { + Lisp_Object callback = XCDR (obj); + while (info_size >= min_size) { Lisp_Object utf_16_fn @@ -3296,23 +3301,17 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f, /* Note: mule-conf is preloaded, so utf-16le must already be defined at this point. */ Lisp_Object fname - = code_convert_string_norecord (utf_16_fn, - intern ("utf-16le"), 0); + = code_convert_string_norecord (utf_16_fn, cs, 0); Lisp_Object action = lispy_file_action (fni->Action); - Lisp_Object obj; - obj = get_watch_object (make_number (notifications_desc)); - if (!NILP (obj) && CONSP (obj)) - { - event->kind = FILE_NOTIFY_EVENT; - event->code = (ptrdiff_t)notifications_desc; - event->timestamp = msg->msg.time; - event->modifiers = 0; - event->frame_or_window = XCDR (obj); - event->arg = Fcons (action, fname); - kbd_buffer_store_event (event); - (*evcount)++; - } + event->kind = FILE_NOTIFY_EVENT; + event->code = (ptrdiff_t)notifications_desc; + event->timestamp = msg->msg.time; + event->modifiers = 0; + event->frame_or_window = callback; + event->arg = Fcons (action, fname); + kbd_buffer_store_event (event); + (*evcount)++; if (!fni->NextEntryOffset) break; -- 2.39.5