From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re-entering the event loop Date: Sat, 18 Jun 2016 12:38:27 +0100 Message-ID: <20160618113827.GA3996@breton.holly.idiocy.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="3MwIy2ne0vdjdPXF" X-Trace: ger.gmane.org 1466249954 16887 80.91.229.3 (18 Jun 2016 11:39:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Jun 2016 11:39:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 18 13:39:14 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bEEam-00019y-TD for ged-emacs-devel@m.gmane.org; Sat, 18 Jun 2016 13:39:13 +0200 Original-Received: from localhost ([::1]:34366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEEal-0007vz-Op for ged-emacs-devel@m.gmane.org; Sat, 18 Jun 2016 07:39:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEEa8-0007vr-NR for emacs-devel@gnu.org; Sat, 18 Jun 2016 07:38:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEEa6-00061v-Fw for emacs-devel@gnu.org; Sat, 18 Jun 2016 07:38:31 -0400 Original-Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:37639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEEa6-00061q-51 for emacs-devel@gnu.org; Sat, 18 Jun 2016 07:38:30 -0400 Original-Received: by mail-wm0-x231.google.com with SMTP id a66so19344347wme.0 for ; Sat, 18 Jun 2016 04:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=4nc5s6oOyUcozxxkL4X4wjwmr7BVZDQobZdVg2+n7AE=; b=uDFGW9CO92TD9FVI4Bv0wrjdp/Y6DB6+zvy0ZVgBXk5GdwFEfleiO0YmBtv3m5T62N QcVKT4Q+5uxZXNNdTPJ5Ql7AgjT2M+EpHzZr/TtqKsERUDysWgJViEm9OeJfd/px1rsM Cyyt8xVNN1ku9ENOrPcoRTKLUhEUR2E8GslUB+g2tMmj00zbZWLgLN5vk04gFEUQyDCj +CpFT4HhWu+P7ndwzizs3O+1VOy0y0+Mtx4/u3Y1fvmLuTumhPmHK9ezfWWsSat+xinR 9JJv7rQJsxtJHGUj7UMAYaWWvhsUpAdhk4DA9K4Gxb6gTK5IQdZrAGMUZwwhZi4g1cVA HpWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:subject:message-id :mime-version:content-disposition:user-agent; bh=4nc5s6oOyUcozxxkL4X4wjwmr7BVZDQobZdVg2+n7AE=; b=YbEcwgu4rK5JNN7UrjKnwuPf5vWiP9YjN3+cdZtwGLLzpXjdUmY8w+r5R/jdAfmvan nt/KCvKVucuBvBd/uQgE7Cd5dlkWnfQJXS//Jgc5gkcBxO6UbwmAlOJ/o6+M1GzLy5Fz /8doJsya0z8no/sfaTL80/P/f88GN8APnKEk1TJee0/9RcRIWUNEWgjD3PPUjNw+rsVY LdWtF1cXU4c8BZiQQShRjR2Lq5wImFjEsn+/KhgSj2L/619QZMsoVvp2zTNBJ2MIxxXa WBFTtN1l/huWcUHCkWITyEPxqP2PtJUAHo5PsF+jJxKSTcnKtFZY/TqDiLoeMahueEze SP8A== X-Gm-Message-State: ALyK8tIN5CVtwNDwV5XmNWCbFgAnQ1Gi7yQzZD+1YZoAQKGvMDj7oPhzf9Fd767b/t9L5Q== X-Received: by 10.194.242.163 with SMTP id wr3mr6314353wjc.1.1466249908888; Sat, 18 Jun 2016 04:38:28 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-ac92-b5d8-4ccd-40fc.holly.idiocy.org. [2001:8b0:3f8:8129:ac92:b5d8:4ccd:40fc]) by smtp.gmail.com with ESMTPSA id w81sm3297004wmg.20.2016.06.18.04.38.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Jun 2016 04:38:27 -0700 (PDT) Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 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:204466 Archived-At: --3MwIy2ne0vdjdPXF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The NS port has an event loop that contains this code: if (++apploopnr != 1) { emacs_abort (); } So if the loop is entered again it crashes Emacs instantly and gives a stack trace. This shows up in a couple of bugs. Bug#11049, for example, is where it receives a SIGHUP and should quit cleanly and write out backups of open buffers, etc. but actually just crashes because it re-enters the event loop. What happens here is that the SIGHUP is received as an event, which then calls a function that unblocks *all* input. Then Emacs tries to clean up before quitting but that results with it handling input events again, therefore re-entering the event loop and aborting. I've sent a patch to this bug that simply re-blocks input, but the alternative is to remove this check and let Emacs re-enter the event loop. As far as I can tell this works fine for this particular case (SIGHUP), but I don't know if it will break something else. Is there any way, other than sending signal to kill it, that would result in Emacs re-entering the event loop? Thanks! -- Alan Third --3MwIy2ne0vdjdPXF Content-Type: text/plain; charset=us-ascii Content-Description: Remove event loop abort Content-Disposition: attachment; filename="remove-abort.patch" diff --git a/src/nsterm.m b/src/nsterm.m index f2b0d90..10e22fd 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -288,7 +288,6 @@ - (NSColor *)colorUsingDefaultColorSpace static struct timespec select_timeout = { 0, 0 }; static int selfds[2] = { -1, -1 }; static pthread_mutex_t select_mutex; -static int apploopnr = 0; static NSAutoreleasePool *outerpool; static struct input_event *emacs_event = NULL; static struct input_event *q_event_ptr = NULL; @@ -4054,15 +4053,6 @@ in certain situations (rapid incoming events). } #endif /* NS_IMPL_COCOA */ -static void -unwind_apploopnr (Lisp_Object not_used) -{ - --apploopnr; - n_emacs_events_pending = 0; - ns_finish_events (); - q_event_ptr = NULL; -} - static int ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) /* -------------------------------------------------------------------------- @@ -4126,13 +4116,8 @@ in certain situations (rapid incoming events). send_appdefined = YES; ns_send_appdefined (-1); - if (++apploopnr != 1) - { - emacs_abort (); - } - record_unwind_protect (unwind_apploopnr, Qt); [NSApp run]; - unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */ + unbind_to (specpdl_count, Qnil); } nevents = n_emacs_events_pending; @@ -4235,16 +4220,10 @@ in certain situations (rapid incoming events). block_input (); ns_init_events (&event); - if (++apploopnr != 1) - { - emacs_abort (); - } - { ptrdiff_t specpdl_count = SPECPDL_INDEX (); - record_unwind_protect (unwind_apploopnr, Qt); [NSApp run]; - unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */ + unbind_to (specpdl_count, Qnil); } ns_finish_events (); --3MwIy2ne0vdjdPXF--