Skip to content

Commit 6059b16

Browse files
committed
nits: Extract to C_TYPE_TO_GO_TYPE
1 parent f77e90c commit 6059b16

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/generator_helper.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ def generate_initial_go_file(go_file_path)
3636
GO
3737
end
3838

39+
C_TYPE_TO_GO_TYPE = {
40+
"RUBY_DATA_FUNC" => "unsafe.Pointer",
41+
"long long" => "Longlong",
42+
"rb_alloc_func_t" => "unsafe.Pointer",
43+
"unsigned char" => "Uchar",
44+
"unsigned int" => "uint",
45+
"unsigned long" => "uint",
46+
"unsigned long long" => "Ulonglong",
47+
"unsigned short" => "Ushort",
48+
}.freeze
49+
3950
# Convert C type to Go type. (used in wrapper function args and return type etc)
4051
# @param typename [String]
4152
# @param pos [Symbol,nil] :arg, :typeref, :return
@@ -45,19 +56,9 @@ def generate_initial_go_file(go_file_path)
4556
def ruby_c_type_to_go_type(typename, pos: nil, pointer: nil, pointer_length: 0)
4657
return ruby_pointer_c_type_to_go_type(typename, pos:, pointer:, pointer_length:) if pointer
4758

59+
return C_TYPE_TO_GO_TYPE[typename] if C_TYPE_TO_GO_TYPE[typename]
60+
4861
case typename
49-
when "unsigned int", "unsigned long"
50-
return "uint"
51-
when "unsigned short"
52-
return "Ushort"
53-
when "unsigned char"
54-
return "Uchar"
55-
when "long long"
56-
return "Longlong"
57-
when "unsigned long long"
58-
return "Ulonglong"
59-
when "RUBY_DATA_FUNC", "rb_alloc_func_t"
60-
return "unsafe.Pointer"
6162
when /^[A-Z]+$/, "int"
6263
# e.g. VALUE
6364
return typename

0 commit comments

Comments
 (0)