unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Jean Abou Samra <jean@abou-samra.fr>
To: slbtty <shenlebantongying@gmail.com>, 58066@debbugs.gnu.org
Subject: bug#58066: pretty-print will make data modified by set-cdr! to random value
Date: Sun, 25 Sep 2022 12:16:29 +0200	[thread overview]
Message-ID: <d961cb23-71d1-efd4-9b7d-10529d109593@abou-samra.fr> (raw)
In-Reply-To: <CAFu5e0LL8eUbxnERwO_E1S5fV3kGsD6-A19CuQnFerANW4wyLQ@mail.gmail.com>

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	other threads:[~2022-09-25 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 10:01 bug#58066: pretty-print will make data modified by set-cdr! to random value slbtty
2022-09-25 10:16 ` Jean Abou Samra [this message]
2023-07-19 22:17 ` Jean Abou Samra

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=d961cb23-71d1-efd4-9b7d-10529d109593@abou-samra.fr \
    --to=jean@abou-samra.fr \
    --cc=58066@debbugs.gnu.org \
    --cc=shenlebantongying@gmail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).