unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 60779@debbugs.gnu.org
Subject: bug#60779: ‘SCM_F_BYTEVECTOR_IMMUTABLE’ is not honored by bytevector instructions
Date: Fri, 13 Jan 2023 12:24:30 +0100	[thread overview]
Message-ID: <87a62meky9.fsf@inria.fr> (raw)

Bytevector literals are marked as ‘SCM_F_BYTEVECTOR_IMMUTABLE’, 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 #<thunk 7f2396b0e2e0>)
In ice-9/boot-9.scm:
    724:2  4 (call-with-prompt ("prompt") #<procedure 7f2396b20c60 …> …)
In ice-9/eval.scm:
    619:8  3 (_ #(#(#<directory (guile-user) 7f2396b14c80>)))
In ice-9/boot-9.scm:
   2836:4  2 (save-module-excursion #<procedure 7f2396b06300 at ice-…>)
  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 (expecting 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 <http://gnu.org/licenses/lgpl.html>.
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 ‘heap-object?’.

Ludo’.





                 reply	other threads:[~2023-01-13 11:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87a62meky9.fsf@inria.fr \
    --to=ludo@gnu.org \
    --cc=60779@debbugs.gnu.org \
    /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).