diff --git a/ChangeLog b/ChangeLog index 6ad5ddfc21..b4ea439f4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,20 @@ Mon Nov 29 13:13:13 2004 NAKAMURA Usaku * win32/win32.c (CreateChild): push back the last space before next loop because CharNext() eats it. +Mon Nov 29 03:08:30 2004 Yukihiro Matsumoto + + * object.c (convert_type): [ruby-core:03845] + + * eval.c (rb_funcall_rescue): new function. + + * object.c (rb_Array): avoid using rb_respond_to(). + + * object.c (rb_Integer): ditto. + + * eval.c (get_backtrace): no conversion for nil. + + * parse.y (reduce_nodes): empty body should return nil. + Mon Nov 29 01:18:18 2004 Tanaka Akira * io.c (rb_io_check_writable): call io_seek regardless of @@ -52,6 +66,10 @@ Sun Nov 28 12:05:48 2004 Kazuo Saito * regcomp.c, regint.h: fixed PLATFORM_UNALIGNED_WORD_ACCESS problem ([ruby-dev:24802] and [ruby-core:3733]) +Sat Nov 27 23:43:39 2004 Yukihiro Matsumoto + + * io.c (rb_io_initialize): [ruby-dev:24972] + Sat Nov 27 21:43:39 2004 Tanaka Akira * io.c: avoid data lost with nonblocking fd and @@ -89,6 +107,10 @@ Sat Nov 27 17:21:30 2004 Kouhei Sutou * sample/rss/rss_recent.rb: ditto. +Sat Nov 27 14:44:15 2004 Kent Sibilev + + * lib/cgi/session.rb (CGI::Session::initialize): [ruby-core:03832] + Sat Nov 27 09:41:21 2004 Yukihiro Matsumoto * io.c (io_fread): old rb_io_fread with file closing checking. diff --git a/eval.c b/eval.c index a2e50cce51..bb4ffba4cf 100644 --- a/eval.c +++ b/eval.c @@ -1079,7 +1079,9 @@ get_backtrace(info) VALUE info; { if (NIL_P(info)) return Qnil; - return rb_check_array_type(rb_funcall(info, rb_intern("backtrace"), 0)); + info = rb_funcall(info, rb_intern("backtrace"), 0); + if (NIL_P(info)) return Qnil; + return rb_check_array_type(info); } static void @@ -5799,6 +5801,32 @@ rb_f_send(argc, argv, recv) return vid; } +static VALUE +vafuncall(recv, mid, n, ar) + VALUE recv; + ID mid; + int n; + va_list *ar; +{ + VALUE *argv; + + if (n > 0) { + long i; + + argv = ALLOCA_N(VALUE, n); + + for (i=0;i 0) { - long i; + return vafuncall(recv, mid, n, &ar); +} - argv = ALLOCA_N(VALUE, n); +VALUE +#ifdef HAVE_STDARG_PROTOTYPES +rb_funcall_rescue(VALUE recv, ID mid, int n, ...) +#else +rb_funcall_rescue(recv, mid, n, va_alist) + VALUE recv; + ID mid; + int n; + va_dcl +#endif +{ + VALUE result = Qnil; /* OK */ + int status; + va_list ar; - va_init_list(ar, n); - for (i=0;ipath); + rb_io_check_closed(fptr); } fptr->mode &= ~FMODE_WBUF; } @@ -1027,6 +1028,7 @@ rb_io_fread(ptr, len, f) of.f = f; of.f2 = NULL; + of.mode = FMODE_READABLE; return io_fread(ptr, len, &of); } @@ -4030,6 +4032,9 @@ rb_io_initialize(argc, argv, io) fp->mode = rb_io_modenum_flags(flags); fp->f = rb_fdopen(fd, rb_io_modenum_mode(flags)); } + else if (RFILE(io)->fptr) { + rb_raise(rb_eRuntimeError, "reinitializing IO"); + } else { GetOpenFile(orig, ofp); if (ofp->refcnt == LONG_MAX) { @@ -4047,11 +4052,6 @@ rb_io_initialize(argc, argv, io) } } } - if (RFILE(io)->fptr) { - rb_io_close(io); - free(RFILE(io)->fptr); - RFILE(io)->fptr = 0; - } ofp->refcnt++; RFILE(io)->fptr = ofp; } diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb index 5d9e767356..1bddaf3260 100644 --- a/lib/cgi/session.rb +++ b/lib/cgi/session.rb @@ -246,7 +246,7 @@ class CGI id = option['session_id'] unless id if option['new_session'] - id = Session::create_new_id + id = create_new_id end end unless id @@ -261,7 +261,7 @@ class CGI if option.key?('new_session') and not option['new_session'] raise ArgumentError, "session_key `%s' should be supplied"%session_key end - id = Session::create_new_id + id = create_new_id end end @session_id = id diff --git a/object.c b/object.c index ab3edb69c7..a196e3bf82 100644 --- a/object.c +++ b/object.c @@ -2056,10 +2056,9 @@ convert_type(val, tname, method, raise) const char *tname, *method; int raise; { - ID m; + VALUE result = rb_funcall_rescue(val, rb_intern(method), 0); - m = rb_intern(method); - if (!rb_respond_to(val, m)) { + if (result == Qundef) { if (raise) { rb_raise(rb_eTypeError, "cannot convert %s into %s", NIL_P(val) ? "nil" : @@ -2069,10 +2068,11 @@ convert_type(val, tname, method, raise) tname); } else { + ruby_errinfo = Qnil; return Qnil; } } - return rb_funcall(val, m, 0); + return result; } VALUE @@ -2139,6 +2139,8 @@ VALUE rb_Integer(val) VALUE val; { + VALUE tmp; + switch (TYPE(val)) { case T_FLOAT: if (RFLOAT(val)->value <= (double)FIXNUM_MAX @@ -2157,10 +2159,11 @@ rb_Integer(val) default: break; } - if (rb_respond_to(val, rb_intern("to_int"))) { - return rb_to_integer(val, "to_int"); + tmp = convert_type(val, "Integer", "to_int", Qfalse); + if (NIL_P(tmp)) { + return rb_to_integer(val, "to_i"); } - return rb_to_integer(val, "to_i"); + return tmp; } /* @@ -2401,18 +2404,10 @@ rb_Array(val) VALUE val; { VALUE tmp = rb_check_array_type(val); - ID to_a; if (NIL_P(tmp)) { - to_a = rb_intern("to_a"); - if (rb_respond_to(val, to_a)) { - val = rb_funcall(val, to_a, 0); - if (TYPE(val) != T_ARRAY) { - rb_raise(rb_eTypeError, "`to_a' did not return Array"); - } - return val; - } - else { + tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a"); + if (NIL_P(tmp)) { return rb_ary_new3(1, val); } } diff --git a/parse.y b/parse.y index 00a458f946..5bc3476014 100644 --- a/parse.y +++ b/parse.y @@ -7178,6 +7178,10 @@ reduce_nodes(body) { NODE *node = *body; + if (!node) { + *body = NEW_NIL(); + return; + } #define subnodes(n1, n2) \ ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \ (!node->n2) ? (body = &node->n1, 1) : \ diff --git a/string.c b/string.c index c33cf55eb9..7f7778d905 100644 --- a/string.c +++ b/string.c @@ -1389,7 +1389,7 @@ rb_str_succ(orig) int c = -1; long n = 0; - str = rb_str_new5(orig,RSTRING(orig)->ptr, RSTRING(orig)->len); + str = rb_str_new5(orig, RSTRING(orig)->ptr, RSTRING(orig)->len); OBJ_INFECT(str, orig); if (RSTRING(str)->len == 0) return str; diff --git a/test/ruby/beginmainend.rb b/test/ruby/beginmainend.rb index f096b96fbc..646140dd22 100644 --- a/test/ruby/beginmainend.rb +++ b/test/ruby/beginmainend.rb @@ -28,11 +28,6 @@ END { puts local_for_end2 # e2 } -END { - raise - puts "should not be dumped" -} - eval <