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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block_given? issue when called via C in Nokogiri #2675

Closed
chrisseaton opened this issue Jun 6, 2022 · 3 comments
Closed

block_given? issue when called via C in Nokogiri #2675

chrisseaton opened this issue Jun 6, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@chrisseaton
Copy link
Collaborator

Error:
Nokogiri::HTML4::DocumentFragment::parse options::HTML4::DocumentFragment.parse#test_0003_takes a config block:
NoMethodError: undefined method `strict?' for nil:NilClass
    /__w/nokogiri/nokogiri/test/html4/test_document_fragment.rb:376:in `test_0003_takes a config block'

This seems to be caused by a block_given? failing due to a method being very distant from where it's logically passed the block due C code in between.

BlockGivenNode here seems to be getting the frame of /Users/chrisseaton/Documents/nokogiri/lib/nokogiri/html4/document_fragment.rb:27, which looks right, but indeed it doesn't have a block. How should rb_obj_call_init be passing it, and how should xml_document_fragment.c#new be passing it?

/Users/chrisseaton/Documents/nokogiri/lib/nokogiri/html4/document_fragment.rb:27:in `initialize'
/Users/chrisseaton/Documents/graalvm/graal/sdk/mxbuild/darwin-aarch64/GRAALVM_B4632A0AE8_JAVA11/graalvm-b4632a0ae8-java11-22.2.0-dev/Contents/Home/languages/ruby/lib/truffle/truffle/cext.rb:1221:in `rb_obj_call_init'
object.c:128:in `rb_obj_call_init'
/Users/chrisseaton/Documents/nokogiri/ext/nokogiri/xml_document_fragment.c:29:in `new'
/Users/chrisseaton/Documents/graalvm/graal/sdk/mxbuild/darwin-aarch64/GRAALVM_B4632A0AE8_JAVA11/graalvm-b4632a0ae8-java11-22.2.0-dev/Contents/Home/languages/ruby/lib/truffle/truffle/cext_ruby.rb:41:in `new'
/Users/chrisseaton/Documents/nokogiri/lib/nokogiri/html4/document_fragment.rb:24:in `parse'
test.rb:7:in `<main>'

Reproduce with

require "nokogiri"

input = "<div>foo</div"

GC.start # then break on BlockGivenNode

Nokogiri::HTML4::DocumentFragment.parse(input) do |config|
  puts 'here'
end

@flavorjones

@aardvark179 aardvark179 self-assigned this Jun 9, 2022
@aardvark179
Copy link
Contributor

CRuby has a macro PASS_PASSED_BLOCK_HANDLER() which it uses explicitly in a couple of places to pass the block. I'll add a spec and refactor our code to do the same sort of thing.

@aardvark179 aardvark179 added this to the 22.2.0 milestone Jun 10, 2022
@aardvark179
Copy link
Contributor

A fix for this has now been pushed to master.

@chrisseaton
Copy link
Collaborator Author

a4e867a

@eregon eregon added the cexts label Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants