Skip to content

Commit 3671b8f

Browse files
committed
Add CONFIG.md
1 parent f93ec99 commit 3671b8f

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
--hide-void-return
44
-
55
CHANGELOG.md
6+
CONFIG.md
67
LICENSE.txt

CONFIG.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Configuration file specification
2+
3+
## Example
4+
```yaml
5+
function:
6+
include_name:
7+
- !ruby/regexp /^rb_/i
8+
- !ruby/regexp /^rstring_/i
9+
10+
exclude_name:
11+
# deprecated functions
12+
- !ruby/regexp /^rb_check_safe_str$/i
13+
- !ruby/regexp /^rb_clear_constant_cache$/i
14+
- !ruby/regexp /^rb_clone_setup$/i
15+
16+
pointer_hint:
17+
RSTRING_PTR:
18+
self: raw
19+
rb_data_object_make:
20+
4: sref
21+
22+
struct:
23+
include_name:
24+
- !ruby/regexp /^rb_/i
25+
- re_registers
26+
27+
exclude_name:
28+
- rb_data_type_struct
29+
30+
type:
31+
include_name:
32+
- !ruby/regexp /^rb_/i
33+
- !ruby/regexp /^st_/i
34+
- ID
35+
- VALUE
36+
37+
exclude_name: []
38+
39+
enum:
40+
include_name:
41+
- ruby_value_type
42+
- rb_io_wait_readwrite
43+
44+
exclude_name: []
45+
```
46+
47+
## Full configuration file
48+
[config/default.yml](config/default.yml) is used by https://github.com/sue445/go-gem-wrapper to generate bindings for Go.
49+
50+
## `function.include_name`, `struct.include_name`, `type.include_name`, `enum.include_name`
51+
Return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
52+
53+
e.g.
54+
55+
```yaml
56+
struct:
57+
include_name:
58+
- !ruby/regexp /^rb_/i
59+
- re_registers
60+
```
61+
62+
Elements in the array accept the following
63+
64+
* `String`: Exact match
65+
* `Regexp`(`!ruby/regexp`): Regular expression match
66+
67+
## `function.exclude_name`, `struct.exclude_name`, `type.exclude_name`, `enum.exclude_name`
68+
Doesn't return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
69+
70+
e.g.
71+
72+
```yaml
73+
function:
74+
exclude_name:
75+
- !ruby/regexp /^rb_check_safe_str$/i
76+
- rb_scan_args_bad_format
77+
```
78+
79+
`exclude_name` is preferred over `include_name`
80+
81+
Other specifications are the same as `include_name`
82+
83+
## `function.pointer_hint`
84+
Provide a hint if the function argument type is a pointer
85+
86+
e.g.
87+
88+
```yaml
89+
function:
90+
pointer_hint:
91+
RSTRING_PTR: # function name (Exact match)
92+
self: raw
93+
rb_data_object_make:
94+
4: sref
95+
```
96+
97+
### Function arguments (`1`, `2`, `3`, ...)
98+
* `ref` (default)
99+
* normal pointer
100+
* e.g. 1st argument of `VALUE rb_const_list(void*)`
101+
* `in_ref`
102+
* input only pointer
103+
* e.g. 2nd argument of `void rb_define_variable(const char *name, VALUE *var)`
104+
* `sref`
105+
* special one for multiple pointer
106+
* e.g. 3rd argument of `rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)`
107+
* `array`
108+
* array
109+
* e.g. 4th argument of `VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)`
110+
* `ref_array`
111+
* array of pointer
112+
* e.g. 10th argument of `rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, int n_lead, int n_opt, int n_trail, bool f_var, bool f_hash, bool f_block, VALUE *vars[], RB_UNUSED_VAR(const char *fmt), RB_UNUSED_VAR(int varc))`
113+
* `str_array`
114+
* array of string
115+
* e.g. 2nd argument of `int rb_find_file_ext(VALUE *feature, const char *const *exts)`
116+
* `function`
117+
* function pointer
118+
* e.g. 4th argument of `void rb_define_method(VALUE klass, const char *mid, VALUE (*func)(), int arity)`
119+
120+
### Function return value (`self`)
121+
* `ref` (default)
122+
* normal pointer
123+
* e.g. Return value of `int *rb_errno_ptr(void)`
124+
* `raw`
125+
* In many cases `char*` can be interpreted as a string. But if `raw` is specified, it suppresses interpretation as a string
126+
* e.g. Return value of `char* RSTRING_PTR(VALUE str)`

0 commit comments

Comments
 (0)