Fix missing write barrier on Generator State#826
Merged
byroot merged 1 commit intoruby:masterfrom Jul 23, 2025
Merged
Conversation
Found by wbcheck
WBCHECK ERROR: Missed write barrier detected!
Parent object: 0x7b7b8487c450 (wb_protected: true)
rb_obj_info_dump: 0x00007b7b8487c450 JSON/Generator/State/JSON::Ext::Generator::State JSON/Generator/State
Reference counts - snapshot: 1, writebarrier: 0, current: 6, missed: 5
Missing reference to: 0x7b7b82f35a10
rb_obj_info_dump: 0x00007b7b82f35a10 T_STRING/String len: 1, capa: 15 "1"
Missing reference to: 0x7b7b82f35e90
rb_obj_info_dump: 0x00007b7b82f35e90 T_STRING/String len: 1, capa: 15 "2"
Missing reference to: 0x7b7b83629e50
rb_obj_info_dump: 0x00007b7b83629e50 T_STRING/String len: 1, capa: 15 "3"
Missing reference to: 0x7b7b83b62190
rb_obj_info_dump: 0x00007b7b83b62190 T_STRING/String len: 1, capa: 15 "4"
Missing reference to: 0x7b7b83629490
rb_obj_info_dump: 0x00007b7b83629490 T_STRING/String len: 1, capa: 15 "5"
Member
|
Good catch. I don't think this can realistically cause a bug, but I'm all for silencing what wbcheck finds. |
Member
Author
|
I agree it's unlikely in practice for the bug here to be hit, but I'm trying to convince both myself and others that nearly everything wbcheck finds is a "real" issue: require "json"
state1 = JSON.state.new
3.times { GC.start }
state1.merge(
indent: 1.to_s,
space: 2.to_s,
space_before: 3.to_s,
object_nl: 4.to_s,
array_nl: 5.to_s
)
GC.start(full_mark: false)
state1.generate({foo: 123}) |
Member
|
Yeah, when I say unlikely, is that the object wouldn't be old by that point (unless GC.stress etc). So defiitely real, but also definitely almost impossible to happen in real world code, hence likely why it was missed. This is more me stating that this doesn't warrant a bug fix release on its own. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Found by wbcheck. This should only be a problem when state is an object rather than stack allocated.