diff options
author | Mark H Weaver <mhw@netris.org> | 2012-01-04 17:59:27 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2012-01-07 10:36:22 -0500 |
commit | 49d09292ac6d92a86b574478a69450b85d2dd8c1 (patch) | |
tree | 610c018369ab10396a0c69dffebd3218e4e357f6 /libguile/strings.c | |
parent | a7e392c1fff2921af027675e8655b5892ac1142e (diff) | |
download | guile-49d09292ac6d92a86b574478a69450b85d2dd8c1.tar.gz |
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 the original shared string. That's because
mutation-sharing substrings store the original string in CELL_1,
whereas all other strings store the stringbuf there.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 870825a77..6e1f9c80b 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))); |