1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2005-03-07 02:05:08 +00:00
parent 57b3ed4cda
commit 6645b92826
8 changed files with 96 additions and 43 deletions

View file

@ -10,6 +10,7 @@
COPYING.LIB COPYING.LIB
ChangeLog.pre-alpha ChangeLog.pre-alpha
ChangeLog.pre1_1 ChangeLog.pre1_1
ChangeLog-1.8.0
Makefile Makefile
README.fat-patch README.fat-patch
README.v6 README.v6

View file

@ -1,3 +1,14 @@
Mon Mar 7 10:28:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nagai@ai.kyutech.ac.jp> Mon Mar 7 01:21:01 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tkutil/tkutil.c: follow the change of st.c (committed * ext/tk/tkutil/tkutil.c: follow the change of st.c (committed

86
eval.c
View file

@ -12991,49 +12991,83 @@ rb_throw(tag, val)
rb_f_throw(2, argv); 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 VALUE
rb_exec_recursive(func, obj, arg) rb_exec_recursive(func, obj, arg)
VALUE (*func)(ANYARGS); /* VALUE obj, VALUE arg, int flag */ VALUE (*func)(ANYARGS); /* VALUE obj, VALUE arg, int flag */
VALUE obj, arg; VALUE obj, arg;
{ {
VALUE list = rb_thread_local_aref(rb_thread_current(), recursive_key); if (recursive_check(obj)) {
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) {
return (*func)(obj, arg, Qtrue); return (*func)(obj, arg, Qtrue);
} }
else { else {
NODE *node = rb_node_newnode(NODE_MEMO, (VALUE)func, obj, list); recursive_push(obj);
VALUE result; VALUE result;
int state; int state;
rb_thread_local_aset(rb_thread_current(), recursive_key, (VALUE)node);
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
result = (*func)(obj, arg, Qfalse); result = (*func)(obj, arg, Qfalse);
} }
POP_TAG(); POP_TAG();
recursive_pop();
if (state) JUMP_TAG(state); 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; return result;
} }
} }

3
io.c
View file

@ -3277,9 +3277,6 @@ rb_f_open(argc, argv)
if (rb_respond_to(argv[0], to_open)) { if (rb_respond_to(argv[0], to_open)) {
VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1); 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()) { if (rb_block_given_p()) {
return rb_ensure(rb_yield, io, io_close, io); return rb_ensure(rb_yield, io, io_close, io);
} }

View file

@ -155,8 +155,8 @@ class CGI
# #
class Session class Session
#:nodoc: class NoSession < RuntimeError #:nodoc:
class NoSession < RuntimeError; end end
# The id of this session. # The id of this session.
attr_reader :session_id, :new_session attr_reader :session_id, :new_session

View file

@ -95,19 +95,29 @@ class PP < PrettyPrint
def guard_inspect_key def guard_inspect_key
if Thread.current[InspectKey] == nil if Thread.current[InspectKey] == nil
Thread.current[InspectKey] = [] Thread.current[InspectKey] = {inspect: []}
end end
save = Thread.current[InspectKey] save = Thread.current[InspectKey][:inspect]
begin begin
Thread.current[InspectKey] = [] Thread.current[InspectKey][:inspect] = []
yield yield
ensure ensure
Thread.current[InspectKey] = save Thread.current[InspectKey][:inspect] = save
end end
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 # Adds +obj+ to the pretty printing buffer
# using Object#pretty_print or Object#pretty_print_cycle. # using Object#pretty_print or Object#pretty_print_cycle.
# #
@ -116,16 +126,16 @@ class PP < PrettyPrint
def pp(obj) def pp(obj)
id = obj.__id__ id = obj.__id__
if Thread.current[InspectKey].include? id if check_inspect_key(id)
group {obj.pretty_print_cycle self} group {obj.pretty_print_cycle self}
return return
end end
begin begin
Thread.current[InspectKey] << id push_inspect_key(id)
group {obj.pretty_print self} group {obj.pretty_print self}
ensure ensure
Thread.current[InspectKey].pop unless PP.sharing_detection pop_inspect_key unless PP.sharing_detection
end end
end end

View file

@ -350,7 +350,7 @@ inspect_obj(obj, str, recur)
int recur; int recur;
{ {
if (recur) { if (recur) {
rb_str_cat2(str, "..."); rb_str_cat2(str, " ...");
} }
else { else {
st_foreach_safe(ROBJECT(obj)->iv_tbl, inspect_i, str); st_foreach_safe(ROBJECT(obj)->iv_tbl, inspect_i, str);

View file

@ -85,18 +85,18 @@ class AuthHeaderPortServer < SOAP::RPC::CGIStub
end end
def on_simple_inbound(my_header, mu) def on_simple_inbound(my_header, mu)
auth = false auth_p = false
userid = my_header["userid"] userid = my_header["userid"]
passwd = my_header["passwd"] passwd = my_header["passwd"]
if login(userid, passwd) if login(userid, passwd)
auth = true auth_p = true
elsif sessionid = my_header["sessionid"] elsif sessionid = my_header["sessionid"]
if userid = auth(sessionid) if userid = auth(sessionid)
destroy_session(sessionid) destroy_session(sessionid)
auth = true auth_p = true
end end
end end
raise RuntimeError.new("authentication failed") unless auth raise RuntimeError.new("authentication failed") unless auth_p
@userid = userid @userid = userid
@sessionid = create_session(userid) @sessionid = create_session(userid)
end end