Bruce Korb <bruce.k...@gmail.com> writes: >> ERROR: In procedure string-upcase: >> ERROR: string is read-only: "" >> Scheme evaluation error. AutoGen ABEND-ing in template >> confmacs.tlib on line 209 >> Failing Guile command: = = = = = >> >> (set! tmp-text (get "act-text")) >> (set! TMP-text (string-upcase tmp-text)) > > What in heck is string-upcase doing trying to write to its input string? > Why was the string returned by ag_scm_get() (the function bound to "get") > an immutable string anyway?
Good questions indeed. I spent a bunch of time investigating this, and found some bugs that might have caused this problem, although I'm not certain. Bruce: Can you please see if the patch below fixes this problem? Mike: Would you be willing to review this (very small) patch to see if it makes sense to you? I'd like a second opinion from someone familiar with that subsystem before I commit it. Thanks, Mark
>From a8da72937ff4d04e8d39531773cc05e676b2be1c Mon Sep 17 00:00:00 2001 From: Mark H Weaver <m...@netris.org> Date: Wed, 4 Jan 2012 17:59:27 -0500 Subject: [PATCH] Fix bugs related to mutation-sharing substrings * libguile/strings.c (scm_i_is_narrow_string, scm_i_try_narrow_string, scm_i_string_set_x): Check to see if the provided string is a mutation-sharing substring, and do the right thing in that case. Previously, if such a string was passed to these functions, they would behave very badly: while trying to fetch and/or mutate the cell containing the stringbuf, they were actually fetching or mutating the cell containing original shared string. That's because mutation-sharing substring store the original string in CELL_1, whereas all other strings store the stringbuf there. --- libguile/strings.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/libguile/strings.c b/libguile/strings.c index 666a951..1628aee 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -436,6 +436,9 @@ scm_i_string_length (SCM str) int scm_i_is_narrow_string (SCM str) { + if (IS_SH_STRING (str)) + str = SH_STRING_STRING (str); + return !STRINGBUF_WIDE (STRING_STRINGBUF (str)); } @@ -446,6 +449,9 @@ scm_i_is_narrow_string (SCM str) int scm_i_try_narrow_string (SCM str) { + if (IS_SH_STRING (str)) + str = SH_STRING_STRING (str); + SET_STRING_STRINGBUF (str, narrow_stringbuf (STRING_STRINGBUF (str))); return scm_i_is_narrow_string (str); @@ -664,6 +670,12 @@ scm_i_string_strcmp (SCM sstr, size_t start_x, const char *cstr) void scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr) { + if (IS_SH_STRING (str)) + { + p += STRING_START (str); + str = SH_STRING_STRING (str); + } + if (chr > 0xFF && scm_i_is_narrow_string (str)) SET_STRING_STRINGBUF (str, wide_stringbuf (STRING_STRINGBUF (str))); -- 1.7.5.4