[前][次][番号順一覧][スレッド一覧]

ruby-changes:29204

From: akr <ko1@a...>
Date: Wed, 12 Jun 2013 18:21:23 +0900 (JST)
Subject: [ruby-changes:29204] akr:r41256 (trunk): * bignum.c (validate_integer_pack_format): supported_flags argument

akr	2013-06-12 18:21:11 +0900 (Wed, 12 Jun 2013)

  New Revision: 41256

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41256

  Log:
    * bignum.c (validate_integer_pack_format): supported_flags argument
      added and validate given flags.
      (rb_integer_pack_internal): Specify supported_flags.
      (rb_integer_unpack): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41255)
+++ ChangeLog	(revision 41256)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 12 18:19:41 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (validate_integer_pack_format): supported_flags argument
+	  added and validate given flags.
+	  (rb_integer_pack_internal): Specify supported_flags.
+	  (rb_integer_unpack): Ditto.
+
 Wed Jun 12 16:41:38 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (rb_ary_sort_bang): remove duplicated assertions.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41255)
+++ bignum.c	(revision 41256)
@@ -735,10 +735,14 @@ rb_absint_singlebit_p(VALUE val) https://github.com/ruby/ruby/blob/trunk/bignum.c#L735
      INTEGER_PACK_NATIVE_BYTE_ORDER)
 
 static void
-validate_integer_pack_format(size_t numwords, size_t wordsize, size_t nails, int flags)
+validate_integer_pack_format(size_t numwords, size_t wordsize, size_t nails, int flags, int supported_flags)
 {
     int wordorder_bits = flags & INTEGER_PACK_WORDORDER_MASK;
     int byteorder_bits = flags & INTEGER_PACK_BYTEORDER_MASK;
+
+    if (flags & ~supported_flags) {
+        rb_raise(rb_eArgError, "unsupported flags specified");
+    }
     if (wordorder_bits == 0) {
         if (1 < numwords)
             rb_raise(rb_eArgError, "word order not specified");
@@ -861,7 +865,12 @@ rb_integer_pack_internal(VALUE val, void https://github.com/ruby/ruby/blob/trunk/bignum.c#L865
 
     val = rb_to_int(val);
 
-    validate_integer_pack_format(numwords, wordsize, nails, flags);
+    validate_integer_pack_format(numwords, wordsize, nails, flags,
+            INTEGER_PACK_MSWORD_FIRST|
+            INTEGER_PACK_LSWORD_FIRST|
+            INTEGER_PACK_MSBYTE_FIRST|
+            INTEGER_PACK_LSBYTE_FIRST|
+            INTEGER_PACK_NATIVE_BYTE_ORDER);
 
     if (FIXNUM_P(val)) {
         long v = FIX2LONG(val);
@@ -1215,7 +1224,14 @@ rb_integer_unpack(const void *words, siz https://github.com/ruby/ruby/blob/trunk/bignum.c#L1224
     BDIGIT_DBL dd;
     int numbits_in_dd;
 
-    validate_integer_pack_format(numwords, wordsize, nails, flags);
+    validate_integer_pack_format(numwords, wordsize, nails, flags,
+            INTEGER_PACK_MSWORD_FIRST|
+            INTEGER_PACK_LSWORD_FIRST|
+            INTEGER_PACK_MSBYTE_FIRST|
+            INTEGER_PACK_LSBYTE_FIRST|
+            INTEGER_PACK_NATIVE_BYTE_ORDER|
+            INTEGER_PACK_FORCE_BIGNUM|
+            INTEGER_PACK_NEGATIVE);
 
     if (numwords <= (SIZE_MAX - (SIZEOF_BDIGITS*CHAR_BIT-1)) / CHAR_BIT / wordsize) {
         num_bdigits = integer_unpack_num_bdigits_small(numwords, wordsize, nails);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]