From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 13 06:24:35 2023 Received: (at submit) by debbugs.gnu.org; 13 Jan 2023 11:24:35 +0000 Received: from localhost ([127.0.0.1]:49750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGIAk-0008Gk-L8 for submit@debbugs.gnu.org; Fri, 13 Jan 2023 06:24:35 -0500 Received: from lists.gnu.org ([209.51.188.17]:32808) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGIAj-0008Gd-Tw for submit@debbugs.gnu.org; Fri, 13 Jan 2023 06:24:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGIAj-0001YK-Oj for bug-guile@gnu.org; Fri, 13 Jan 2023 06:24:33 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGIAj-0008QP-Gu for bug-guile@gnu.org; Fri, 13 Jan 2023 06:24:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=eD44wXp4uR+PiQBb4MC5c7S0NQpgkYPc3Xjs6wMTTas=; b=Sxi8lUlQa0GS9S WP95fYqufy0vtCoBhR/g6sbxAZ0/UBQbNEQolRJEe9yMaSI8Rnr/ETM62dGQFWctRpjn55LPFgYhV r+U6EOviozcthW6aiddv7ZIc12A+AzioLItWiXMrAQeaRryuXUfr8sv23yMAQ8EddaJH9yXktGw30 3C//HZZEkofOH9mLayc0BgxZItxYbrafUKidMPJa4scrC3my2+Q7lJIzc5vFqajgi99RDzwYStoDf t6k1kDof55KQoLz58O1Mx5InDfA6ntmi2b30hogZTBvvetfzYaS7J/C1ImjZgy7tnIBw1HYQzmoGu uNCxtTX9yi0BCHKVNJ6g==; Received: from [193.50.110.246] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGIAj-00084Q-1R for bug-guile@gnu.org; Fri, 13 Jan 2023 06:24:33 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: bug-guile@gnu.org Subject: =?utf-8?Q?=E2=80=98SCM=5FF=5FBYTEVECTOR=5FIMMUTABLE=E2=80=99?= is not honored by bytevector instructions X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 24 =?utf-8?Q?Niv=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Cuivre X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Fri, 13 Jan 2023 12:24:30 +0100 Message-ID: <87a62meky9.fsf@inria.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Bytevector literals are marked as =E2=80=98SCM_F_BYTEVECTOR_IMMUTABLE=E2=80= =99, but VM instructions that access bytevectors do not check that flag, which can lead to segfaults: --8<---------------cut here---------------start------------->8--- $ cat t.scm (use-modules (rnrs bytevectors)) (define bv #vu8(1 2 3)) (bytevector-u8-set! bv 0 1) $ guild compile -O2 t.scm wrote `/home/ludo/.cache/guile/ccache/3.0-LE-8-4.6/data/src/guile-3.0/t.scm= .go' $ guile t.scm Segmentation fault --8<---------------cut here---------------end--------------->8--- Conversely, the subrs from bytevector.c do check the flag: --8<---------------cut here---------------start------------->8--- $ guild compile -O0 t.scm wrote `/home/ludo/.cache/guile/ccache/3.0-LE-8-4.6/data/src/guile-3.0/t.scm= .go' $ guile t.scm Backtrace: In ice-9/boot-9.scm: 1752:10 6 (with-exception-handler _ _ #:unwind? _ # _) In unknown file: 5 (apply-smob/0 #) In ice-9/boot-9.scm: 724:2 4 (call-with-prompt ("prompt") # =E2=80=A6) In ice-9/eval.scm: 619:8 3 (_ #(#(#))) In ice-9/boot-9.scm: 2836:4 2 (save-module-excursion #) 4388:12 1 (_) In unknown file: 0 (bytevector-u8-set! #vu8(1 2 3) 0 1) ERROR: In procedure bytevector-u8-set!: In procedure bytevector-u8-set!: Wrong type argument in position 1 (expecti= ng mutable bytevector): #vu8(1 2 3) $ guile --version guile (GNU Guile) 3.0.8 Copyright (C) 2021 Free Software Foundation, Inc. License LGPLv3+: GNU LGPL 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. --8<---------------cut here---------------end--------------->8--- I suppose the immutability test would have to be done not at the level of individual VM instructions but at a higher-level in generated code, such that the compiler could lift the test outside loops that access bytevectors, similar to what it does with =E2=80=98heap-object?=E2=80=99. Ludo=E2=80=99.