Permalink
Browse files

[GH #835] Fix set ByteBuffer from string

set_string_native() did not reset char* content, only the STRING *source.
  • Loading branch information...
1 parent 8da9b50 commit 196f596c10c99bdcb4dbf925f0ce96eebb88f108 Reini Urban committed Sep 21, 2012
Showing with 8 additions and 3 deletions.
  1. +2 −0 ChangeLog
  2. +5 −2 src/pmc/bytebuffer.pmc
  3. +1 −1 t/pmc/bytebuffer2.t
View
@@ -1,5 +1,7 @@
2012-10-16 release 4.9.0
- Core
+ + Fixed ByteBuffer set_string_native, which became out of sync with
+ two internal buffers. [GH #835]
- Documentation
- Tests
- Community
View
@@ -200,15 +200,18 @@ Reset the buffer with the content of the string.
VTABLE void set_string_native(STRING *new_string) {
INTVAL allocated_size;
+ INTVAL new_length;
GET_ATTR_allocated_size(INTERP, SELF, allocated_size);
+ new_length = Parrot_str_byte_length(interp, new_string);
if (allocated_size) {
unsigned char *content;
GET_ATTR_content(INTERP, SELF, content);
Parrot_gc_free_memory_chunk(INTERP, content);
- SET_ATTR_allocated_size(INTERP, SELF, 0);
+ SET_ATTR_allocated_size(INTERP, SELF, new_length);
}
SET_ATTR_source(INTERP, SELF, new_string);
- SET_ATTR_size(INTERP, SELF, Parrot_str_byte_length(INTERP, new_string));
+ SET_ATTR_content(INTERP, SELF, new_string->strstart);
+ SET_ATTR_size(INTERP, SELF, new_length);
}
/*
View
@@ -43,7 +43,7 @@ function from there does not expose this problem.
i = b_resize_normal[0]
is(i, 65, 'simple init - no problem expected')
- # oddly also works resize to smallar values like 2,1,0
+ # oddly also works resize to smaller values like 2,1,0
b_resize_normal = 3
b_resize_normal = s2
i = b_resize_normal[0]

0 comments on commit 196f596

Please sign in to comment.