1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use libc;
use super::*;

#[link(name = "gmp")]
#[cfg_attr(target_os = "macos", link(name = "CoreFoundation", kind = "framework"))]
extern "C" {
    pub fn ruby_init();
    pub fn ruby_setup() -> libc::c_int;
    pub fn ruby_cleanup(_: libc::c_int);

    pub fn rb_eval_string(_: *const libc::c_char) -> VALUE;
    pub fn rb_eval_string_protect(_: *const libc::c_char, _: *mut libc::c_int) -> VALUE;
    pub fn rb_eval_string_wrap(_: *const libc::c_char, _: *mut libc::c_int) -> VALUE;

    pub fn rb_errinfo() -> VALUE;
    pub fn rb_set_errinfo(_: VALUE);

    pub fn rb_intern(_: *const libc::c_char) -> ID;
    pub fn rb_intern2(_: *const libc::c_char, _: libc::c_long) -> ID;
    pub fn rb_intern_str(s: VALUE) -> ID;
    pub fn rb_id2name(_: ID) -> *const libc::c_char;
    pub fn rb_check_id(_: *mut VALUE) -> ID;
    pub fn rb_to_id(_: VALUE) -> ID;
    pub fn rb_id2str(_: ID) -> VALUE;
    pub fn rb_sym2str(_: VALUE) -> VALUE;
    pub fn rb_to_symbol(name: VALUE) -> VALUE;
    pub fn rb_check_symbol(namep: *mut VALUE) -> VALUE;
    pub fn rb_id2sym(_: ID) -> VALUE;

    pub fn rb_class2name(_: VALUE) -> *const libc::c_char;
    pub fn rb_obj_classname(_: VALUE) -> *const libc::c_char;

    pub fn rb_funcall(_: VALUE, _: ID, _: libc::c_int, ...) -> VALUE;
    pub fn rb_funcallv(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
    pub fn rb_funcallv_public(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
    pub fn rb_funcall_passing_block(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE) -> VALUE;
    pub fn rb_funcall_with_block(_: VALUE, _: ID, _: libc::c_int, _: *const VALUE, _: VALUE) -> VALUE;
    pub fn rb_string_value_cstr(_: *const VALUE) -> *const libc::c_char;

    pub fn rb_define_class(_: *const libc::c_char, _: VALUE) -> VALUE;
    pub fn rb_define_module(_: *const libc::c_char) -> VALUE;
    pub fn rb_define_class_under(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;
    pub fn rb_define_module_under(_: VALUE, _: *const libc::c_char) -> VALUE;

    pub fn rb_include_module(_: VALUE, _: VALUE) -> VALUE;
    pub fn rb_extend_object(_: VALUE, _: VALUE) -> VALUE;
    pub fn rb_prepend_module(_: VALUE, _: VALUE) -> VALUE;

    pub fn rb_define_variable(_: *const libc::c_char, _: *const VALUE) -> VALUE;
    pub fn rb_define_virtual_variable(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: *mut extern fn());
    pub fn rb_define_hooked_variable(_: *const libc::c_char, _: *mut VALUE, _: *mut extern fn() -> VALUE, _: *mut extern fn());
    pub fn rb_define_readonly_variable(_: *const libc::c_char, _: *const VALUE) -> VALUE;
    pub fn rb_define_const(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;
    pub fn rb_define_global_const(_: *const libc::c_char, _: VALUE);

    pub fn rb_define_method(_: VALUE, _: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;
    pub fn rb_define_module_function(_: VALUE, _: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;
    pub fn rb_define_global_function(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: libc::c_int) -> VALUE;

    pub fn rb_undef_method(_: VALUE, _: *const libc::c_char) -> VALUE;
    pub fn rb_define_alias(_: VALUE, _: *const libc::c_char, _: *const libc::c_char) -> VALUE;
    pub fn rb_define_attr(_: VALUE, _: *const libc::c_char, _: libc::c_int, _: libc::c_int) -> VALUE;

    pub fn rb_global_variable(_: *mut VALUE);
    pub fn rb_gc_register_mark_object(_: *mut VALUE);
    pub fn rb_gc_register_address(_: *mut VALUE);
    pub fn rb_gc_unregister_address(_: *mut VALUE);

    pub fn rb_scan_args(_: libc::c_int, _: *const VALUE, _: *const libc::c_char, ...) -> libc::c_int;
    pub fn rb_call_super(_: libc::c_int, _: *const VALUE) -> VALUE;
    pub fn rb_current_receiver() -> VALUE;
    pub fn rb_get_kwargs(keyword_hash: VALUE, table: *const ID, required: libc::c_int, optional: libc::c_int, _: *const VALUE) -> libc::c_int;
    pub fn rb_extract_keywords(orighash: *mut VALUE) -> VALUE;

    pub fn rb_gv_set(_: *const libc::c_char, _: VALUE) -> VALUE;
    pub fn rb_gv_get(_: *const libc::c_char) -> VALUE;
    pub fn rb_iv_get(_: VALUE, _: *const libc::c_char) -> VALUE;
    pub fn rb_iv_set(_: VALUE, _: *const libc::c_char, _: VALUE) -> VALUE;

    pub fn rb_equal(_: VALUE, _: VALUE) -> VALUE;
    pub fn rb_ruby_verbose_ptr() -> *mut VALUE;
    pub fn rb_ruby_debug_ptr() -> *mut VALUE;

    pub fn rb_raise(_: VALUE, _: *const libc::c_char, ...) -> !;
    pub fn rb_fatal(_: *const libc::c_char, ...) -> !;
    pub fn rb_bug(_: *const libc::c_char, ...) -> !;
    pub fn rb_bug_errno(_: *const libc::c_char, _: libc::c_int) -> !;
    pub fn rb_sys_fail(_: *const libc::c_char) -> !;
    pub fn rb_sys_fail_str(_: VALUE) -> !;
    pub fn rb_mod_sys_fail(_: VALUE, _: *const libc::c_char) -> !;
    pub fn rb_mod_sys_fail_str(_: VALUE, _: VALUE) -> !;
    pub fn rb_readwrite_sys_fail(rb_io_wait_readwrite: libc::c_int, _: *const libc::c_char) -> !;
    pub fn rb_iter_break() -> !;
    pub fn rb_iter_break_value(_: VALUE) -> !;
    pub fn rb_exit(_: libc::c_int) -> !;
    pub fn rb_notimplement() -> !;
    pub fn rb_syserr_new(_: libc::c_int, _: *const libc::c_char) -> VALUE;
    pub fn rb_syserr_new_str(n: libc::c_int, arg: VALUE) -> VALUE;
    pub fn rb_syserr_fail(_: libc::c_int, _: *const libc::c_char) -> !;
    pub fn rb_syserr_fail_str(_: libc::c_int, _: VALUE) -> !;
    pub fn rb_mod_syserr_fail(_: VALUE, _: libc::c_int, _: *const libc::c_char) -> !;
    pub fn rb_mod_syserr_fail_str(_: VALUE, _: libc::c_int, _: VALUE) -> !;
    pub fn rb_readwrite_syserr_fail(rb_io_wait_readwrite: libc::c_int, _: libc::c_int, _: *const libc::c_char) -> !;

    pub fn rb_warning(format: *const libc::c_char, ...);
    pub fn rb_compile_warning(format: *const libc::c_char, _: libc::c_int, _: *const libc::c_char, ...);
    pub fn rb_sys_warning(format: *const libc::c_char, ...);
    pub fn rb_warn(format: *const libc::c_char, ...);
    pub fn rb_compile_warn(_: *const libc::c_char, _: libc::c_int, _: *const libc::c_char, ...);

    pub fn rb_each(_: VALUE) -> VALUE;
    pub fn rb_yield(_: VALUE) -> VALUE;
    pub fn rb_yield_values(n: libc::c_int, ...) -> VALUE;
    pub fn rb_yield_values2(n: libc::c_int, argv: *const VALUE) -> VALUE;
    pub fn rb_yield_splat(_: VALUE) -> VALUE;
    pub fn rb_yield_block(_: VALUE, _: VALUE, _: libc::c_int, _: *const VALUE, _: VALUE) -> VALUE;
    pub fn rb_block_given_pvoid() -> libc::c_int;
    pub fn rb_need_block();
    pub fn rb_iterate(_: *mut extern fn(VALUE) -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
    pub fn rb_rescue(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;

    pub fn rb_rescue2(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE, ...) -> VALUE;
    pub fn rb_ensure(_: *mut extern fn() -> VALUE, _: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
    pub fn rb_catch(_: *const libc::c_char, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;
    pub fn rb_catch_obj(_: VALUE, _: *mut extern fn() -> VALUE, _: VALUE) -> VALUE;

    pub fn rb_throw(_: *const libc::c_char, _: VALUE) -> !;
    pub fn rb_throw_obj(_: VALUE, _: VALUE) -> !;

    pub fn rb_p(_: VALUE);

    pub fn rb_require(_: *const libc::c_char) -> VALUE;

    pub fn ruby_sysinit(argc: *mut libc::c_int, _: *mut *mut *mut libc::c_char);
    pub fn ruby_options(argc: libc::c_int, argv: *mut *mut libc::c_char) -> *mut libc::c_void;
    pub fn ruby_executable_node(n: *mut libc::c_void, status: *mut libc::c_int) -> libc::c_int;
    pub fn ruby_run_node(n: *mut libc::c_void) -> libc::c_int;
    pub fn ruby_show_version();
    pub fn ruby_show_copyright();

    pub fn ruby_finalize();
    pub fn ruby_stop(_: libc::c_int) -> !;

    pub fn ruby_set_stack_size(_: libc::size_t);
    pub fn ruby_stack_check() -> libc::c_int;
    pub fn ruby_stack_length(_: *mut *mut VALUE) -> libc::size_t;

    pub fn ruby_exec_node(n: *mut libc::c_void) -> libc::c_int;

    pub fn ruby_script(name: *const libc::c_char);
    pub fn ruby_set_script_name(name: VALUE);

    pub fn ruby_prog_init();
    pub fn ruby_set_argv(_: libc::c_int, _: *mut *mut libc::c_char);
    pub fn ruby_process_options(_: libc::c_int, _: *mut *mut libc::c_char) -> *mut libc::c_void;
    pub fn ruby_init_loadpath();
    pub fn ruby_incpush(_: *const libc::c_char);
    pub fn ruby_sig_finalize();

    pub fn rb_check_type(_: VALUE, _: libc::c_int);
    pub fn rb_str_to_str(_: VALUE) -> VALUE;
    pub fn rb_string_value(_: *mut VALUE) -> VALUE;
    pub fn rb_string_value_ptr(_: *mut VALUE) -> *mut libc::c_char;
    pub fn rb_check_safe_obj(_: VALUE);
    pub fn rb_str_export(_: VALUE) -> VALUE;
    pub fn rb_str_export_locale(_: VALUE) -> VALUE;
    pub fn rb_get_path(_: VALUE) -> VALUE;
    pub fn rb_get_path_no_checksafe(_: VALUE) -> VALUE;
    pub fn rb_secure(_: libc::c_int);
    pub fn rb_safe_level() -> libc::c_int;
    pub fn rb_set_safe_level(_: libc::c_int);
    pub fn rb_set_safe_level_force(_: libc::c_int);

    pub fn rb_num2dbl(_: VALUE) -> libc::c_double;
    pub fn rb_num2long(_: VALUE) -> libc::c_long;
    pub fn rb_num2ulong(_: VALUE) -> libc::c_ulong;

    pub fn rb_num2uint(_: VALUE) -> libc::c_ulong;
    pub fn rb_fix2uint(_: VALUE) -> libc::c_ulong;

    pub fn rb_num2short(_: VALUE) -> libc::c_short;
    pub fn rb_num2ushort(_: VALUE) -> libc::c_ushort;
    pub fn rb_fix2short(_: VALUE) -> libc::c_short;
    pub fn rb_fix2ushort(_: VALUE) -> libc::c_ushort;

    pub fn rb_newobj() -> VALUE;
    pub fn rb_newobj_of(_: VALUE, _: VALUE) -> VALUE;
    pub fn rb_obj_setup(obj: VALUE, klass: VALUE, ty: VALUE) -> VALUE;

    pub fn rb_float_new(_: libc::c_double) -> VALUE;
    pub fn rb_float_new_in_heap(_: libc::c_double) -> VALUE;
}

#[allow(non_snake_case)]
pub fn INT2FIX(i: INNER_VALUE) -> VALUE {
    VALUE(((i<<1) as INNER_VALUE) | (FIXNUM_FLAG.0 as INNER_VALUE))
}