@@ -68,36 +68,26 @@ def ruby_c_type_to_go_type(typename, pos: nil, pointer: nil, pointer_length: 0)
68
68
snake_to_camel ( typename )
69
69
end
70
70
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
+
71
86
# Cast C type to cgo type. (Used in wrapper function)
72
87
# @param typename [String]
73
88
# @return [String]
74
89
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 ]
101
91
102
92
"C.#{ typename } "
103
93
end
0 commit comments