Skip to content

Commit 23721a7

Browse files
authored
rb_gc_register_address() must be called after the variable was assigned (#345)
rb_gc_register_address() must be called after the variable was assigned. Otherwise the GC might read the variable when it is not pointing to a Ruby object yet. TruffleRuby also assumes it can read the pointer when rb_gc_register_address() is called: truffleruby/truffleruby#2720 * Prefer rb_gc_register_mark_object() since the variable is never reassigned * Mark immediately after assigning the variable to prevent the VALUE to move by GC compaction on CRuby
1 parent 6607e64 commit 23721a7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/sqlite3/aggregator.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
265265
void
266266
rb_sqlite3_aggregator_init(void)
267267
{
268-
rb_gc_register_address(&cAggregatorWrapper);
269-
rb_gc_register_address(&cAggregatorInstance);
270268
/* rb_class_new generatos class with undefined allocator in ruby 1.9 */
271269
cAggregatorWrapper = rb_funcall(rb_cClass, rb_intern("new"), 0);
270+
rb_gc_register_mark_object(cAggregatorWrapper);
271+
272272
cAggregatorInstance = rb_funcall(rb_cClass, rb_intern("new"), 0);
273+
rb_gc_register_mark_object(cAggregatorInstance);
273274
}

0 commit comments

Comments
 (0)