1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

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.
This commit is contained in:
Mark H Weaver 2012-01-04 17:59:27 -05:00
parent a7e392c1ff
commit 49d09292ac

View file

@ -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)));