summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--file.c7
-rw-r--r--io.c33
-rw-r--r--numeric.c4
-rw-r--r--rubyio.h2
-rw-r--r--string.c2
6 files changed, 42 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 2cf5470..0a11d9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Mon Apr 14 03:22:33 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * rubyio.h (struct OpenFile): add error raise flag to finalizer.
+
+ * io.c (Init_IO): define $/, $-0, and $\ as string-only
+ variables.
+
+ * string.c (rb_str_split_m): does not generate empty string if
+ there's no match in the receiver.
+
+ * io.c (fptr_finalize): should raise error on EBADF for readable
+ IOs as well.
+
Mon Apr 14 15:54:18 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* bignum.c (rb_cstr_to_inum, rb_big2str): allow 2-36 as radix.
@@ -22,6 +35,10 @@ Sat Apr 12 20:59:40 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* misc/ruby-mode.el (ruby-forward-sexp, ruby-backward-sexp):
support special char literal, and negative arguments.
+Sat Apr 12 17:52:47 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * file.c (rb_stat): use rb_check_convert_type() to retrieve IO.
+
Fri Apr 11 19:00:14 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* win32/win32.c (rb_w32_stat): check arguments. [ruby-dev:20007]
diff --git a/file.c b/file.c
index bd793c5..93ed79b 100644
--- a/file.c
+++ b/file.c
@@ -346,11 +346,14 @@ rb_stat(file, st)
VALUE file;
struct stat *st;
{
- if (TYPE(file) == T_FILE) {
+ VALUE tmp;
+
+ tmp = rb_check_convert_type(file, T_FILE, "IO", "to_io");
+ if (!NIL_P(tmp)) {
OpenFile *fptr;
rb_secure(2);
- GetOpenFile(file, fptr);
+ GetOpenFile(tmp, fptr);
return fstat(fileno(fptr->f), st);
}
SafeStringValue(file);
diff --git a/io.c b/io.c
index e90db24..55fcfa4 100644
--- a/io.c
+++ b/io.c
@@ -1318,9 +1318,9 @@ rb_io_isatty(io)
}
static void
-fptr_finalize(fptr, fin)
+fptr_finalize(fptr, noraise)
OpenFile *fptr;
- int fin;
+ int noraise;
{
int n1 = 0, n2 = 0, e = 0, f1, f2 = -1;
@@ -1341,28 +1341,26 @@ fptr_finalize(fptr, fin)
if (!rb_io_wait_writable(f1)) break;
}
fptr->f = 0;
- if (n1 < 0 && errno == EBADF) {
- if (f1 == f2 || !(fptr->mode & FMODE_WBUF)) {
- n1 = 0;
- }
+ if (n1 < 0 && errno == EBADF && f1 == f2) {
+ n1 = 0;
}
}
- if (!fin && (n1 < 0 || n2 < 0)) {
+ if (!noraise && (n1 < 0 || n2 < 0)) {
if (n1 == 0) errno = e;
rb_sys_fail(fptr->path);
}
}
static void
-rb_io_fptr_cleanup(fptr, fin)
+rb_io_fptr_cleanup(fptr, noraise)
OpenFile *fptr;
- int fin;
+ int noraise;
{
if (fptr->finalize) {
- (*fptr->finalize)(fptr);
+ (*fptr->finalize)(fptr, noraise);
}
else {
- fptr_finalize(fptr, fin);
+ fptr_finalize(fptr, noraise);
}
if (fptr->path) {
@@ -1937,11 +1935,12 @@ pipe_atexit _((void))
}
#endif
-static void pipe_finalize _((OpenFile *fptr));
+static void pipe_finalize _((OpenFile *fptr,int));
static void
-pipe_finalize(fptr)
+pipe_finalize(fptr, noraise)
OpenFile *fptr;
+ int noraise;
{
#if !defined (__CYGWIN__) && !defined(_WIN32)
extern VALUE rb_last_status;
@@ -1958,7 +1957,7 @@ pipe_finalize(fptr)
#endif
rb_last_status = INT2FIX(status);
#else
- fptr_finalize(fptr, Qtrue);
+ fptr_finalize(fptr, noraise);
#endif
pipe_del_fptr(fptr);
}
@@ -3988,9 +3987,9 @@ Init_IO()
rb_output_rs = Qnil;
rb_global_variable(&rb_default_rs);
OBJ_FREEZE(rb_default_rs); /* avoid modifying RS_default */
- rb_define_variable("$/", &rb_rs);
- rb_define_variable("$-0", &rb_rs);
- rb_define_variable("$\\", &rb_output_rs);
+ rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
rb_define_hooked_variable("$.", &lineno, 0, lineno_setter);
rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
diff --git a/numeric.c b/numeric.c
index bd8be06..13466d7 100644
--- a/numeric.c
+++ b/numeric.c
@@ -93,11 +93,11 @@ static VALUE
coerce_rescue(x)
VALUE *x;
{
- volatile VALUE v;
+ volatile VALUE v = rb_inspect(x[1]);
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
rb_special_const_p(x[1])?
- RSTRING(v = rb_inspect(x[1]))->ptr:
+ RSTRING(v)->ptr:
rb_obj_classname(x[1]),
rb_obj_classname(x[0]));
return Qnil; /* dummy */
diff --git a/rubyio.h b/rubyio.h
index fd9c6e3..26f86b0 100644
--- a/rubyio.h
+++ b/rubyio.h
@@ -23,7 +23,7 @@ typedef struct OpenFile {
int pid; /* child's pid (for pipes) */
int lineno; /* number of lines read */
char *path; /* pathname for file */
- void (*finalize) _((struct OpenFile*)); /* finalize proc */
+ void (*finalize) _((struct OpenFile*,int)); /* finalize proc */
} OpenFile;
#define FMODE_READABLE 1
diff --git a/string.c b/string.c
index 35cfb39..733a7df 100644
--- a/string.c
+++ b/string.c
@@ -2613,7 +2613,7 @@ rb_str_split_m(argc, argv, str)
if (!NIL_P(limit) && lim <= ++i) break;
}
}
- if (!NIL_P(limit) || RSTRING(str)->len > beg || lim < 0) {
+ if (RSTRING(str)->len > 0 && (!NIL_P(limit) || RSTRING(str)->len > beg || lim < 0)) {
if (RSTRING(str)->len == beg)
tmp = rb_str_new5(str, 0, 0);
else