Skip to content

Conversation

@okuramasafumi
Copy link
Contributor

StringScanner.new('foo').named_captures

This commit fixes a crash in the case above.

@okuramasafumi
Copy link
Contributor Author

CI fails since a new test case for crash was added.

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a NULL check to the implementation.

The CI job failures show that installed strscan gem isn't used (Ruby's strscan is used)...

data.self = self;
data.captures = rb_hash_new();
onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
if (p->regex != Qnil) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (p->regex != Qnil) {
if (!RB_NIL_P(p->regex)) {

@okuramasafumi okuramasafumi force-pushed the fix-named_capture-crash branch from f32ab68 to 187aea6 Compare February 12, 2023 08:14
@okuramasafumi
Copy link
Contributor Author

@kou Thank you, I've fixed it.
https://github.com/ruby/strscan/blob/master/.github/workflows/ci.yml#L62
This line specifies Ruby version as 3.1, but should we add 3.2 to avoid CI failures?

@kou
Copy link
Member

kou commented Feb 12, 2023

Could you also add a NULL check to the implementation.

Oh, sorry. I wanted to say "Could you also add a NULL check to the JRuby implementation?"

https://github.com/ruby/strscan/blob/master/.github/workflows/ci.yml#L62
This line specifies Ruby version as 3.1, but should we add 3.2 to avoid CI failures?

It's better but it's not related to the CI failures.

```ruby
StringScanner.new('foo').named_captures
```

This commit fixes a crash in the case above.
@okuramasafumi okuramasafumi force-pushed the fix-named_capture-crash branch 2 times, most recently from 3f79064 to 8bc404c Compare February 13, 2023 05:32
@okuramasafumi
Copy link
Contributor Author

@kou OK, so I changed JRuby version as well and run-test to use locally installed version. I'm not sure if these fixes are ideal but CI now passes. Could you check it, thanks!

run-test.rb Outdated
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby

require "bundler/setup"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this, we always use local strscan not strscan gem.

https://github.com/ruby/strscan/actions/runs/4160453753/jobs/7197443977#step:11:5

Loaded strscan from /home/runner/work/strscan/strscan/lib/strscan.so
Gem from /home/runner/work/strscan/strscan

We should use strscan gem like https://github.com/ruby/strscan/actions/runs/4134931150/jobs/7146703286#step:11:5 :

Loaded strscan from /opt/hostedtoolcache/Ruby/3.1.3/x64/lib/ruby/gems/3.1.0/gems/strscan-3.0.7/lib/strscan.so
Gem from /opt/hostedtoolcache/Ruby/3.1.3/x64/lib/ruby/gems/3.1.0/gems/strscan-3.0.7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I reverted that change with force push.
Should I do something to make CI pass? I believe after releasing a new gem including this fix Ci will become green.
Or more general question, what should we do if a fix and a test are included in the same commit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I do something to make CI pass?

Can you take a look at why installed gem isn't used only with Ruby 3.2 and master?
Or could you create an issue for this?

It may be a RubyGems/Bundler bug in Ruby 3.2 and master...

I believe after releasing a new gem including this fix Ci will become green.

It's not the intention for the test. The test should use "not-released" gem to prevent releasing a buggy gem.

Or more general question, what should we do if a fix and a test are included in the same commit?

If our CI jobs work as expected (installed gem is used), our test will be passed in the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so this might be an issue outside of strscan, now I understand.
I'll try to resolve it myself, and if it's too difficult I'll submit an issue.

@okuramasafumi okuramasafumi force-pushed the fix-named_capture-crash branch from 8bc404c to 36447b8 Compare February 13, 2023 08:59
@okuramasafumi
Copy link
Contributor Author

The output from gem install --verbose --backtrace pkg/*.gem.

3.0
https://github.com/ruby/strscan/actions/runs/4171325802/jobs/7221150111

["/opt/hostedtoolcache/Ruby/3.0.5/x64/bin/ruby", "-I", "/opt/hostedtoolcache/Ruby/3.0.5/x64/lib/ruby/site_ruby/3.0.0", "extconf.rb"]

3.1
https://github.com/ruby/strscan/actions/runs/4171325802/jobs/7221150216

["/opt/hostedtoolcache/Ruby/3.1.3/x64/bin/ruby", "-I", "/opt/hostedtoolcache/Ruby/3.1.3/x64/lib/ruby/site_ruby/3.1.0", "extconf.rb"]

3.2
https://github.com/ruby/strscan/actions/runs/4171325802/jobs/7221150323

["/opt/hostedtoolcache/Ruby/3.2.1/x64/bin/ruby", "-I", "/opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/3.2.0", "extconf.rb"]

It looks like 3.2 include path is different from 3.1 and 3.0 that are successful. This is might be related to this problem.

@tenderlove
Copy link
Member

What do we need to do to merge this? I ran in to the same bug. 😅

@kou
Copy link
Member

kou commented Mar 7, 2023

We need to debug a problem that Ruby 3.2 and Ruby master doesn't use gem install-ed strscan.
But we can work on the problem as a separated pull request and merge this as-is.

@hsbt
Copy link
Member

hsbt commented Mar 7, 2023

FYI: I fixed installation failure related C-ext default gems ruby/rubygems#6430.

I'm not sure this fix resolve issue of this PR.

@kou
Copy link
Member

kou commented Mar 7, 2023

Oh, thanks for the info.
Can we try the change in this repository?

@kou
Copy link
Member

kou commented Mar 10, 2023

I merge this for now.
We can work on the CI failures in a separated pull request.

@eregon
Copy link
Member

eregon commented Feb 12, 2025

I merge this for now. We can work on the CI failures in a separated pull request.

How was this fixed? I don't see any change in https://github.com/ruby/strscan/commits/master/.github/workflows
Maybe simply by updating to newer CRuby versions which have that RubyGems fix in?

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.

5 participants