From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#33034: `unwind-protect' cleanup form is not executed if body dies in stack overflow Date: Sun, 14 Oct 2018 10:02:59 -0700 Organization: UCLA Computer Science Department Message-ID: <3f05af02-38e2-c03a-8449-bad3d1bb7670@cs.ucla.edu> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------398AD4004868A0B1D8E44526" X-Trace: blaine.gmane.org 1539536531 2258 195.159.176.226 (14 Oct 2018 17:02:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 14 Oct 2018 17:02:11 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cc: 33034-done@debbugs.gnu.org To: Paul Pogonyshev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 14 19:02:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1gBjmG-0000Ru-Pi for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Oct 2018 19:02:04 +0200 Original-Received: from localhost ([::1]:49046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBjoM-0002hd-Mf for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Oct 2018 13:04:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBjoF-0002gp-FY for bug-gnu-emacs@gnu.org; Sun, 14 Oct 2018 13:04:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gBjoA-0004Lp-Dz for bug-gnu-emacs@gnu.org; Sun, 14 Oct 2018 13:04:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45219) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gBjoA-0004LY-8M for bug-gnu-emacs@gnu.org; Sun, 14 Oct 2018 13:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gBjo9-00039d-U0 for bug-gnu-emacs@gnu.org; Sun, 14 Oct 2018 13:04:01 -0400 In-Reply-To: Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Oct 2018 17:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 33034 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 33034@debbugs.gnu.org, eggert@cs.ucla.edu, pogonyshev@gmail.com Original-Received: via spool by 33034-done@debbugs.gnu.org id=D33034.153953659412067 (code D ref 33034); Sun, 14 Oct 2018 17:04:01 +0000 Original-Received: (at 33034-done) by debbugs.gnu.org; 14 Oct 2018 17:03:14 +0000 Original-Received: from localhost ([127.0.0.1]:49475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gBjnO-00038Z-HH for submit@debbugs.gnu.org; Sun, 14 Oct 2018 13:03:14 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:56774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gBjnM-00038M-FH for 33034-done@debbugs.gnu.org; Sun, 14 Oct 2018 13:03:13 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5AD431609A0; Sun, 14 Oct 2018 10:03:06 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id zkh3BIPifpFe; Sun, 14 Oct 2018 10:03:05 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0DDCC160E48; Sun, 14 Oct 2018 10:03:05 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id D23C8eBRSts6; Sun, 14 Oct 2018 10:03:04 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id C1E9B1609A0; Sun, 14 Oct 2018 10:03:04 -0700 (PDT) Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:151245 Archived-At: This is a multi-part message in MIME format. --------------398AD4004868A0B1D8E44526 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for the bug report; I installed the attached to fix it. The problem with your test case was neither C stack overflow nor failure to unwind the Lisp stack: it was failure to restore the Lisp evaluation depth (which is a separate thing from the Lisp stack size). By the way, why are there two different limits? That slows the interpreter down a bit. Why don't we simply have a limit for the Lisp stack size? Every time lisp_eval_depth grows, the stack size grows, so limiting the stack limits the evaluation depth for free. If we had done things this way, the interpreter would be a bit faster and this bug would never have occurred. --------------398AD4004868A0B1D8E44526 Content-Type: text/x-patch; name="0001-Fix-lisp_eval_depth-in-unwind-protect-cleanup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-lisp_eval_depth-in-unwind-protect-cleanup.patch" >From 5dfbdff57be6e93efe79f9b07e8b6383ec02959a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 Oct 2018 09:51:32 -0700 Subject: [PATCH] Fix lisp_eval_depth in unwind-protect cleanup Problem reported by Paul Pogonyshev (Bug#33034). * src/lisp.h (union specbinding): New member unwind.eval_depth. * src/eval.c (record_unwind_protect, set_unwind_protect): Set it. (do_one_unbind): Use it. --- src/eval.c | 3 +++ src/lisp.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/eval.c b/src/eval.c index 42c275de6b..a51d0c9083 100644 --- a/src/eval.c +++ b/src/eval.c @@ -3429,6 +3429,7 @@ record_unwind_protect (void (*function) (Lisp_Object), Lisp_Object arg) specpdl_ptr->unwind.kind = SPECPDL_UNWIND; specpdl_ptr->unwind.func = function; specpdl_ptr->unwind.arg = arg; + specpdl_ptr->unwind.eval_depth = lisp_eval_depth; grow_specpdl (); } @@ -3501,6 +3502,7 @@ do_one_unbind (union specbinding *this_binding, bool unwinding, switch (this_binding->kind) { case SPECPDL_UNWIND: + lisp_eval_depth = this_binding->unwind.eval_depth; this_binding->unwind.func (this_binding->unwind.arg); break; case SPECPDL_UNWIND_ARRAY: @@ -3595,6 +3597,7 @@ set_unwind_protect (ptrdiff_t count, void (*func) (Lisp_Object), p->unwind.kind = SPECPDL_UNWIND; p->unwind.func = func; p->unwind.arg = arg; + p->unwind.eval_depth = lisp_eval_depth; } void diff --git a/src/lisp.h b/src/lisp.h index 5ecc48b025..a7a26ef350 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3071,6 +3071,7 @@ union specbinding ENUM_BF (specbind_tag) kind : CHAR_BIT; void (*func) (Lisp_Object); Lisp_Object arg; + EMACS_INT eval_depth; } unwind; struct { ENUM_BF (specbind_tag) kind : CHAR_BIT; -- 2.17.1 --------------398AD4004868A0B1D8E44526--