all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Sam Steingold <sds@gnu.org>
Cc: 25345@debbugs.gnu.org
Subject: bug#25345: 26.0.50; crash on mac, just rebuilt from git tip
Date: Tue, 3 Jan 2017 17:54:49 +0000	[thread overview]
Message-ID: <20170103175449.GB49916@breton.holly.idiocy.org> (raw)
In-Reply-To: <m1shp0vyp9.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]

On Tue, Jan 03, 2017 at 12:29:54PM -0500, Sam Steingold wrote:
> In GNU Emacs 26.0.50.3 (x86_64-apple-darwin16.3.0, NS appkit-1504.76 Version 10.12.2 (Build 16C67))
>  of 2017-01-03 built on clr-sds
> Repository revision: 134e86b360cab0d0a5cb634b71a4b06ec26c5f1f
> Windowing system distributor 'Apple', version 10.3.1504
> 
> rebuilt from git tip.
> now emacs is very slow: it takes up to a second for the character to
> appear on the screen as I type.

Sorry about this, we’re trying to rework the NS port so it can handle
the new concurrency code.

Can you please try applying the attached patch, and let us know
whether it improves things?

Thanks!
-- 
Alan Third

[-- Attachment #2: 0001-Improve-NS-event-handling-bug-25265.patch --]
[-- Type: text/plain, Size: 4546 bytes --]

From 9663d300d231242fc77f93a35219d56ba9c90601 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Tue, 3 Jan 2017 14:16:37 +0000
Subject: [PATCH] Improve NS event handling (bug#25265)

* src/nsterm.h: Remove reference to timeout_handler.
* src/nsterm.m (ns_select): Monitor fd changes using NSFileHandler.
---
 src/nsterm.h |  1 -
 src/nsterm.m | 62 +++++++++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/src/nsterm.h b/src/nsterm.h
index dc222a7..8b5b691 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -392,7 +392,6 @@ char const * nstrace_fullscreen_type_name (int);
 - (void)sendEvent: (NSEvent *)theEvent;
 - (void)showPreferencesWindow: (id)sender;
 - (BOOL) openFile: (NSString *)fileName;
-- (void)timeout_handler: (NSTimer *)timedEntry;
 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
 #ifdef NS_IMPL_GNUSTEP
 - (void)sendFromMainThread:(id)unused;
diff --git a/src/nsterm.m b/src/nsterm.m
index 98fd8ab..51cccd0 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4098,28 +4098,55 @@ overwriting cursor (usually when cursor on a tab) */
     return pselect(nfds, readfds, writefds,
                    exceptfds, timeout, sigmask);
 
-  result = pselect(nfds, readfds, writefds, exceptfds,
-                   &(struct timespec){.tv_sec = 0, .tv_nsec = 100},
-                   sigmask);
-
   [outerpool release];
   outerpool = [[NSAutoreleasePool alloc] init];
 
+  /* Set up one NSFileHandle for each fd we want to monitor. */
+  for (int i = 0 ; i < nfds ; i++)
+    {
+      if ((readfds != NULL && FD_ISSET(i, readfds))
+          || (writefds != NULL && FD_ISSET(i, writefds))
+          || (exceptfds != NULL &&FD_ISSET(i, exceptfds)))
+        {
+          NSFileHandle *fh = [[NSFileHandle alloc] initWithFileDescriptor: i
+                                                           closeOnDealloc: NO];
+          /* Send a notification to EmacsApp:fileHandleDataAvailable,
+             which will raise an appDefined event. */
+          /* NOTE: I don't think this will pick up writes and
+             exceptions, so ns_select may not always behave correctly.
+             I've yet to see a problem, though. */
+          [fh waitForDataInBackgroundAndNotify];
+          [fh autorelease];
+        }
+    }
+
   if (timeout)
     {
       double time = timespectod (*timeout);
-      timeout_date = [NSDate dateWithTimeIntervalSinceNow:time];
+      timeout_date = [NSDate dateWithTimeIntervalSinceNow: time];
     }
 
   /* Listen for a new NSEvent. */
-  ns_event = [NSApp nextEventMatchingMask:NSEventMaskAny
-                                untilDate:timeout_date
-                                   inMode:NSDefaultRunLoopMode
-                                  dequeue:NO];
+  ns_event = [NSApp nextEventMatchingMask: NSEventMaskAny
+                                untilDate: timeout_date
+                                   inMode: NSDefaultRunLoopMode
+                                  dequeue: NO];
 
   if (ns_event != nil)
     {
-      raise (SIGIO);
+      if ([ns_event type] == NSEventTypeApplicationDefined
+          && [ns_event data1] == -3)
+        {
+          result = pselect(nfds, readfds, writefds, exceptfds,
+                           &(struct timespec){.tv_sec = 0, .tv_nsec = 0},
+                           sigmask);
+        }
+      else
+        {
+          raise (SIGIO);
+          errno = EINTR;
+          return -1;
+        }
     }
 
   return result;
@@ -5132,6 +5159,12 @@ - (void)applicationDidFinishLaunching: (NSNotification *)notification
 	 object:nil];
 #endif
 
+  [[NSNotificationCenter defaultCenter]
+      addObserver: self
+         selector: @selector (fileHandleDataAvailable:)
+             name: NSFileHandleDataAvailableNotification
+           object: nil];
+
   ns_send_appdefined (-2);
 }
 
@@ -5315,14 +5348,9 @@ - (void)applicationDidResignActive: (NSNotification *)notification
 
    ========================================================================== */
 
-
-- (void)timeout_handler: (NSTimer *)timedEntry
-/* --------------------------------------------------------------------------
-     The timeout specified to ns_select has passed.
-   -------------------------------------------------------------------------- */
+- (void)fileHandleDataAvailable: (NSNotification *)notification
 {
-  /*NSTRACE ("timeout_handler"); */
-  ns_send_appdefined (-2);
+  ns_send_appdefined (-3);
 }
 
 - (void)sendFromMainThread:(id)unused
-- 
2.10.2


  reply	other threads:[~2017-01-03 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-03 17:29 bug#25345: 26.0.50; crash on mac, just rebuilt from git tip Sam Steingold
2017-01-03 17:54 ` Alan Third [this message]
2017-01-03 20:53   ` Sam Steingold
2017-01-03 21:00     ` Sam Steingold
2017-01-03 21:07       ` Alan Third
2017-01-03 21:14         ` Sam Steingold
2017-01-04 21:12           ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170103175449.GB49916@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=25345@debbugs.gnu.org \
    --cc=sds@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.