Skip to content

Commit 1271492

Browse files
committed
Fixed cannot use _cgo2 (variable of type unsafe.Pointer) as *unsafe.Pointer value in argument to _Cfunc_rb_data_typed_object_make
1 parent eb1f1b1 commit 1271492

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
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
@@ -46,6 +46,8 @@ def cast_to_cgo
4646
when :ref_array
4747
return "toCArray[*#{ruby_c_type_to_go_type(type)}, *#{cast_to_cgo_type(type)}](#{go_name})"
4848
when :sref
49+
return go_name if type == "void" && length == 2
50+
4951
return "(#{"*" * length}#{cast_to_cgo_type(type)})(unsafe.Pointer(#{go_name}))"
5052
end
5153

_tools/ruby_h_to_go/lib/ruby_h_to_go/generator_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def cast_to_cgo_type(typename)
113113
def ruby_pointer_c_type_to_go_type(typename, pos:, pointer:, pointer_length:)
114114
case pointer
115115
when :sref
116+
return "*unsafe.Pointer" if typename == "void" && pointer_length == 2
117+
116118
go_type_name = ruby_c_type_to_go_type(typename, pos:, pointer: nil)
117119
return "#{"*" * pointer_length}#{go_type_name}"
118120
when :str_array

_tools/ruby_h_to_go/spec/ruby_h_to_go/function_definition_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,41 @@
434434

435435
it { should eq go_content }
436436
end
437+
438+
context "rb_data_typed_object_make" do
439+
let(:definition) do
440+
RubyHeaderParser::FunctionDefinition.new(
441+
name: "rb_data_typed_object_make",
442+
definition: "rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)",
443+
typeref: typedef(type: "VALUE"),
444+
args: [
445+
argument(type: "VALUE", name: "klass"),
446+
argument(type: "rb_data_type_t", name: "type", pointer: :ref),
447+
argument(type: "void", name: "datap", pointer: :sref, length: 2),
448+
argument(type: "size_t", name: "size"),
449+
],
450+
)
451+
end
452+
453+
let(:go_content) do
454+
<<~GO
455+
// RbDataTypedObjectMake calls `rb_data_typed_object_make` in C
456+
//
457+
// Original definition is following
458+
//
459+
// rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)
460+
func RbDataTypedObjectMake(klass VALUE, r *RbDataTypeT, datap *unsafe.Pointer, size SizeT) VALUE {
461+
var cR C.rb_data_type_t
462+
ret := VALUE(C.rb_data_typed_object_make(C.VALUE(klass), &cR, datap, C.size_t(size)))
463+
*r = RbDataTypeT(cR)
464+
return ret
465+
}
466+
467+
GO
468+
end
469+
470+
it { should eq go_content }
471+
end
437472
end
438473

439474
describe "#go_function_name" do

ruby/function_generated.go

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

0 commit comments

Comments
 (0)