From c0acb3ce179ff038ee24f608a3615069645a7799 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 29 Nov 2004 15:58:18 +0000 Subject: [PATCH] * io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992] * lib/ostruct.rb (OpenStruct::method_missing): check method duplication for -d. * lib/ostruct.rb (OpenStruct::initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ io.c | 8 +++++++- lib/ostruct.rb | 14 ++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 71b96d81e7..1aeb4d1691 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Nov 30 00:49:08 2004 Yukihiro Matsumoto + + * io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992] + Tue Nov 30 00:12:57 2004 Kazuo Saito * regparse.c: now handles many alternatives (over 500000) @@ -8,6 +12,13 @@ Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_write): insufficiently filled string being extended when overwriting. [ruby-core:03836] +Mon Nov 29 15:59:05 2004 Yukihiro Matsumoto + + * 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 * test/io/nonblock/test_flush.rb: abandon tests when io/nonblock is diff --git a/io.c b/io.c index b9b2c78f3c..6fdd9e9466 100644 --- a/io.c +++ b/io.c @@ -2321,13 +2321,19 @@ rb_io_sysread(argc, argv, io) if (READ_DATA_BUFFERED(fptr->f)) { rb_raise(rb_eIOError, "sysread for buffered IO"); } + rb_str_locktmp(str); + n = fileno(fptr->f); rb_thread_wait_fd(fileno(fptr->f)); rb_io_check_closed(fptr); + if (RSTRING(str)->len != ilen) { + rb_raise(rb_eRuntimeError, "buffer string modified"); + } TRAP_BEG; - n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len); + n = read(fileno(fptr->f), RSTRING(str)->ptr, ilen); TRAP_END; + rb_str_unlocktmp(str); if (n == -1) { rb_str_resize(str, 0); rb_sys_fail(fptr->path); diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 8d8484caf5..4d9bb33606 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -47,6 +47,9 @@ class OpenStruct @table = {} if hash for k,v in hash + if $DEBUG and self.respond_to?(k, true) + raise NameError, "already existing member #{k}", caller(2) + end @table[k.to_sym] = v end end @@ -58,13 +61,6 @@ class OpenStruct @table = @table.dup end - def new_ostruct_member(name) - self.instance_eval %{ - def #{name}; @table[:#{name}]; end - def #{name}=(x); @table[:#{name}] = x; end - } - end - def method_missing(mid, *args) # :nodoc: mname = mid.id2name len = args.length @@ -76,8 +72,10 @@ class OpenStruct raise TypeError, "can't modify frozen #{self.class}", caller(1) end mname.chop! + if $DEBUG and self.respond_to?(mname, true) + raise NameError, "already existing member #{mname}", caller(1) + end @table[mname.intern] = args[0] - self.new_ostruct_member(mname) elsif len == 0 @table[mid] else