all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: 31146@debbugs.gnu.org
Subject: bug#31146: 27.0.50; ielm via cl-prin1 infloops when printing circular object
Date: Sat, 14 Apr 2018 01:16:00 -0400	[thread overview]
Message-ID: <87sh7yjrlb.fsf@gmail.com> (raw)
In-Reply-To: <87in8v435z.fsf@tcd.ie> (Basil L. Contovounesios's message of "Fri, 13 Apr 2018 15:00:24 +0100")

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

retitle 31146 cl-prin1 infloops when printing list with circularity in the tail
tags 31146 + patch
quit

"Basil L. Contovounesios" <contovob@tcd.ie> writes:

> 1. emacs -Q
> 2. M-x ielm RET
> 3. (let ((l (make-list 2 0)))
>      (nconc l (cdr l)))
> 4. C-m
>      => infloop

Right, though the bug is really about cl-prin1, ielm is just incidental.

Here's a patch.  Hmm, how should cl-defmethod changes be specified in
the ChangeLog?  I just put (cl-print-object), but is there some notation
to indicate it's this particular defmethod?

    (cl-defmethod cl-print-object ((object cons) stream)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2245 bytes --]

From 57d1b421826b0b605abf2e9023e1a4f004b3502e Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 14 Apr 2018 01:02:25 -0400
Subject: [PATCH v1] Fix cl-print for circular sublists (Bug#31146)

* lisp/emacs-lisp/cl-print.el (cl-print-object): Push each element of
list being printed onto cl-print--currently-printing.
* test/lisp/emacs-lisp/cl-print-tests.el (cl-print-circle-2): New
test.
---
 lisp/emacs-lisp/cl-print.el            |  9 ++++++---
 test/lisp/emacs-lisp/cl-print-tests.el | 10 ++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el
index 78cd6f9d9e..ada5923515 100644
--- a/lisp/emacs-lisp/cl-print.el
+++ b/lisp/emacs-lisp/cl-print.el
@@ -62,9 +62,12 @@ cl-print--currently-printing
       (princ "(" stream)
       (cl-print-object car stream)
       (while (and (consp object)
-                  (not (if cl-print--number-table
-                           (numberp (gethash object cl-print--number-table))
-                         (memq object cl-print--currently-printing))))
+                  (not (cond
+                        (cl-print--number-table
+                         (numberp (gethash object cl-print--number-table)))
+                        ((memq object cl-print--currently-printing))
+                        (t (push object cl-print--currently-printing)
+                           nil))))
         (princ " " stream)
         (cl-print-object (pop object) stream))
       (when object
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el
index 660d5c8069..d986c4015d 100644
--- a/test/lisp/emacs-lisp/cl-print-tests.el
+++ b/test/lisp/emacs-lisp/cl-print-tests.el
@@ -55,4 +55,14 @@
     (let ((print-circle t))
       (should (equal "(#1=(a . #1#) #1#)" (cl-prin1-to-string x))))))
 
+(ert-deftest cl-print-circle-2 ()
+  ;; Bug#31146.
+  (let ((x '(0 . #1=(0 . #1#))))
+    (let ((print-circle nil))
+      (should (string-match "\\`(0 0 . #[0-9])\\'"
+                            (cl-prin1-to-string x))))
+    (let ((print-circle t))
+      (should (equal "(0 . #1=(0 . #1#))" (cl-prin1-to-string x))))))
+
+
 ;;; cl-print-tests.el ends here.
-- 
2.11.0


  reply	other threads:[~2018-04-14  5:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 14:00 bug#31146: 27.0.50; ielm via cl-prin1 infloops when printing circular object Basil L. Contovounesios
2018-04-14  5:16 ` Noam Postavsky [this message]
2018-04-14 21:26   ` Basil L. Contovounesios
2018-04-26 12:00   ` Noam Postavsky

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=87sh7yjrlb.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=31146@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    /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.