1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.

* file.c (rb_stat): use rb_check_convert_type() to retrieve IO.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-04-14 09:04:43 +00:00
parent 0b4c9491ec
commit f34f20ebc5
6 changed files with 42 additions and 23 deletions

View file

@ -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]

7
file.c
View file

@ -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);

33
io.c
View file

@ -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);

View file

@ -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 */

View file

@ -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

View file

@ -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