From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Andrew Choi Newsgroups: gmane.emacs.devel Subject: Re: Mac OS X - Hang / C-g problem patch Date: Wed, 04 Dec 2002 23:48:03 -0700 Sender: emacs-devel-admin@gnu.org Message-ID: References: <11A91199-07B3-11D7-AADA-00039390AB82@mac.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT X-Trace: main.gmane.org 1039071119 5620 80.91.224.249 (5 Dec 2002 06:51:59 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 5 Dec 2002 06:51:59 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18JprZ-0001SV-00 for ; Thu, 05 Dec 2002 07:51:57 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18Jq1u-0007Y0-00 for ; Thu, 05 Dec 2002 08:02:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18Jpre-00013e-00; Thu, 05 Dec 2002 01:52:02 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18Jpq5-0005dh-00 for emacs-devel@gnu.org; Thu, 05 Dec 2002 01:50:25 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18Jpq1-0005bl-00 for emacs-devel@gnu.org; Thu, 05 Dec 2002 01:50:25 -0500 Original-Received: from shawidc-mo1.cg.shawcable.net ([24.71.223.10] helo=pd3mo2so.prod.shaw.ca) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18Jpq0-0005Xm-00 for emacs-devel@gnu.org; Thu, 05 Dec 2002 01:50:21 -0500 Original-Received: from pd6mr2so.prod.shaw.ca (pd6mr2so-qfe3.prod.shaw.ca [10.0.141.217]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with ESMTP id <0H6M00I1GW86X6@l-daemon> for emacs-devel@gnu.org; Wed, 04 Dec 2002 23:48:06 -0700 (MST) Original-Received: from pn2ml9so.prod.shaw.ca (pn2ml9so-qfe0.prod.shaw.ca [10.0.121.7]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with ESMTP id <0H6M00L30W86GT@l-daemon> for emacs-devel@gnu.org; Wed, 04 Dec 2002 23:48:06 -0700 (MST) Original-Received: from owlbear.local.shawmail (h68-144-207-94.cg.shawcable.net [68.144.207.94]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with ESMTP id <0H6M005GAW85Q9@l-daemon> for emacs-devel@gnu.org; Wed, 04 Dec 2002 23:48:06 -0700 (MST) In-reply-to: <11A91199-07B3-11D7-AADA-00039390AB82@mac.com> Original-To: Steven Tamm User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-Lines: 174 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:9872 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:9872 Steven Tamm writes: > I just found some free time on my hands and got back around to working > on the problem where in the carbon gui, C-g does not interrupt > synchronous subprocesses. This caused much consternation and after > checking with some people at apple, there was no easy way. The > alternatives were to finish my Jaguar/MT UI patch (which I won't go > into), or to make all blocking reads be in a separate thread. [...] Hi Steven, I've checked that your patch works as advertised. I've worked out a simpler solution that uses polling though. The idea is to patch `read' to call `select' to check for available input. If none is after one second, poll for a user-cancel and check for input again and repeat. Since I've used CheckEventQueueForUserCancel, the command-period key is used instead of C-g. We can probably change it to C-g if we want. The patch also handles the following cases: when Emacs is stuck in a loop executing Lisp code and when it is stuck waiting for select instead of read (e.g., sleep-for). Performance will not be a problem except perhaps for the check in `eval'. Andrew. Index: eval.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/eval.c,v retrieving revision 1.197 diff -u -r1.197 eval.c --- eval.c 21 Nov 2002 17:33:01 -0000 1.197 +++ eval.c 5 Dec 2002 05:22:48 -0000 @@ -27,6 +27,9 @@ #include "keyboard.h" #include "dispextern.h" #include +#ifdef MAC_OSX +#include +#endif /* This definition is duplicated in alloc.c and keyboard.c */ /* Putting it in lisp.h makes cc bomb out! */ @@ -2154,6 +2157,12 @@ if (backtrace.debug_on_exit) val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); backtrace_list = backtrace.next; + +#ifdef MAC_OSX + if (CheckEventQueueForUserCancel ()) + kill (getpid (), SIGINT); +#endif + return val; } Index: keyboard.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keyboard.c,v retrieving revision 1.716 diff -u -r1.716 keyboard.c --- keyboard.c 22 Nov 2002 12:23:13 -0000 1.716 +++ keyboard.c 5 Dec 2002 05:23:00 -0000 @@ -10494,6 +10494,11 @@ poll_suppress_count = 1; start_polling (); #endif + +#ifdef MAC_OSX + /* At least provide an escape route since C-g doesn't work. */ + signal (SIGINT, interrupt_signal); +#endif } /* This type's only use is in syms_of_keyboard, to initialize the Index: mac.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/mac.c,v retrieving revision 1.10 diff -u -r1.10 mac.c --- mac.c 18 Oct 2002 10:00:10 -0000 1.10 +++ mac.c 5 Dec 2002 05:23:01 -0000 @@ -2748,6 +2748,8 @@ } #ifdef MAC_OSX +#include + #undef select extern int inhibit_window_system; @@ -2768,9 +2770,60 @@ if (!inhibit_window_system && rfds && FD_ISSET (0, rfds)) return 1; else - return select (n, rfds, wfds, efds, timeout); + { + EMACS_TIME end_time, now; + + EMACS_GET_TIME (end_time); + EMACS_ADD_TIME (end_time, end_time, *timeout); + + do + { + int r; + EMACS_TIME one_second; + + EMACS_SET_SECS (one_second, 1); + EMACS_SET_USECS (one_second, 0); + + if ((r = select (n, rfds, wfds, efds, &one_second)) > 0) + return r; + + if (CheckEventQueueForUserCancel ()) + { + kill (getpid (), SIGINT); + return 0; + } + + EMACS_GET_TIME (now); + EMACS_SUB_TIME (now, end_time, now); + } + while (!EMACS_TIME_NEG_P (now)); + + return 0; + } } +#undef read +int sys_read (fds, buf, nbyte) + int fds; + char *buf; + unsigned int nbyte; +{ + SELECT_TYPE rfds; + EMACS_TIME one_second; + int r; + + do + { + FD_ZERO (&rfds); + FD_SET (fds, &rfds); + + EMACS_SET_SECS (one_second, 1); + EMACS_SET_USECS (one_second, 0); + } + while (sys_select (fds+1, &rfds, 0, 0, &one_second) == 0); + + return read (fds, buf, nbyte); +} /* Set up environment variables so that Emacs can correctly find its support files when packaged as an application bundle. Directories Index: sysdep.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/sysdep.c,v retrieving revision 1.245 diff -u -r1.245 sysdep.c --- sysdep.c 22 Nov 2002 12:22:43 -0000 1.245 +++ sysdep.c 5 Dec 2002 05:23:04 -0000 @@ -69,6 +69,10 @@ #endif #endif /* not WINDOWSNT */ +#ifdef HAVE_CARBON +#define read sys_read +#endif + /* Does anyone other than VMS need this? */ #ifndef fwrite #define sys_fwrite fwrite