Skip to content

Commit 46135da

Browse files
committed
Define RB_GC_GUARD in a way it cannot be an assignment LHS
* Because the form `RB_GC_GUARD(a) = b` is not supported on TruffleRuby, as we need the value to be set before RB_GC_GUARD() is called.
1 parent 35f9d3c commit 46135da

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

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/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
}

0 commit comments

Comments
 (0)