+2005-01-24 Ben Maurer <bmaurer@ximian.com>
+
+ * marshal.c (mono_string_utf8_to_builder)
+ (mono_string_builder_to_utf16): We might not have ownership of the
+ string. In thise case, we need to create a new buffer.
+
+ * object-internals.h (mono_stringbuilder_capacity): sb->str might
+ be null, in which case, use the default capacity.
Mon Jan 24 16:42:29 CET 2005 Paolo Molaro <lupus@ximian.com>
items_written = mono_stringbuilder_capacity (sb);
if (!error) {
+ if (! sb->str || sb->str == sb->cached_str) {
+ sb->str = mono_string_new_size (mono_domain_get (), items_written);
+ sb->cached_str = NULL;
+ }
+
memcpy (mono_string_chars (sb->str), ut, items_written * 2);
sb->length = items_written;
} else
if (!sb)
return NULL;
+ /*
+ * The sb could have been allocated with the default capacity and be empty.
+ * we need to alloc a buffer of the default capacity in this case.
+ */
+ if (! sb->str)
+ sb->str = mono_string_new_size (mono_domain_get (), mono_stringbuilder_capacity (sb));
+ /*
+ * The stringbuilder might not have ownership of this string. If this is
+ * the case, we must duplicate the string, so that we don't munge immutable
+ * strings
+ */
+ else if (sb->str == sb->cached_str) {
+ sb->str = mono_string_new_utf16 (mono_domain_get (), mono_string_chars (sb->str), mono_stringbuilder_capacity (sb));
+ sb->cached_str = NULL;
+ }
+
return mono_string_chars (sb->str);
}