From 6645b928266cf7f8139f58b6b260e82f291d8446 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 7 Mar 2005 02:05:08 +0000 Subject: [PATCH] * object.c (inspect_obj): unintended space removal. [ruby-dev:25810] * eval.c (rb_exec_recursive): should not use NODE in disclosed context. [ruby-dev:25812] * io.c (rb_f_open): need not to check if to_open value is a T_FILE. [ruby-dev:25812] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .cvsignore | 1 + ChangeLog | 11 +++++ eval.c | 86 ++++++++++++++++++++++++++----------- io.c | 3 -- lib/cgi/session.rb | 4 +- lib/pp.rb | 24 ++++++++--- object.c | 2 +- test/soap/header/server.cgi | 8 ++-- 8 files changed, 96 insertions(+), 43 deletions(-) diff --git a/.cvsignore b/.cvsignore index 0c885edbf7..62afb836b0 100644 --- a/.cvsignore +++ b/.cvsignore @@ -10,6 +10,7 @@ COPYING.LIB ChangeLog.pre-alpha ChangeLog.pre1_1 +ChangeLog-1.8.0 Makefile README.fat-patch README.v6 diff --git a/ChangeLog b/ChangeLog index d913ebee30..e05857c154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Mar 7 10:28:00 2005 Yukihiro Matsumoto + + * object.c (inspect_obj): unintended space removal. + [ruby-dev:25810] + + * eval.c (rb_exec_recursive): should not use NODE in disclosed + context. [ruby-dev:25812] + + * io.c (rb_f_open): need not to check if to_open value is a + T_FILE. [ruby-dev:25812] + Mon Mar 7 01:21:01 2005 Hidetoshi NAGAI * ext/tk/tkutil/tkutil.c: follow the change of st.c (committed diff --git a/eval.c b/eval.c index df2487febb..92925b1dd5 100644 --- a/eval.c +++ b/eval.c @@ -12991,49 +12991,83 @@ rb_throw(tag, val) rb_f_throw(2, argv); } +static VALUE +recursive_check(obj) + VALUE obj; +{ + VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key); + + if (NIL_P(hash) || TYPE(hash) != T_HASH) { + return Qfalse; + } + else { + VALUE list = rb_hash_aref(hash, ID2SYM(ruby_frame->this_func)); + + if (NIL_P(list)) return Qfalse; + return rb_ary_includes(list, rb_obj_id(obj)); + } +} + +static void +recursive_push(obj) + VALUE obj; +{ + VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key); + VALUE list, sym; + + sym = ID2SYM(ruby_frame->this_func); + if (NIL_P(hash) || TYPE(hash) != T_HASH) { + hash = rb_hash_new(); + rb_thread_local_aset(rb_thread_current(), recursive_key, hash); + list = Qnil; + } + else { + list = rb_hash_aref(hash, sym); + } + if (NIL_P(list)) { + list = rb_ary_new(); + rb_hash_aset(hash, sym, list); + } + rb_ary_push(list, rb_obj_id(obj)); +} + +static void +recursive_pop() +{ + VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key); + VALUE list, sym; + + sym = ID2SYM(ruby_frame->this_func); + if (NIL_P(hash) || TYPE(hash) != T_HASH) { + rb_bug("invalid inspect_tbl hash"); + } + list = rb_hash_aref(hash, sym); + if (NIL_P(list) || TYPE(list) != T_ARRAY) { + rb_bug("invalid inspect_tbl list"); + } + rb_ary_pop(list); +} + VALUE rb_exec_recursive(func, obj, arg) VALUE (*func)(ANYARGS); /* VALUE obj, VALUE arg, int flag */ VALUE obj, arg; { - VALUE list = rb_thread_local_aref(rb_thread_current(), recursive_key); - int found = Qfalse; - - if (NIL_P(list) || TYPE(list) != T_NODE) { - list = Qnil; - } - else { - NODE *tmp = (NODE*)list; - - while (!NIL_P(tmp)) { - if (tmp->nd_cfnc == func && tmp->nd_tval == obj) { - found = Qtrue; - break; - } - tmp = tmp->nd_next; - } - } - if (found) { + if (recursive_check(obj)) { return (*func)(obj, arg, Qtrue); } else { - NODE *node = rb_node_newnode(NODE_MEMO, (VALUE)func, obj, list); + recursive_push(obj); VALUE result; int state; - rb_thread_local_aset(rb_thread_current(), recursive_key, (VALUE)node); PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = (*func)(obj, arg, Qfalse); } POP_TAG(); + recursive_pop(); if (state) JUMP_TAG(state); - - /* remove pushed tag */ - list = rb_thread_local_aref(rb_thread_current(), recursive_key); - node = (NODE*)list; - - rb_thread_local_aset(rb_thread_current(), recursive_key, (VALUE)node->nd_next); return result; } } diff --git a/io.c b/io.c index c8de07f1e2..0b137ff795 100644 --- a/io.c +++ b/io.c @@ -3277,9 +3277,6 @@ rb_f_open(argc, argv) if (rb_respond_to(argv[0], to_open)) { VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1); - if (TYPE(io) != T_FILE) { - rb_raise(rb_eTypeError, "to_open should return IO value"); - } if (rb_block_given_p()) { return rb_ensure(rb_yield, io, io_close, io); } diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb index 8741799390..2bb6571bf6 100644 --- a/lib/cgi/session.rb +++ b/lib/cgi/session.rb @@ -155,8 +155,8 @@ class CGI # class Session - #:nodoc: - class NoSession < RuntimeError; end + class NoSession < RuntimeError #:nodoc: + end # The id of this session. attr_reader :session_id, :new_session diff --git a/lib/pp.rb b/lib/pp.rb index 3fd3aeab3a..3826a12f79 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -95,19 +95,29 @@ class PP < PrettyPrint def guard_inspect_key if Thread.current[InspectKey] == nil - Thread.current[InspectKey] = [] + Thread.current[InspectKey] = {inspect: []} end - save = Thread.current[InspectKey] + save = Thread.current[InspectKey][:inspect] begin - Thread.current[InspectKey] = [] + Thread.current[InspectKey][:inspect] = [] yield ensure - Thread.current[InspectKey] = save + Thread.current[InspectKey][:inspect] = save end end + def check_inspect_key(id) + Thread.current[InspectKey][:inspect].include?(id) + end + def push_inspect_key(id) + Thread.current[InspectKey][:inspect] << id + end + def pop_inspect_key + Thread.current[InspectKey][:inspect].pop + end + # Adds +obj+ to the pretty printing buffer # using Object#pretty_print or Object#pretty_print_cycle. # @@ -116,16 +126,16 @@ class PP < PrettyPrint def pp(obj) id = obj.__id__ - if Thread.current[InspectKey].include? id + if check_inspect_key(id) group {obj.pretty_print_cycle self} return end begin - Thread.current[InspectKey] << id + push_inspect_key(id) group {obj.pretty_print self} ensure - Thread.current[InspectKey].pop unless PP.sharing_detection + pop_inspect_key unless PP.sharing_detection end end diff --git a/object.c b/object.c index 743de94242..b95b097b6a 100644 --- a/object.c +++ b/object.c @@ -350,7 +350,7 @@ inspect_obj(obj, str, recur) int recur; { if (recur) { - rb_str_cat2(str, "..."); + rb_str_cat2(str, " ..."); } else { st_foreach_safe(ROBJECT(obj)->iv_tbl, inspect_i, str); diff --git a/test/soap/header/server.cgi b/test/soap/header/server.cgi index f9739d0d15..a4326828cc 100644 --- a/test/soap/header/server.cgi +++ b/test/soap/header/server.cgi @@ -85,18 +85,18 @@ class AuthHeaderPortServer < SOAP::RPC::CGIStub end def on_simple_inbound(my_header, mu) - auth = false + auth_p = false userid = my_header["userid"] passwd = my_header["passwd"] if login(userid, passwd) - auth = true + auth_p = true elsif sessionid = my_header["sessionid"] if userid = auth(sessionid) destroy_session(sessionid) - auth = true + auth_p = true end end - raise RuntimeError.new("authentication failed") unless auth + raise RuntimeError.new("authentication failed") unless auth_p @userid = userid @sessionid = create_session(userid) end