Skip to content

Commit

Permalink
rb_gc_register_address() must be called after the variable was assign…
Browse files Browse the repository at this point in the history
…ed (#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: oracle/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
  • Loading branch information
eregon authored Sep 7, 2022
1 parent 6607e64 commit 23721a7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/sqlite3/aggregator.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
void
rb_sqlite3_aggregator_init(void)
{
rb_gc_register_address(&cAggregatorWrapper);
rb_gc_register_address(&cAggregatorInstance);
/* rb_class_new generatos class with undefined allocator in ruby 1.9 */
cAggregatorWrapper = rb_funcall(rb_cClass, rb_intern("new"), 0);
rb_gc_register_mark_object(cAggregatorWrapper);

cAggregatorInstance = rb_funcall(rb_cClass, rb_intern("new"), 0);
rb_gc_register_mark_object(cAggregatorInstance);
}

0 comments on commit 23721a7

Please sign in to comment.