Skip to content

Commit cf2b728

Browse files
committed
Use TypeHelper#cast_to_cgo_type instead of GoUtil.cast_to_cgo_type
1 parent 3725ff0 commit cf2b728

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/argument_definition.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ def go_function_arg
4242
def cast_to_cgo
4343
case pointer
4444
when :array
45-
return "toCArray[#{ruby_c_type_to_go_type}, #{GoUtil.cast_to_cgo_type(type)}](#{go_name})"
45+
return "toCArray[#{ruby_c_type_to_go_type}, #{cast_to_cgo_type}](#{go_name})"
4646
when :ref_array
47-
return "toCArray[*#{ruby_c_type_to_go_type}, *#{GoUtil.cast_to_cgo_type(type)}](#{go_name})"
47+
return "toCArray[*#{ruby_c_type_to_go_type}, *#{cast_to_cgo_type}](#{go_name})"
4848
when :sref
4949
return go_name if type == "void" && length == 2
5050

51-
return "(#{"*" * length}#{GoUtil.cast_to_cgo_type(type)})(unsafe.Pointer(#{go_name}))"
51+
return "(#{"*" * length}#{cast_to_cgo_type})(unsafe.Pointer(#{go_name}))"
5252
when :in_ref
53-
return "(*#{GoUtil.cast_to_cgo_type(type)})(#{go_name})"
53+
return "(*#{cast_to_cgo_type})(#{go_name})"
5454
end
5555

56-
"#{GoUtil.cast_to_cgo_type(type)}(#{go_name})"
56+
"#{cast_to_cgo_type}(#{go_name})"
5757
end
5858

5959
# @param char_var_count [Integer]
@@ -77,7 +77,7 @@ def generate_go_arguments(char_var_count:, chars_var_count:)
7777
else
7878
c_var_name = "c#{GoUtil.snake_to_camel(go_name)}"
7979

80-
before_call_function_line = "var #{c_var_name} #{GoUtil.cast_to_cgo_type(type)}"
80+
before_call_function_line = "var #{c_var_name} #{cast_to_cgo_type}"
8181
after_call_function_line = "*#{go_name} = #{ruby_c_type_to_go_type(pos: :arg)}(#{c_var_name})"
8282

8383
["&#{c_var_name}", [before_call_function_line], [after_call_function_line]]

_tools/ruby_h_to_go/lib/ruby_h_to_go/type_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ module TypeHelper
1010
def ruby_c_type_to_go_type(pos: nil, pointer: nil, pointer_length: 0)
1111
GoUtil.ruby_c_type_to_go_type(type, pos:, pointer:, pointer_length:)
1212
end
13+
14+
# Cast C type to cgo type. (Used in wrapper function)
15+
# @return [String]
16+
def cast_to_cgo_type
17+
GoUtil.cast_to_cgo_type(type)
18+
end
1319
end
1420
end

0 commit comments

Comments
 (0)