Skip to content

Commit 35f9d3c

Browse files
committed
Avoid RB_GC_GUARD(a) = b in bigdecimal extension
* This is not supported on TruffleRuby, which requires the value to be set before RB_GC_GUARD() is called.
1 parent f1971ab commit 35f9d3c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/c/bigdecimal/bigdecimal.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,11 +3953,14 @@ BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
39533953
}
39543954
x = VpCheckGetValue(vx);
39553955

3956-
RB_GC_GUARD(one) = VpCheckGetValue(VpCreateRbObject(1, "1", true));
3957-
RB_GC_GUARD(two) = VpCheckGetValue(VpCreateRbObject(1, "2", true));
3956+
one = VpCheckGetValue(VpCreateRbObject(1, "1", true));
3957+
two = VpCheckGetValue(VpCreateRbObject(1, "2", true));
3958+
RB_GC_GUARD(one);
3959+
RB_GC_GUARD(two);
39583960

39593961
n = prec + BIGDECIMAL_DOUBLE_FIGURES;
3960-
RB_GC_GUARD(vn) = SSIZET2NUM(n);
3962+
vn = SSIZET2NUM(n);
3963+
RB_GC_GUARD(vn);
39613964
expo = VpExponent10(vx);
39623965
if (expo < 0 || expo >= 3) {
39633966
char buf[DECIMAL_SIZE_OF_BITS(SIZEOF_VALUE * CHAR_BIT) + 4];
@@ -3969,9 +3972,12 @@ BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
39693972
}
39703973
w = BigDecimal_sub(x, one);
39713974
x = BigDecimal_div2(w, BigDecimal_add(x, one), vn);
3972-
RB_GC_GUARD(x2) = BigDecimal_mult2(x, x, vn);
3973-
RB_GC_GUARD(y) = x;
3974-
RB_GC_GUARD(d) = y;
3975+
x2 = BigDecimal_mult2(x, x, vn);
3976+
y = x;
3977+
d = y;
3978+
RB_GC_GUARD(x2);
3979+
RB_GC_GUARD(y);
3980+
RB_GC_GUARD(d);
39753981
i = 1;
39763982
while (!VpIsZero((Real*)DATA_PTR(d))) {
39773983
SIGNED_VALUE const ey = VpExponent10(DATA_PTR(y));

0 commit comments

Comments
 (0)