Skip to content

Commit f77e90c

Browse files
committed
nits: Extract to C_TYPE_TO_CGO_TYPE
1 parent f5600d7 commit f77e90c

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/generator_helper.rb

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,26 @@ def ruby_c_type_to_go_type(typename, pos: nil, pointer: nil, pointer_length: 0)
6868
snake_to_camel(typename)
6969
end
7070

71+
C_TYPE_TO_CGO_TYPE = {
72+
"RUBY_DATA_FUNC" => "toCFunctionPointer",
73+
"long long" => "C.longlong",
74+
"rb_io_wait_readwrite" => "C.enum_rb_io_wait_readwrite",
75+
"ruby_value_type" => "C.enum_ruby_value_type",
76+
"unsigned char" => "C.uchar",
77+
"unsigned int" => "C.uint",
78+
"unsigned long" => "C.ulong",
79+
"unsigned long long" => "C.ulonglong",
80+
"unsigned short" => "C.ushort",
81+
"st_hash_type" => "C.struct_st_hash_type",
82+
"timespec" => "C.struct_timespec",
83+
"timeval" => "C.struct_timeval",
84+
}.freeze
85+
7186
# Cast C type to cgo type. (Used in wrapper function)
7287
# @param typename [String]
7388
# @return [String]
7489
def cast_to_cgo_type(typename)
75-
case typename
76-
when "unsigned long"
77-
return "C.ulong"
78-
when "unsigned int"
79-
return "C.uint"
80-
when "unsigned char"
81-
return "C.uchar"
82-
when "unsigned short"
83-
return "C.ushort"
84-
when "long long"
85-
return "C.longlong"
86-
when "unsigned long long"
87-
return "C.ulonglong"
88-
when "timeval"
89-
return "C.struct_timeval"
90-
when "timespec"
91-
return "C.struct_timespec"
92-
when "st_hash_type"
93-
return "C.struct_st_hash_type"
94-
when "ruby_value_type"
95-
return "C.enum_ruby_value_type"
96-
when "rb_io_wait_readwrite"
97-
return "C.enum_rb_io_wait_readwrite"
98-
when "RUBY_DATA_FUNC"
99-
return "toCFunctionPointer"
100-
end
90+
return C_TYPE_TO_CGO_TYPE[typename] if C_TYPE_TO_CGO_TYPE[typename]
10191

10292
"C.#{typename}"
10393
end

0 commit comments

Comments
 (0)