* pack.c (pack_pack): fix more than one modifiers appear in the

format string. [ruby-core:32793]

* pack.c (pack_unpack): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-10-15 07:42:21 +00:00
Родитель dfd139b819
Коммит ccaf61d5af
3 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Oct 15 16:40:37 2010 NARUSE, Yui <naruse@ruby-lang.org>
* pack.c (pack_pack): fix more than one modifiers appear in the
format string. [ruby-core:32793]
* pack.c (pack_unpack): ditto.
Thu Oct 14 23:20:42 2010 Masaki Suketa <masaki.suketa@nifty.ne.jp> Thu Oct 14 23:20:42 2010 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_folderitem2_invokeverb.rb: refactoring. * test/win32ole/test_folderitem2_invokeverb.rb: refactoring.

4
pack.c
Просмотреть файл

@ -428,7 +428,6 @@ pack_pack(VALUE ary, VALUE fmt)
int natint; /* native integer */ int natint; /* native integer */
#endif #endif
int signed_p, integer_size, bigendian_p; int signed_p, integer_size, bigendian_p;
int explicit_endian = 0;
StringValue(fmt); StringValue(fmt);
p = RSTRING_PTR(fmt); p = RSTRING_PTR(fmt);
@ -443,6 +442,7 @@ pack_pack(VALUE ary, VALUE fmt)
#define NEXTFROM (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW) #define NEXTFROM (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW)
while (p < pend) { while (p < pend) {
int explicit_endian = 0;
if (RSTRING_PTR(fmt) + RSTRING_LEN(fmt) != pend) { if (RSTRING_PTR(fmt) + RSTRING_LEN(fmt) != pend) {
rb_raise(rb_eRuntimeError, "format string modified"); rb_raise(rb_eRuntimeError, "format string modified");
} }
@ -1366,7 +1366,6 @@ pack_unpack(VALUE str, VALUE fmt)
#endif #endif
int block_p = rb_block_given_p(); int block_p = rb_block_given_p();
int signed_p, integer_size, bigendian_p; int signed_p, integer_size, bigendian_p;
int explicit_endian = 0;
#define UNPACK_PUSH(item) do {\ #define UNPACK_PUSH(item) do {\
VALUE item_val = (item);\ VALUE item_val = (item);\
if (block_p) {\ if (block_p) {\
@ -1386,6 +1385,7 @@ pack_unpack(VALUE str, VALUE fmt)
ary = block_p ? Qnil : rb_ary_new(); ary = block_p ? Qnil : rb_ary_new();
while (p < pend) { while (p < pend) {
int explicit_endian = 0;
type = *p++; type = *p++;
#ifdef NATINT_PACK #ifdef NATINT_PACK
natint = 0; natint = 0;

Просмотреть файл

@ -145,6 +145,8 @@ class TestPack < Test::Unit::TestCase
else else
_integer_little_endian() _integer_little_endian()
end end
assert_equal("\x01\x02\x02\x01", [0x0102,0x0102].pack("s>s<"))
assert_equal([0x0102,0x0102], "\x01\x02\x02\x01".unpack("s>s<"))
end end
def test_integer_endian_explicit def test_integer_endian_explicit