From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Abou Samra Newsgroups: gmane.lisp.guile.bugs Subject: bug#58066: pretty-print will make data modified by set-cdr! to random value Date: Sun, 25 Sep 2022 12:16:29 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20083"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: slbtty , 58066@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sun Sep 25 12:18:38 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocOic-00056D-FG for guile-bugs@m.gmane-mx.org; Sun, 25 Sep 2022 12:18:38 +0200 Original-Received: from localhost ([::1]:57938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ocOib-0001N6-2f for guile-bugs@m.gmane-mx.org; Sun, 25 Sep 2022 06:18:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocOh5-0000oV-21 for bug-guile@gnu.org; Sun, 25 Sep 2022 06:17:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ocOh4-00045S-Lz for bug-guile@gnu.org; Sun, 25 Sep 2022 06:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ocOh4-0006DD-B9 for bug-guile@gnu.org; Sun, 25 Sep 2022 06:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jean Abou Samra Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 25 Sep 2022 10:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58066 X-GNU-PR-Package: guile Original-Received: via spool by 58066-submit@debbugs.gnu.org id=B58066.166410100823855 (code B ref 58066); Sun, 25 Sep 2022 10:17:02 +0000 Original-Received: (at 58066) by debbugs.gnu.org; 25 Sep 2022 10:16:48 +0000 Original-Received: from localhost ([127.0.0.1]:45920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ocOgp-0006Ch-UJ for submit@debbugs.gnu.org; Sun, 25 Sep 2022 06:16:48 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.24]:38989) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ocOgl-0006CP-NO for 58066@debbugs.gnu.org; Sun, 25 Sep 2022 06:16:46 -0400 Original-Received: from [172.20.10.5] ([37.170.74.76]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.184]) with ESMTPSA (Nemesis) id 1MGA0o-1oSTbk1eRQ-00GWg7; Sun, 25 Sep 2022 12:16:36 +0200 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:x1Zo+CGW8zGNILa0q1MFh+FmKiDCQEQHbRHHi89lsurqvj6ZysF 6/1L5wePz7bVZVRtPF5YCM2agbriG8OsJNfrqLqbGtRHihbvTmkeIwWoTBmHZjAGJaxoNJq lsFyrASztQn6O58UgNJdkJphxuwNkroppGhYJchLaf+RZOb9BWHOn26iHi0yu1Chck/8/QM f2ZcITc9tuZXsgjnY5i6Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:zVWgX60lIfo=:VoD9qhjXKsziFWWQQGURZ+ lat3EqN3C+ibLWgfazh7i56N26RCYc/IVJXn2wh0IuxnUrFE90dbIEW0SVScFr9mRpOHOUP7I KVpouvYNLU8qylftfq+YYyOeqXMQEh3CsIyRt+ZOA8Qhx9ZoaTP5GcexEgPa4ItcrIEYBY4sm Mz7zdKbjAoYH4DNn9Cf0mDL7p7R0ToSA9KnGzdAXC3Ulrld0v748xNdj/lUrrJfnMEJ9q/4BU rlWN9NSIxoYAE2+YD+Kf9tviMHknDhqjdA8W9WlULvdF18TndizoZSwKRm4qaah0TezukHtw9 fd+H4coH2+KDYYGGWVlK/J4/q/Y4cZMjRohw2u0DRmBiD7gqVKb3ziTrXUbSSwCMMCBgQcKl/ XlsdG25Bfp2I+HaNWUy0BO4gd+PsSxABC/zxSZidA7pkzes0Jnp15jiztDLExXq7MpKubpoYB DOq/BwBqNqNAYLCFx/yWB2XQCsg5pUDvN3UhcD4uJ3SuOWXYKcluC3JWFLyWzAkFjrWKVi09w ggyiq6rMEBTgLym9SzNcIHjLLNOxT1IFku3G+Z5w475AKjeBDP9/ftL/JEQ0JGaiNzrt7TnO4 /xZeeE7k5ko6/QeitvCbbYkUTR1X56DLqJ3A7lIN05oayrNiKdlbaXjX1h/8XWzhfNYIfwURG vq+3cnZP52KXXiGbuyaMKZBUJqQJw84WAz23WkEP0PXFeaUGyg3t0URlECO0exYE+iqrFk1Jb uDlF0Gl0x/Nn4tkmcNZkfYIn4KGlXLy5+jDmS7lkr+RGwc2qfnaIhS0870ETRtxjbs8wkO3R X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10380 Archived-At: 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.