summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 06:09:40 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 06:09:40 +0000
commit83cb605d69f20be5fe842a913e51d017f61cdc44 (patch)
treeb227250a931f8465854064c4860265d76a1974c9
parent6e221605373ff89fd52d08d5df86cfb0bd805de7 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog22
-rw-r--r--eval.c69
-rw-r--r--intern.h1
-rw-r--r--io.c10
-rw-r--r--lib/cgi/session.rb4
-rw-r--r--object.c29
-rw-r--r--parse.y4
-rw-r--r--string.c2
-rw-r--r--test/ruby/beginmainend.rb5
9 files changed, 104 insertions, 42 deletions
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 <usa@ruby-lang.org>
* 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 <matz@ruby-lang.org>
+
+ * 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 <akr@m17n.org>
* io.c (rb_io_check_writable): call io_seek regardless of
@@ -52,6 +66,10 @@ Sun Nov 28 12:05:48 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
* 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 <matz@ruby-lang.org>
+
+ * io.c (rb_io_initialize): [ruby-dev:24972]
+
Sat Nov 27 21:43:39 2004 Tanaka Akira <akr@m17n.org>
* io.c: avoid data lost with nonblocking fd and
@@ -89,6 +107,10 @@ Sat Nov 27 17:21:30 2004 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/rss_recent.rb: ditto.
+Sat Nov 27 14:44:15 2004 Kent Sibilev <ksibilev@bellsouth.net>
+
+ * lib/cgi/session.rb (CGI::Session::initialize): [ruby-core:03832]
+
Sat Nov 27 09:41:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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,18 +5801,13 @@ rb_f_send(argc, argv, recv)
return vid;
}
-VALUE
-#ifdef HAVE_STDARG_PROTOTYPES
-rb_funcall(VALUE recv, ID mid, int n, ...)
-#else
-rb_funcall(recv, mid, n, va_alist)
+static VALUE
+vafuncall(recv, mid, n, ar)
VALUE recv;
ID mid;
int n;
- va_dcl
-#endif
+ va_list *ar;
{
- va_list ar;
VALUE *argv;
if (n > 0) {
@@ -5818,11 +5815,10 @@ rb_funcall(recv, mid, n, va_alist)
argv = ALLOCA_N(VALUE, n);
- va_init_list(ar, n);
for (i=0;i<n;i++) {
- argv[i] = va_arg(ar, VALUE);
+ argv[i] = va_arg(*ar, VALUE);
}
- va_end(ar);
+ va_end(*ar);
}
else {
argv = 0;
@@ -5832,6 +5828,55 @@ rb_funcall(recv, mid, n, va_alist)
}
VALUE
+#ifdef HAVE_STDARG_PROTOTYPES
+rb_funcall(VALUE recv, ID mid, int n, ...)
+#else
+rb_funcall(recv, mid, n, va_alist)
+ VALUE recv;
+ ID mid;
+ int n;
+ va_dcl
+#endif
+{
+ va_list ar;
+ va_init_list(ar, n);
+
+ return vafuncall(recv, mid, n, &ar);
+}
+
+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);
+
+ PUSH_TAG(PROT_NONE);
+ if ((status = EXEC_TAG()) == 0) {
+ result = vafuncall(recv, mid, n, &ar);
+ }
+ POP_TAG();
+ switch (status) {
+ case 0:
+ return result;
+ case TAG_RAISE:
+ return Qundef;
+ default:
+ JUMP_TAG(status);
+ }
+}
+
+VALUE
rb_funcall2(recv, mid, argc, argv)
VALUE recv;
ID mid;
diff --git a/intern.h b/intern.h
index b7340cf83a..74df097ab5 100644
--- a/intern.h
+++ b/intern.h
@@ -224,6 +224,7 @@ VALUE rb_thread_main _((void));
VALUE rb_thread_local_aref _((VALUE, ID));
VALUE rb_thread_local_aset _((VALUE, ID, VALUE));
void rb_thread_atfork _((void));
+VALUE rb_funcall_rescue __((VALUE, ID, int, ...));
/* file.c */
int eaccess _((const char*, int));
VALUE rb_file_s_expand_path _((int, VALUE *));
diff --git a/io.c b/io.c
index 0cd715798c..b9b2c78f3c 100644
--- a/io.c
+++ b/io.c
@@ -334,6 +334,7 @@ io_fflush(f, fptr)
if (n != EOF) break;
if (!rb_io_wait_writable(fileno(f)))
rb_sys_fail(fptr->path);
+ 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 <<EOE
BEGIN {
puts "b3"