summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog62
-rw-r--r--NEWS44
-rw-r--r--eval.c31
-rw-r--r--ext/stringio/stringio.c56
-rw-r--r--file.c23
-rw-r--r--io.c142
-rw-r--r--process.c8
-rw-r--r--version.h6
8 files changed, 348 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 3558f2d3d1..1e2d1ddaa0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,65 @@
+Tue May 27 18:54:02 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
+ StringIO#{each_char,chars}.
+
+Tue May 27 17:59:34 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * 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@iDaemons.org>
+
+ * eval.c (rb_mod_module_exec, Init_eval): Add
+ Module#{module_exec,class_exec}.
+
+Tue May 27 15:36:37 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * 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@iDaemons.org>
+
+ * ext/stringio/stringio.c (Init_stringio): Define
+ StringIO#{getbyte,readbyte}.
+
+Tue May 27 13:38:51 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * io.c (Init_IO): Define {IO#,ARGF.}{getbyte,readbyte}.
+
+Tue May 27 13:26:15 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/stringio/stringio.c (Init_stringio): Define #bytes and
+ #lines.
+
+Tue May 27 13:20:35 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * 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@ruby-lang.org>
+
+ * 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@ruby-lang.org>
+
+ * 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@ruby-lang.org>
+
+ * 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@iDaemons.org>
* .: Release as Ruby 1.8.7-preview4.
diff --git a/NEWS b/NEWS
index ae520a971d..63b8ab26b3 100644
--- a/NEWS
+++ b/NEWS
@@ -178,9 +178,26 @@ with all sufficient information, see the ChangeLog file.
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 @@ with all sufficient information, see the ChangeLog file.
* 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 @@ with all sufficient information, see the ChangeLog file.
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
diff --git a/eval.c b/eval.c
index d13cd63329..89659bb21f 100644
--- a/eval.c
+++ b/eval.c
@@ -6918,6 +6918,35 @@ rb_mod_module_eval(argc, argv, mod)
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 @@ Init_eval()
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");
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 4fd8526fa5..f912c4193e 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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_rewind _((VALUE));
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 @@ strio_each_byte(self)
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 @@ strio_readchar(self)
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 @@ strio_each(argc, argv, self)
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 @@ Init_stringio()
rb_define_method(StringIO, "path", strio_path, 0);
rb_define_method(StringIO, "each", 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, "lines", strio_each, -1);
+ rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
+ 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);
diff --git a/file.c b/file.c
index ba00e9d34a..c844e3f88b 100644
--- a/file.c
+++ b/file.c
@@ -2474,6 +2474,7 @@ rb_path_end(path)
static char *
ntfs_tail(const char *path)
{
+ while (*path == '.') path++;
while (*path && *path != ':') {
if (istrailinggabage(*path)) {
const char *last = path++;
@@ -2496,13 +2497,13 @@ ntfs_tail(const char *path)
#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 @@ file_expand_path(fname, dname, result)
p += s-b;
}
if (p == skiproot(buf) - 1) p++;
- buflen = p - buf;
#if USE_NTFS
*p = '\0';
@@ -2784,19 +2784,20 @@ file_expand_path(fname, dname, result)
#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;
}
diff --git a/io.c b/io.c
index 83e748f633..94c2fe8e9d 100644
--- a/io.c
+++ b/io.c
@@ -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 @@ rb_io_each_line(argc, argv, io)
/*
* 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,6 +2027,97 @@ rb_io_each_byte(io)
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
@@ -5567,6 +5659,42 @@ argf_each_byte(argf)
}
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 @@ Init_IO()
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 @@ Init_IO()
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 @@ Init_IO()
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 @@ Init_IO()
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);
diff --git a/process.c b/process.c
index fa45829196..642c5982a6 100644
--- a/process.c
+++ b/process.c
@@ -1632,6 +1632,10 @@ rb_f_sleep(argc, argv)
}
+#if defined(SIGCLD) && !defined(SIGCHLD)
+# define SIGCHLD SIGCLD
+#endif
+
/*
* call-seq:
* Process.getpgrp => integer
@@ -1643,10 +1647,6 @@ rb_f_sleep(argc, argv)
* Process.getpgrp #=> 25527
*/
-#if defined(SIGCLD) && !defined(SIGCHLD)
-# define SIGCHLD SIGCLD
-#endif
-
static VALUE
proc_getpgrp()
{
diff --git a/version.h b/version.h
index 0311bcf6ee..39caaad093 100644
--- a/version.h
+++ b/version.h
@@ -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[];