GNU bug report logs - #31146
cl-prin1 infloops when printing list with circularity in the tail

Previous Next

Package: emacs;

Reported by: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Date: Fri, 13 Apr 2018 14:01:01 UTC

Severity: normal

Tags: fixed, patch

Found in versions 26.1, 27.0.50

Fixed in versions 27.1, 26.2

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 31146 in the body.
You can then email your comments to 31146 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#31146; Package emacs. (Fri, 13 Apr 2018 14:01:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Basil L. Contovounesios" <contovob <at> tcd.ie>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 13 Apr 2018 14:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; ielm via cl-prin1 infloops when printing circular object
Date: Fri, 13 Apr 2018 15:00:24 +0100
(This is a repeat of a recipe I sent to bug#18012 as a separate report.)

The following change:

81b5131e11: 2018-01-15 17:04:05 -0500
  * lisp/ielm.el (ielm-eval-input): Use cl-print.
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=81b5131e11fa96d32a1718c6e2ebf40994d7d281

now results in the following behaviour:

1. emacs -Q
2. M-x ielm RET
3. (let ((l (make-list 2 0)))
     (nconc l (cdr l)))
4. C-m
     => infloop
5. C-g
     => *** IELM Error ***  Quit during pretty-printing

Evaluating (4) in *scratch* via C-j, by contrast, inserts (0 0 . #1)
without inflooping, presumably because pp is used instead of cl-prin1.

-- 
Basil

In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2018-04-12 built on thunk
Repository revision: 17174d3f77fe6d5103bfe7e858035a0038010522
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Debian GNU/Linux buster/sid

Configured using:
 'configure --config-cache --prefix=/home/blc/.local --with-mailutils
 --with-x-toolkit=lucid --with-modules --with-file-notification=yes
 --with-x 'CFLAGS=-march=native -O2 -pipe''

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS LUCID X11 MODULES THREADS LIBSYSTEMD JSON LCMS2




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31146; Package emacs. (Sat, 14 Apr 2018 05:17:01 GMT) Full text and rfc822 format available.

Message #8 received at 31146 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 31146 <at> debbugs.gnu.org
Subject: Re: bug#31146: 27.0.50;
 ielm via cl-prin1 infloops when printing circular object
Date: Sat, 14 Apr 2018 01:16:00 -0400
[Message part 1 (text/plain, inline)]
retitle 31146 cl-prin1 infloops when printing list with circularity in the tail
tags 31146 + patch
quit

"Basil L. Contovounesios" <contovob <at> 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)

[v1-0001-Fix-cl-print-for-circular-sublists-Bug-31146.patch (text/x-diff, inline)]
From 57d1b421826b0b605abf2e9023e1a4f004b3502e Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


Changed bug title to 'cl-prin1 infloops when printing list with circularity in the tail' from '27.0.50; ielm via cl-prin1 infloops when printing circular object' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 14 Apr 2018 05:17:02 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 14 Apr 2018 05:17:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31146; Package emacs. (Sat, 14 Apr 2018 21:27:02 GMT) Full text and rfc822 format available.

Message #15 received at 31146 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31146 <at> debbugs.gnu.org
Subject: Re: bug#31146: 27.0.50;
 ielm via cl-prin1 infloops when printing circular object
Date: Sat, 14 Apr 2018 22:26:00 +0100
Noam Postavsky <npostavs <at> gmail.com> writes:

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

Indeed.  The only significance of ielm I was alluding to in this case is
that, as a presumably popular interactive environment, it probably
shouldn't infloop, regardless of implementation.

> Here's a patch.

Thanks for working on this,

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31146; Package emacs. (Thu, 26 Apr 2018 12:01:02 GMT) Full text and rfc822 format available.

Message #18 received at 31146 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 31146 <at> debbugs.gnu.org
Subject: Re: bug#31146: 27.0.50;
 ielm via cl-prin1 infloops when printing circular object
Date: Thu, 26 Apr 2018 08:00:28 -0400
found 31146 26.1
tags 31146 fixed
close 31146 27.1
quit

Noam Postavsky <npostavs <at> gmail.com> writes:

> Here's a patch.

Pushed to master.

> 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?

It looks like <...> is (sometimes) used for this.

[1: b8aa7ecf54]: 2018-04-26 07:37:48 -0400
  Fix cl-print for circular sublists (Bug#31146)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=b8aa7ecf54c9b164a59f1b0e9f9fe90531dadd20




bug Marked as found in versions 26.1. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 26 Apr 2018 12:01:02 GMT) Full text and rfc822 format available.

Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 26 Apr 2018 12:01:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 31146 <at> debbugs.gnu.org and "Basil L. Contovounesios" <contovob <at> tcd.ie> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 26 Apr 2018 12:01:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 25 May 2018 11:24:04 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Jun 2018 09:28:02 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 26.2. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Jun 2018 09:28:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 02 Jul 2018 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 300 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.