Register C global variables to Ruby GC to avoid problems with GC.compact #1115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since Ruby 2.7, C global variables holding references to Ruby objects must be declared to the GC even if they are also held from the Ruby side, otherwise a call to GC.compact might move them to another location.
For instance here's an exception we've seen caused by this:
In this instance
Mysql2::Errorwas moved to another location, andcMysql2Errorwas now pointing to an instance of"2".We had a similar issue in Shopify/liquid-c#55, however here I tried to reproduce it in the test suite by repeatedly calling
GC.compact, but without any success. Maybe the mysql2 test suite is not producing enough GC objects to demonstrate the bug.cc @csfrancis @XrXr @rafaelfranca