summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-12 03:35:54 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-12 03:35:54 +0000
commitff6104ba62164a4808ac96839a7201c2bec16ff7 (patch)
tree50a582acb757c07b14b8b5d1b364ad7a328ef306 /pack.c
parent174e3fb6e40e517275c0acf3cda0e991c47fa572 (diff)
downloadruby-ff6104ba62164a4808ac96839a7201c2bec16ff7.tar.gz
* 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
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/pack.c b/pack.c
index 4d877b3a35..66aa08f178 100644
--- a/pack.c
+++ b/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;
}