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

ruby-changes:29099

From: akr <ko1@a...>
Date: Sat, 8 Jun 2013 00:03:42 +0900 (JST)
Subject: [ruby-changes:29099] akr:r41151 (trunk): * bignum.c (rb_integer_pack): Arguments changed. Use flags to

akr	2013-06-08 00:02:39 +0900 (Sat, 08 Jun 2013)

  New Revision: 41151

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

  Log:
    * bignum.c (rb_integer_pack): Arguments changed.  Use flags to
      specify word order and byte order.
      (rb_integer_unpack): Ditto.
      (validate_integer_format): Follow the above change.
      (integer_format_loop_setup): Ditto.
    
    * pack.c: Ditto.
    
    * internal.h: Ditto.
      (INTEGER_PACK_MSWORD_FIRST): Defined.
      (INTEGER_PACK_LSWORD_FIRST): Ditto.
      (INTEGER_PACK_MSBYTE_FIRST): Ditto.
      (INTEGER_PACK_LSBYTE_FIRST): Ditto.
      (INTEGER_PACK_NATIVE_BYTE_ORDER): Ditto.
      (INTEGER_PACK_LITTLE_ENDIAN): Ditto.
      (INTEGER_PACK_BIG_ENDIAN): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/ext/-test-/bignum/pack.c
    trunk/internal.h
    trunk/pack.c
    trunk/test/-ext-/bignum/test_pack.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41150)
+++ ChangeLog	(revision 41151)
@@ -1,3 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun  7 23:58:06 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_integer_pack): Arguments changed.  Use flags to
+	  specify word order and byte order.
+	  (rb_integer_unpack): Ditto.
+	  (validate_integer_format): Follow the above change.
+	  (integer_format_loop_setup): Ditto.
+
+	* pack.c: Ditto.
+
+	* internal.h: Ditto.
+	  (INTEGER_PACK_MSWORD_FIRST): Defined.
+	  (INTEGER_PACK_LSWORD_FIRST): Ditto.
+	  (INTEGER_PACK_MSBYTE_FIRST): Ditto.
+	  (INTEGER_PACK_LSBYTE_FIRST): Ditto.
+	  (INTEGER_PACK_NATIVE_BYTE_ORDER): Ditto.
+	  (INTEGER_PACK_LITTLE_ENDIAN): Ditto.
+	  (INTEGER_PACK_BIG_ENDIAN): Ditto.
+
 Fri Jun  7 22:10:50 2013  NARUSE, Yui  <naruse@r...>
 
 	* lib/rubygems/specification.rb (Gem::Specification#to_yaml):
Index: pack.c
===================================================================
--- pack.c	(revision 41150)
+++ pack.c	(revision 41151)
@@ -1023,7 +1023,7 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L1023
                     numbytes = 1;
                 buf = rb_str_new(NULL, numbytes);
 
-                rb_integer_pack(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, 1, 1);
+                rb_integer_pack(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, INTEGER_PACK_BIG_ENDIAN);
 
                 if (sign < 0)
                     rb_raise(rb_eArgError, "can't compress negative numbers");
@@ -2142,7 +2142,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L2142
                     }
                     else {
                         s++;
-                        UNPACK_PUSH(rb_integer_unpack(1, s0, s-s0, 1, 1, 1, 1));
+                        UNPACK_PUSH(rb_integer_unpack(1, s0, s-s0, 1, 1, INTEGER_PACK_BIG_ENDIAN));
                         len--;
                         s0 = s;
                     }
Index: ext/-test-/bignum/pack.c
===================================================================
--- ext/-test-/bignum/pack.c	(revision 41150)
+++ ext/-test-/bignum/pack.c	(revision 41151)
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/pack.c#L2
 #include "internal.h"
 
 static VALUE
-rb_integer_pack_m(VALUE val, VALUE buf, VALUE wordorder, VALUE wordsize_arg, VALUE endian, VALUE nails)
+rb_integer_pack_m(VALUE val, VALUE buf, VALUE wordsize_arg, VALUE nails, VALUE flags)
 {
   int sign;
   size_t count = 0;
@@ -17,24 +17,31 @@ rb_integer_pack_m(VALUE val, VALUE buf, https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/pack.c#L17
 
   ret = rb_integer_pack(val,
       &sign, &count, NIL_P(buf) ? NULL : RSTRING_PTR(buf), count,
-      NUM2INT(wordorder), wordsize, NUM2INT(endian), NUM2INT(nails));
+      wordsize, NUM2SIZET(nails), NUM2INT(flags));
 
   return rb_ary_new_from_args(3, INT2NUM(sign), ret ? rb_str_new(ret, wordsize * count) : Qnil, SIZET2NUM(count));
 }
 
 static VALUE
-rb_integer_unpack_m(VALUE klass, VALUE sign, VALUE buf, VALUE wordcount, VALUE wordorder, VALUE wordsize, VALUE endian, VALUE nails)
+rb_integer_unpack_m(VALUE klass, VALUE sign, VALUE buf, VALUE wordcount, VALUE wordsize, VALUE nails, VALUE flags)
 {
     StringValue(buf);
 
     return rb_integer_unpack(NUM2INT(sign), RSTRING_PTR(buf),
-            NUM2SIZET(wordcount), NUM2INT(wordorder), NUM2SIZET(wordsize),
-            NUM2INT(endian), NUM2SIZET(nails));
+            NUM2SIZET(wordcount), NUM2SIZET(wordsize),
+            NUM2SIZET(nails), NUM2INT(flags));
 }
 
 void
 Init_pack(VALUE klass)
 {
-    rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_m, 5);
-    rb_define_singleton_method(rb_cInteger, "test_unpack", rb_integer_unpack_m, 7);
+    rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_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));
+    rb_define_const(rb_cInteger, "INTEGER_PACK_MSBYTE_FIRST", INT2NUM(INTEGER_PACK_MSBYTE_FIRST));
+    rb_define_const(rb_cInteger, "INTEGER_PACK_LSBYTE_FIRST", INT2NUM(INTEGER_PACK_LSBYTE_FIRST));
+    rb_define_const(rb_cInteger, "INTEGER_PACK_NATIVE_BYTE_ORDER", INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER));
+    rb_define_const(rb_cInteger, "INTEGER_PACK_LITTLE_ENDIAN", INT2NUM(INTEGER_PACK_LITTLE_ENDIAN));
+    rb_define_const(rb_cInteger, "INTEGER_PACK_BIG_ENDIAN", INT2NUM(INTEGER_PACK_BIG_ENDIAN));
 }
Index: internal.h
===================================================================
--- internal.h	(revision 41150)
+++ internal.h	(revision 41151)
@@ -53,6 +53,20 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L53
 #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
 #define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
 
+/* "MS" in MSWORD and MSBYTE means "most significant" */
+/* "LS" in LSWORD and LSBYTE means "least significant" */
+#define INTEGER_PACK_MSWORD_FIRST       0x01
+#define INTEGER_PACK_LSWORD_FIRST       0x02
+#define INTEGER_PACK_MSBYTE_FIRST       0x10
+#define INTEGER_PACK_LSBYTE_FIRST       0x20
+#define INTEGER_PACK_NATIVE_BYTE_ORDER  0x40
+#define INTEGER_PACK_LITTLE_ENDIAN \
+    (INTEGER_PACK_LSWORD_FIRST | \
+     INTEGER_PACK_LSBYTE_FIRST)
+#define INTEGER_PACK_BIG_ENDIAN \
+    (INTEGER_PACK_MSWORD_FIRST | \
+     INTEGER_PACK_MSBYTE_FIRST)
+
 struct rb_deprecated_classext_struct {
     char conflict[sizeof(VALUE) * 3];
 };
@@ -428,8 +442,9 @@ const char *rb_objspace_data_type_name(V https://github.com/ruby/ruby/blob/trunk/internal.h#L442
 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
 
 /* bignum.c */
-void *rb_integer_pack(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
-VALUE rb_integer_unpack(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
+
+void *rb_integer_pack(VALUE val, int *signp, size_t *numwords_allocated, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
+VALUE rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
 
 /* io.c */
 void rb_maygvl_fd_fix_cloexec(int fd);
Index: bignum.c
===================================================================
--- bignum.c	(revision 41150)
+++ bignum.c	(revision 41151)
@@ -537,13 +537,26 @@ rb_absint_size_in_word(VALUE val, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L537
     return numwords;
 }
 
+#define INTEGER_PACK_WORDORDER_MASK \
+    (INTEGER_PACK_MSWORD_FIRST | \
+     INTEGER_PACK_LSWORD_FIRST)
+#define INTEGER_PACK_BYTEORDER_MASK \
+    (INTEGER_PACK_MSBYTE_FIRST | \
+     INTEGER_PACK_LSBYTE_FIRST | \
+     INTEGER_PACK_NATIVE_BYTE_ORDER)
+
 static void
-validate_integer_format(int wordorder, size_t wordsize, int endian, size_t nails)
+validate_integer_format(size_t wordsize, size_t nails, int flags)
 {
-    if (wordorder != 1 && wordorder != -1)
-        rb_raise(rb_eArgError, "unexpected wordorder: %d", wordorder);
-    if (endian != 1 && endian != -1 && endian != 0)
-        rb_raise(rb_eArgError, "unexpected endian: %d", endian);
+    int wordorder_bits = flags & INTEGER_PACK_WORDORDER_MASK;
+    int byteorder_bits = flags & INTEGER_PACK_BYTEORDER_MASK;
+    if (wordorder_bits != INTEGER_PACK_MSWORD_FIRST &&
+        wordorder_bits != INTEGER_PACK_LSWORD_FIRST)
+        rb_raise(rb_eArgError, "unexpected wordorder");
+    if (byteorder_bits != INTEGER_PACK_MSBYTE_FIRST &&
+        byteorder_bits != INTEGER_PACK_LSBYTE_FIRST &&
+        byteorder_bits != INTEGER_PACK_NATIVE_BYTE_ORDER)
+        rb_raise(rb_eArgError, "unexpected endian");
     if (wordsize == 0)
         rb_raise(rb_eArgError, "invalid wordsize: %"PRI_SIZE_PREFIX"u", wordsize);
     if (SSIZE_MAX < wordsize)
@@ -553,7 +566,8 @@ validate_integer_format(int wordorder, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L566
 }
 
 static void
-integer_format_loop_setup(size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails,
+integer_format_loop_setup(
+    size_t numwords, size_t wordsize, size_t nails, int flags,
     size_t *word_num_fullbytes_ret,
     int *word_num_partialbits_ret,
     size_t *word_num_nailbytes_ret,
@@ -563,6 +577,8 @@ integer_format_loop_setup(size_t wordcou https://github.com/ruby/ruby/blob/trunk/bignum.c#L577
     size_t *byte_start_ret,
     int *byte_step_ret)
 {
+    int wordorder_bits = flags & INTEGER_PACK_WORDORDER_MASK;
+    int byteorder_bits = flags & INTEGER_PACK_BYTEORDER_MASK;
     size_t word_num_fullbytes;
     int word_num_partialbits;
     size_t word_num_nailbytes;
@@ -584,25 +600,25 @@ integer_format_loop_setup(size_t wordcou https://github.com/ruby/ruby/blob/trunk/bignum.c#L600
         word_num_nailbytes = wordsize - word_num_fullbytes;
     }
 
-    if (wordorder == 1) {
-        word_start = wordsize*(wordcount-1);
+    if (wordorder_bits == INTEGER_PACK_MSWORD_FIRST) {
+        word_start = wordsize*(numwords-1);
         word_step = -(ssize_t)wordsize;
         word_last = 0;
     }
     else {
         word_start = 0;
         word_step = wordsize;
-        word_last = wordsize*(wordcount-1);
+        word_last = wordsize*(numwords-1);
     }
 
-    if (endian == 0) {
+    if (byteorder_bits == INTEGER_PACK_NATIVE_BYTE_ORDER) {
 #ifdef WORDS_BIGENDIAN
-        endian = 1;
+        byteorder_bits = INTEGER_PACK_MSBYTE_FIRST;
 #else
-        endian = -1;
+        byteorder_bits = INTEGER_PACK_LSBYTE_FIRST;
 #endif
     }
-    if (endian == 1) {
+    if (byteorder_bits == INTEGER_PACK_MSBYTE_FIRST) {
         byte_step = -1;
         byte_start = wordsize-1;
     }
@@ -653,21 +669,20 @@ int_export_take_lowbits(int n, BDIGIT_DB https://github.com/ruby/ruby/blob/trunk/bignum.c#L669
  *   0 for zero.
  *   -1 for negative without overflow.  1 for positive without overflow.
  *   -2 for negative overflow.  2 for positive overflow.
- * [wordcount_allocated] the number of words allocated is returned in *wordcount_allocated if it is not NULL.
+ * [numwords_allocated] the number of words allocated is returned in *numwords_allocated if it is not NULL.
  *   It is not modified if words is not NULL.
  * [words] buffer to export abs(val).  allocated by xmalloc if it is NULL.
- * [wordcount] the size of given buffer as number of words (only meaningful when words is not NULL).
- * [wordorder] order of words: 1 for most significant word first.  -1 for least significant word first.
+ * [numwords] the size of given buffer as number of words (only meaningful when words is not NULL).
  * [wordsize] the size of word as number of bytes.
- * [endian] order of bytes in a word: 1 for most significant byte first.  -1 for least significant byte first.  0 for native endian.
  * [nails] number of padding bits in a word.  Most significant nails bits of each word are filled by zero.
+ * [flags] bitwise or of constants which name starts "INTEGER_PACK_".  It specifies word order and byte order.
  *
  * This function returns words or the allocated buffer if words is NULL.
  *
  */
 
 void *
-rb_integer_pack(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
+rb_integer_pack(VALUE val, int *signp, size_t *numwords_allocated, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 {
     int sign;
     BDIGIT *dp;
@@ -677,9 +692,9 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L692
 
     val = rb_to_int(val);
 
-    validate_integer_format(wordorder, wordsize, endian, nails);
-    if (words && SIZE_MAX / wordsize < wordcount)
-        rb_raise(rb_eArgError, "too big count * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", wordcount, wordsize);
+    validate_integer_format(wordsize, nails, flags);
+    if (words && SIZE_MAX / wordsize < numwords)
+        rb_raise(rb_eArgError, "too big count * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", numwords, wordsize);
 
     if (FIXNUM_P(val)) {
         long v = FIX2LONG(val);
@@ -717,15 +732,15 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L732
 
     if (words) {
         buf = words;
-        bufend = buf + wordcount * wordsize;
+        bufend = buf + numwords * wordsize;
     }
     else {
         /*
          * val_numbits = (de - dp) * SIZEOF_BDIGITS * CHAR_BIT - nlz(de[-1])
          * word_numbits = wordsize * CHAR_BIT - nails
-         * wordcount = (val_numbits + word_numbits - 1) / word_numbits
+         * numwords = (val_numbits + word_numbits - 1) / word_numbits
          */
-        VALUE val_numbits, word_numbits, wordcountv;
+        VALUE val_numbits, word_numbits, numwordsv;
         val_numbits = SIZET2NUM((de - dp) * SIZEOF_BDIGITS);
         val_numbits = rb_funcall(val_numbits, '*', 1, LONG2FIX(CHAR_BIT));
         if (dp != de)
@@ -734,12 +749,12 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L749
         word_numbits = rb_funcall(word_numbits, '*', 1, LONG2FIX(CHAR_BIT));
         if (nails != 0)
             word_numbits = rb_funcall(word_numbits, '-', 1, SIZET2NUM(nails));
-        wordcountv = rb_funcall(val_numbits, '+', 1, word_numbits);
-        wordcountv = rb_funcall(wordcountv, '-', 1, LONG2FIX(1));
-        wordcountv = rb_funcall(wordcountv, rb_intern("div"), 1, word_numbits);
-        wordcount = NUM2SIZET(wordcountv);
-        buf = xmalloc(wordcount * wordsize);
-        bufend = buf + wordcount * wordsize;
+        numwordsv = rb_funcall(val_numbits, '+', 1, word_numbits);
+        numwordsv = rb_funcall(numwordsv, '-', 1, LONG2FIX(1));
+        numwordsv = rb_funcall(numwordsv, rb_intern("div"), 1, word_numbits);
+        numwords = NUM2SIZET(numwordsv);
+        buf = xmalloc(numwords * wordsize);
+        bufend = buf + numwords * wordsize;
     }
 
     if (buf == bufend) {
@@ -763,7 +778,7 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L778
         BDIGIT_DBL dd;
         int numbits_in_dd;
 
-        integer_format_loop_setup(wordcount, wordorder, wordsize, endian, nails,
+        integer_format_loop_setup(numwords, wordsize, nails, flags,
             &word_num_fullbytes, &word_num_partialbits, &word_num_nailbytes,
             &word_start, &word_step, &word_last, &byte_start, &byte_step);
 
@@ -811,8 +826,8 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L826
     if (signp)
         *signp = sign;
 
-    if (!words && wordcount_allocated)
-        *wordcount_allocated = wordcount;
+    if (!words && numwords_allocated)
+        *numwords_allocated = numwords;
 
     return buf;
 #undef FILL_DD
@@ -837,16 +852,15 @@ int_import_push_bits(int data, int numbi https://github.com/ruby/ruby/blob/trunk/bignum.c#L852
  * [sign] signedness of the value.
  *   -1 for non-positive.  0 or 1 for non-negative.
  * [words] buffer to import.
- * [wordcount] the size of given buffer as number of words.
- * [wordorder] order of words: 1 for most significant word first.  -1 for least significant word first.
+ * [numwords] the size of given buffer as number of words.
  * [wordsize] the size of word as number of bytes.
- * [endian] order of bytes in a word: 1 for most significant byte first.  -1 for least significant byte first.  0 for native endian.
  * [nails] number of padding bits in a word.  Most significant nails bits of each word are filled by zero.
+ * [flags] bitwise or of constants which name starts "INTEGER_PACK_".  It specifies word order and byte order.
  *
  * This function returns the imported integer as Fixnum or Bignum.
  */
 VALUE
-rb_integer_unpack(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
+rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 {
     VALUE num_bits, num_bdigits;
     VALUE result;
@@ -868,9 +882,9 @@ rb_integer_unpack(int sign, const void * https://github.com/ruby/ruby/blob/trunk/bignum.c#L882
     BDIGIT_DBL dd;
     int numbits_in_dd;
 
-    validate_integer_format(wordorder, wordsize, endian, nails);
-    if (SIZE_MAX / wordsize < wordcount)
-        rb_raise(rb_eArgError, "too big wordcount * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", wordcount, wordsize);
+    validate_integer_format(wordsize, nails, flags);
+    if (SIZE_MAX / wordsize < numwords)
+        rb_raise(rb_eArgError, "too big numwords * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", numwords, wordsize);
     if (sign != 1 && sign != 0 && sign != -1)
         rb_raise(rb_eArgError, "unexpected sign: %d", sign);
 
@@ -878,7 +892,7 @@ rb_integer_unpack(int sign, const void * https://github.com/ruby/ruby/blob/trunk/bignum.c#L892
     num_bits = SIZET2NUM(wordsize);
     num_bits = rb_funcall(num_bits, '*', 1, LONG2FIX(CHAR_BIT));
     num_bits = rb_funcall(num_bits, '-', 1, SIZET2NUM(nails));
-    num_bits = rb_funcall(num_bits, '*', 1, SIZET2NUM(wordcount));
+    num_bits = rb_funcall(num_bits, '*', 1, SIZET2NUM(numwords));
 
     if (num_bits == LONG2FIX(0))
         return LONG2FIX(0);
@@ -892,7 +906,7 @@ rb_integer_unpack(int sign, const void * https://github.com/ruby/ruby/blob/trunk/bignum.c#L906
     dp = BDIGITS(result);
     de = dp + RBIGNUM_LEN(result);
 
-    integer_format_loop_setup(wordcount, wordorder, wordsize, endian, nails,
+    integer_format_loop_setup(numwords, wordsize, nails, flags,
         &word_num_fullbytes, &word_num_partialbits, NULL,
         &word_start, &word_step, &word_last, &byte_start, &byte_step);
 
Index: test/-ext-/bignum/test_pack.rb
===================================================================
--- test/-ext-/bignum/test_pack.rb	(revision 41150)
+++ test/-ext-/bignum/test_pack.rb	(revision 41151)
@@ -5,107 +5,116 @@ require "-test-/bignum" https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_pack.rb#L5
 
 class TestBignum < Test::Unit::TestCase
   class TestPack < Test::Unit::TestCase
+
+    MSWORD_FIRST = Integer::INTEGER_PACK_MSWORD_FIRST
+    LSWORD_FIRST = Integer::INTEGER_PACK_LSWORD_FIRST
+    MSBYTE_FIRST = Integer::INTEGER_PACK_MSBYTE_FIRST
+    LSBYTE_FIRST = Integer::INTEGER_PACK_LSBYTE_FIRST
+    NATIVE_BYTE_ORDER = Integer::INTEGER_PACK_NATIVE_BYTE_ORDER
+    LITTLE_ENDIAN = Integer::INTEGER_PACK_LITTLE_ENDIAN
+    BIG_ENDIAN = Integer::INTEGER_PACK_BIG_ENDIAN
+
     def test_pack_zero
-      assert_equal([0, "", 0], 0.test_pack(nil, 1, 1, 1, 0))
+      assert_equal([0, "", 0], 0.test_pack(nil, 1, 0, BIG_ENDIAN))
     end
 
-    def test_argument_check
-      assert_raise(ArgumentError) { 0.test_pack(nil, 0, 1, 1, 0) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 2, 0) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, 1, 0) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 1, 8) }
+    def test_pack_argument_check
+      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, MSBYTE_FIRST) }
+      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, MSWORD_FIRST) }
+      assert_raise(ArgumentError) { 0.test_pack(nil, 0, 0, BIG_ENDIAN) }
+      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 8, BIG_ENDIAN) }
 
       # assume sizeof(ssize_t) == sizeof(intptr_t)
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
+      assert_raise(ArgumentError) { 0.test_pack(nil, 1 << ([""].pack("p"). (... truncated)

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

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