mri_sys/
functions.rs

1use libc;
2use super::*;
3
4#[link(name = "gmp")]
5#[cfg_attr(target_os = "macos", link(name = "CoreFoundation", kind = "framework"))]
6extern "C" {
7    pub fn ruby_init();
8    pub fn ruby_setup() -> libc::c_int;
9    pub fn ruby_cleanup(_: libc::c_int);
10
11    pub fn rb_eval_string(_: *const libc::c_char) -> VALUE;
12    pub fn rb_eval_string_protect(_: *const libc::c_char, _: *mut libc::c_int) -> VALUE;
13    pub fn rb_eval_string_wrap(_: *const libc::c_char, _: *mut libc::c_int) -> VALUE;
14    /// Note: argv format is as follows: `eval(string [, binding [, filename [,lineno]]])`
15    // pub fn rb_f_eval(argc: libc::c_int, argv: *const VALUE, receiver: VALUE) -> VALUE;
16
17    pub fn rb_errinfo() -> VALUE;
18    pub fn rb_set_errinfo(_: VALUE);
19
20
21    /// Protects a  function call from  potential global escapes from  the function.
22    /// Such global escapes include exceptions, `throw`, `break`, for example.
23    ///
24    /// Calls your C function with the value specified in `args`. If the C function does not
25    /// escape, sets `state` to `0`.
26    pub fn rb_protect(f: extern "C" fn(VALUE) -> VALUE, args: VALUE, state: *mut libc::c_int) -> VALUE;
27
28    /// Convert a C string to a symbol (adding to the symbol table).
29    pub fn rb_intern(_: *const libc::c_char) -> ID;
30    pub fn rb_intern2(_: *const libc::c_char, _: libc::c_long) -> ID;
31    /// Convert a Ruby `String` to a symbol (adding to the symbol table).
32    pub fn rb_intern_str(s: VALUE) -> ID;
33    pub fn rb_id2name(_: ID) -> *const libc::c_char;
34    pub fn rb_check_id(_: *mut VALUE) -> ID;
35    pub fn rb_to_id(_: VALUE) -> ID;
36    pub fn rb_id2str(_: ID) -> VALUE;
37    pub fn rb_sym2str(_: VALUE) -> VALUE;
38    pub fn rb_to_symbol(name: VALUE) -> VALUE;
39    pub fn rb_check_symbol(namep: *mut VALUE) -> VALUE;
40    pub fn rb_id2sym(_: ID) -> VALUE;
41
42    pub fn rb_class2name(_: VALUE) -> *const libc::c_char;
43    pub fn rb_obj_classname(_: VALUE) -> *const libc::c_char;
44
45    /// Call a Ruby function using varargs to pass the arguments.
46    pub fn rb_funcall(receiver: VALUE, name: ID, argc: libc::c_int, ...) -> VALUE;
47    /// Call a Ruby function using C arrays to pass the arguments.
48    pub fn rb_funcallv(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
49    /// Call a public Ruby function using C arrays to pass the arguments.
50    pub fn rb_funcallv_public(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
51    pub fn rb_funcall_passing_block(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
52    pub fn rb_funcall_with_block(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE, _: VALUE) -> VALUE;
53
54    /// Gets the value of a constant.
55    pub fn rb_const_get(space: VALUE, name: ID) -> VALUE;
56    /// Sets the value of a constant.
57    pub fn rb_const_set(space: VALUE, name: ID, value: VALUE);
58
59    /// Convert Ruby `String` to a C string.
60    pub fn rb_string_value_cstr(_: *const VALUE) -> *const libc::c_char;
61    /// Convert C string to a Ruby `String`.
62    pub fn rb_str_new_cstr(ptr: *const libc::c_char) -> VALUE;
63
64    pub fn rb_define_class(_: *const libc::c_char, _: VALUE) -> VALUE;
65    pub fn rb_define_module(_: *const libc::c_char) -> VALUE;
66    pub fn rb_define_class_under(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;
67    pub fn rb_define_module_under(_: VALUE, _: *const libc::c_char) -> VALUE;
68
69    pub fn rb_include_module(_: VALUE, _: VALUE) -> VALUE;
70    pub fn rb_extend_object(_: VALUE, _: VALUE) -> VALUE;
71    pub fn rb_prepend_module(_: VALUE, _: VALUE) -> VALUE;
72
73    pub fn rb_define_variable(_: *const libc::c_char, _: *const VALUE) -> VALUE;
74    pub fn rb_define_virtual_variable(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: *mut extern fn());
75    pub fn rb_define_hooked_variable(_: *const libc::c_char, _: *mut VALUE, _: *mut extern fn() -> VALUE, _: *mut extern fn());
76    pub fn rb_define_readonly_variable(_: *const libc::c_char, _: *const VALUE) -> VALUE;
77    pub fn rb_define_const(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;
78    pub fn rb_define_global_const(_: *const libc::c_char, _: VALUE);
79
80    pub fn rb_define_method(_: VALUE, _: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;
81    pub fn rb_define_module_function(_: VALUE, _: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;
82    pub fn rb_define_global_function(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;
83
84    pub fn rb_undef_method(_: VALUE, _: *const libc::c_char) -> VALUE;
85    pub fn rb_define_alias(_: VALUE, _: *const libc::c_char, _: *const libc::c_char) -> VALUE;
86    pub fn rb_define_attr(_: VALUE, _: *const libc::c_char, _: libc::c_int, _: libc::c_int) -> VALUE;
87
88    pub fn rb_global_variable(_: *mut VALUE);
89    pub fn rb_gc_register_mark_object(_: *mut VALUE);
90    pub fn rb_gc_register_address(_: *mut VALUE);
91    pub fn rb_gc_unregister_address(_: *mut VALUE);
92
93    pub fn rb_scan_args(_: libc::c_int, _: *const VALUE, _: *const libc::c_char, ...) -> libc::c_int;
94    pub fn rb_call_super(_: libc::c_int, _: *const VALUE) -> VALUE;
95    pub fn rb_current_receiver() -> VALUE;
96    pub fn rb_get_kwargs(keyword_hash: VALUE, table: *const ID, required: libc::c_int, optional: libc::c_int, _: *const VALUE) -> libc::c_int;
97    pub fn rb_extract_keywords(orighash: *mut VALUE) -> VALUE;
98
99    pub fn rb_gv_set(_: *const libc::c_char, _: VALUE) -> VALUE;
100    pub fn rb_gv_get(_: *const libc::c_char) -> VALUE;
101    pub fn rb_iv_get(_: VALUE, _: *const libc::c_char) -> VALUE;
102    pub fn rb_iv_set(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;
103
104    pub fn rb_equal(_: VALUE, _: VALUE) -> VALUE;
105    pub fn rb_ruby_verbose_ptr() -> *mut VALUE;
106    pub fn rb_ruby_debug_ptr() -> *mut VALUE;
107
108    pub fn rb_raise(_: VALUE, _: *const libc::c_char, ...) -> !;
109    pub fn rb_fatal(_: *const libc::c_char, ...) -> !;
110    pub fn rb_bug(_: *const libc::c_char, ...) -> !;
111    pub fn rb_bug_errno(_: *const libc::c_char, _: libc::c_int) -> !;
112    pub fn rb_sys_fail(_: *const libc::c_char) -> !;
113    pub fn rb_sys_fail_str(_: VALUE) -> !;
114    pub fn rb_mod_sys_fail(_: VALUE, _: *const libc::c_char) -> !;
115    pub fn rb_mod_sys_fail_str(_: VALUE, _: VALUE) -> !;
116    pub fn rb_readwrite_sys_fail(rb_io_wait_readwrite: libc::c_int, _: *const libc::c_char) -> !;
117    pub fn rb_iter_break() -> !;
118    pub fn rb_iter_break_value(_: VALUE) -> !;
119    pub fn rb_exit(_: libc::c_int) -> !;
120    pub fn rb_notimplement() -> !;
121    pub fn rb_syserr_new(_: libc::c_int, _: *const libc::c_char) -> VALUE;
122    pub fn rb_syserr_new_str(n: libc::c_int, arg: VALUE) -> VALUE;
123    pub fn rb_syserr_fail(_: libc::c_int, _: *const libc::c_char) -> !;
124    pub fn rb_syserr_fail_str(_: libc::c_int, _: VALUE) -> !;
125    pub fn rb_mod_syserr_fail(_: VALUE, _: libc::c_int, _: *const libc::c_char) -> !;
126    pub fn rb_mod_syserr_fail_str(_: VALUE, _: libc::c_int, _: VALUE) -> !;
127    pub fn rb_readwrite_syserr_fail(rb_io_wait_readwrite: libc::c_int, _: libc::c_int, _: *const libc::c_char) -> !;
128
129    pub fn rb_warning(format: *const libc::c_char, ...);
130    pub fn rb_compile_warning(format: *const libc::c_char, _: libc::c_int, _: *const libc::c_char, ...);
131    pub fn rb_sys_warning(format: *const libc::c_char, ...);
132    pub fn rb_warn(format: *const libc::c_char, ...);
133    pub fn rb_compile_warn(_: *const libc::c_char, _: libc::c_int, _: *const libc::c_char, ...);
134
135    pub fn rb_each(_: VALUE) -> VALUE;
136    pub fn rb_yield(_: VALUE) -> VALUE;
137    pub fn rb_yield_values(n: libc::c_int, ...) -> VALUE;
138    pub fn rb_yield_values2(n: libc::c_int, argv: *const VALUE) -> VALUE;
139    pub fn rb_yield_splat(_: VALUE) -> VALUE;
140    pub fn rb_yield_block(_: VALUE, _: VALUE, _: libc::c_int, _: *const VALUE, _: VALUE) -> VALUE;
141    pub fn rb_block_given_pvoid() -> libc::c_int;
142    pub fn rb_need_block();
143    pub fn rb_iterate(_: *mut extern fn(VALUE) -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
144    pub fn rb_rescue(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
145
146    pub fn rb_rescue2(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE, ...) -> VALUE;
147    pub fn rb_ensure(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
148    pub fn rb_catch(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
149    pub fn rb_catch_obj(_: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
150
151    pub fn rb_throw(_: *const libc::c_char, _: VALUE) -> !;
152    pub fn rb_throw_obj(_: VALUE, _: VALUE) -> !;
153
154    pub fn rb_p(_: VALUE);
155
156    pub fn rb_require(_: *const libc::c_char) -> VALUE;
157
158    pub fn ruby_sysinit(argc: *mut libc::c_int, _: *mut *mut *mut libc::c_char);
159    pub fn ruby_options(argc: libc::c_int, argv: *mut *mut libc::c_char) -> *mut libc::c_void;
160    pub fn ruby_executable_node(n: *mut libc::c_void, status: *mut libc::c_int) -> libc::c_int;
161    pub fn ruby_run_node(n: *mut libc::c_void) -> libc::c_int;
162    pub fn ruby_show_version();
163    pub fn ruby_show_copyright();
164
165    pub fn ruby_finalize();
166    pub fn ruby_stop(_: libc::c_int) -> !;
167
168    pub fn ruby_set_stack_size(_: libc::size_t);
169    pub fn ruby_stack_check() -> libc::c_int;
170    pub fn ruby_stack_length(_: *mut *mut VALUE) -> libc::size_t;
171
172    pub fn ruby_exec_node(n: *mut libc::c_void) -> libc::c_int;
173
174    pub fn ruby_script(name: *const libc::c_char);
175    pub fn ruby_set_script_name(name: VALUE);
176
177    pub fn ruby_prog_init();
178    pub fn ruby_set_argv(_: libc::c_int, _: *mut *mut libc::c_char);
179    pub fn ruby_process_options(_: libc::c_int, _: *mut *mut libc::c_char) -> *mut libc::c_void;
180    pub fn ruby_init_loadpath();
181    pub fn ruby_incpush(_: *const libc::c_char);
182    pub fn ruby_sig_finalize();
183
184    pub fn rb_check_type(_: VALUE, _: libc::c_int);
185    pub fn rb_str_to_str(_: VALUE) -> VALUE;
186    pub fn rb_string_value(_: *mut VALUE) -> VALUE;
187    pub fn rb_string_value_ptr(_: *mut VALUE) -> *mut libc::c_char;
188    pub fn rb_check_safe_obj(_: VALUE);
189    pub fn rb_str_export(_: VALUE) -> VALUE;
190    pub fn rb_str_export_locale(_: VALUE) -> VALUE;
191    pub fn rb_get_path(_: VALUE) -> VALUE;
192    pub fn rb_get_path_no_checksafe(_: VALUE) -> VALUE;
193    pub fn rb_secure(_: libc::c_int);
194    pub fn rb_safe_level() -> libc::c_int;
195    pub fn rb_set_safe_level(_: libc::c_int);
196    pub fn rb_set_safe_level_force(_: libc::c_int);
197
198    pub fn rb_num2dbl(_: VALUE) -> libc::c_double;
199    pub fn rb_num2long(_: VALUE) -> libc::c_long;
200    pub fn rb_num2ulong(_: VALUE) -> libc::c_ulong;
201
202    pub fn rb_num2uint(_: VALUE) -> libc::c_ulong;
203    pub fn rb_fix2uint(_: VALUE) -> libc::c_ulong;
204
205    pub fn rb_num2short(_: VALUE) -> libc::c_short;
206    pub fn rb_num2ushort(_: VALUE) -> libc::c_ushort;
207    pub fn rb_fix2short(_: VALUE) -> libc::c_short;
208    pub fn rb_fix2ushort(_: VALUE) -> libc::c_ushort;
209
210    pub fn rb_newobj() -> VALUE;
211    pub fn rb_newobj_of(_: VALUE, _: VALUE) -> VALUE;
212    pub fn rb_obj_setup(obj: VALUE, klass: VALUE, ty: VALUE) -> VALUE;
213
214    pub fn rb_float_new(_: libc::c_double) -> VALUE;
215    pub fn rb_float_new_in_heap(_: libc::c_double) -> VALUE;
216}
217
218#[allow(non_snake_case)]
219pub fn INT2FIX(i: INNER_VALUE) -> VALUE {
220    VALUE(((i<<1) as INNER_VALUE) | (FIXNUM_FLAG.0 as INNER_VALUE))
221}
222