Skip to content

Commit 7b29579

Browse files
eregonmrkn
authored andcommitted
Avoid RB_GC_GUARD(a) = b in bigdecimal
* This is not supported on TruffleRuby, which requires the value to be set before RB_GC_GUARD() is called. * See oracle/truffleruby#2879
1 parent c8eb21c commit 7b29579

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,11 +4142,14 @@ BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
41424142
}
41434143
x = VpCheckGetValue(vx);
41444144

4145-
RB_GC_GUARD(one) = VpCheckGetValue(NewOneWrapLimited(1, 1));
4146-
RB_GC_GUARD(two) = VpCheckGetValue(VpCreateRbObject(1, "2", true));
4145+
one = VpCheckGetValue(NewOneWrapLimited(1, 1));
4146+
two = VpCheckGetValue(VpCreateRbObject(1, "2", true));
4147+
RB_GC_GUARD(one);
4148+
RB_GC_GUARD(two);
41474149

41484150
n = prec + BIGDECIMAL_DOUBLE_FIGURES;
4149-
RB_GC_GUARD(vn) = SSIZET2NUM(n);
4151+
vn = SSIZET2NUM(n);
4152+
RB_GC_GUARD(vn);
41504153
expo = VpExponent10(vx);
41514154
if (expo < 0 || expo >= 3) {
41524155
char buf[DECIMAL_SIZE_OF_BITS(SIZEOF_VALUE * CHAR_BIT) + 4];
@@ -4158,9 +4161,12 @@ BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
41584161
}
41594162
w = BigDecimal_sub(x, one);
41604163
x = BigDecimal_div2(w, BigDecimal_add(x, one), vn);
4161-
RB_GC_GUARD(x2) = BigDecimal_mult2(x, x, vn);
4162-
RB_GC_GUARD(y) = x;
4163-
RB_GC_GUARD(d) = y;
4164+
x2 = BigDecimal_mult2(x, x, vn);
4165+
y = x;
4166+
d = y;
4167+
RB_GC_GUARD(x2);
4168+
RB_GC_GUARD(y);
4169+
RB_GC_GUARD(d);
41644170
i = 1;
41654171
while (!VpIsZero((Real*)DATA_PTR(d))) {
41664172
SIGNED_VALUE const ey = VpExponent10(DATA_PTR(y));

0 commit comments

Comments
 (0)