Stringbufs immutable by default
* libguile/snarf.h (SCM_IMMUTABLE_STRINGBUF): Remove shared flag.
Stringbufs are immutable by default.
* libguile/strings.c: Rewrite blurb. Change to have stringbufs be
immutable by default and mutable only when marked as such. Going
mutable means making a private copy.
(STRINGBUF_MUTABLE, STRINGBUF_F_MUTABLE): New definitions.
(SET_STRINGBUF_SHARED): Remove.
(scm_i_print_stringbuf): Simplify to just alias the stringbuf as-is.
(substring_with_immutable_stringbuf): New helper.
(scm_i_substring, scm_i_substring_read_only, scm_i_substring_copy):
use new helper.
(scm_i_string_ensure_mutable_x): New helper.
(scm_i_substring_shared): Use scm_i_string_ensure_mutable_x.
(stringbuf_write_mutex): Remove; yaaaaaaaay.
(scm_i_string_start_writing): Use scm_i_string_ensure_mutable_x. No
more mutex.
(scm_i_string_stop_writing): Now a no-op.
(scm_i_make_symbol): Use substring/copy.
(scm_sys_string_dump, scm_sys_symbol_dump): Update.
* libguile/strings.h (SCM_I_STRINGBUF_F_SHARED): Remove.
(SCM_I_STRINGBUF_F_MUTABLE): Add.
* module/system/vm/assembler.scm (link-data): Don't add shared flag any
more. Existing compiled flags are harmless tho.
* test-suite/tests/strings.test ("string internals"): Update.
This commit is contained in:
parent
c38b9625c8
commit
d0934df1f2
5 changed files with 158 additions and 214 deletions
|
|
@ -111,27 +111,45 @@
|
|||
(not (eq? (assq-ref (%string-dump s2) 'shared)
|
||||
s1))))
|
||||
|
||||
(pass-if "ASCII substrings share stringbufs before copy-on-write"
|
||||
(pass-if "ASCII substrings immutable before copy-on-write"
|
||||
(let* ((s1 "foobar")
|
||||
(s2 (substring s1 0 3)))
|
||||
(assq-ref (%string-dump s1) 'stringbuf-shared)))
|
||||
(and (not (assq-ref (%string-dump s1) 'stringbuf-mutable))
|
||||
(not (assq-ref (%string-dump s2) 'stringbuf-mutable)))))
|
||||
|
||||
(pass-if "BMP substrings share stringbufs before copy-on-write"
|
||||
(pass-if "BMP substrings immutable before copy-on-write"
|
||||
(let* ((s1 "\u0100\u0101\u0102\u0103\u0104\u0105")
|
||||
(s2 (substring s1 0 3)))
|
||||
(assq-ref (%string-dump s1) 'stringbuf-shared)))
|
||||
(and (not (assq-ref (%string-dump s1) 'stringbuf-mutable))
|
||||
(not (assq-ref (%string-dump s2) 'stringbuf-mutable)))))
|
||||
|
||||
(pass-if "ASCII substrings don't share stringbufs after copy-on-write"
|
||||
(pass-if "ASCII base string still immutable after copy-on-write"
|
||||
(let* ((s1 "foobar")
|
||||
(s2 (substring s1 0 3)))
|
||||
(string-set! s2 0 #\F)
|
||||
(not (assq-ref (%string-dump s2) 'stringbuf-shared))))
|
||||
(and (not (assq-ref (%string-dump s1) 'stringbuf-mutable))
|
||||
(assq-ref (%string-dump s2) 'stringbuf-mutable))))
|
||||
|
||||
(pass-if "BMP substrings don't share stringbufs after copy-on-write"
|
||||
(pass-if "BMP base string still immutable after copy-on-write"
|
||||
(let* ((s1 "\u0100\u0101\u0102\u0103\u0104\u0105")
|
||||
(s2 (substring s1 0 3)))
|
||||
(string-set! s2 0 #\F)
|
||||
(not (assq-ref (%string-dump s2) 'stringbuf-shared))))
|
||||
(and (not (assq-ref (%string-dump s1) 'stringbuf-mutable))
|
||||
(assq-ref (%string-dump s2) 'stringbuf-mutable))))
|
||||
|
||||
(pass-if "ASCII substrings mutable after shared mutation"
|
||||
(let* ((s1 "foobar")
|
||||
(s2 (substring/shared s1 0 3)))
|
||||
(string-set! s2 0 #\F)
|
||||
(and (assq-ref (%string-dump s1) 'stringbuf-mutable)
|
||||
(assq-ref (%string-dump s2) 'stringbuf-mutable))))
|
||||
|
||||
(pass-if "BMP substrings mutable after shared mutation"
|
||||
(let* ((s1 "\u0100\u0101\u0102\u0103\u0104\u0105")
|
||||
(s2 (substring/shared s1 0 3)))
|
||||
(string-set! s2 0 #\F)
|
||||
(and (assq-ref (%string-dump s1) 'stringbuf-mutable)
|
||||
(assq-ref (%string-dump s2) 'stringbuf-mutable))))
|
||||
|
||||
(with-test-prefix "encodings"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue