Permalink
Browse files

Merge 'rurban/bytebuffer-resize-gh835'

Fixed conflict in ChangeLog
  • Loading branch information...
Reini Urban
Reini Urban committed Sep 21, 2012
2 parents 81f3b68 + 196f596 commit 2b950944c0227ae34128d4894983a205565080d6
Showing with 144 additions and 4 deletions.
  1. +2 −0 ChangeLog
  2. +1 −0 MANIFEST
  3. +5 −2 src/pmc/bytebuffer.pmc
  4. +57 −2 t/pmc/bytebuffer.t
  5. +79 −0 t/pmc/bytebuffer2.t
View
@@ -3,6 +3,8 @@
+ Keep encoding information in the imcc optimizer, which fixes the
concat op but probably many more cases with non-ascii encoded
constant strings. [GH #837]
+ + Fixed ByteBuffer set_string_native, which became out of sync with
+ two internal buffers. [GH #835]
- Documentation
- Tests
- Community
View
@@ -1861,6 +1861,7 @@ t/pmc/bigint.t [test]
t/pmc/bignum.t [test]
t/pmc/boolean.t [test]
t/pmc/bytebuffer.t [test]
+t/pmc/bytebuffer2.t [test]
t/pmc/callcontext.t [test]
t/pmc/capture.t [test]
t/pmc/class.t [test]
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
@@ -1,5 +1,5 @@
#!./parrot
-# Copyright (C) 2010, Parrot Foundation.
+# Copyright (C) 2010-2012, Parrot Foundation.
=head1 NAME
@@ -21,7 +21,7 @@ Tests C<ByteBuffer> PMC..
.sub 'main' :main
.include 'test_more.pir'
- plan(46)
+ plan(52)
test_init()
test_set_string()
@@ -33,6 +33,7 @@ Tests C<ByteBuffer> PMC..
test_iterate()
test_invalid()
test_get_chars()
+ test_resize()
.end
################################################################
@@ -404,6 +405,60 @@ end:
throws_type(get_chars_oob, .EXCEPTION_OUT_OF_BOUNDS, 'get_chars out of bounds')
.end
+# GH 835
+.sub test_resize
+ .local int i
+ .local string s1, s2
+ s1 = 'ABC'
+ s2 = 'DEF'
+
+ .local pmc b_normal, b_resize_normal, b_init_size, b_resize_too_big
+ b_normal = new ['ByteBuffer']
+ b_resize_normal = new ['ByteBuffer']
+ b_init_size = new ['ByteBuffer'],4
+ b_resize_too_big = new ['ByteBuffer']
+
+ b_normal = s1
+ i = b_normal[0]
+ is(i, 65, 'simple init - no problem expected')
+ b_normal = s2
+ i = b_normal[0]
+ is(i, 68, 'reset string with new value')
+
+ b_resize_normal = s1
+ i = b_resize_normal[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ # oddly also works resize to smallar values like 2,1,0
+ b_resize_normal = 3
+ b_resize_normal = s2
+ i = b_resize_normal[0]
+ is(i, 68, 'reset resized normal buff with new string')
+
+ b_init_size[0] = 65
+ b_init_size[1] = 66
+ b_init_size[2] = 67
+ # line below probably not needed but I shouldn't cause problem
+ b_init_size[3] = 0
+
+ i = b_init_size[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ b_init_size = s2
+ i = b_init_size[0]
+ is(i, 68, 'reset sized buff with new string', 'todo' => 'GH #835')
+
+ b_resize_too_big = s1
+ i = b_resize_too_big[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ b_resize_too_big = 5
+ b_resize_too_big = s2
+ i = b_resize_too_big[0]
+ is(i, 68, 'reset resized too big buff with new string', 'todo' => 'GH #835')
+.end
+
+
# Local Variables:
# mode: pir
# fill-column: 100
View
@@ -0,0 +1,79 @@
+#!./parrot
+# Copyright (C) 2012, Parrot Foundation.
+
+=head1 NAME
+
+t/pmc/bytebuffer2.t - Test ByteBuffer resize behaviour
+
+=head1 SYNOPSIS
+
+ % prove t/pmc/bytebuffer2.t
+
+=head1 DESCRIPTION
+
+This file must be seperate from F<t/pmc/bytebuffer.t> as calling the
+function from there does not expose this problem.
+
+=cut
+
+# GH 835
+.sub test :main
+ .include 'test_more.pir'
+
+ .local int i
+
+ .local string s1, s2
+ s1 = 'ABC'
+ s2 = 'DEF'
+
+ .local pmc b_normal, b_resize_normal, b_init_size, b_resize_too_big
+ b_normal = new ['ByteBuffer']
+ b_resize_normal = new ['ByteBuffer']
+ b_init_size = new ['ByteBuffer'],4
+ b_resize_too_big = new ['ByteBuffer']
+
+ b_normal = s1
+ i = b_normal[0]
+ is(i, 65, 'simple init - no problem expected')
+ b_normal = s2
+ i = b_normal[0]
+ is(i, 68, 'reset string with new value')
+
+ b_resize_normal = s1
+ i = b_resize_normal[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ # oddly also works resize to smaller values like 2,1,0
+ b_resize_normal = 3
+ b_resize_normal = s2
+ i = b_resize_normal[0]
+ is(i, 68, 'reset resized normal buff with new string')
+
+ b_init_size[0] = 65
+ b_init_size[1] = 66
+ b_init_size[2] = 67
+ # line below probably not needed but I shouldn't cause problem
+ b_init_size[3] = 0
+
+ i = b_init_size[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ b_init_size = s2
+ i = b_init_size[0]
+ is(i, 68, 'reset sized buff with new string', 'todo' => 'GH #835')
+
+ b_resize_too_big = s1
+ i = b_resize_too_big[0]
+ is(i, 65, 'simple init - no problem expected')
+
+ b_resize_too_big = 5
+ b_resize_too_big = s2
+ i = b_resize_too_big[0]
+ is(i, 68, 'reset resized too big buff with new string', 'todo' => 'GH #835')
+.end
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

0 comments on commit 2b95094

Please sign in to comment.