mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* pack.c (pack_pack): Use rb_integer_pack_2comp.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
174e3fb6e4
commit
ff6104ba62
2 changed files with 8 additions and 23 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Jun 12 12:35:13 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* pack.c (pack_pack): Use rb_integer_pack_2comp.
|
||||
|
||||
Wed Jun 12 12:07:04 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* sprintf.c (rb_str_format): Fix a dynamic format string.
|
||||
|
|
27
pack.c
27
pack.c
|
@ -796,31 +796,12 @@ pack_pack(VALUE ary, VALUE fmt)
|
|||
if (integer_size > MAX_INTEGER_PACK_SIZE)
|
||||
rb_bug("unexpected intger size for pack: %d", integer_size);
|
||||
while (len-- > 0) {
|
||||
union {
|
||||
unsigned long i[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG];
|
||||
char a[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG*SIZEOF_LONG];
|
||||
} v;
|
||||
int num_longs = (integer_size+SIZEOF_LONG-1)/SIZEOF_LONG;
|
||||
int i;
|
||||
char intbuf[MAX_INTEGER_PACK_SIZE];
|
||||
|
||||
from = NEXTFROM;
|
||||
rb_big_pack(from, v.i, num_longs);
|
||||
if (bigendian_p) {
|
||||
for (i = 0; i < num_longs/2; i++) {
|
||||
unsigned long t = v.i[i];
|
||||
v.i[i] = v.i[num_longs-1-i];
|
||||
v.i[num_longs-1-i] = t;
|
||||
}
|
||||
}
|
||||
if (bigendian_p != BIGENDIAN_P()) {
|
||||
for (i = 0; i < num_longs; i++)
|
||||
v.i[i] = swapl(v.i[i]);
|
||||
}
|
||||
rb_str_buf_cat(res,
|
||||
bigendian_p ?
|
||||
v.a + sizeof(long)*num_longs - integer_size :
|
||||
v.a,
|
||||
integer_size);
|
||||
rb_integer_pack_2comp(from, intbuf, integer_size, 1, 0,
|
||||
bigendian_p ? INTEGER_PACK_BIG_ENDIAN : INTEGER_PACK_LITTLE_ENDIAN);
|
||||
rb_str_buf_cat(res, intbuf, integer_size);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue