Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopefully fix Ruby's GC marking stack objects after return #2291

Closed
wants to merge 1 commit into from
Closed

Hopefully fix Ruby's GC marking stack objects after return #2291

wants to merge 1 commit into from

Conversation

stevecheckoway
Copy link
Contributor

rb_ensure() was being used to handle the situation that an exception
was raised during the construction of the tree. For some reason, Ruby's
GC was keeping a reference to the ParseArgs even after rb_ensure()
returned. This was causing parse_args_mark() to be called.

This changes this situation by

  • Replacing the stack-allocated object with a heap-allocated object;
  • Moving the deallocation code into the wrapped object's free
    function; and
  • Changing from the deprecated Data_Wrap_Struct to
    TypedData_Wrap_Struct.

This change simplifies the control flow since the parse() and
fragment() functions are no longer split into three pieces.

It's likely that the runtime cost of an extra heap allocation is offset
by not needing rb_ensure(), but I didn't bother measuring this because
one additional allocation is trivial since there's at least one
allocation per DOM node anyway.

Fixes #2276

What problem is this PR intended to solve?

#2276

Have you included adequate test coverage?

I'm unsure how to test this. Hopefully the valgrind CI jobs will let us know if I succeeded. 馃槥

Does this change affect the behavior of either the C or the Java implementations?

This is only relevant the C implementation of HTML5.

`rb_ensure()` was being used to handle the situation that an exception
was raised during the construction of the tree. For some reason, Ruby's
GC was keeping a reference to the `ParseArgs` even after `rb_ensure()`
returned. This was causing `parse_args_mark()` to be called.

This changes this situation by
- Replacing the stack-allocated object with a heap-allocated object;
- Moving the deallocation code into the wrapped object's `free`
  function; and
- Changing from the deprecated `Data_Wrap_Struct` to
  `TypedData_Wrap_Struct`.

This change simplifies the control flow since the `parse()` and
`fragment()` functions are no longer split into three pieces.

It's likely that the runtime cost of an extra heap allocation is offset
by not needing `rb_ensure()`, but I didn't bother measuring this because
one additional allocation is trivial since there's at least one
allocation per DOM node anyway.

Fixes #2276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] valgrind errors spotted in gumbo parser
1 participant