summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 06:13:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 06:13:52 +0000
commitf6348ca0eac1eb3fd89f1bce233204b096de3e98 (patch)
treecb8bf5f5497b32eea8882dc159a4b8b41a85ecea /object.c
parentc56fa330b24863f5e946caf7846a1a8b44674e48 (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. * lib/cgi/session.rb (CGI::Session::initialize): [ruby-core:03832] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/object.c b/object.c
index 5fd722b338..1a54739d05 100644
--- a/object.c
+++ b/object.c
@@ -2036,10 +2036,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" :
@@ -2049,10 +2048,11 @@ convert_type(val, tname, method, raise)
tname);
}
else {
+ ruby_errinfo = Qnil;
return Qnil;
}
}
- return rb_funcall(val, m, 0);
+ return result;
}
VALUE
@@ -2116,6 +2116,8 @@ VALUE
rb_Integer(val)
VALUE val;
{
+ VALUE tmp;
+
switch (TYPE(val)) {
case T_FLOAT:
if (RFLOAT(val)->value <= (double)FIXNUM_MAX
@@ -2134,10 +2136,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;
}
/*
@@ -2379,18 +2382,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);
}
}