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

Fix --ext=c generating buggy code #6269

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt
Expand Up @@ -2,8 +2,20 @@

VALUE rb_m<%= config[:constant_array].join %>;

VALUE rb_<%= config[:constant_array].join %>_hello(VALUE self, VALUE str);

void
Init_<%= config[:underscored_name] %>(void)
{
rb_m<%= config[:constant_array].join %> = rb_define_module(<%= config[:constant_name].inspect %>);
rb_define_singleton_method(rb_m<%= config[:constant_array].join %>, "hello", rb_<%= config[:constant_array].join %>_hello, 1);
}

VALUE
rb_<%= config[:constant_array].join %>_hello(VALUE self, VALUE str)
{
if (RB_TYPE_P(str, T_STRING) == 1) {
return rb_sprintf("Hello from C, %s!", StringValueCStr(str));
}
return Qnil;
}
2 changes: 1 addition & 1 deletion bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt
Expand Up @@ -2,7 +2,7 @@

require_relative "<%= File.basename(config[:namespaced_path]) %>/version"
<%- if config[:ext] -%>
require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
require "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
<%- end -%>

<%- config[:constant_array].each_with_index do |c, i| -%>
Expand Down
5 changes: 1 addition & 4 deletions bundler/lib/bundler/templates/newgem/newgem.gemspec.tt
Expand Up @@ -35,12 +35,9 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
<%- if config[:ext] == 'c' -%>
<%- if %w[c rust].include? config[:ext] -%>
spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
<%- end -%>
<%- if config[:ext] == 'rust' -%>
spec.extensions = ["ext/<%= config[:underscored_name] %>/Cargo.toml"]
<%- end -%>

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
Expand Down