unofficial mirror of 
 help / color / mirror / Atom feed
* bug#60779: ‘SCM_F_BYTEVECTOR_IMMUTABLE’ is not honored by bytevector instructions
@ 2023-01-13 11:24 Ludovic Courtès
  0 siblings, 0 replies; only message in thread
From: Ludovic Courtès @ 2023-01-13 11:24 UTC (permalink / raw)
  To: 60779

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
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 <>.
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?’.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-13 11:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 11:24 bug#60779: ‘SCM_F_BYTEVECTOR_IMMUTABLE’ is not honored by bytevector instructions Ludovic Courtès

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).