[svn:parrot] r47724 - in trunk: src/pmc t/pmc
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Sun Jun 20 09:17:23 UTC 2010
Author: NotFound
Date: Sun Jun 20 09:17:23 2010
New Revision: 47724
URL: https://trac.parrot.org/parrot/changeset/47724
Log:
fix a bug in ByteBuffer resizing and add more test for it
Modified:
trunk/src/pmc/bytebuffer.pmc
trunk/t/pmc/bytebuffer.t
Modified: trunk/src/pmc/bytebuffer.pmc
==============================================================================
--- trunk/src/pmc/bytebuffer.pmc Sun Jun 20 08:51:52 2010 (r47723)
+++ trunk/src/pmc/bytebuffer.pmc Sun Jun 20 09:17:23 2010 (r47724)
@@ -147,7 +147,7 @@
GET_ATTR_size(INTERP, SELF, size);
/* If reducing size, just change the size value */
if (set_size > size) {
- INTVAL copysize = set_size > size ? set_size : size;
+ INTVAL copysize = set_size < size ? set_size : size;
if (allocated_size == 0) {
content = (unsigned char *)Parrot_gc_allocate_memory_chunk(INTERP, set_size);
if (size > 0) {
Modified: trunk/t/pmc/bytebuffer.t
==============================================================================
--- trunk/t/pmc/bytebuffer.t Sun Jun 20 08:51:52 2010 (r47723)
+++ trunk/t/pmc/bytebuffer.t Sun Jun 20 09:17:23 2010 (r47724)
@@ -22,7 +22,7 @@
.sub 'main' :main
.include 'test_more.pir'
- plan(33)
+ plan(37)
test_init()
test_set_string()
@@ -210,6 +210,10 @@
n = elements bb
is(n, 42, 'reduce size')
+ bb = 999
+ n = elements bb
+ is(n, 999, 'increase size')
+
bb = 0
n = elements bb
is(n, 0, 'resize to 0')
@@ -223,9 +227,24 @@
is(s, 'foo', 'resized string content has correct value')
bb = 'foobar'
- bb = 24
+ bb = 7
+ n = elements bb
+ is(n, 7, 'increase size from string content')
+
+ # This test is for code coverage, zero filling is not a feature
+ # you should expect, it can be changed for performance reasons.
+ s = bb.'get_string_as'(binary:"")
+ is(s, binary:"foobar\x{0}", 'resized from string content is zero filled')
+
+ bb = 'barfoo'
+ bb = 0
+ n = elements bb
+ is(n, 0, 'resize to zero from string content')
+
+ bb = 42
+ bb = 0
n = elements bb
- is(n, 24, 'increase size from string content')
+ is(n, 0, 'resize to zero from allocated content')
.local pmc eh
eh = new ['ExceptionHandler']
More information about the parrot-commits
mailing list