[svn:parrot] r47086 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Fri May 28 12:51:56 UTC 2010
Author: bacek
Date: Fri May 28 12:51:56 2010
New Revision: 47086
URL: https://trac.parrot.org/parrot/changeset/47086
Log:
Fix memory allocation issues in StringBuilder. Closes TT#1665. masak++
Modified:
trunk/src/pmc/stringbuilder.pmc
trunk/t/pmc/stringbuilder.t
Modified: trunk/src/pmc/stringbuilder.pmc
==============================================================================
--- trunk/src/pmc/stringbuilder.pmc Fri May 28 07:51:09 2010 (r47085)
+++ trunk/src/pmc/stringbuilder.pmc Fri May 28 12:51:56 2010 (r47086)
@@ -145,6 +145,8 @@
/* TODO Ask chromatic why in Parrot_str_join he ignored charset */
cs = Parrot_str_rep_compatible(interp, buffer, s, &enc);
if (!cs) {
+ STRING *new_buffer;
+
cs = Parrot_unicode_charset_ptr;
enc = (buffer->encoding == Parrot_utf16_encoding_ptr
|| s->encoding == Parrot_utf16_encoding_ptr
@@ -153,9 +155,18 @@
? Parrot_utf16_encoding_ptr
: Parrot_utf8_encoding_ptr;
- buffer = Parrot_unicode_charset_ptr->to_charset(interp, buffer);
s = Parrot_unicode_charset_ptr->to_charset(interp, s);
+ /* Create new temporary string */
+ new_buffer = Parrot_unicode_charset_ptr->to_charset(interp, buffer);
+ mem_gc_free(INTERP, buffer->_bufstart);
+ STRUCT_COPY(buffer, new_buffer);
+ buffer->flags = PObj_is_string_FLAG | PObj_live_FLAG | PObj_external_FLAG;
+
+ buffer->_bufstart = buffer->strstart = mem_gc_allocate_n_typed(INTERP,
+ new_buffer->_buflen, char);
+ mem_sys_memcopy(buffer->_bufstart, new_buffer->_bufstart, new_buffer->_buflen);
+
SET_ATTR_buffer(INTERP, SELF, buffer);
}
@@ -164,8 +175,9 @@
/* Reallocate if necessary */
if (total_size > Buffer_buflen(buffer)) {
+ /* Parrot_unicode_charset_ptr can produce NULL buffer */
buffer->_bufstart = buffer->strstart = mem_gc_realloc_n_typed(INTERP,
- buffer->_bufstart, total_size, char);
+ buffer->_bufstart, total_size, char);
buffer->_buflen = total_size;
}
Modified: trunk/t/pmc/stringbuilder.t
==============================================================================
--- trunk/t/pmc/stringbuilder.t Fri May 28 07:51:09 2010 (r47085)
+++ trunk/t/pmc/stringbuilder.t Fri May 28 12:51:56 2010 (r47086)
@@ -33,6 +33,8 @@
emit_with_named_args()
emit_with_pos_and_named_args()
+ test_unicode_conversion_tt1665()
+
done_testing()
# END_OF_TESTS
@@ -247,6 +249,29 @@
CODE
.end
+.sub "test_unicode_conversion_tt1665"
+ .local pmc list
+ list = new 'ResizablePMCArray'
+ push list, 195
+ push list, 182
+
+ .local pmc iterator
+ iterator = iter list
+ .local pmc sb
+ sb = new 'StringBuilder'
+ sb = unicode:""
+ loop:
+ unless iterator goto done
+ $P1 = shift iterator
+ $I1 = $P1
+ $S1 = chr $I1
+ sb .= $S1
+ goto loop
+ done:
+ $S0 = sb
+
+ ok( $S0, "Pushing unicode strings doesn't kill StringBuilder")
+.end
# Local Variables:
# mode: pir
More information about the parrot-commits
mailing list