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

ruby-changes:5141

From: knu <ko1@a...>
Date: Tue, 27 May 2008 19:07:25 +0900 (JST)
Subject: [ruby-changes:5141] Ruby:r16636 (ruby_1_8_7): Merge from ruby_1_8.

knu	2008-05-27 19:07:07 +0900 (Tue, 27 May 2008)

  New Revision: 16636

  Modified files:
    branches/ruby_1_8_7/ChangeLog
    branches/ruby_1_8_7/NEWS
    branches/ruby_1_8_7/eval.c
    branches/ruby_1_8_7/ext/stringio/stringio.c
    branches/ruby_1_8_7/file.c
    branches/ruby_1_8_7/io.c
    branches/ruby_1_8_7/process.c
    branches/ruby_1_8_7/version.h

  Log:
    Merge from ruby_1_8.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/io.c?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/ext/stringio/stringio.c?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/eval.c?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/ChangeLog?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/process.c?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/NEWS?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/file.c?r1=16636&r2=16635&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/version.h?r1=16636&r2=16635&diff_format=u

Index: ruby_1_8_7/process.c
===================================================================
--- ruby_1_8_7/process.c	(revision 16635)
+++ ruby_1_8_7/process.c	(revision 16636)
@@ -1632,6 +1632,10 @@
 }
 
 
+#if defined(SIGCLD) && !defined(SIGCHLD)
+# define SIGCHLD SIGCLD
+#endif
+
 /*
  *  call-seq:
  *     Process.getpgrp   => integer
@@ -1643,10 +1647,6 @@
  *     Process.getpgrp      #=> 25527
  */
 
-#if defined(SIGCLD) && !defined(SIGCHLD)
-# define SIGCHLD SIGCLD
-#endif
-
 static VALUE
 proc_getpgrp()
 {
Index: ruby_1_8_7/ext/stringio/stringio.c
===================================================================
--- ruby_1_8_7/ext/stringio/stringio.c	(revision 16635)
+++ ruby_1_8_7/ext/stringio/stringio.c	(revision 16636)
@@ -14,6 +14,7 @@
 
 #include "ruby.h"
 #include "rubyio.h"
+#include "re.h"
 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
 #include <fcntl.h>
 #elif defined(HAVE_SYS_FCNTL_H)
@@ -162,6 +163,7 @@
 static VALUE strio_seek _((int, VALUE *, VALUE));
 static VALUE strio_get_sync _((VALUE));
 static VALUE strio_each_byte _((VALUE));
+static VALUE strio_each_char _((VALUE));
 static VALUE strio_getc _((VALUE));
 static VALUE strio_ungetc _((VALUE, VALUE));
 static VALUE strio_readchar _((VALUE));
@@ -710,11 +712,14 @@
     VALUE self;
 {
     struct StringIO *ptr = readable(StringIO(self));
-    while (ptr->pos < RSTRING(ptr->string)->len) {
-	char c = RSTRING(ptr->string)->ptr[ptr->pos++];
+
+    RETURN_ENUMERATOR(self, 0, 0);
+
+    while (ptr->pos < RSTRING_LEN(ptr->string)) {
+	char c = RSTRING_PTR(ptr->string)[ptr->pos++];
 	rb_yield(CHR2FIX(c));
     }
-    return Qnil;
+    return self;
 }
 
 /*
@@ -803,6 +808,41 @@
     return c;
 }
 
+/*
+ * call-seq:
+ *   strio.each_char {|char| block }  -> strio
+ *
+ * See IO#each_char.
+ */
+static VALUE
+strio_each_char(self)
+    VALUE self;
+{
+    struct StringIO *sio;
+    VALUE str;
+    const char *ptr;
+    size_t len;
+
+    RETURN_ENUMERATOR(self, 0, 0);
+
+    sio = readable(StringIO(self));
+    str = sio->string;
+    ptr = RSTRING_PTR(str);
+    len = RSTRING_LEN(str);
+
+    while (sio->pos < len) {
+	int pos = sio->pos;
+	char c = ptr[pos];
+        int n = mbclen(c);
+
+	if (len < pos + n) n = len - pos;
+
+	sio->pos += n;
+        rb_yield(rb_str_substr(str, pos, n));
+    }
+    return self;
+}
+
 static void
 bm_init_skip(skip, pat, m)
      long *skip;
@@ -971,6 +1011,8 @@
     struct StringIO *ptr = StringIO(self);
     VALUE line;
 
+    RETURN_ENUMERATOR(self, argc, argv);
+
     while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
 	rb_yield(line);
     }
@@ -1294,11 +1336,17 @@
     rb_define_method(StringIO, "path", strio_path, 0);
 
     rb_define_method(StringIO, "each", strio_each, -1);
+    rb_define_method(StringIO, "each_line", strio_each, -1);
+    rb_define_method(StringIO, "lines", strio_each, -1);
     rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
-    rb_define_method(StringIO, "each_line", strio_each, -1);
+    rb_define_method(StringIO, "bytes", strio_each_byte, 0);
+    rb_define_method(StringIO, "each_char", strio_each_char, 0);
+    rb_define_method(StringIO, "chars", strio_each_char, 0);
     rb_define_method(StringIO, "getc", strio_getc, 0);
+    rb_define_method(StringIO, "getbyte", strio_getc, 0);
     rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
     rb_define_method(StringIO, "readchar", strio_readchar, 0);
+    rb_define_method(StringIO, "readbyte", strio_readchar, 0);
     rb_define_method(StringIO, "gets", strio_gets, -1);
     rb_define_method(StringIO, "readline", strio_readline, -1);
     rb_define_method(StringIO, "readlines", strio_readlines, -1);
Index: ruby_1_8_7/NEWS
===================================================================
--- ruby_1_8_7/NEWS	(revision 16635)
+++ ruby_1_8_7/NEWS	(revision 16636)
@@ -178,9 +178,26 @@
 
     Return an enumerator if no block is given.
 
-  * Method#receiver
+  * IO#bytes
+  * IO#chars
+  * IO#each_char
+  * IO#getbyte
+  * IO#lines
+  * IO#readbyte
+  * ARGF.bytes
+  * ARGF.chars
+  * ARGF.each_char
+  * ARGF.getbyte
+  * ARGF.lines
+  * ARGF.readbyte
+
+    New methods. 
+
+  * Method#class_exec
+  * Method#module_exec
   * Method#name
   * Method#owner
+  * Method#receiver
   * UnboundMethod#name
   * UnboundMethod#owner
 
@@ -309,6 +326,24 @@
     * Shellwords.split (alias shellwords)
     * String#shellsplit
 
+* stringio
+
+  * StringIO#getbyte
+  * StringIO#readbyte
+
+    New methods. (aliases for compatibility with 1.9)
+
+  * StringIO#each_char
+  * StringIO#chars
+
+    New methods.
+
+  * StringIO#each
+  * StringIO#each_line
+  * StringIO#each_byte
+
+    Return an enumerator if no block is given.
+
 * tempfile
 
   * Tempfile.open and Tempfile.new now accept a suffix for the
@@ -387,6 +422,13 @@
     always use Date.strptime() when you know what you are dealing
     with.
 
+* stringio
+
+  * StringIO#each_byte
+
+    The return value changed from nil to self.  This is what the
+    document says and the same as each_line() does.
+
 * tempfile
 
   * The file name format has changed.  No dots are included by default
Index: ruby_1_8_7/ChangeLog
===================================================================
--- ruby_1_8_7/ChangeLog	(revision 16635)
+++ ruby_1_8_7/ChangeLog	(revision 16636)
@@ -1,3 +1,65 @@
+Tue May 27 18:54:02 2008  Akinori MUSHA  <knu@i...>
+
+	* ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
+	  StringIO#{each_char,chars}.
+
+Tue May 27 17:59:34 2008  Akinori MUSHA  <knu@i...>
+
+	* ext/stringio/stringio.c (strio_each): Return an enumerator if no
+	  block is given.
+	  (strio_each_byte): Return an enumerator if no block is given,
+	  and return self if one is given as the rdoc says.
+
+	* io.c (rb_io_each_byte): Fix rdoc.  IO#each_byte returns self,
+	  not nil.
+
+Tue May 27 16:02:58 2008  Akinori MUSHA  <knu@i...>
+
+	* eval.c (rb_mod_module_exec, Init_eval): Add
+	  Module#{module_exec,class_exec}.
+
+Tue May 27 15:36:37 2008  Akinori MUSHA  <knu@i...>
+
+	* io.c (rb_io_each_char, argf_each_char, Init_IO):
+	  Add {IO#,ARGF.}{each_char,chars}.
+
+Tue May 27 13:46:52 2008  Akinori MUSHA  <knu@i...>
+
+	* ext/stringio/stringio.c (Init_stringio): Define
+	  StringIO#{getbyte,readbyte}.
+
+Tue May 27 13:38:51 2008  Akinori MUSHA  <knu@i...>
+
+	* io.c (Init_IO): Define {IO#,ARGF.}{getbyte,readbyte}.
+
+Tue May 27 13:26:15 2008  Akinori MUSHA  <knu@i...>
+
+	* ext/stringio/stringio.c (Init_stringio): Define #bytes and
+	  #lines.
+
+Tue May 27 13:20:35 2008  Akinori MUSHA  <knu@i...>
+
+	* io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
+	  IO#{lines,bytes} and ARGF.{lines,bytes}.
+
+Tue May 27 12:13:17 2008  NAKAMURA Usaku  <usa@r...>
+
+	* file.c (BUFCHECK): wrong condition. [ruby-core:16921]
+
+	* file.c (file_expand_buf): shouldn't use buflen for length of string.
+
+Mon May 26 18:24:48 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (BUFCHECK): no resize if enough room.
+
+	* file.c (file_expand_path): use BUFCHECK.
+
+Mon May 26 16:46:19 2008  NAKAMURA Usaku  <usa@r...>
+
+	* file.c (ntfs_tail): filename which starts with '.' is valid.
+
+	* file.c (file_expand_path): cygwin symlink support.
+
 Mon May 26 12:16:43 2008  Akinori MUSHA  <knu@i...>
 
 	* .: Release as Ruby 1.8.7-preview4.
Index: ruby_1_8_7/version.h
===================================================================
--- ruby_1_8_7/version.h	(revision 16635)
+++ ruby_1_8_7/version.h	(revision 16636)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.8.7"
-#define RUBY_RELEASE_DATE "2008-05-26"
+#define RUBY_RELEASE_DATE "2008-05-27"
 #define RUBY_VERSION_CODE 187
-#define RUBY_RELEASE_CODE 20080526
+#define RUBY_RELEASE_CODE 20080527
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 7
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 26
+#define RUBY_RELEASE_DAY 27
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8_7/io.c
===================================================================
--- ruby_1_8_7/io.c	(revision 16635)
+++ ruby_1_8_7/io.c	(revision 16636)
@@ -21,6 +21,7 @@
 #include "rubyio.h"
 #include "rubysig.h"
 #include "env.h"
+#include "re.h"
 #include <ctype.h>
 #include <errno.h>
 
@@ -1980,7 +1981,7 @@
 
 /*
  *  call-seq:
- *     ios.each_byte {|byte| block }  => nil
+ *     ios.each_byte {|byte| block }  => ios
  *  
  *  Calls the given block once for each byte (0..255) in <em>ios</em>,
  *  passing the byte as an argument. The stream must be opened for
@@ -2026,8 +2027,99 @@
     return io;
 }
 
+VALUE rb_io_getc _((VALUE));
+
 /*
  *  call-seq:
+ *     ios.each_char {|c| block }  => ios
+ *
+ *  Calls the given block once for each character in <em>ios</em>,
+ *  passing the character as an argument. The stream must be opened for
+ *  reading or an <code>IOError</code> will be raised.  Multibyte
+ *  characters are dealt with according to $KCODE.
+ *
+ *     f = File.new("testfile")
+ *     f.each_char {|c| print c, ' ' }   #=> #<File:testfile>
+ */
+
+static VALUE
+rb_io_each_char(io)
+    VALUE io;
+{
+    VALUE ch;
+
+    RETURN_ENUMERATOR(io, 0, 0);
+
+    while (!NIL_P(ch = rb_io_getc(io))) {
+	unsigned char c;
+	int n;
+	VALUE str;
+
+	c= FIX2INT(ch);
+	n = mbclen(c);
+	str = rb_tainted_str_new((const char *)&c, 1);
+
+	while (--n > 0) {
+	    if (NIL_P(ch = rb_io_getc(io))) {
+		rb_yield(str);
+		return io;
+	    }
+	    c = FIX2INT(ch);
+	    rb_str_cat(str, (const char *)&c, 1);
+	}
+	rb_yield(str);
+    }
+    return io;
+}
+
+/*
+ *  call-seq:
+ *     ios.lines(sep=$/)     => anEnumerator
+ *     ios.lines(limit)      => anEnumerator
+ *     ios.lines(sep, limit) => anEnumerator
+ *
+ *  Returns an enumerator that gives each line in <em>ios</em>.
+ *  The stream must be opened for reading or an <code>IOError</code>
+ *  will be raised.
+ *
+ *     f = File.new("testfile")
+ *     f.lines.to_a  #=> ["foo\n", "bar\n"]
+ *     f.rewind
+ *     f.lines.sort  #=> ["bar\n", "foo\n"]
+ */
+
+static VALUE
+rb_io_lines(argc, argv, io)
+    int argc;
+    VALUE *argv;
+    VALUE io;
+{
+    return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
+}
+
+/*
+ *  call-seq:
+ *     ios.bytes   => anEnumerator
+ *
+ *  Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
+ *  The stream must be opened for reading or an <code>IOError</code>
+ *  will be raised.
+ *     
+ *     f = File.new("testfile")
+ *     f.bytes.to_a  #=> [104, 101, 108, 108, 111]
+ *     f.rewind
+ *     f.bytes.sort  #=> [101, 104, 108, 108, 111]
+ */
+
+static VALUE
+rb_io_bytes(io)
+    VALUE io;
+{
+    return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
+}
+
+/*
+ *  call-seq:
  *     ios.getc   => fixnum or nil
  *  
  *  Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
@@ -5567,6 +5659,42 @@
 }
 
 static VALUE
+argf_each_char(argf)
+    VALUE argf;
+{
+    VALUE ch;
+
+    RETURN_ENUMERATOR(argf, 0, 0);
+
+    while (!NIL_P(ch = argf_getc())) {
+	unsigned char c;
+	int n;
+	VALUE str, file;
+
+      first_char:
+	c = FIX2INT(ch);
+	n = mbclen(c);
+	str = rb_tainted_str_new((const char *)&c, 1);
+	file = current_file;
+
+	while (--n > 0) {
+	    if (NIL_P(ch = argf_getc())) {
+		rb_yield(str);
+		return argf;
+	    }
+	    if (current_file != file) {
+		rb_yield(str);
+		goto first_char;
+	    }
+	    c = FIX2INT(ch);
+	    rb_str_cat(str, (const char *)&c, 1);
+	}
+	rb_yield(str);
+    }
+    return argf;
+}
+
+static VALUE
 argf_filename()
 {
     next_argv();
@@ -5808,6 +5936,10 @@
     rb_define_method(rb_cIO, "each",  rb_io_each_line, -1);
     rb_define_method(rb_cIO, "each_line",  rb_io_each_line, -1);
     rb_define_method(rb_cIO, "each_byte",  rb_io_each_byte, 0);
+    rb_define_method(rb_cIO, "each_char",  rb_io_each_char, 0);
+    rb_define_method(rb_cIO, "lines",  rb_io_lines, -1);
+    rb_define_method(rb_cIO, "bytes",  rb_io_bytes, 0);
+    rb_define_method(rb_cIO, "chars",  rb_io_each_char, 0);
 
     rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
     rb_define_method(rb_cIO, "sysread",  rb_io_sysread, -1);
@@ -5833,7 +5965,9 @@
     rb_define_method(rb_cIO, "gets",  rb_io_gets_m, -1);
     rb_define_method(rb_cIO, "readline",  rb_io_readline, -1);
     rb_define_method(rb_cIO, "getc",  rb_io_getc, 0);
+    rb_define_method(rb_cIO, "getbyte",  rb_io_getc, 0);
     rb_define_method(rb_cIO, "readchar",  rb_io_readchar, 0);
+    rb_define_method(rb_cIO, "readbyte",  rb_io_readchar, 0);
     rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
     rb_define_method(rb_cIO, "<<",    rb_io_addstr, 1);
     rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
@@ -5895,6 +6029,10 @@
     rb_define_singleton_method(argf, "each",  argf_each_line, -1);
     rb_define_singleton_method(argf, "each_line",  argf_each_line, -1);
     rb_define_singleton_method(argf, "each_byte",  argf_each_byte, 0);
+    rb_define_singleton_method(argf, "each_char",  argf_each_char, 0);
+    rb_define_singleton_method(argf, "lines",  argf_each_line, -1);
+    rb_define_singleton_method(argf, "bytes",  argf_each_byte, 0);
+    rb_define_singleton_method(argf, "chars",  argf_each_char, 0);
 
     rb_define_singleton_method(argf, "read",  argf_read, -1);
     rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
@@ -5902,7 +6040,9 @@
     rb_define_singleton_method(argf, "gets", rb_f_gets, -1);
     rb_define_singleton_method(argf, "readline", rb_f_readline, -1);
     rb_define_singleton_method(argf, "getc", argf_getc, 0);
+    rb_define_singleton_method(argf, "getbyte", argf_getc, 0);
     rb_define_singleton_method(argf, "readchar", argf_readchar, 0);
+    rb_define_singleton_method(argf, "readbyte", argf_readchar, 0);
     rb_define_singleton_method(argf, "tell", argf_tell, 0);
     rb_define_singleton_method(argf, "seek", argf_seek_m, -1);
     rb_define_singleton_method(argf, "rewind", argf_rewind, 0);
Index: ruby_1_8_7/file.c
===================================================================
--- ruby_1_8_7/file.c	(revision 16635)
+++ ruby_1_8_7/file.c	(revision 16636)
@@ -2474,6 +2474,7 @@
 static char *
 ntfs_tail(const char *path)
 {
+    while (*path == '.') path++;
     while (*path && *path != ':') {
 	if (istrailinggabage(*path)) {
 	    const char *last = path++;
@@ -2496,13 +2497,13 @@
 
 #define BUFCHECK(cond) do {\
     long bdiff = p - buf;\
-    while (cond) {\
-	buflen *= 2;\
+    if (cond) {\
+	do {buflen *= 2;} while (cond);\
+	rb_str_resize(result, buflen);\
+	buf = RSTRING_PTR(result);\
+	p = buf + bdiff;\
+	pend = buf + buflen;\
     }\
-    rb_str_resize(result, buflen);\
-    buf = RSTRING(result)->ptr;\
-    p = buf + bdiff;\
-    pend = buf + buflen;\
 } while (0)
 
 #define BUFINIT() (\
@@ -2738,7 +2739,6 @@
 	p += s-b;
     }
     if (p == skiproot(buf) - 1) p++;
-    buflen = p - buf;
 
 #if USE_NTFS
     *p = '\0';
@@ -2784,19 +2784,20 @@
 #ifdef __CYGWIN__
 	    if (lnk_added && len > 4 &&
 		strcasecmp(wfd.cFileName + len - 4, ".lnk") == 0) {
-		len -= 4;
+		wfd.cFileName[len -= 4] = '\0';
 	    }
 #endif
 	    if (!p) p = buf;
-	    buflen = ++p - buf + len;
-	    rb_str_resize(result, buflen);
+	    ++p;
+	    BUFCHECK(bdiff + len >= buflen);
 	    memcpy(p, wfd.cFileName, len + 1);
+	    p += len;
 	}
     }
 #endif
 
     if (tainted) OBJ_TAINT(result);
-    rb_str_set_len(result, buflen);
+    rb_str_set_len(result, p - buf);
     return result;
 }
 
Index: ruby_1_8_7/eval.c
===================================================================
--- ruby_1_8_7/eval.c	(revision 16635)
+++ ruby_1_8_7/eval.c	(revision 16636)
@@ -6918,6 +6918,35 @@
     return specific_eval(argc, argv, mod, mod);
 }
 
+/*
+ *  call-seq:
+ *     mod.module_exec(arg...) {|var...| block }       => obj
+ *     mod.class_exec(arg...) {|var...| block }        => obj
+ *
+ *  Evaluates the given block in the context of the class/module.
+ *  The method defined in the block will belong to the receiver.
+ *
+ *     class Thing
+ *     end
+ *     Thing.class_exec{
+ *       def hello() "Hello there!" end
+ *     }
+ *     puts Thing.new.hello()
+ *
+ *  <em>produces:</em>
+ *
+ *     Hello there!
+ */
+
+VALUE
+rb_mod_module_exec(argc, argv, mod)
+    int argc;
+    VALUE *argv;
+    VALUE mod;
+{
+    return yield_under(mod, mod, rb_ary_new4(argc, argv));
+}
+
 VALUE rb_load_path;
 
 NORETURN(static void load_failed _((VALUE)));
@@ -8187,7 +8216,9 @@
     rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
     rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
     rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
+    rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
     rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
+    rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
 
     rb_undef_method(rb_cClass, "module_function");
 

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

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