Skip to content

Commit 3107b5d

Browse files
authored
Merge pull request #129 from sue445/fix_rubocop
Fix rubocop
2 parents 3bbdfbe + 37ff07f commit 3107b5d

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
paths-ignore:
1313
- ".github/workflows/patch_for_go_gem.yml"
1414
- "_benchmark/**"
15-
- "_tools/**"
1615

1716
env:
1817
TEST_ARGS: -coverprofile coverage.out -covermode atomic

_tools/ruby_h_to_go/lib/ruby_header_parser/parser.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(header_dir)
1919

2020
# @return [Array<RubyHeaderParser::FunctionDefinition>]
2121
def extract_function_definitions
22-
stdout = `ctags --recurse --c-kinds=p --languages=C --language-force=C --fields=+nS --extras=+q -f - #{header_dir}`
22+
stdout = `ctags --recurse --c-kinds=p --languages=C --language-force=C --fields=+nS --extras=+q -f - #{header_dir}` # rubocop:disable Layout/LineLength
2323

2424
stdout.each_line.with_object([]) do |line, definitions|
2525
parts = line.split("\t")
@@ -43,20 +43,11 @@ def extract_function_definitions
4343
# Exclude functions with variable-length arguments
4444
next if args&.last&.type == "..."
4545

46-
typeref_type = definition[0...definition.index(parts[0])].gsub("char *", "char*").strip
47-
typeref_pointer = nil
48-
if typeref_type.match?(/\*+$/)
49-
typeref_type = typeref_type.gsub(/\*+$/, "").strip
50-
typeref_pointer = :ref
51-
end
52-
53-
typeref = TyperefDefinition.new(type: typeref_type, pointer: typeref_pointer)
54-
5546
definitions << FunctionDefinition.new(
5647
definition:,
5748
name: parts[0],
5849
filepath: parts[1],
59-
typeref:,
50+
typeref: create_typeref(definition, function_name),
6051
args:,
6152
)
6253
end
@@ -248,5 +239,19 @@ def function_arg_pointer_hint(function_name, index)
248239

249240
:ref
250241
end
242+
243+
# @param definition [String]
244+
# @param function_name [String]
245+
# @return [RubyHeaderParser::TyperefDefinition]
246+
def create_typeref(definition, function_name)
247+
typeref_type = definition[0...definition.index(function_name)].gsub("char *", "char*").strip
248+
typeref_pointer = nil
249+
if typeref_type.match?(/\*+$/)
250+
typeref_type = typeref_type.gsub(/\*+$/, "").strip
251+
typeref_pointer = :ref
252+
end
253+
254+
TyperefDefinition.new(type: typeref_type, pointer: typeref_pointer)
255+
end
251256
end
252257
end

_tools/ruby_h_to_go/spec/ruby_header_parser/parser_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
end
7979

8080
its(:name) { should eq "rb_tracepoint_new" }
81-
its(:definition) { should eq "VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data)" }
81+
its(:definition) { should eq "VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data)" } # rubocop:disable Layout/LineLength
8282
its(:filepath) { should be_end_with "/ruby/debug.h" }
8383
its(:typeref) { should eq typedef(type: "VALUE") }
8484
its(:args) { should eq args }

_tools/ruby_h_to_go/spec/ruby_header_parser/util_spec.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,33 @@
2525
context "simple case" do
2626
let(:signature) { "VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2" }
2727

28-
it { should eq ["VALUE obj", "ID mid", "int argc", "const VALUE *argv", "rb_block_call_func_t proc", "VALUE data2"] }
28+
let(:args) do
29+
[
30+
"VALUE obj",
31+
"ID mid",
32+
"int argc",
33+
"const VALUE *argv",
34+
"rb_block_call_func_t proc",
35+
"VALUE data2",
36+
]
37+
end
38+
39+
it { should eq args }
2940
end
3041

3142
context "with function pointer" do
32-
let(:signature) { "VALUE target_thread_not_supported_yet,rb_event_flag_t events,void (* func)(VALUE,void *),void * data" }
33-
34-
it { should eq ["VALUE target_thread_not_supported_yet", "rb_event_flag_t events", "void (* func)(VALUE,void *)", "void * data"] }
43+
let(:signature) { "VALUE target_thread_not_supported_yet,rb_event_flag_t events,void (* func)(VALUE,void *),void * data" } # rubocop:disable Layout/LineLength
44+
45+
let(:args) do
46+
[
47+
"VALUE target_thread_not_supported_yet",
48+
"rb_event_flag_t events",
49+
"void (* func)(VALUE,void *)",
50+
"void * data",
51+
]
52+
end
53+
54+
it { should eq args }
3555
end
3656
end
3757
end

0 commit comments

Comments
 (0)