Skip to content

Commit a25f7df

Browse files
committed
[GR-44350] Define RB_GC_GUARD in a way it cannot be an assignment LHS
PullRequest: truffleruby/3660
2 parents a448f7e + fe0ba46 commit a25f7df

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ Bug fixes:
242242
* Fix `rb_id2name` to ensure the native string will have the same lifetime as the id (#2630, @aardvark179).
243243
* Fix `Integer#fdiv` and `Rational#to_f` for large `Integer` values (#2631, @bjfish).
244244
* Remove the `RB_NEWOBJ/NEWOBJ` and `OBJSETUP` macros since we cannot support them in TruffleRuby and native extensions may use `#ifdef` to detect features (#2869, @nirvdrum).
245+
* Fix memory leak in `--native` mode for native extension handles and native pointers (@eregon).
245246

246247
Compatibility:
247248

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2
1+
3

lib/cext/include/ruby/internal/memory.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,10 @@ typedef uint128_t DSIZE_T;
158158
* @post `v` is still alive.
159159
*/
160160
#ifdef TRUFFLERUBY
161-
#define RB_GC_GUARD(v) \
162-
(*__extension__ ({ \
163-
polyglot_invoke(RUBY_CEXT, "rb_tr_gc_guard", v); \
164-
volatile VALUE *rb_gc_guarded_ptr = &v; \
165-
rb_gc_guarded_ptr; \
166-
}))
161+
RBIMPL_SYMBOL_EXPORT_BEGIN()
162+
VALUE rb_tr_gc_guard(VALUE value);
163+
RBIMPL_SYMBOL_EXPORT_END()
164+
#define RB_GC_GUARD(v) rb_tr_gc_guard(v)
167165
#else
168166
#ifdef __GNUC__
169167
#define RB_GC_GUARD(v) \

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));

src/main/c/cext/gc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
// GC, rb_gc_*
1414

15+
VALUE rb_tr_gc_guard(VALUE value) {
16+
polyglot_invoke(RUBY_CEXT, "rb_tr_gc_guard", value);
17+
return value;
18+
}
19+
1520
void rb_global_variable(VALUE *address) {
1621
rb_gc_register_address(address);
1722
}

test/mri/tests/lib/core_assertions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def message msg = nil, ending = nil, &default
3131
end
3232

3333
module CoreAssertions
34-
ALLOW_SUBPROCESSES = true # !defined?(::TruffleRuby)
34+
ALLOW_SUBPROCESSES = ENV['MRI_TEST_SUBPROCESSES'] != 'false' # !defined?(::TruffleRuby)
3535

3636
require_relative 'envutil'
3737
require 'pp'

tool/jt.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ def help
823823
jt test mri test/mri/tests/test_find.rb [-- <MRI runner options>]
824824
run tests in given file, -n option of the runner can be used to further
825825
limit executed test methods
826+
MRI_TEST_SUBPROCESSES=false skip MRI tests using subprocesses
826827
jt retag FILE Remove MRI excludes and re-add as necessary for MRI tests
827828
---
828829
jt test basictest run MRI's basictest suite

0 commit comments

Comments
 (0)