summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 12:06:40 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 12:06:40 +0000
commitd5a3818f8e3d096a4e192b61008f886f940192df (patch)
tree4c8da8fb3d17f84b154c6af3f5565b2b54d07dcc /ext/-test-
parentb7597efb48126e28dd0bbb12ef07a5e1066093fc (diff)
* bignum.c (rb_integer_pack_internal): Renamed from rb_integer_pack
and overflow_2comp argument added. (rb_integer_pack): Just call rb_integer_pack_internal. (rb_integer_pack_2comp): New function. * internal.h (rb_integer_pack_2comp): Declared. * sprintf.c (rb_str_format): Use rb_integer_pack and rb_integer_pack_2comp to format binary/octal/hexadecimal integers. (ruby_digitmap): Declared. (remove_sign_bits): Removed. (BITSPERDIG): Ditto. (EXTENDSIGN): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/bignum/pack.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/-test-/bignum/pack.c b/ext/-test-/bignum/pack.c
index 62f8f62..6d64636 100644
--- a/ext/-test-/bignum/pack.c
+++ b/ext/-test-/bignum/pack.c
@@ -19,6 +19,24 @@ rb_integer_pack_m(VALUE val, VALUE buf, VALUE wordsize_arg, VALUE nails, VALUE f
}
static VALUE
+rb_integer_pack_2comp_m(VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
+{
+ int sign;
+ size_t numwords = NUM2SIZET(numwords_arg);
+ size_t wordsize = NUM2SIZET(wordsize_arg);
+ VALUE buf;
+
+ if (numwords != 0 && wordsize != 0 && LONG_MAX / wordsize < numwords)
+ rb_raise(rb_eArgError, "too big numwords * wordsize");
+ buf = rb_str_new(NULL, numwords * wordsize);
+ sign = rb_integer_pack_2comp(val,
+ RSTRING_PTR(buf), numwords,
+ wordsize, NUM2SIZET(nails), NUM2INT(flags));
+
+ return rb_assoc_new(INT2NUM(sign), buf);
+}
+
+static VALUE
rb_integer_unpack_m(VALUE klass, VALUE sign, VALUE buf, VALUE wordcount, VALUE wordsize, VALUE nails, VALUE flags)
{
StringValue(buf);
@@ -32,6 +50,7 @@ void
Init_pack(VALUE klass)
{
rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_m, 4);
+ rb_define_method(rb_cInteger, "test_pack_2comp", rb_integer_pack_2comp_m, 4);
rb_define_singleton_method(rb_cInteger, "test_unpack", rb_integer_unpack_m, 6);
rb_define_const(rb_cInteger, "INTEGER_PACK_MSWORD_FIRST", INT2NUM(INTEGER_PACK_MSWORD_FIRST));
rb_define_const(rb_cInteger, "INTEGER_PACK_LSWORD_FIRST", INT2NUM(INTEGER_PACK_LSWORD_FIRST));