Skip to content

Commit 5ca334c

Browse files
committed
Impl function_self_pointer_hint
1 parent 57be41c commit 5ca334c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

_tools/ruby_h_to_go/lib/ruby_header_parser/data.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def function_arg_pointer_hint(function_name:, pos:)
2222
:ref
2323
end
2424

25+
# @param function_name [String]
26+
# @return [Symbol] :ref, :raw
27+
def function_self_pointer_hint(function_name)
28+
pointer_hint = data["function"]["pointer_hint"].dig(function_name, "self")
29+
return pointer_hint.to_sym if pointer_hint
30+
31+
:ref
32+
end
33+
2534
# rubocop:disable Style/CaseEquality
2635

2736
# Whether generate C function to go

_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
@@ -68,6 +68,8 @@ function:
6868
- rb_class_descendants
6969

7070
pointer_hint:
71+
RSTRING_PTR:
72+
self: raw
7173
rb_data_object_make:
7274
4: sref
7375
rb_data_typed_object_make:

_tools/ruby_h_to_go/spec/ruby_header_parser/data_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
end
2222
end
2323

24+
describe "#function_self_pointer_hint" do
25+
subject { data.function_self_pointer_hint(function_name) }
26+
27+
context "found in data.yml" do
28+
let(:function_name) { "RSTRING_PTR" }
29+
30+
it { should eq :raw }
31+
end
32+
33+
context "not found in data.yml" do
34+
let(:function_name) { "rb_class2name" }
35+
36+
it { should eq :ref }
37+
end
38+
end
39+
2440
describe "#should_generate_function?" do
2541
subject { data.should_generate_function?(function_name) }
2642

0 commit comments

Comments
 (0)