mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (set_stdin): assigned value must respond to "read" and
"getc". * io.c (set_outfile): assigned value must respond to "write". (ruby-bugs-ja:PR#425) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
95eb316d44
commit
0b984f51a1
2 changed files with 32 additions and 8 deletions
|
@ -1,3 +1,11 @@
|
|||
Fri Apr 11 02:41:35 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
|
||||
* io.c (set_stdin): assigned value must respond to "read" and
|
||||
"getc".
|
||||
|
||||
* io.c (set_outfile): assigned value must respond to "write".
|
||||
(ruby-bugs-ja:PR#425)
|
||||
|
||||
Thu Apr 10 21:12:19 2003 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* lib/net/pop.rb: Exception line was accidentaly removed.
|
||||
|
|
32
io.c
32
io.c
|
@ -105,7 +105,7 @@ VALUE rb_default_rs;
|
|||
|
||||
static VALUE argf;
|
||||
|
||||
static ID id_write;
|
||||
static ID id_write, id_read, id_getc;
|
||||
|
||||
extern char *ruby_inplace_mode;
|
||||
|
||||
|
@ -2678,15 +2678,25 @@ rb_obj_display(argc, argv, self)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static void
|
||||
must_respond_to(mid, val, id)
|
||||
ID mid;
|
||||
VALUE val;
|
||||
ID id;
|
||||
{
|
||||
if (!rb_respond_to(val, mid)) {
|
||||
rb_raise(rb_eTypeError, "%s must have %s method, %s given",
|
||||
rb_id2name(id), rb_id2name(mid),
|
||||
rb_obj_classname(val));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rb_io_defset(val, id)
|
||||
VALUE val;
|
||||
ID id;
|
||||
{
|
||||
if (!rb_respond_to(val, id_write)) {
|
||||
rb_raise(rb_eTypeError, "$> must have write method, %s given",
|
||||
rb_obj_classname(val));
|
||||
}
|
||||
must_respond_to(id_write, val, id);
|
||||
rb_defout = val;
|
||||
}
|
||||
|
||||
|
@ -2700,6 +2710,8 @@ set_stdin(val, id, var)
|
|||
|
||||
if (val == *var) return;
|
||||
if (TYPE(val) != T_FILE) {
|
||||
must_respond_to(id_read, val, id);
|
||||
must_respond_to(id_getc, val, id);
|
||||
*var = val;
|
||||
return;
|
||||
}
|
||||
|
@ -2723,8 +2735,9 @@ set_stdin(val, id, var)
|
|||
}
|
||||
|
||||
static void
|
||||
set_outfile(val, var, orig, stdf)
|
||||
set_outfile(val, id, var, orig, stdf)
|
||||
VALUE val;
|
||||
ID id;
|
||||
VALUE *var;
|
||||
VALUE orig;
|
||||
FILE *stdf;
|
||||
|
@ -2739,6 +2752,7 @@ set_outfile(val, var, orig, stdf)
|
|||
rb_io_flush(*var);
|
||||
}
|
||||
if (TYPE(val) != T_FILE) {
|
||||
must_respond_to(id_write, val, id);
|
||||
*var = val;
|
||||
return;
|
||||
}
|
||||
|
@ -2769,7 +2783,7 @@ set_stdout(val, id, var)
|
|||
ID id;
|
||||
VALUE *var;
|
||||
{
|
||||
set_outfile(val, var, orig_stdout, stdout);
|
||||
set_outfile(val, id, var, orig_stdout, stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2778,7 +2792,7 @@ set_stderr(val, id, var)
|
|||
ID id;
|
||||
VALUE *var;
|
||||
{
|
||||
set_outfile(val, var, orig_stderr, stderr);
|
||||
set_outfile(val, id, var, orig_stderr, stderr);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -3928,6 +3942,8 @@ Init_IO()
|
|||
rb_eEOFError = rb_define_class("EOFError", rb_eIOError);
|
||||
|
||||
id_write = rb_intern("write");
|
||||
id_read = rb_intern("read");
|
||||
id_getc = rb_intern("getc");
|
||||
|
||||
rb_define_global_function("syscall", rb_f_syscall, -1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue