From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: SIGIO and the NS port Date: Sun, 21 May 2017 00:24:06 +0100 Message-ID: <20170520232406.GA21521@breton.holly.idiocy.org> References: <20170310124117.GA74077@breton.holly.idiocy.org> <20170313163817.GA40836@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1495322664 12518 195.159.176.226 (20 May 2017 23:24:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 20 May 2017 23:24:24 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) To: Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 21 01:24:19 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dCDjP-000324-1P for ged-emacs-devel@m.gmane.org; Sun, 21 May 2017 01:24:19 +0200 Original-Received: from localhost ([::1]:35700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCDjR-0005RL-5D for ged-emacs-devel@m.gmane.org; Sat, 20 May 2017 19:24:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCDjJ-0005RF-1o for emacs-devel@gnu.org; Sat, 20 May 2017 19:24:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dCDjI-0006Hu-1r for emacs-devel@gnu.org; Sat, 20 May 2017 19:24:13 -0400 Original-Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:36164) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dCDjH-0006Gh-NK for emacs-devel@gnu.org; Sat, 20 May 2017 19:24:11 -0400 Original-Received: by mail-wr0-x243.google.com with SMTP id v42so5834176wrc.3 for ; Sat, 20 May 2017 16:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=GaxrwZIywYrwBsvi8Y3HpVzhrkZAidP+giuqCvd9MRI=; b=sb6kAblhboNWYg0RSyahniNgFpKSce7stlc42Ose/jL8/Fn1cC/301Ki+NkVG8XRtY R9Z3WcOjgPS19hr1sZAkvbRNDu9u3hX7zsIIIAspYuS4an4zoTtEGc/tZlMmRcpXYu+N CXl83PCdAMzkxWOl9AtLKsI71RIMdc6ve4v4wuQiEXEpRM/hXssk4PbmWWGuUdQKy0PM FoUSHVoWalJfc0EaI9BVljbEKaq6ZsFPhiAnkAKcJYR0uvgPOO76iH1WWxIqMkm98cnY kWixMLnp3cjjwymfmWQ6WSYQZLHieT7DA3FHNRbLSCSUjqP52FAuqA4lFsve10zTFgKg EgwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=GaxrwZIywYrwBsvi8Y3HpVzhrkZAidP+giuqCvd9MRI=; b=FlMomo8zDXldlyhTMvMwrogXt++qUTt0Yog0ri2lC4wnI9PABgGQX76I7MOtJ5ahmf mV4uxOjGNHyk6NYkT91BNr/fNgvnh3G2GgWbolUsa6XzUGnU8TSBgpbJYJiPLdaf9Jlk jnOEaSLIpHxtj7c87L880Iqw30KtEeG+zbqfNuBJFgyuSq4XPD9CijOr1tyo2q0fPRBa wBZ8eGCSExnjIpGSIGbO8Dz3h9sK22c6ukPbhGsMIsD5h0YQyriGN8E/PTx/c4e5e+hJ lsJ0V1wb3PP5l02PqEP67QwE+vw/L7QNZ0KOWnu6/piTOfGLvE1H3E+xWZZAUfiMmPY+ BJ9w== X-Gm-Message-State: AODbwcDDjo1IA6hpTKuTzxi88nB0avXpe2KzGi7NcZEJvQoOOSzrcoGj Pw8Y7phFsjgzGEh9Ep8= X-Received: by 10.223.161.30 with SMTP id o30mr6564378wro.186.1495322650063; Sat, 20 May 2017 16:24:10 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-1c23-04ca-53b1-12e4.holly.idiocy.org. [2001:8b0:3f8:8129:1c23:4ca:53b1:12e4]) by smtp.gmail.com with ESMTPSA id 137sm13941621wmi.19.2017.05.20.16.24.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 16:24:08 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20170313163817.GA40836@breton.holly.idiocy.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215033 Archived-At: --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Mon, Mar 13, 2017 at 04:38:17PM +0000, Alan Third wrote: > On Fri, Mar 10, 2017 at 12:41:17PM +0000, Alan Third wrote: > > The NS port doesn’t use SIGIO to signal for input (I think it polls > > using ns_select), and if I comment these two defines out I can remove > > block_input/unblock_input from various places with no ill effects. > > It looks like this isn’t right. The NS port works without SIGIO most > of the time, but if wait_reading_process_output is called with > read_kbd=0 then it goes into an infinite loop. (At least, I think > that’s what’s happening.) So I’ve been using the attached patch for a few weeks now with no issues. I’ve stopped the signal handler from responding to SIGIO, and the two places where the NS GUI used to raise SIGIO have been replaced with direct calls to the SIGIO handler code. I’m not sure if this is a sensible approach. It fixes at least one crash, and we could remove some HAVE_NS‐only code, so I think it’s desirable. I’m just not sure about my implementation. Any thoughts, anyone? -- Alan Third --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Don-t-use-SIGIO-in-NS.patch" >From bff3dbfe43a24ee924edd777a7a876b627f94f11 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 29 Apr 2017 23:35:16 +0100 Subject: [PATCH] Don't use SIGIO in NS * src/keyboard.c (handle_user_signal) [HAVE_NS]: Don't handle SIGIO. * src/keyboard.h (handle_input_available_signal) [HAVE_NS]: Make available to external code. * src/nsterm.m (hold_event, ns_Select): Call handle_input_available_signal directly. * src/sysdep.c (emacs_sigaction_init) [HAVE_NS]: Ignore SIGIO. --- src/keyboard.c | 3 ++- src/keyboard.h | 11 +++++++++++ src/nsterm.m | 4 ++-- src/sysdep.c | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index c9fa2a9f5e..d22f7b08c6 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -7264,7 +7264,8 @@ handle_user_signal (int sig) } p->npending++; -#ifdef USABLE_SIGIO +#if defined (USABLE_SIGIO) && !defined (HAVE_NS) + /* Dont use the interrupt handler in NS. */ if (interrupt_input) handle_input_available_signal (sig); else diff --git a/src/keyboard.h b/src/keyboard.h index 2219c01135..29279bef86 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -495,6 +495,17 @@ extern void mark_kboards (void); extern const char *const lispy_function_keys[]; #endif +#ifdef HAVE_NS +/* The NS port only uses SIGIO internally, and even then only in two + places in the code, but it causes crashes if certain code is not + properly wrapped in block_input/unblock_input. + + Since it's only used internally, we should be able to disable it, + and call the SIGIO handler directly. + */ +extern void handle_input_available_signal (int sig); +#endif + extern char const DEV_TTY[]; INLINE_HEADER_END diff --git a/src/nsterm.m b/src/nsterm.m index c22c5a70ba..00b7a89472 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -472,7 +472,7 @@ - (NSColor *)colorUsingDefaultColorSpace hold_event_q.q[hold_event_q.nr++] = *event; /* Make sure ns_read_socket is called, i.e. we have input. */ - raise (SIGIO); + handle_input_available_signal (SIGIO); send_appdefined = YES; } @@ -4289,7 +4289,7 @@ in certain situations (rapid incoming events). if (hold_event_q.nr > 0) { /* We already have events pending. */ - raise (SIGIO); + handle_input_available_signal (SIGIO); errno = EINTR; return -1; } diff --git a/src/sysdep.c b/src/sysdep.c index 91b2a5cb94..70fdf92964 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1606,7 +1606,7 @@ emacs_sigaction_init (struct sigaction *action, signal_handler_t handler) { sigaddset (&action->sa_mask, SIGINT); sigaddset (&action->sa_mask, SIGQUIT); -#ifdef USABLE_SIGIO +#if defined (USABLE_SIGIO) && !defined (HAVE_NS) sigaddset (&action->sa_mask, SIGIO); #endif } -- 2.12.0 --TB36FDmn/VVEgNH/--