summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-24 09:33:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-24 09:33:30 +0000
commit9ce253a2cfc26cc7a0d2cfeeaf15d6216d522077 (patch)
tree6f6334590a5705de7f7288d3eb8e572bfe75453f /object.c
parent8581fa1549787fc64e0d8a198838fe47104726c1 (diff)
gtk/nested local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/object.c b/object.c
index 41acb4d021..bdf1373c4f 100644
--- a/object.c
+++ b/object.c
@@ -794,10 +794,32 @@ num2dbl(val)
}
static VALUE
+to_s(obj)
+ VALUE obj;
+{
+ return rb_funcall(obj, rb_intern("to_s"), 0);
+}
+
+static VALUE
+fail_to_str(val)
+ VALUE val;
+{
+ TypeError("failed to convert %s into Sting",
+ rb_class2name(CLASS_OF(val)));
+}
+
+static VALUE
f_string(obj, arg)
VALUE obj, arg;
{
- return rb_funcall(arg, rb_intern("to_s"), 0);
+ return rb_rescue(to_s, arg, fail_to_str, arg);
+}
+
+static VALUE
+to_str(obj)
+ VALUE obj;
+{
+ return rb_funcall(obj, rb_intern("to_str"), 0);
}
char*
@@ -805,7 +827,10 @@ str2cstr(str)
VALUE str;
{
if (NIL_P(str)) return NULL;
- Check_Type(str, T_STRING);
+ if (TYPE(str) != T_STRING) {
+ str = rb_rescue(to_str, str, fail_to_str, str);
+ Check_Type(str, T_STRING);
+ }
return RSTRING(str)->ptr;
}