summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 460456d953..189b983870 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -205,10 +205,7 @@ static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise
static Real*
GetVpValueWithPrec(VALUE v, long prec, int must)
{
- ENTER(1);
Real *pv;
- VALUE bg;
- char szD[128];
switch(TYPE(v)) {
case T_FLOAT: {
@@ -233,9 +230,11 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
}
break;
- case T_FIXNUM:
+ case T_FIXNUM: {
+ char szD[128];
sprintf(szD, "%ld", FIX2LONG(v));
return VpCreateRbObject(VpBaseFig() * 2 + 1, szD, true);
+ }
#ifdef ENABLE_NUMERIC_STRING
case T_STRING:
@@ -244,11 +243,14 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
RSTRING_PTR(v), true);
#endif /* ENABLE_NUMERIC_STRING */
- case T_BIGNUM:
- bg = rb_big2str(v, 10);
- PUSH(bg);
- return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
- RSTRING_PTR(bg), true);
+ case T_BIGNUM: {
+ VALUE bg = rb_big2str(v, 10);
+ pv = VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
+ RSTRING_PTR(bg), true);
+ RB_GC_GUARD(bg);
+ return pv;
+ }
+
default:
goto SomeOneMayDoIt;
}