Skip to content

Commit 653cc6d

Browse files
authored
Merge pull request #161 from sue445/feature/fix_function_generator
Diet generated function line
2 parents 8a5d3ba + eac9edd commit 653cc6d

File tree

4 files changed

+642
-1263
lines changed

4 files changed

+642
-1263
lines changed

.rubocop_todo.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-09-30 08:46:06 UTC using RuboCop version 1.66.1.
3+
# on 2024-10-03 13:07:51 UTC using RuboCop version 1.66.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -9,25 +9,30 @@
99
# Offense count: 8
1010
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1111
Metrics/AbcSize:
12-
Max: 79
12+
Max: 81
1313

1414
# Offense count: 2
1515
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1616
# AllowedMethods: refine
1717
Metrics/BlockLength:
1818
Max: 48
1919

20-
# Offense count: 7
20+
# Offense count: 1
21+
# Configuration parameters: CountComments, CountAsOne.
22+
Metrics/ClassLength:
23+
Max: 102
24+
25+
# Offense count: 5
2126
# Configuration parameters: AllowedMethods, AllowedPatterns.
2227
Metrics/CyclomaticComplexity:
23-
Max: 15
28+
Max: 16
2429

25-
# Offense count: 15
30+
# Offense count: 14
2631
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
2732
Metrics/MethodLength:
28-
Max: 75
33+
Max: 77
2934

3035
# Offense count: 3
3136
# Configuration parameters: AllowedMethods, AllowedPatterns.
3237
Metrics/PerceivedComplexity:
33-
Max: 16
38+
Max: 17

_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def generate_go_content
121121
if cast_func == ""
122122
go_function_lines << call_c_method
123123
go_function_lines.push(*after_call_function_lines)
124+
elsif after_call_function_lines.empty?
125+
go_function_lines << "return #{cast_func}(#{call_c_method})"
124126
else
125127
go_function_lines << "ret := #{cast_func}(#{call_c_method})"
126128
go_function_lines.push(*after_call_function_lines)

_tools/ruby_h_to_go/spec/ruby_h_to_go/function_definition_spec.rb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@
9999
//
100100
// VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
101101
func RbFuncallv(recv VALUE, mid ID, argc int, argv []VALUE) VALUE {
102-
ret := VALUE(C.rb_funcallv(C.VALUE(recv), C.ID(mid), C.int(argc), toCArray[VALUE, C.VALUE](argv)))
103-
return ret
102+
return VALUE(C.rb_funcallv(C.VALUE(recv), C.ID(mid), C.int(argc), toCArray[VALUE, C.VALUE](argv)))
104103
}
105104
106105
GO
@@ -130,8 +129,7 @@
130129
//
131130
// void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
132131
func RbThreadCallWithGvl(arg1 unsafe.Pointer, data1 unsafe.Pointer) unsafe.Pointer {
133-
ret := unsafe.Pointer(C.rb_thread_call_with_gvl(toCFunctionPointer(arg1), data1))
134-
return ret
132+
return unsafe.Pointer(C.rb_thread_call_with_gvl(toCFunctionPointer(arg1), data1))
135133
}
136134
137135
GO
@@ -161,8 +159,7 @@
161159
//
162160
// int rb_uv_to_utf8(char buf[6], unsigned long uv)
163161
func RbUvToUtf8(buf []Char, uv uint) int {
164-
ret := int(C.rb_uv_to_utf8(toCArray[Char, C.char](buf), C.ulong(uv)))
165-
return ret
162+
return int(C.rb_uv_to_utf8(toCArray[Char, C.char](buf), C.ulong(uv)))
166163
}
167164
168165
GO
@@ -189,8 +186,7 @@
189186
//
190187
// int *rb_errno_ptr(void)
191188
func RbErrnoPtr() *Int {
192-
ret := (*Int)(C.rb_errno_ptr())
193-
return ret
189+
return (*Int)(C.rb_errno_ptr())
194190
}
195191
196192
GO
@@ -219,8 +215,7 @@
219215
//
220216
// rb_big2ll(VALUE)
221217
func RbBig2Ll(arg1 VALUE) Longlong {
222-
ret := Longlong(C.rb_big2ll(C.VALUE(arg1)))
223-
return ret
218+
return Longlong(C.rb_big2ll(C.VALUE(arg1)))
224219
}
225220
226221
GO
@@ -249,8 +244,7 @@
249244
//
250245
// rb_big2ull(VALUE)
251246
func RbBig2Ull(arg1 VALUE) Ulonglong {
252-
ret := Ulonglong(C.rb_big2ull(C.VALUE(arg1)))
253-
return ret
247+
return Ulonglong(C.rb_big2ull(C.VALUE(arg1)))
254248
}
255249
256250
GO
@@ -325,8 +319,7 @@
325319
//
326320
// RSTRING_END(VALUE str)
327321
func RSTRING_END(str VALUE) string {
328-
ret := char2String(C.RSTRING_END(C.VALUE(str)))
329-
return ret
322+
return char2String(C.RSTRING_END(C.VALUE(str)))
330323
}
331324
332325
GO
@@ -355,8 +348,7 @@
355348
//
356349
// VALUE rb_const_list(void*)
357350
func RbConstList(arg1 unsafe.Pointer) VALUE {
358-
ret := VALUE(C.rb_const_list(arg1))
359-
return ret
351+
return VALUE(C.rb_const_list(arg1))
360352
}
361353
362354
GO
@@ -389,8 +381,7 @@
389381
char, clean := string2Char(feature)
390382
defer clean()
391383
392-
ret := int(C.rb_feature_provided(char, (**C.char)(unsafe.Pointer(loading))))
393-
return ret
384+
return int(C.rb_feature_provided(char, (**C.char)(unsafe.Pointer(loading))))
394385
}
395386
396387
GO
@@ -523,8 +514,7 @@
523514
//
524515
// RSTRING_PTR(VALUE str)
525516
func RSTRING_PTR(str VALUE) *Char {
526-
ret := (*Char)(C.RSTRING_PTR(C.VALUE(str)))
527-
return ret
517+
return (*Char)(C.RSTRING_PTR(C.VALUE(str)))
528518
}
529519
530520
GO

0 commit comments

Comments
 (0)