summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--io.c8
-rw-r--r--lib/ostruct.rb14
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 <matz@ruby-lang.org>
+
+ * io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992]
+
Tue Nov 30 00:12:57 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
* regparse.c: now handles many alternatives (over 500000)
@@ -8,6 +12,13 @@ Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <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>
* 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