Use recommended way to name/load c extension#4
Merged
ko1 merged 1 commit intoruby:masterfrom May 10, 2021
Merged
Conversation
This commit follows rubygems' official guideline on c extension to load the debug extension. Link: https://guides.rubygems.org/gems-with-extensions Summary of the commit: 1. Use `require` instead of `require_relative` to load the extension file. 2. Use the recommended way to name the extension in `extconf.rb`. According to Rubygems' guideline, we should use `"debug/debug"` when calling `create_makefile`. Then we can use `require "debug/debug" to require the extension. https://guides.rubygems.org/gems-with-extensions/#extension-naming Currently, `create_makefile "debug"` means that the require path would be `require "debug"`, which confuses Ruby. As a result it'd always load `debug.rb` instead of the compiled extension. **Test Command** ``` $ gem build debug.gemspec; gem install --local *.gem; rdbg ext/debug/extconf.rb ``` **Before This Commit** ``` gem build debug.gemspec; gem install --local *.gem; rdbg ext/debug/extconf.rb Successfully built RubyGem Name: debug Version: 1.0.0.beta1 File: debug-1.0.0.beta1.gem Building native extensions. This could take a while... Successfully installed debug-1.0.0.beta1 Done installing documentation for debug after 0 seconds 1 gem installed /Users/st0012/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/debug-1.0.0.beta1/lib/debug/session.rb:7:in `require_relative': cannot load such file -- /Users/st0012/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/debug-1.0.0.beta1/lib/debug/debug.so (LoadError) ``` **After This Commit** ``` gem build debug.gemspec; gem install --local *.gem; rdbg ext/debug/extconf.rb Successfully built RubyGem Name: debug Version: 1.0.0.beta1 File: debug-1.0.0.beta1.gem Building native extensions. This could take a while... Successfully installed debug-1.0.0.beta1 Done installing documentation for debug after 0 seconds 1 gem installed [1, 2] in ext/debug/extconf.rb => 1| require 'mkmf' 2| create_makefile 'debug/debug' --> #0 ext/debug/extconf.rb:1:in `<main>' (rdbg) ```
Collaborator
Could you explain about it more? |
Collaborator
|
Ah, |
Collaborator
|
Thank you!! |
Member
Author
|
@ko1 thanks for merging and releasing it so quickly. I can confirm that the beta2 version installs and runs correctly on my machine 🙂 |
ko1
added a commit
that referenced
this pull request
May 10, 2021
Show more pretty backtrace like:
```
(rdbg) bt
=>#0 block{|i=0, j=nil|} (3 levels) in foo at ~/src/rb/target.rb:12
#1 [C] Integer#times at ~/src/rb/target.rb:11
#2 rescue in rescue in block (2 levels) in foo at ~/src/rb/target.rb:11
#3 rescue in block (2 levels) in foo at ~/src/rb/target.rb:8
#4 block (2 levels) in foo at ~/src/rb/target.rb:5
#5 [C] Integer#times at ~/src/rb/target.rb:4
#6 block{|e=2|} in foo at ~/src/rb/target.rb:4
#7 [C] Range#each at ~/src/rb/target.rb:3
#8 [C] Enumerable#map at ~/src/rb/target.rb:3
#9 Object#foo(a=3) at ~/src/rb/target.rb:3
#10 <main> at ~/src/rb/target.rb:20
```
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.
This is to solve #3 by using Rubygems' recommended approach to name/load this gem's c extension.
Summary of the commit:
requireinstead ofrequire_relativeto load the extension file.extconf.rb.According to Rubygems' guideline, we should use
"debug/debug"when callingcreate_makefile. Then we can userequire "debug/debug"to require the extension.https://guides.rubygems.org/gems-with-extensions/#extension-naming
Currently,
create_makefile "debug"means that the require path would berequire "debug", which confuses Ruby. As a result it'd always loaddebug.rbinstead of the compiled extension.Test Command
Before This Commit
After This Commit