ruby-changes:64812
From: Kenta <ko1@a...>
Date: Sun, 10 Jan 2021 08:45:42 +0900 (JST)
Subject: [ruby-changes:64812] 72d504c1fd (master): [ruby/bigdecimal] Use smallest local variable scope in GetVpValueWithPrec
https://git.ruby-lang.org/ruby.git/commit/?id=72d504c1fd From 72d504c1fde34894d797ac7fb881609d81711e06 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> Date: Sun, 10 Jan 2021 08:29:53 +0900 Subject: [ruby/bigdecimal] Use smallest local variable scope in GetVpValueWithPrec https://github.com/ruby/bigdecimal/commit/44f26b9aa0 diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 460456d..189b983 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 https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L205 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) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L230 } 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) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L243 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; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/