From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: C-g while exiting the minibuffer Date: Sun, 01 Dec 2013 17:13:12 -0500 Message-ID: References: <52977725.50800@gmx.at> <5299D72F.7060902@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1385936020 19858 80.91.229.3 (1 Dec 2013 22:13:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Dec 2013 22:13:40 +0000 (UTC) Cc: emacs-devel@gnu.org To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 01 23:13:44 2013 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 1VnFGn-0008E8-MI for ged-emacs-devel@m.gmane.org; Sun, 01 Dec 2013 23:13:41 +0100 Original-Received: from localhost ([::1]:33056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnFGn-0006EU-6N for ged-emacs-devel@m.gmane.org; Sun, 01 Dec 2013 17:13:41 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnFGT-0005wz-6P for emacs-devel@gnu.org; Sun, 01 Dec 2013 17:13:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VnFGL-0004aq-Kj for emacs-devel@gnu.org; Sun, 01 Dec 2013 17:13:20 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:24727) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnFGL-0004am-GX for emacs-devel@gnu.org; Sun, 01 Dec 2013 17:13:13 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFFMCox4/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCws0EhQYDSSIHgbBLZEKA4hhnBmBXoMV X-IPAS-Result: Av8EABK/CFFMCox4/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCws0EhQYDSSIHgbBLZEKA4hhnBmBXoMV X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="40860006" Original-Received: from 76-10-140-120.dsl.teksavvy.com (HELO pastel.home) ([76.10.140.120]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 01 Dec 2013 17:13:12 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 7848F60CCE; Sun, 1 Dec 2013 17:13:12 -0500 (EST) In-Reply-To: <5299D72F.7060902@gmx.at> (martin rudalics's message of "Sat, 30 Nov 2013 13:16:47 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:165993 Archived-At: >> But the problem remains of what to do with a C-g interrupting a unwind >> form: in the case of an Fset_window_configuration in an unwind form, the >> intention is to make that "no matter what happens, we end up recovering >> the original state", but a C-g at the wrong time will break this promise. > I'm afraid that C-g at the wrong time might produce an inconsistent > state which IMO seems more fatal than a non-original state. An inconsistent state would also be a non-original state, so yes, an inconsistent would also break the promise. >> - checking cycles here gives us no guarantee since the caller can do >> (set-window-prev-buffers w bufs) >> (setcdr bufs bufs) >> and you again end up with a cycle in your window-prev-buffers. > Right. So we'd need a safe implementation of delq and I wouldn't know > how to do that reasonably via DOLIST. Indeed, the FOREACH macro was designed for "read-only" traversals, just like the DOLIST macro. I don't think the hare/tortoise trick is inapplicable, tho: it just requires more care (since the deletions of Fdelq might give the tortoise shortcuts that risk making the tortoise catch up with the hare). See patch below. > I'd rather use a simple routine to find out whether the original > argument list of delq is infinite (if we think this could be a real > problem). I think the hare/tortoise is a "simple routine to find out if the list is infinite". Stefan === modified file 'src/fns.c' --- src/fns.c 2013-11-29 19:47:58 +0000 +++ src/fns.c 2013-12-01 22:02:46 +0000 @@ -1537,15 +1537,12 @@ the value of a list `foo'. */) (register Lisp_Object elt, Lisp_Object list) { - register Lisp_Object tail, prev; - register Lisp_Object tem; + Lisp_Object tail, tortoise, prev = Qnil; + bool skip; - tail = list; - prev = Qnil; - while (CONSP (tail)) + FOR_EACH_TAIL (tail, list, tortoise, skip) { - CHECK_LIST_CONS (tail, list); - tem = XCAR (tail); + Lisp_Object tem = XCAR (tail); if (EQ (elt, tem)) { if (NILP (prev)) @@ -1555,8 +1552,6 @@ } else prev = tail; - tail = XCDR (tail); - QUIT; } return list; } === modified file 'src/lisp.h' --- src/lisp.h 2013-11-30 09:25:31 +0000 +++ src/lisp.h 2013-12-01 22:05:02 +0000 @@ -4443,6 +4443,20 @@ memory_full (SIZE_MAX); \ } while (0) +/* Loop over all tails of a list, checking for cycles. + FIXME: Make tortoise and n internal declarations. + FIXME: Unroll the loop body so we don't need `n'. */ +#define FOR_EACH_TAIL(hare, list, tortoise, n) \ + for (tortoise = hare = (list), n = true; \ + CONSP (hare); \ + (hare = XCDR (hare), n = !n, \ + (n \ + ? ((EQ (hare, tortoise) \ + && (xsignal1 (Qcircular_list, (list)), 0))) \ + /* Move tortoise before the next iteration, in case */ \ + /* the next iteration does an Fsetcdr. */ \ + : (tortoise = XCDR (tortoise), 0)))) + /* Do a `for' loop over alist values. */ #define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var) \