Skip to content

Commit 4cfaa86

Browse files
committed
Fix rb_define_variable
1 parent dc2fe1e commit 4cfaa86

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/argument_definition.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def cast_to_cgo
4949
return go_name if type == "void" && length == 2
5050

5151
return "(#{"*" * length}#{cast_to_cgo_type(type)})(unsafe.Pointer(#{go_name}))"
52+
when :in_ref
53+
return "(*#{cast_to_cgo_type(type)})(#{go_name})"
5254
end
5355

5456
"#{cast_to_cgo_type(type)}(#{go_name})"

_tools/ruby_h_to_go/spec/ruby_h_to_go/function_definition_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,39 @@
469469

470470
it { should eq go_content }
471471
end
472+
473+
context "rb_define_variable" do
474+
let(:definition) do
475+
RubyHeaderParser::FunctionDefinition.new(
476+
name: "rb_define_variable",
477+
definition: "void rb_define_variable(const char *name, VALUE *var)",
478+
typeref: typedef(type: "void"),
479+
args: [
480+
argument(type: "char", name: "name", pointer: :ref),
481+
argument(type: "VALUE", name: "var", pointer: :in_ref),
482+
],
483+
)
484+
end
485+
486+
let(:go_content) do
487+
<<~GO
488+
// RbDefineVariable calls `rb_define_variable` in C
489+
//
490+
// Original definition is following
491+
//
492+
// void rb_define_variable(const char *name, VALUE *var)
493+
func RbDefineVariable(name string, v *VALUE) {
494+
char, clean := string2Char(name)
495+
defer clean()
496+
497+
C.rb_define_variable(char, (*C.VALUE)(v))
498+
}
499+
500+
GO
501+
end
502+
503+
it { should eq go_content }
504+
end
472505
end
473506

474507
describe "#go_function_name" do

ruby/function_generated.go

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)