File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,14 @@ def generate_go_content
110
110
go_function_lines << call_c_method
111
111
go_function_lines . push ( *after_call_function_lines )
112
112
else
113
- go_function_lines << "ret := #{ go_function_typeref } (#{ call_c_method } )"
113
+ cast_func =
114
+ if go_function_typeref . start_with? ( "*" )
115
+ "(#{ go_function_typeref } )"
116
+ else
117
+ go_function_typeref
118
+ end
119
+
120
+ go_function_lines << "ret := #{ cast_func } (#{ call_c_method } )"
114
121
go_function_lines . push ( *after_call_function_lines )
115
122
go_function_lines << "return ret"
116
123
end
Original file line number Diff line number Diff line change 187
187
188
188
it { should eq go_content }
189
189
end
190
+
191
+ context "rb_errno_ptr" do
192
+ let ( :definition ) do
193
+ RubyHeaderParser ::FunctionDefinition . new (
194
+ name : "rb_errno_ptr" ,
195
+ definition : "int *rb_errno_ptr(void)" ,
196
+ filepath : "/path/to/include/ruby/ruby.h" ,
197
+ typeref : typedef ( type : "int" , pointer : :ref ) ,
198
+ args : [ ] ,
199
+ )
200
+ end
201
+
202
+ let ( :go_content ) do
203
+ <<~GO
204
+ // RbErrnoPtr calls `rb_errno_ptr` in C
205
+ //
206
+ // Original definition is following
207
+ //
208
+ // int *rb_errno_ptr(void)
209
+ //
210
+ // ref. https://github.com/ruby/ruby/blob/master/include/ruby/ruby.h
211
+ func RbErrnoPtr() *int {
212
+ ret := (*int)(C.rb_errno_ptr())
213
+ return ret
214
+ }
215
+
216
+ GO
217
+ end
218
+
219
+ it { should eq go_content }
220
+ end
190
221
end
191
222
end
Original file line number Diff line number Diff line change 136
136
its ( :typeref ) { should eq typedef ( type : "int" ) }
137
137
its ( :args ) { should eq args }
138
138
end
139
+
140
+ context "rb_errno_ptr" do
141
+ subject { definitions . find { |d | d . name == "rb_errno_ptr" } }
142
+
143
+ let ( :args ) do
144
+ [ ]
145
+ end
146
+
147
+ its ( :name ) { should eq "rb_errno_ptr" }
148
+ its ( :definition ) { should eq "int *rb_errno_ptr(void)" }
149
+ its ( :filepath ) { should be_end_with "/ruby/ruby.h" }
150
+ its ( :typeref ) { should eq typedef ( type : "int" , pointer : :ref ) }
151
+ its ( :args ) { should eq args }
152
+ end
139
153
end
140
154
141
155
describe "#extract_static_inline_function_definitions" do
You can’t perform that action at this time.
0 commit comments