From 5847fadf7b173479fca0521b2301e6ff89cbd09a Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 2 Dec 2004 15:17:35 +0000 Subject: [PATCH] * io.c (rb_file_initialize): [ruby-dev:25032] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ eval.c | 2 +- io.c | 4 +--- lib/ostruct.rb | 29 +++++++++++++++++++++++------ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8859ab50e..227ca7fad9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Dec 3 00:11:48 2004 Yukihiro Matsumoto + + * io.c (rb_file_initialize): [ruby-dev:25032] + Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada * eval.c (rb_protect): prevent continuations created inside from being @@ -10,6 +14,11 @@ Thu Dec 2 10:45:02 2004 Shugo Maeda * test/readline/test_readline.rb: fix for NetBSD. +Thu Dec 2 09:57:24 2004 Yukihiro Matsumoto + + * lib/ostruct.rb (OpenStruct::Marshaler): OpenStruct can be + marshaled again. [ruby-core:03862] + Thu Dec 2 09:30:58 2004 Nobuyoshi Nakada * eval.c (thread_mark): mark thread group. [ruby-dev:25020] diff --git a/eval.c b/eval.c index 260d8fd422..5c702b2fff 100644 --- a/eval.c +++ b/eval.c @@ -2477,7 +2477,7 @@ call_trace_func(event, node, self, id, klass) srcfile, INT2FIX(ruby_sourceline), id?ID2SYM(id):Qnil, - self?rb_f_binding(self):Qnil, + self ? rb_f_binding(self) : Qnil, klass?klass:Qnil), Qundef, 0); } diff --git a/io.c b/io.c index eae5f9ddee..6a5af2576c 100644 --- a/io.c +++ b/io.c @@ -4094,9 +4094,7 @@ rb_file_initialize(argc, argv, io) VALUE io; { if (RFILE(io)->fptr) { - rb_io_close_m(io); - free(RFILE(io)->fptr); - RFILE(io)->fptr = 0; + rb_raise(rb_eRuntimeError, "reinitializing File"); } if (0 < argc && argc < 3) { VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int"); diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 4d9bb33606..7f4668283b 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -47,10 +47,8 @@ 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 + new_ostruct_member(k) end end end @@ -61,6 +59,27 @@ class OpenStruct @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) + unless self.respond_to?(name) + self.instance_eval %{ + extend OpenStruct::Marshaler + def #{name}; @table[:#{name}]; end + def #{name}=(x); @table[:#{name}] = x; end + } + end + end + def method_missing(mid, *args) # :nodoc: mname = mid.id2name len = args.length @@ -72,10 +91,8 @@ 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