* eval.c (proc_invoke): copy arguments to frame.argv.

[ruby-core:03861]

* object.c (convert_type): use rb_respond_to() again.
  [ruby-dev:25021]

* eval.c (rb_respond_to): funcall respond_to? if it's redefined.
  [ruby-dev:25021]

* io.c (rb_file_initialize): [ruby-dev:25032]

* lib/ostruct.rb (OpenStruct::Marshaler): OpenStruct can be
  marshaled again.  [ruby-core:03862]

* io.c (rb_io_ctl): [ruby-dev:25019]

* io.c (io_fread): need not to null terminate.  [ruby-dev:24998]

* io.c (read_all): remove unnecessary rb_str_resize().
  [ruby-dev:24996]

* io.c (io_read): ditto.

* io.c (rb_io_sysread): use temporary lock.  [ruby-dev:24992]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-12-03 09:30:33 +00:00
parent 744ec6294c
commit 379e85a5f5
5 changed files with 107 additions and 16 deletions

View file

@ -1,7 +1,20 @@
Fri Dec 3 13:45:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): copy arguments to frame.argv.
[ruby-core:03861]
Fri Dec 3 12:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Dec 3 12:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* st.h: fix prototypes. * st.h: fix prototypes.
Fri Dec 3 00:21:05 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (convert_type): use rb_respond_to() again.
[ruby-dev:25021]
* eval.c (rb_respond_to): funcall respond_to? if it's redefined.
[ruby-dev:25021]
Fri Dec 3 01:55:24 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Fri Dec 3 01:55:24 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: widget configuration by TkWindow#method_missing * ext/tk/lib/tk.rb: widget configuration by TkWindow#method_missing
@ -20,6 +33,10 @@ Fri Dec 3 01:55:24 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-jp/widget: ditto. * ext/tk/sample/demos-jp/widget: ditto.
Fri Dec 3 00:11:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_file_initialize): [ruby-dev:25032]
Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_protect): prevent continuations created inside from being * eval.c (rb_protect): prevent continuations created inside from being
@ -28,12 +45,26 @@ Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_callcc, rb_cont_call): prohibit calling from different * eval.c (rb_callcc, rb_cont_call): prohibit calling from different
signal contexts. [ruby-dev:25022] signal contexts. [ruby-dev:25022]
Thu Dec 2 09:57:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/ostruct.rb (OpenStruct::Marshaler): OpenStruct can be
marshaled again. [ruby-core:03862]
Thu Dec 2 09:30:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Dec 2 09:30:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (thread_mark): mark thread group. [ruby-dev:25020] * eval.c (thread_mark): mark thread group. [ruby-dev:25020]
* eval.c (thgroup_add): check whether the argument is really a Thread. * eval.c (thgroup_add): check whether the argument is really a Thread.
Thu Dec 2 07:57:16 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_ctl): [ruby-dev:25019]
Wed Dec 1 02:21:02 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (sighandler): call handler immediately only for default
handlers. [ruby-dev:25003]
Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_fread): need not to null terminate. [ruby-dev:24998] * io.c (io_fread): need not to null terminate. [ruby-dev:24998]
@ -45,11 +76,31 @@ Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_read): ditto. * io.c (io_read): ditto.
Tue Nov 30 16:18:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_fread): need not to null terminate. [ruby-dev:24998]
* io.c (read_all): remove unnecessary rb_str_resize().
[ruby-dev:24996]
* io.c (io_read): ditto.
Tue Nov 30 00:49:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992]
Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_write): insufficiently filled string * ext/stringio/stringio.c (strio_write): insufficiently filled string
being extended when overwriting. [ruby-core:03836] being extended when overwriting. [ruby-core:03836]
Mon Nov 29 15:59:05 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/ostruct.rb (OpenStruct::method_missing): check method
duplication for -d.
* lib/ostruct.rb (OpenStruct::initialize): ditto.
Mon Nov 29 15:22:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Nov 29 15:22:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/io/nonblock/test_flush.rb: abandon tests when io/nonblock is * test/io/nonblock/test_flush.rb: abandon tests when io/nonblock is

21
eval.c
View file

@ -312,7 +312,7 @@ rb_clear_cache_by_class(klass)
static ID init, eqq, each, aref, aset, match, missing; static ID init, eqq, each, aref, aset, match, missing;
static ID added, singleton_added; static ID added, singleton_added;
static ID __id__, __send__; static ID __id__, __send__, respond_to;
void void
rb_add_method(klass, mid, node, noex) rb_add_method(klass, mid, node, noex)
@ -3943,17 +3943,25 @@ module_setup(module, n)
return result; return result;
} }
static NODE *basic_respond_to = 0;
int int
rb_respond_to(obj, id) rb_respond_to(obj, id)
VALUE obj; VALUE obj;
ID id; ID id;
{ {
if (rb_method_boundp(CLASS_OF(obj), id, 0)) { VALUE klass = CLASS_OF(obj);
if (rb_method_node(klass, respond_to) == basic_respond_to &&
rb_method_boundp(klass, id, 0)) {
return Qtrue; return Qtrue;
} }
else{
return rb_funcall(obj, respond_to, 1, ID2SYM(id));
}
return Qfalse; return Qfalse;
} }
/* /*
* call-seq: * call-seq:
* obj.respond_to?(symbol, include_private=false) => true or false * obj.respond_to?(symbol, include_private=false) => true or false
@ -7581,7 +7589,10 @@ Init_eval()
rb_define_global_function("loop", rb_f_loop, 0); rb_define_global_function("loop", rb_f_loop, 0);
rb_define_method(rb_mKernel, "respond_to?", rb_obj_respond_to, -1); rb_define_method(rb_mKernel, "respond_to?", rb_obj_respond_to, -1);
respond_to = rb_intern("respond_to?");
basic_respond_to = rb_method_node(rb_cObject, respond_to);
rb_global_variable((VALUE*)&basic_respond_to);
rb_define_global_function("raise", rb_f_raise, -1); rb_define_global_function("raise", rb_f_raise, -1);
rb_define_global_function("fail", rb_f_raise, -1); rb_define_global_function("fail", rb_f_raise, -1);
@ -8152,6 +8163,10 @@ proc_invoke(proc, args, self, klass)
_block = *data; _block = *data;
if (self != Qundef) _block.frame.self = self; if (self != Qundef) _block.frame.self = self;
if (klass) _block.frame.last_class = klass; if (klass) _block.frame.last_class = klass;
_block.frame.argc = RARRAY(args)->len;
_block.frame.argv = ALLOCA_N(VALUE, RARRAY(args)->len);
MEMCPY(_block.frame.argv, RARRAY(args)->ptr, VALUE, RARRAY(args)->len);
_block.frame.flags = FRAME_ALLOCA;
ruby_block = &_block; ruby_block = &_block;
PUSH_ITER(ITER_CUR); PUSH_ITER(ITER_CUR);

14
io.c
View file

@ -2177,13 +2177,19 @@ rb_io_sysread(argc, argv, io)
if (READ_DATA_BUFFERED(fptr->f)) { if (READ_DATA_BUFFERED(fptr->f)) {
rb_raise(rb_eIOError, "sysread for buffered IO"); rb_raise(rb_eIOError, "sysread for buffered IO");
} }
rb_str_locktmp(str);
n = fileno(fptr->f); n = fileno(fptr->f);
rb_thread_wait_fd(fileno(fptr->f)); rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
if (RSTRING(str)->len != ilen) {
rb_raise(rb_eRuntimeError, "buffer string modified");
}
TRAP_BEG; TRAP_BEG;
n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len); n = read(fileno(fptr->f), RSTRING(str)->ptr, ilen);
TRAP_END; TRAP_END;
rb_str_unlocktmp(str);
if (n == -1) { if (n == -1) {
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
} }
@ -3867,9 +3873,7 @@ rb_file_initialize(argc, argv, io)
VALUE io; VALUE io;
{ {
if (RFILE(io)->fptr) { if (RFILE(io)->fptr) {
rb_io_close_m(io); rb_raise(rb_eRuntimeError, "reinitializing File");
free(RFILE(io)->fptr);
RFILE(io)->fptr = 0;
} }
if (0 < argc && argc < 3) { if (0 < argc && argc < 3) {
VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int"); VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
@ -4477,7 +4481,6 @@ rb_io_ctl(io, req, arg, io_p)
int retval; int retval;
rb_secure(2); rb_secure(2);
GetOpenFile(io, fptr);
if (NIL_P(arg) || arg == Qfalse) { if (NIL_P(arg) || arg == Qfalse) {
narg = 0; narg = 0;
@ -4518,6 +4521,7 @@ rb_io_ctl(io, req, arg, io_p)
narg = (long)RSTRING(arg)->ptr; narg = (long)RSTRING(arg)->ptr;
} }
} }
GetOpenFile(io, fptr);
retval = io_cntl(fileno(fptr->f), cmd, narg, io_p); retval = io_cntl(fileno(fptr->f), cmd, narg, io_p);
if (retval < 0) rb_sys_fail(fptr->path); if (retval < 0) rb_sys_fail(fptr->path);
if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[len] != 17) { if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[len] != 17) {

View file

@ -48,15 +48,36 @@ class OpenStruct
if hash if hash
for k,v in hash for k,v in hash
@table[k.to_sym] = v @table[k.to_sym] = v
new_ostruct_member(k)
end end
end end
end end
# Duplicate an OpenStruct object members.
def initialize_copy(orig)
super
@table = @table.dup
end
module Marshaler
def marshal_dump
table = @table
OpenStruct.new.instance_eval{@table=table; self}
end
def marshal_load(x)
@table = x.instance_variable_get("@table")
@table.each_key{|key| new_ostruct_member(key)}
end
end
def new_ostruct_member(name) def new_ostruct_member(name)
self.instance_eval %{ unless self.respond_to?(name)
def #{name}; @table[:#{name}]; end self.instance_eval %{
def #{name}=(x); @table[:#{name}] = x; end extend OpenStruct::Marshaler
} def #{name}; @table[:#{name}]; end
def #{name}=(x); @table[:#{name}] = x; end
}
end
end end
def method_missing(mid, *args) # :nodoc: def method_missing(mid, *args) # :nodoc:

View file

@ -2036,9 +2036,10 @@ convert_type(val, tname, method, raise)
const char *tname, *method; const char *tname, *method;
int raise; int raise;
{ {
VALUE result = rb_funcall_rescue(val, rb_intern(method), 0); ID m;
if (result == Qundef) { m = rb_intern(method);
if (!rb_respond_to(val, m)) {
if (raise) { if (raise) {
rb_raise(rb_eTypeError, "cannot convert %s into %s", rb_raise(rb_eTypeError, "cannot convert %s into %s",
NIL_P(val) ? "nil" : NIL_P(val) ? "nil" :
@ -2048,11 +2049,10 @@ convert_type(val, tname, method, raise)
tname); tname);
} }
else { else {
ruby_errinfo = Qnil;
return Qnil; return Qnil;
} }
} }
return result; return rb_funcall(val, m, 0);
} }
VALUE VALUE