GNU bug report logs - #58066
pretty-print will make data modified by set-cdr! to random value

Previous Next

Package: guile;

Reported by: slbtty <shenlebantongying <at> gmail.com>

Date: Sun, 25 Sep 2022 07:44:02 UTC

Severity: normal

Done: Jean Abou Samra <jean <at> abou-samra.fr>

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 58066 in the body.
You can then email your comments to 58066 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-guile <at> gnu.org:
bug#58066; Package guile. (Sun, 25 Sep 2022 07:44:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to slbtty <shenlebantongying <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sun, 25 Sep 2022 07:44:02 GMT) Full text and rfc822 format available.

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

From: slbtty <shenlebantongying <at> gmail.com>
To: bug-guile <at> gnu.org
Subject: pretty-print will make data modified by set-cdr! to random value
Date: Sat, 24 Sep 2022 06:01:13 -0400
GNU Guile 3.0.8

Using `guile3 < file.scm` to run the code below will makes the result
of tp unpredictable (pointing to very random things)

(use-modules (ice-9 pretty-print))
(define tl '(1 2))
(define tp (cdr tl))
(set-cdr! tp (cons 3 '()))
  (pretty-print tl)
  (pretty-print tp)
---

However, if i use plain old (display tp), the code will out put
expected valve (1 2 3) (3)
(define tl '(1 2))
(define tp (cdr tl))
(set-cdr! tp (cons 3 '()))
  (display tl) (newline)
  (display tp) (newline)

---

Context:

I am using guile3's repl and whenever i access a variable's by typing
its name after (set-cdr!), the result will goes wild.




Information forwarded to bug-guile <at> gnu.org:
bug#58066; Package guile. (Sun, 25 Sep 2022 10:17:02 GMT) Full text and rfc822 format available.

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

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: slbtty <shenlebantongying <at> gmail.com>, 58066 <at> debbugs.gnu.org
Subject: Re: bug#58066: pretty-print will make data modified by set-cdr! to
 random value
Date: Sun, 25 Sep 2022 12:16:29 +0200
Le 24/09/2022 à 12:01, slbtty a écrit :
> GNU Guile 3.0.8
>
> Using `guile3 < file.scm` to run the code below will makes the result
> of tp unpredictable (pointing to very random things)
>
> (use-modules (ice-9 pretty-print))
> (define tl '(1 2))
> (define tp (cdr tl))
> (set-cdr! tp (cons 3 '()))
>    (pretty-print tl)
>    (pretty-print tp)
> ---
>
> However, if i use plain old (display tp), the code will out put
> expected valve (1 2 3) (3)
> (define tl '(1 2))
> (define tp (cdr tl))
> (set-cdr! tp (cons 3 '()))
>    (display tl) (newline)
>    (display tp) (newline)
>
> ---
>
> Context:
>
> I am using guile3's repl and whenever i access a variable's by typing
> its name after (set-cdr!), the result will goes wild.



Interesting. It looks like scm_is_mutable_pair is broken? It's
defined (in pairs.h) as

static inline int
scm_is_mutable_pair (SCM x)
{
  /* Guile embeds literal pairs into compiled object files.  It's not
     valid Scheme to mutate literal values.  Two practical reasons to
     enforce this restriction are to allow literals to share share
     structure (pairs) with other literals in the compilation unit, and
     to allow literals containing immediates to be allocated in the
     read-only, shareable section of the file.  Attempting to mutate a
     pair in the read-only section would cause a segmentation fault, so
     to avoid that, we really do need to enforce the restriction. */
  return scm_is_pair (x) && GC_is_heap_ptr (SCM2PTR (x));
}


I don't know why that breaks or how to fix it, though.

As you can read from the comment, this code is actually
invalid Scheme, since it mutates literal data. However,
it is true that Guile should raise an error for this,
not segfault (which is what it does for me) or start
printing random things.

If you define tl as (list 1 2 3) instead of '(1 2 3),
everything will be fine.






Reply sent to Jean Abou Samra <jean <at> abou-samra.fr>:
You have taken responsibility. (Wed, 19 Jul 2023 22:18:02 GMT) Full text and rfc822 format available.

Notification sent to slbtty <shenlebantongying <at> gmail.com>:
bug acknowledged by developer. (Wed, 19 Jul 2023 22:18:02 GMT) Full text and rfc822 format available.

Message #13 received at 58066-done <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: 58066-done <at> debbugs.gnu.org
Subject: Re: bug#58066: pretty-print will make data modified by set-cdr! to
 random value
Date: Thu, 20 Jul 2023 00:17:10 +0200
[Message part 1 (text/plain, inline)]
Closing this as a duplicate
of https://debbugs.gnu.org/cgi/bugreport.cgi?bug=16060
[Message part 2 (text/html, inline)]
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 17 Aug 2023 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 252 days ago.

Previous Next


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