all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Gemini Lasswell <gazally@runbox.com>
To: Daniel Colascione <dancol@dancol.org>
Cc: 25965@debbugs.gnu.org, Stefan Monnier <monnier@IRO.UMontreal.CA>,
	Andreas Politz <politza@hochschule-trier.de>
Subject: bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice
Date: Thu, 21 Sep 2017 14:36:34 -0700	[thread overview]
Message-ID: <87r2uzwx7h.fsf@runbox.com> (raw)
In-Reply-To: <r0251su7toag.fsf@dancol.org> (Daniel Colascione's message of "Wed, 08 Mar 2017 14:08:07 -0800")

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

tags 25965 patch
quit

Daniel Colascione <dancol@dancol.org> writes:

> I think it's safe to remove it. Let's make
> sure to add a test too.

Here's a patch which removes the second ,form and adds a test:


[-- Attachment #2: 0001-Fix-dynamic-binding-wrapper-in-iter-lambda-bug-25965.patch --]
[-- Type: text/plain, Size: 2116 bytes --]

From 46720f235ff11f64a35b91e74110fd3a8e01be4f Mon Sep 17 00:00:00 2001
From: Gemini Lasswell <gazally@runbox.com>
Date: Wed, 20 Sep 2017 10:17:35 -0700
Subject: [PATCH] Fix dynamic binding wrapper in iter-lambda (bug#25965)

* lisp/emacs-lisp/generator.el (cps--make-dynamic-binding-wrapper):
Remove extra evaluation of form.
* test/lisp/emacs-lisp/generator-tests.el
(cps-iter-lambda-with-dynamic-binding): New test.
---
 lisp/emacs-lisp/generator.el            |  3 +--
 test/lisp/emacs-lisp/generator-tests.el | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el
index f3597cc387..3e9885900c 100644
--- a/lisp/emacs-lisp/generator.el
+++ b/lisp/emacs-lisp/generator.el
@@ -142,8 +142,7 @@ cps--make-dynamic-binding-wrapper
     `(let ((,dynamic-var ,static-var))
        (unwind-protect ; Update the static shadow after evaluation is done
             ,form
-         (setf ,static-var ,dynamic-var))
-       ,form)))
+         (setf ,static-var ,dynamic-var)))))
 
 (defmacro cps--with-dynamic-binding (dynamic-var static-var &rest body)
   "Evaluate BODY such that generated atomic evaluations run with
diff --git a/test/lisp/emacs-lisp/generator-tests.el b/test/lisp/emacs-lisp/generator-tests.el
index 4cc6c841da..cbb136ae91 100644
--- a/test/lisp/emacs-lisp/generator-tests.el
+++ b/test/lisp/emacs-lisp/generator-tests.el
@@ -282,3 +282,13 @@ cps-test-closed-flag
 (ert-deftest cps-test-declarations-preserved ()
   (should (equal (documentation 'generator-with-docstring) "Documentation!"))
   (should (equal (get 'generator-with-docstring 'lisp-indent-function) 5)))
+
+(ert-deftest cps-iter-lambda-with-dynamic-binding ()
+  "`iter-lambda' with dynamic binding produces correct result (bug#25965)."
+  (should (= 1
+             (iter-next
+              (funcall (iter-lambda ()
+                         (let* ((fill-column 10) ;;any special variable will do
+                                (i 0)
+                                (j (setq i (1+ i))))
+                           (iter-yield i))))))))
-- 
2.14.1


  reply	other threads:[~2017-09-21 21:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-04  8:02 bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice Andreas Politz
2017-03-08 21:52 ` Stefan Monnier
2017-03-08 22:08   ` Daniel Colascione
2017-09-21 21:36     ` Gemini Lasswell [this message]
2017-10-05 19:51       ` Gemini Lasswell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r2uzwx7h.fsf@runbox.com \
    --to=gazally@runbox.com \
    --cc=25965@debbugs.gnu.org \
    --cc=dancol@dancol.org \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=politza@hochschule-trier.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.