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

ruby-changes:58653

From: Yusuke <ko1@a...>
Date: Fri, 8 Nov 2019 23:52:10 +0900 (JST)
Subject: [ruby-changes:58653] a3141e3c76 (master): Rubified the APIs of pack.c

https://git.ruby-lang.org/ruby.git/commit/?id=a3141e3c76

From a3141e3c76ef057080d5aab22130a326378094e2 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 8 Nov 2019 11:54:39 +0900
Subject: Rubified the APIs of pack.c


diff --git a/.document b/.document
index e4a19e9..b8e2d44 100644
--- a/.document
+++ b/.document
@@ -15,6 +15,7 @@ trace_point.rb https://github.com/ruby/ruby/blob/trunk/.document#L15
 ast.rb
 io.rb
 gc.rb
+pack.rb
 
 # the lib/ directory (which has its own .document file)
 lib
diff --git a/common.mk b/common.mk
index 5fc7ec5..f51a1d8 100644
--- a/common.mk
+++ b/common.mk
@@ -1108,6 +1108,9 @@ builtin_binary.inc: $(PREP) $(BUILTIN_RB_SRCS) $(srcdir)/tool/mk_builtin_binary. https://github.com/ruby/ruby/blob/trunk/common.mk#L1108
 
 $(BUILTIN_RB_INCS): $(top_srcdir)/tool/mk_builtin_loader.rb
 
+load_pack.inc: $(srcdir)/pack.rb $(srcdir)/tool/mk_builtin_loader.rb
+	$(Q) $(BASERUBY) $(srcdir)/tool/mk_builtin_loader.rb $(srcdir)/pack.rb
+
 $(srcdir)/revision.h:
 	$(Q)$(gnumake:yes=#) $(RM) $(@F)
 	$(Q)$(gnumake:yes=#) exit > $@ || exit > $(@F)
@@ -2569,12 +2572,14 @@ object.$(OBJEXT): {$(VPATH)}util.h https://github.com/ruby/ruby/blob/trunk/common.mk#L2572
 pack.$(OBJEXT): $(hdrdir)/ruby.h
 pack.$(OBJEXT): $(hdrdir)/ruby/ruby.h
 pack.$(OBJEXT): {$(VPATH)}assert.h
+pack.$(OBJEXT): {$(VPATH)}builtin.h
 pack.$(OBJEXT): {$(VPATH)}config.h
 pack.$(OBJEXT): {$(VPATH)}defines.h
 pack.$(OBJEXT): {$(VPATH)}encoding.h
 pack.$(OBJEXT): {$(VPATH)}intern.h
 pack.$(OBJEXT): {$(VPATH)}internal.h
 pack.$(OBJEXT): {$(VPATH)}io.h
+pack.$(OBJEXT): {$(VPATH)}load_pack.inc
 pack.$(OBJEXT): {$(VPATH)}missing.h
 pack.$(OBJEXT): {$(VPATH)}onigmo.h
 pack.$(OBJEXT): {$(VPATH)}oniguruma.h
diff --git a/inits.c b/inits.c
index c4a6a62..9ced248 100644
--- a/inits.c
+++ b/inits.c
@@ -42,7 +42,6 @@ rb_call_inits(void) https://github.com/ruby/ruby/blob/trunk/inits.c#L42
     CALL(Hash);
     CALL(Struct);
     CALL(Regexp);
-    CALL(pack);
     CALL(transcode);
     CALL(marshal);
     CALL(Range);
@@ -73,5 +72,6 @@ rb_call_inits(void) https://github.com/ruby/ruby/blob/trunk/inits.c#L72
     CALL(IO_nonblock);
     CALL(ast);
     CALL(vm_trace);
+    CALL(pack);
 }
 #undef CALL
diff --git a/pack.c b/pack.c
index ba2348c..c91531f 100644
--- a/pack.c
+++ b/pack.c
@@ -15,6 +15,7 @@ https://github.com/ruby/ruby/blob/trunk/pack.c#L15
 #include <ctype.h>
 #include <errno.h>
 #include <float.h>
+#include "builtin.h"
 
 /*
  * It is intentional that the condition for natstr is HAVE_TRUE_LONG_LONG
@@ -169,145 +170,13 @@ VALUE_to_float(VALUE obj) https://github.com/ruby/ruby/blob/trunk/pack.c#L170
     }
 }
 
-/*
- *  call-seq:
- *     arr.pack( aTemplateString ) -> aBinaryString
- *     arr.pack( aTemplateString, buffer: aBufferString ) -> aBufferString
- *
- *  Packs the contents of <i>arr</i> into a binary sequence according to
- *  the directives in <i>aTemplateString</i> (see the table below)
- *  Directives ``A,'' ``a,'' and ``Z'' may be followed by a count,
- *  which gives the width of the resulting field. The remaining
- *  directives also may take a count, indicating the number of array
- *  elements to convert. If the count is an asterisk
- *  (``<code>*</code>''), all remaining array elements will be
- *  converted. Any of the directives ``<code>sSiIlL</code>'' may be
- *  followed by an underscore (``<code>_</code>'') or
- *  exclamation mark (``<code>!</code>'') to use the underlying
- *  platform's native size for the specified type; otherwise, they use a
- *  platform-independent size. Spaces are ignored in the template
- *  string. See also String#unpack.
- *
- *     a = [ "a", "b", "c" ]
- *     n = [ 65, 66, 67 ]
- *     a.pack("A3A3A3")   #=> "a  b  c  "
- *     a.pack("a3a3a3")   #=> "a\000\000b\000\000c\000\000"
- *     n.pack("ccc")      #=> "ABC"
- *
- *  If <i>aBufferString</i> is specified and its capacity is enough,
- *  +pack+ uses it as the buffer and returns it.
- *  When the offset is specified by the beginning of <i>aTemplateString</i>,
- *  the result is filled after the offset.
- *  If original contents of <i>aBufferString</i> exists and it's longer than
- *  the offset, the rest of <i>offsetOfBuffer</i> are overwritten by the result.
- *  If it's shorter, the gap is filled with ``<code>\0</code>''.
- *
- *  Note that ``buffer:'' option does not guarantee not to allocate memory
- *  in +pack+.  If the capacity of <i>aBufferString</i> is not enough,
- *  +pack+ allocates memory.
- *
- *  Directives for +pack+.
- *
- *   Integer       | Array   |
- *   Directive     | Element | Meaning
- *   ----------------------------------------------------------------------------
- *   C             | Integer | 8-bit unsigned (unsigned char)
- *   S             | Integer | 16-bit unsigned, native endian (uint16_t)
- *   L             | Integer | 32-bit unsigned, native endian (uint32_t)
- *   Q             | Integer | 64-bit unsigned, native endian (uint64_t)
- *   J             | Integer | pointer width unsigned, native endian (uintptr_t)
- *                 |         | (J is available since Ruby 2.3.)
- *                 |         |
- *   c             | Integer | 8-bit signed (signed char)
- *   s             | Integer | 16-bit signed, native endian (int16_t)
- *   l             | Integer | 32-bit signed, native endian (int32_t)
- *   q             | Integer | 64-bit signed, native endian (int64_t)
- *   j             | Integer | pointer width signed, native endian (intptr_t)
- *                 |         | (j is available since Ruby 2.3.)
- *                 |         |
- *   S_ S!         | Integer | unsigned short, native endian
- *   I I_ I!       | Integer | unsigned int, native endian
- *   L_ L!         | Integer | unsigned long, native endian
- *   Q_ Q!         | Integer | unsigned long long, native endian (ArgumentError
- *                 |         | if the platform has no long long type.)
- *                 |         | (Q_ and Q! is available since Ruby 2.1.)
- *   J!            | Integer | uintptr_t, native endian (same with J)
- *                 |         | (J! is available since Ruby 2.3.)
- *                 |         |
- *   s_ s!         | Integer | signed short, native endian
- *   i i_ i!       | Integer | signed int, native endian
- *   l_ l!         | Integer | signed long, native endian
- *   q_ q!         | Integer | signed long long, native endian (ArgumentError
- *                 |         | if the platform has no long long type.)
- *                 |         | (q_ and q! is available since Ruby 2.1.)
- *   j!            | Integer | intptr_t, native endian (same with j)
- *                 |         | (j! is available since Ruby 2.3.)
- *                 |         |
- *   S> s> S!> s!> | Integer | same as the directives without ">" except
- *   L> l> L!> l!> |         | big endian
- *   I!> i!>       |         | (available since Ruby 1.9.3)
- *   Q> q> Q!> q!> |         | "S>" is same as "n"
- *   J> j> J!> j!> |         | "L>" is same as "N"
- *                 |         |
- *   S< s< S!< s!< | Integer | same as the directives without "<" except
- *   L< l< L!< l!< |         | little endian
- *   I!< i!<       |         | (available since Ruby 1.9.3)
- *   Q< q< Q!< q!< |         | "S<" is same as "v"
- *   J< j< J!< j!< |         | "L<" is same as "V"
- *                 |         |
- *   n             | Integer | 16-bit unsigned, network (big-endian) byte order
- *   N             | Integer | 32-bit unsigned, network (big-endian) byte order
- *   v             | Integer | 16-bit unsigned, VAX (little-endian) byte order
- *   V             | Integer | 32-bit unsigned, VAX (little-endian) byte order
- *                 |         |
- *   U             | Integer | UTF-8 character
- *   w             | Integer | BER-compressed integer
- *
- *   Float        | Array   |
- *   Directive    | Element | Meaning
- *   ---------------------------------------------------------------------------
- *   D d          | Float   | double-precision, native format
- *   F f          | Float   | single-precision, native format
- *   E            | Float   | double-precision, little-endian byte order
- *   e            | Float   | single-precision, little-endian byte order
- *   G            | Float   | double-precision, network (big-endian) byte order
- *   g            | Float   | single-precision, network (big-endian) byte order
- *
- *   String       | Array   |
- *   Directive    | Element | Meaning
- *   ---------------------------------------------------------------------------
- *   A            | String  | arbitrary binary string (space padded, count is width)
- *   a            | String  | arbitrary binary string (null padded, count is width)
- *   Z            | String  | same as ``a'', except that null is added with *
- *   B            | String  | bit string (MSB first)
- *   b            | String  | bit string (LSB first)
- *   H            | String  | hex string (high nibble first)
- *   h            | String  | hex string (low nibble first)
- *   u            | String  | UU-encoded string
- *   M            | String  | quoted printable, MIME encoding (see also RFC2045)
- *                |         | (text mode but input must use LF and output LF)
- *   m            | String  | base64 encoded string (see RFC 2045)
- *                |         | (if count is 0, no line feed are added, see RFC 4648)
- *                |         | (count specifies input bytes between each LF,
- *                |         | rounded down to nearest multiple of 3)
- *   P            | String  | pointer to a structure (fixed-length string)
- *   p            | String  | pointer to a null-terminated string
- *
- *   Misc.        | Array   |
- *   Directive    | Element | Meaning
- *   ---------------------------------------------------------------------------
- *   @            | ---     | moves to absolute position
- *   X            | ---     | back up a byte
- *   x            | ---     | null byte
- */
-
 static VALUE
-pack_pack(int argc, VALU (... truncated)

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

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