fix Bitmap's object to string conversion

Calling #to_s might not return a string (it should though).
This commit is contained in:
cremno 2014-08-31 09:31:18 +02:00
parent d8bb6aa2fc
commit b8fc8cf9b6
1 changed files with 9 additions and 12 deletions

View File

@ -29,6 +29,12 @@
DEF_TYPE(Bitmap); DEF_TYPE(Bitmap);
static const char *objAsStringPtr(VALUE obj)
{
VALUE str = rb_obj_as_string(obj);
return RSTRING_PTR(str);
}
void bitmapInitProps(Bitmap *b, VALUE self) void bitmapInitProps(Bitmap *b, VALUE self)
{ {
/* Wrap properties */ /* Wrap properties */
@ -258,10 +264,7 @@ RB_METHOD(bitmapDrawText)
VALUE strObj; VALUE strObj;
rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END); rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END);
if (!RB_TYPE_P(strObj, RUBY_T_STRING)) str = objAsStringPtr(strObj);
strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0);
str = RSTRING_PTR(strObj);
} }
else else
{ {
@ -281,10 +284,7 @@ RB_METHOD(bitmapDrawText)
VALUE strObj; VALUE strObj;
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END); rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END);
if (!RB_TYPE_P(strObj, RUBY_T_STRING)) str = objAsStringPtr(strObj);
strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0);
str = RSTRING_PTR(strObj);
} }
else else
{ {
@ -308,10 +308,7 @@ RB_METHOD(bitmapTextSize)
VALUE strObj; VALUE strObj;
rb_get_args(argc, argv, "o", &strObj RB_ARG_END); rb_get_args(argc, argv, "o", &strObj RB_ARG_END);
if (!RB_TYPE_P(strObj, RUBY_T_STRING)) str = objAsStringPtr(strObj);
strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0);
str = RSTRING_PTR(strObj);
} }
else else
{ {