ruby-changes:46017
From: usa <ko1@a...>
Date: Sun, 26 Mar 2017 00:16:08 +0900 (JST)
Subject: [ruby-changes:46017] usa:r58088 (ruby_2_2): merge revision(s) 57187, 57234: [Backport #13075]
usa 2017-03-26 00:16:04 +0900 (Sun, 26 Mar 2017) New Revision: 58088 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58088 Log: merge revision(s) 57187,57234: [Backport #13075] pack.c: avoid returning uninitialized String Fix unpacking with 'b', 'B', 'h' and 'H' format. Do not return an uninitialized String to Ruby before filling the content bytes. Fixes r11175 ("pack.c (pack_unpack): execute block if given with unpacked value instead of creating an array", 2006-10-15). [ruby-core:78841] [Bug #13075] test/ruby/test_pack.rb: fix test case added by r57187 The test case for String#unpack added by r57187 is not properly testing because the String will be filled after the block invocation. [ruby-core:78841] [Bug #13075] Thanks to nagachika for pointing this out: http://d.hatena.ne.jp/nagachika/20161226/ruby_trunk_changes_57184_57194#r57187 Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/pack.c branches/ruby_2_2/test/ruby/test_pack.rb branches/ruby_2_2/version.h Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 58087) +++ ruby_2_2/version.h (revision 58088) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2017-03-26" -#define RUBY_PATCHLEVEL 420 +#define RUBY_PATCHLEVEL 421 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_2/test/ruby/test_pack.rb =================================================================== --- ruby_2_2/test/ruby/test_pack.rb (revision 58087) +++ ruby_2_2/test/ruby/test_pack.rb (revision 58088) @@ -727,4 +727,11 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_pack.rb#L727 } } end + + def test_unpack_with_block + ret = []; "ABCD".unpack("CCCC") {|v| ret << v } + assert_equal [65, 66, 67, 68], ret + ret = []; "A".unpack("B*") {|v| ret << v } + assert_equal ["01000001"], ret + end end Index: ruby_2_2/pack.c =================================================================== --- ruby_2_2/pack.c (revision 58087) +++ ruby_2_2/pack.c (revision 58088) @@ -1259,13 +1259,14 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1259 if (p[-1] == '*' || len > (send - s) * 8) len = (send - s) * 8; bits = 0; - UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len)); + bitstr = rb_usascii_str_new(0, len); t = RSTRING_PTR(bitstr); for (i=0; i<len; i++) { if (i & 7) bits >>= 1; else bits = (unsigned char)*s++; *t++ = (bits & 1) ? '1' : '0'; } + UNPACK_PUSH(bitstr); } break; @@ -1279,13 +1280,14 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1280 if (p[-1] == '*' || len > (send - s) * 8) len = (send - s) * 8; bits = 0; - UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len)); + bitstr = rb_usascii_str_new(0, len); t = RSTRING_PTR(bitstr); for (i=0; i<len; i++) { if (i & 7) bits <<= 1; else bits = (unsigned char)*s++; *t++ = (bits & 128) ? '1' : '0'; } + UNPACK_PUSH(bitstr); } break; @@ -1299,7 +1301,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1301 if (p[-1] == '*' || len > (send - s) * 2) len = (send - s) * 2; bits = 0; - UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len)); + bitstr = rb_usascii_str_new(0, len); t = RSTRING_PTR(bitstr); for (i=0; i<len; i++) { if (i & 1) @@ -1308,6 +1310,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1310 bits = (unsigned char)*s++; *t++ = hexdigits[bits & 15]; } + UNPACK_PUSH(bitstr); } break; @@ -1321,7 +1324,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1324 if (p[-1] == '*' || len > (send - s) * 2) len = (send - s) * 2; bits = 0; - UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len)); + bitstr = rb_usascii_str_new(0, len); t = RSTRING_PTR(bitstr); for (i=0; i<len; i++) { if (i & 1) @@ -1330,6 +1333,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/pack.c#L1333 bits = (unsigned char)*s++; *t++ = hexdigits[(bits >> 4) & 15]; } + UNPACK_PUSH(bitstr); } break; Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r57187 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/