diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2021-01-10 08:29:53 +0900 |
---|---|---|
committer | Kenta Murata <mrkn@mrkn.jp> | 2021-01-10 08:35:43 +0900 |
commit | 72d504c1fde34894d797ac7fb881609d81711e06 (patch) | |
tree | c749b8114b5a1f78cfbeaf001dc1c91d447463c6 | |
parent | 590dc06e3840cc7b00d80ccaac9fbf42573428f8 (diff) |
[ruby/bigdecimal] Use smallest local variable scope in GetVpValueWithPrec
https://github.com/ruby/bigdecimal/commit/44f26b9aa0
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 20 |
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; } |