rb-sys 0.9.127

Rust bindings for the CRuby API
Documentation
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
use super::StableApiDefinition;
use crate::{ruby_value_type, timeval, RUBY_API_VERSION_MAJOR, RUBY_API_VERSION_MINOR, VALUE};
use std::{
    ffi::c_void,
    os::raw::{c_char, c_int, c_long},
    ptr::NonNull,
    time::Duration,
};

#[allow(dead_code)]
extern "C" {
    #[link_name = "impl_rstring_len"]
    fn impl_rstring_len(str: VALUE) -> c_long;

    #[link_name = "impl_rstring_ptr"]
    fn impl_rstring_ptr(str: VALUE) -> *const c_char;

    #[link_name = "impl_rarray_len"]
    fn impl_rarray_len(ary: VALUE) -> c_long;

    #[link_name = "impl_rarray_const_ptr"]
    fn impl_rarray_const_ptr(ary: VALUE) -> *const VALUE;

    #[link_name = "impl_rarray_aref"]
    fn impl_rarray_aref(ary: VALUE, idx: c_long) -> VALUE;

    #[link_name = "impl_rarray_aset"]
    fn impl_rarray_aset(ary: VALUE, idx: c_long, val: VALUE);

    #[link_name = "impl_rbasic_class"]
    fn impl_rbasic_class(obj: VALUE) -> VALUE;

    #[link_name = "impl_frozen_p"]
    fn impl_frozen_p(obj: VALUE) -> bool;

    #[link_name = "impl_special_const_p"]
    fn impl_special_const_p(value: VALUE) -> bool;

    #[link_name = "impl_bignum_positive_p"]
    fn impl_bignum_positive_p(obj: VALUE) -> bool;

    #[link_name = "impl_bignum_negative_p"]
    fn impl_bignum_negative_p(obj: VALUE) -> bool;

    #[link_name = "impl_builtin_type"]
    fn impl_builtin_type(obj: VALUE) -> ruby_value_type;

    #[link_name = "impl_nil_p"]
    fn impl_nil_p(obj: VALUE) -> bool;

    #[link_name = "impl_fixnum_p"]
    fn impl_fixnum_p(obj: VALUE) -> bool;

    #[link_name = "impl_static_sym_p"]
    fn impl_static_sym_p(obj: VALUE) -> bool;

    #[link_name = "impl_flonum_p"]
    fn impl_flonum_p(obj: VALUE) -> bool;

    #[link_name = "impl_immediate_p"]
    fn impl_immediate_p(obj: VALUE) -> bool;

    #[link_name = "impl_rb_test"]
    fn impl_rb_test(obj: VALUE) -> bool;

    #[link_name = "impl_type_p"]
    fn impl_type_p(obj: VALUE, ty: ruby_value_type) -> bool;

    #[link_name = "impl_dynamic_sym_p"]
    fn impl_dynamic_sym_p(obj: VALUE) -> bool;

    #[link_name = "impl_symbol_p"]
    fn impl_symbol_p(obj: VALUE) -> bool;

    #[link_name = "impl_float_type_p"]
    fn impl_float_type_p(obj: VALUE) -> bool;

    #[link_name = "impl_rb_type"]
    fn impl_rb_type(obj: VALUE) -> ruby_value_type;

    #[link_name = "impl_integer_type_p"]
    fn impl_integer_type_p(obj: VALUE) -> bool;

    #[link_name = "impl_rstring_interned_p"]
    fn impl_rstring_interned_p(obj: VALUE) -> bool;

    #[link_name = "impl_thread_sleep"]
    fn impl_thread_sleep(interval: timeval);

    // RTypedData functions
    #[link_name = "impl_rtypeddata_p"]
    fn impl_rtypeddata_p(obj: VALUE) -> bool;

    #[link_name = "impl_rtypeddata_type"]
    fn impl_rtypeddata_type(obj: VALUE) -> *const crate::rb_data_type_t;

    #[link_name = "impl_rtypeddata_get_data"]
    fn impl_rtypeddata_get_data(obj: VALUE) -> *mut c_void;

    // Accessor functions
    #[link_name = "impl_rstring_end"]
    fn impl_rstring_end(obj: VALUE) -> *const c_char;

    #[link_name = "impl_rdata_ptr"]
    fn impl_rdata_ptr(obj: VALUE) -> *mut c_void;

    #[link_name = "impl_rb_obj_freeze"]
    fn impl_rb_obj_freeze(obj: VALUE);

    #[link_name = "impl_rb_obj_promoted"]
    fn impl_rb_obj_promoted(obj: VALUE) -> c_int;

    #[link_name = "impl_rb_obj_promoted_raw"]
    fn impl_rb_obj_promoted_raw(obj: VALUE) -> c_int;

    #[link_name = "impl_num2dbl"]
    fn impl_num2dbl(obj: VALUE) -> f64;

    #[link_name = "impl_dbl2num"]
    fn impl_dbl2num(val: f64) -> VALUE;

    #[link_name = "impl_rhash_size"]
    fn impl_rhash_size(obj: VALUE) -> usize;

    #[link_name = "impl_rhash_empty_p"]
    fn impl_rhash_empty_p(obj: VALUE) -> std::os::raw::c_int;

    #[link_name = "impl_encoding_get"]
    fn impl_encoding_get(obj: VALUE) -> std::os::raw::c_int;

    #[link_name = "impl_fl_able"]
    fn impl_fl_able(obj: VALUE) -> c_int;

    // Symbol/ID conversion functions
    #[link_name = "impl_id2sym"]
    fn impl_id2sym(id: crate::ID) -> VALUE;

    #[link_name = "impl_sym2id"]
    fn impl_sym2id(obj: VALUE) -> crate::ID;

    // Integer conversion functions
    #[link_name = "impl_fix2long"]
    fn impl_fix2long(obj: VALUE) -> c_long;

    #[link_name = "impl_fix2ulong"]
    fn impl_fix2ulong(obj: VALUE) -> std::os::raw::c_ulong;

    #[link_name = "impl_long2fix"]
    fn impl_long2fix(val: c_long) -> VALUE;

    #[link_name = "impl_fixable"]
    fn impl_fixable(val: c_long) -> std::os::raw::c_int;

    #[link_name = "impl_posfixable"]
    fn impl_posfixable(val: std::os::raw::c_ulong) -> std::os::raw::c_int;

    #[link_name = "impl_num2long"]
    fn impl_num2long(obj: VALUE) -> c_long;

    #[link_name = "impl_num2ulong"]
    fn impl_num2ulong(obj: VALUE) -> std::os::raw::c_ulong;

    #[link_name = "impl_long2num"]
    fn impl_long2num(val: c_long) -> VALUE;

    #[link_name = "impl_ulong2num"]
    fn impl_ulong2num(val: std::os::raw::c_ulong) -> VALUE;

    #[link_name = "impl_rb_obj_write"]
    fn impl_rb_obj_write(old: VALUE, slot: *mut VALUE, young: VALUE) -> VALUE;

    #[link_name = "impl_rb_obj_written"]
    fn impl_rb_obj_written(old: VALUE, oldv: VALUE, young: VALUE) -> VALUE;
}

pub struct Definition;

impl StableApiDefinition for Definition {
    const VERSION_MAJOR: u32 = RUBY_API_VERSION_MAJOR;
    const VERSION_MINOR: u32 = RUBY_API_VERSION_MINOR;

    #[inline]
    unsafe fn rstring_len(&self, obj: VALUE) -> std::os::raw::c_long {
        impl_rstring_len(obj)
    }

    #[inline]
    unsafe fn rstring_ptr(&self, obj: VALUE) -> *const std::os::raw::c_char {
        impl_rstring_ptr(obj)
    }

    #[inline]
    unsafe fn rarray_len(&self, obj: VALUE) -> std::os::raw::c_long {
        impl_rarray_len(obj)
    }

    #[inline]
    unsafe fn rarray_const_ptr(&self, obj: VALUE) -> *const VALUE {
        impl_rarray_const_ptr(obj)
    }

    #[inline]
    unsafe fn rarray_aref(&self, obj: VALUE, idx: isize) -> VALUE {
        impl_rarray_aref(obj, idx as c_long)
    }

    #[inline]
    unsafe fn rarray_aset(&self, obj: VALUE, idx: isize, val: VALUE) {
        impl_rarray_aset(obj, idx as c_long, val)
    }

    #[inline]
    unsafe fn rbasic_class(&self, obj: VALUE) -> Option<NonNull<VALUE>> {
        NonNull::<VALUE>::new(impl_rbasic_class(obj) as _)
    }

    unsafe fn frozen_p(&self, obj: VALUE) -> bool {
        impl_frozen_p(obj)
    }

    #[inline]
    fn special_const_p(&self, value: VALUE) -> bool {
        unsafe { impl_special_const_p(value) }
    }

    #[inline]
    unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool {
        impl_bignum_positive_p(obj)
    }

    #[inline]
    unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool {
        impl_bignum_negative_p(obj)
    }

    #[inline]
    unsafe fn builtin_type(&self, obj: VALUE) -> ruby_value_type {
        impl_builtin_type(obj)
    }

    #[inline]
    fn nil_p(&self, obj: VALUE) -> bool {
        unsafe { impl_nil_p(obj) }
    }

    #[inline]
    fn fixnum_p(&self, obj: VALUE) -> bool {
        unsafe { impl_fixnum_p(obj) }
    }

    #[inline]
    fn static_sym_p(&self, obj: VALUE) -> bool {
        unsafe { impl_static_sym_p(obj) }
    }

    #[inline]
    fn flonum_p(&self, obj: VALUE) -> bool {
        unsafe { impl_flonum_p(obj) }
    }

    #[inline]
    fn immediate_p(&self, obj: VALUE) -> bool {
        unsafe { impl_immediate_p(obj) }
    }

    #[inline]
    fn rb_test(&self, obj: VALUE) -> bool {
        unsafe { impl_rb_test(obj) }
    }

    #[inline]
    unsafe fn type_p(&self, obj: VALUE, ty: ruby_value_type) -> bool {
        impl_type_p(obj, ty)
    }

    #[inline]
    unsafe fn dynamic_sym_p(&self, obj: VALUE) -> bool {
        impl_dynamic_sym_p(obj)
    }

    #[inline]
    unsafe fn symbol_p(&self, obj: VALUE) -> bool {
        impl_symbol_p(obj)
    }

    #[inline]
    unsafe fn float_type_p(&self, obj: VALUE) -> bool {
        impl_float_type_p(obj)
    }

    #[inline]
    unsafe fn rb_type(&self, obj: VALUE) -> crate::ruby_value_type {
        impl_rb_type(obj)
    }

    #[inline]
    unsafe fn integer_type_p(&self, obj: VALUE) -> bool {
        impl_integer_type_p(obj)
    }

    #[inline]
    unsafe fn rstring_interned_p(&self, obj: VALUE) -> bool {
        impl_rstring_interned_p(obj)
    }

    #[inline]
    fn thread_sleep(&self, duration: Duration) {
        let seconds = duration.as_secs() as _;
        let microseconds = duration.subsec_micros() as _;

        let time = crate::timeval {
            tv_sec: seconds,
            tv_usec: microseconds,
        };

        unsafe { impl_thread_sleep(time) }
    }

    #[inline]
    unsafe fn rtypeddata_p(&self, obj: VALUE) -> bool {
        impl_rtypeddata_p(obj)
    }

    #[inline]
    unsafe fn rtypeddata_type(&self, obj: VALUE) -> *const crate::rb_data_type_t {
        impl_rtypeddata_type(obj)
    }

    #[inline]
    unsafe fn rtypeddata_get_data(&self, obj: VALUE) -> *mut c_void {
        impl_rtypeddata_get_data(obj)
    }

    #[inline]
    fn id2sym(&self, id: crate::ID) -> VALUE {
        unsafe { impl_id2sym(id) }
    }

    #[inline]
    unsafe fn sym2id(&self, obj: VALUE) -> crate::ID {
        impl_sym2id(obj)
    }

    #[inline]
    fn fix2long(&self, obj: VALUE) -> c_long {
        unsafe { impl_fix2long(obj) }
    }

    #[inline]
    fn fix2ulong(&self, obj: VALUE) -> std::os::raw::c_ulong {
        unsafe { impl_fix2ulong(obj) }
    }

    #[inline]
    fn long2fix(&self, val: c_long) -> VALUE {
        unsafe { impl_long2fix(val) }
    }

    #[inline]
    fn fixable(&self, val: c_long) -> bool {
        unsafe { impl_fixable(val) != 0 }
    }

    #[inline]
    fn posfixable(&self, val: std::os::raw::c_ulong) -> bool {
        unsafe { impl_posfixable(val) != 0 }
    }

    #[inline]
    unsafe fn num2long(&self, obj: VALUE) -> c_long {
        impl_num2long(obj)
    }

    #[inline]
    unsafe fn num2ulong(&self, obj: VALUE) -> std::os::raw::c_ulong {
        impl_num2ulong(obj)
    }

    #[inline]
    fn long2num(&self, val: c_long) -> VALUE {
        unsafe { impl_long2num(val) }
    }

    #[inline]
    fn ulong2num(&self, val: std::os::raw::c_ulong) -> VALUE {
        unsafe { impl_ulong2num(val) }
    }

    #[inline]
    unsafe fn rb_obj_write(&self, old: VALUE, slot: *mut VALUE, young: VALUE) -> VALUE {
        impl_rb_obj_write(old, slot, young)
    }

    #[inline]
    unsafe fn rb_obj_written(&self, old: VALUE, oldv: VALUE, young: VALUE) -> VALUE {
        impl_rb_obj_written(old, oldv, young)
    }

    #[inline]
    fn fl_able(&self, obj: VALUE) -> bool {
        unsafe { impl_fl_able(obj) != 0 }
    }

    #[inline]
    unsafe fn rstring_end(&self, obj: VALUE) -> *const c_char {
        impl_rstring_end(obj)
    }

    #[inline]
    unsafe fn rdata_ptr(&self, obj: VALUE) -> *mut c_void {
        impl_rdata_ptr(obj)
    }

    #[inline]
    unsafe fn rb_obj_freeze(&self, obj: VALUE) {
        impl_rb_obj_freeze(obj)
    }

    #[inline]
    unsafe fn rb_obj_promoted(&self, obj: VALUE) -> bool {
        impl_rb_obj_promoted(obj) != 0
    }

    #[inline]
    unsafe fn rb_obj_promoted_raw(&self, obj: VALUE) -> bool {
        impl_rb_obj_promoted_raw(obj) != 0
    }
    #[inline]
    unsafe fn num2dbl(&self, obj: VALUE) -> std::os::raw::c_double {
        impl_num2dbl(obj)
    }

    #[inline]
    fn dbl2num(&self, val: std::os::raw::c_double) -> VALUE {
        unsafe { impl_dbl2num(val) }
    }

    #[inline]
    unsafe fn rhash_size(&self, obj: VALUE) -> usize {
        impl_rhash_size(obj)
    }

    #[inline]
    unsafe fn rhash_empty_p(&self, obj: VALUE) -> bool {
        impl_rhash_empty_p(obj) != 0
    }

    #[inline]
    unsafe fn encoding_get(&self, obj: VALUE) -> std::os::raw::c_int {
        impl_encoding_get(obj)
    }
}