From 9ce253a2cfc26cc7a0d2cfeeaf15d6216d522077 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 24 Apr 1998 09:33:30 +0000 Subject: gtk/nested local variables git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 41acb4d021..bdf1373c4f 100644 --- a/object.c +++ b/object.c @@ -793,11 +793,33 @@ num2dbl(val) return RFLOAT(v)->value; } +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; } -- cgit v1.2.3