Skip to content

Commit 93fe67c

Browse files
committed
Add sref pointer type
1 parent 0841831 commit 93fe67c

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

_tools/ruby_h_to_go/lib/ruby_header_parser/data.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize
1414

1515
# @param function_name [String]
1616
# @param pos [Integer] arg position (1 origin)
17-
# @return [Symbol] :ref, :array, :ref_array, :function
17+
# @return [Symbol] :ref, :array, :ref_array, :function, :sref
1818
def function_arg_pointer_hint(function_name:, pos:)
1919
pointer_hint = data["function"]["pointer_hint"].dig(function_name, pos)
2020
return pointer_hint.to_sym if pointer_hint

_tools/ruby_h_to_go/lib/ruby_header_parser/data.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function:
8181
1: function
8282
rb_exec_recursive_paired_outer:
8383
1: function
84+
rb_feature_provided:
85+
2: sref
8486
rb_funcallv:
8587
4: array
8688
rb_funcallv_public:

_tools/ruby_h_to_go/lib/ruby_header_parser/parser.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,24 @@ def parse_definition_args(function_name, signature)
223223
parts << "arg#{arg_pos}"
224224
end
225225

226-
type = Util.sanitize_type(parts[0...-1].join(" "))
226+
type = ""
227+
original_type = Util.sanitize_type(parts[0...-1].join(" "))
227228
name = parts[-1]
228229

229-
if type.match?(/\*+$/)
230-
type = type.gsub(/\*+$/, "").strip
230+
if original_type.match?(/\*+$/)
231+
type = original_type.gsub(/\*+$/, "").strip
231232
pointer = data.function_arg_pointer_hint(function_name:, pos: arg_pos)
232-
elsif /^void\s*\s/.match?(type) || /\(.*\)/.match?(type)
233+
elsif /^void\s*\s/.match?(original_type) || /\(.*\)/.match?(original_type)
233234
# function pointer (e.g. void *(*func)(void *)) is treated as `void*`
234235
type = "void"
235236
pointer = data.function_arg_pointer_hint(function_name:, pos: arg_pos)
237+
else
238+
type = original_type
239+
end
240+
241+
if pointer == :sref
242+
original_type =~ /(\*+)$/
243+
length = ::Regexp.last_match(1).length
236244
end
237245

238246
ArgumentDefinition.new(

_tools/ruby_h_to_go/spec/ruby_header_parser/parser_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@
169169
its(:typeref) { should eq typedef(type: "VALUE") }
170170
its(:args) { should eq args }
171171
end
172+
173+
context "rb_feature_provided" do
174+
subject { definitions.find { |d| d.name == "rb_feature_provided" } }
175+
176+
let(:args) do
177+
[
178+
argument(type: "char", name: "feature", pointer: :ref),
179+
argument(type: "char", name: "loading", pointer: :sref, length: 2),
180+
]
181+
end
182+
183+
its(:name) { should eq "rb_feature_provided" }
184+
its(:definition) { should eq "int rb_feature_provided(const char *feature, const char **loading)" }
185+
its(:typeref) { should eq typedef(type: "int") }
186+
its(:args) { should eq args }
187+
end
172188
end
173189

174190
describe "#extract_static_inline_function_definitions" do

0 commit comments

Comments
 (0)