Skip to content

Commit 673e1f3

Browse files
committed
Add GitHub link to generated code
1 parent d0ccd31 commit 673e1f3

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ def generate_go_content
4848

4949
go_function_typeref = typeref.go_function_typeref
5050

51+
github_url = generate_include_github_url(header_dir:, ruby_header_file: filepath)
52+
5153
go_function_lines = [
5254
"// #{go_function_name} calls `#{name}` in C",
5355
"//",
5456
"// Original definition is following",
5557
"//",
5658
"//\t#{definition}",
59+
"//",
60+
"// ref. #{github_url}",
5761
]
5862

5963
go_function_lines << "func #{go_function_name}(#{go_function_args.join(", ")}) #{go_function_typeref} {"

_tools/ruby_h_to_go/lib/ruby_h_to_go/struct_definition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ def write_go_file(dist_dir)
3434

3535
# @return [String]
3636
def generate_go_content
37+
github_url = generate_include_github_url(header_dir:, ruby_header_file: filepath)
38+
3739
go_type_name = snake_to_camel(name)
3840

3941
<<~GO
4042
// #{go_type_name} is a type for passing `C.#{name}` in and out of package
43+
//
44+
// ref. #{github_url}
4145
type #{go_type_name} C.#{name}
4246
4347
GO

_tools/ruby_h_to_go/lib/ruby_h_to_go/type_definition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ def write_go_file(dist_dir)
3333

3434
# @return [String]
3535
def generate_go_content
36+
github_url = generate_include_github_url(header_dir:, ruby_header_file: filepath)
37+
3638
go_type_name = snake_to_camel(name)
3739

3840
<<~GO
3941
// #{go_type_name} is a type for passing `C.#{name}` in and out of package
42+
//
43+
// ref. #{github_url}
4044
type #{go_type_name} C.#{name}
4145
4246
GO

_tools/ruby_h_to_go/spec/ruby_h_to_go/function_definition_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// Original definition is following
3030
//
3131
// void rb_define_method(VALUE klass, const char *mid, VALUE (*func)(ANYARGS), int arity)
32+
//
33+
// ref. https://github.com/ruby/ruby/blob/master/include/ruby/internal/method.h
3234
func RbDefineMethod(klass VALUE, mid string, arg3 unsafe.Pointer, arity int) {
3335
char, clean := string2Char(mid)
3436
defer clean()
@@ -67,6 +69,8 @@
6769
// Original definition is following
6870
//
6971
// VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2)
72+
//
73+
// ref. https://github.com/ruby/ruby/blob/master/include/ruby/internal/iterator.h
7074
func RbBlockCall(obj VALUE, mid ID, argc int, argv *VALUE, proc RbBlockCallFuncT, data2 VALUE) VALUE {
7175
var cArgv C.VALUE
7276
ret := VALUE(C.rb_block_call(C.VALUE(obj), C.ID(mid), C.int(argc), &cArgv, C.rb_block_call_func_t(proc), C.VALUE(data2)))
@@ -103,6 +107,8 @@
103107
// Original definition is following
104108
//
105109
// VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
110+
//
111+
// ref. https://github.com/ruby/ruby/blob/master/include/ruby/internal/eval.h
106112
func RbFuncallv(recv VALUE, mid ID, argc int, argv []VALUE) VALUE {
107113
ret := VALUE(C.rb_funcallv(C.VALUE(recv), C.ID(mid), C.int(argc), toCArray[VALUE, C.VALUE](argv)))
108114
return ret
@@ -135,6 +141,8 @@
135141
// Original definition is following
136142
//
137143
// void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
144+
//
145+
// ref. https://github.com/ruby/ruby/blob/master/include/rubythread.h
138146
func RbThreadCallWithGvl(arg1 unsafe.Pointer, data1 unsafe.Pointer) unsafe.Pointer {
139147
ret := unsafe.Pointer(C.rb_thread_call_with_gvl(toCPointer(arg1), toCPointer(data1)))
140148
return ret
@@ -167,6 +175,8 @@
167175
// Original definition is following
168176
//
169177
// int rb_uv_to_utf8(char buf[6], unsigned long uv)
178+
//
179+
// ref. https://github.com/ruby/ruby/blob/master/include/intern/bignum.h
170180
func RbUvToUtf8(buf []Char, uv uint) int {
171181
ret := int(C.rb_uv_to_utf8(toCArray[Char, C.char](buf), C.ulong(uv)))
172182
return ret

_tools/ruby_h_to_go/spec/ruby_h_to_go/struct_definition_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
let(:go_content) do
1818
<<~GO
1919
// RbDataTypeStruct is a type for passing `C.rb_data_type_struct` in and out of package
20+
//
21+
// ref. https://github.com/ruby/ruby/blob/master/include/ruby/internal/core/rtypeddata.h
2022
type RbDataTypeStruct C.rb_data_type_struct
2123
2224
GO

_tools/ruby_h_to_go/spec/ruby_h_to_go/type_definition_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
let(:go_content) do
1818
<<~GO
1919
// VALUE is a type for passing `C.VALUE` in and out of package
20+
//
21+
// ref. https://github.com/ruby/ruby/blob/master/include/ruby/internal/value.h
2022
type VALUE C.VALUE
2123
2224
GO

0 commit comments

Comments
 (0)