Ruby 4.1.0dev (2026-09-21 revision 61de3dd727146cfcf24e8051595bb2fb842f37aa)
yjit.c (61de3dd727146cfcf24e8051595bb2fb842f37aa)
1// This part of YJIT helps interfacing with the rest of CRuby and with the OS.
2// Sometimes our FFI binding generation tool gives undesirable outputs when it
3// sees C features that Rust doesn't support well. We mitigate that by binding
4// functions which have simple parameter types. The boilerplate C functions for
5// that purpose are in this file.
6// Similarly, we wrap OS facilities we need in simple functions to help with
7// FFI and to avoid the need to use external crates.io Rust libraries.
8
9#include "internal.h"
10#include "internal/sanitizers.h"
11#include "internal/string.h"
12#include "internal/hash.h"
13#include "internal/variable.h"
14#include "internal/compile.h"
15#include "internal/class.h"
16#include "internal/fixnum.h"
17#include "internal/numeric.h"
18#include "internal/gc.h"
19#include "vm_core.h"
20#include "vm_callinfo.h"
21#include "builtin.h"
22#include "insns.inc"
23#include "insns_info.inc"
24#include "yjit.h"
25#include "zjit.h"
26#include "vm_insnhelper.h"
27#include "probes.h"
28#include "probes_helper.h"
29#include "iseq.h"
30#include "ruby/debug.h"
31#include "internal/cont.h"
32#include "internal/jit.h"
33
34// For mmapp(), sysconf()
35#ifndef _WIN32
36#include <unistd.h>
37#include <sys/mman.h>
38#endif
39
40#include <errno.h>
41
42// We need size_t to have a known size to simplify code generation and FFI.
43// TODO(alan): check this in configure.ac to fail fast on 32 bit platforms.
44STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
45// I don't know any C implementation that has uint64_t and puts padding bits
46// into size_t but the standard seems to allow it.
47STATIC_ASSERT(size_t_no_padding_bits, sizeof(size_t) == sizeof(uint64_t));
48
49// This build config impacts the pointer tagging scheme and we only want to
50// support one scheme for simplicity.
51STATIC_ASSERT(pointer_tagging_scheme, USE_FLONUM);
52
53enum yjit_bindgen_constants {
54 // ISEQ_TRANSLATED expands to an enum value through a chain of macros,
55 // which bindgen cannot evaluate, so it needs to be re-exposed here.
56 YJIT_ISEQ_TRANSLATED = ISEQ_TRANSLATED,
57};
58
59// NOTE: We can trust that uint8_t has no "padding bits" since the C spec
60// guarantees it. Wording about padding bits is more explicit in C11 compared
61// to C99. See C11 7.20.1.1p2. All this is to say we have _some_ standards backing to
62// use a Rust `*mut u8` to represent a C `uint8_t *`.
63//
64// If we don't want to trust that we can interpreter the C standard correctly, we
65// could outsource that work to the Rust standard library by sticking to fundamental
66// types in C such as int, long, etc. and use `std::os::raw::c_long` and friends on
67// the Rust side.
68//
69// What's up with the long prefix? Even though we build with `-fvisibility=hidden`
70// we are sometimes a static library where the option doesn't prevent name collision.
71// The "_yjit_" part is for trying to be informative. We might want different
72// suffixes for symbols meant for Rust and symbols meant for broader CRuby.
73
74// For a given raw_sample (frame), set the hash with the caller's
75// name, file, and line number. Return the hash with collected frame_info.
76static void
77rb_yjit_add_frame(VALUE hash, VALUE frame)
78{
79 VALUE frame_id = PTR2NUM(frame);
80
81 if (RTEST(rb_hash_aref(hash, frame_id))) {
82 return;
83 }
84 else {
85 VALUE frame_info = rb_hash_new();
86 // Full label for the frame
88 // Absolute path of the frame from rb_iseq_realpath
90 // Line number of the frame
92
93 // If absolute path isn't available use the rb_iseq_path
94 if (NIL_P(file)) {
95 file = rb_profile_frame_path(frame);
96 }
97
98 rb_hash_aset(frame_info, ID2SYM(rb_intern("name")), name);
99 rb_hash_aset(frame_info, ID2SYM(rb_intern("file")), file);
100 rb_hash_aset(frame_info, ID2SYM(rb_intern("samples")), INT2NUM(0));
101 rb_hash_aset(frame_info, ID2SYM(rb_intern("total_samples")), INT2NUM(0));
102 rb_hash_aset(frame_info, ID2SYM(rb_intern("edges")), rb_hash_new());
103 rb_hash_aset(frame_info, ID2SYM(rb_intern("lines")), rb_hash_new());
104
105 if (line != INT2FIX(0)) {
106 rb_hash_aset(frame_info, ID2SYM(rb_intern("line")), line);
107 }
108
109 rb_hash_aset(hash, frame_id, frame_info);
110 }
111}
112
113// Parses the YjitExitLocations raw_samples and line_samples collected by
114// rb_yjit_record_exit_stack and turns them into 3 hashes (raw, lines, and frames) to
115// be used by RubyVM::YJIT.exit_locations. yjit_raw_samples represents the raw frames information
116// (without name, file, and line), and yjit_line_samples represents the line information
117// of the iseq caller.
118VALUE
119rb_yjit_exit_locations_dict(VALUE *yjit_raw_samples, int *yjit_line_samples, int samples_len)
120{
121 VALUE result = rb_hash_new();
122 VALUE raw_samples = rb_ary_new_capa(samples_len);
123 VALUE line_samples = rb_ary_new_capa(samples_len);
124 VALUE frames = rb_hash_new();
125 int idx = 0;
126
127 // While the index is less than samples_len, parse yjit_raw_samples and
128 // yjit_line_samples, then add casted values to raw_samples and line_samples array.
129 while (idx < samples_len) {
130 int num = (int)yjit_raw_samples[idx];
131 int line_num = (int)yjit_line_samples[idx];
132 idx++;
133
134 // + 1 as we append an additional sample for the insn
135 rb_ary_push(raw_samples, SIZET2NUM(num + 1));
136 rb_ary_push(line_samples, INT2NUM(line_num + 1));
137
138 // Loop through the length of samples_len and add data to the
139 // frames hash. Also push the current value onto the raw_samples
140 // and line_samples array respectively.
141 for (int o = 0; o < num; o++) {
142 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
143 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
144 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
145 idx++;
146 }
147
148 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
149 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
150 idx++;
151
152 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
153 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
154 idx++;
155 }
156
157 // Set add the raw_samples, line_samples, and frames to the results
158 // hash.
159 rb_hash_aset(result, ID2SYM(rb_intern("raw")), raw_samples);
160 rb_hash_aset(result, ID2SYM(rb_intern("lines")), line_samples);
161 rb_hash_aset(result, ID2SYM(rb_intern("frames")), frames);
162
163 return result;
164}
165
166// Is anyone listening for :c_call and :c_return event currently?
167bool
168rb_c_method_tracing_currently_enabled(const rb_execution_context_t *ec)
169{
170 return ruby_vm_c_events_enabled > 0;
171}
172
173// The code we generate in gen_send_cfunc() doesn't fire the c_return TracePoint event
174// like the interpreter. When tracing for c_return is enabled, we patch the code after
175// the C method return to call into this to fire the event.
176void
177rb_full_cfunc_return(rb_execution_context_t *ec, VALUE return_value)
178{
179 rb_control_frame_t *cfp = ec->cfp;
180 RUBY_ASSERT_ALWAYS(cfp == GET_EC()->cfp);
181 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
182
183 RUBY_ASSERT_ALWAYS(RUBYVM_CFUNC_FRAME_P(cfp));
184 RUBY_ASSERT_ALWAYS(me->def->type == VM_METHOD_TYPE_CFUNC);
185
186 // CHECK_CFP_CONSISTENCY("full_cfunc_return"); TODO revive this
187
188 // Pop the C func's frame and fire the c_return TracePoint event
189 // Note that this is the same order as vm_call_cfunc_with_frame().
190 rb_vm_pop_frame(ec);
191 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
192 // Note, this deviates from the interpreter in that users need to enable
193 // a c_return TracePoint for this DTrace hook to work. A reasonable change
194 // since the Ruby return event works this way as well.
195 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
196
197 // Push return value into the caller's stack. We know that it's a frame that
198 // uses cfp->sp because we are patching a call done with gen_send_cfunc().
199 ec->cfp->sp[0] = return_value;
200 ec->cfp->sp++;
201}
202
203// This is defined only as a named struct inside rb_iseq_constant_body.
204// By giving it a separate typedef, we make it nameable by rust-bindgen.
205// Bindgen's temp/anon name isn't guaranteed stable.
206typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
207
208ID rb_get_symbol_id(VALUE namep);
209
210// If true, the iseq has only opt_invokebuiltin_delegate(_leave) and leave insns.
211static bool
212invokebuiltin_delegate_leave_p(const rb_iseq_t *iseq)
213{
214 int insn1 = rb_vm_insn_addr2opcode((void *)ISEQ_BODY(iseq)->iseq_encoded[0]);
215 if ((int)ISEQ_BODY(iseq)->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
216 return false;
217 }
218 int insn2 = rb_vm_insn_addr2opcode((void *)ISEQ_BODY(iseq)->iseq_encoded[insn_len(insn1)]);
219 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
220 insn2 == BIN(leave);
221}
222
223// Return an rb_builtin_function if the iseq contains only that builtin function.
224const struct rb_builtin_function *
225rb_yjit_builtin_function(const rb_iseq_t *iseq)
226{
227 if (invokebuiltin_delegate_leave_p(iseq)) {
228 return (const struct rb_builtin_function *)ISEQ_BODY(iseq)->iseq_encoded[1];
229 }
230 else {
231 return NULL;
232 }
233}
234
235extern VALUE *rb_vm_base_ptr(struct rb_control_frame_struct *cfp);
236
237VALUE
238rb_str_neq_internal(VALUE str1, VALUE str2)
239{
240 return rb_str_eql_internal(str1, str2) == Qtrue ? Qfalse : Qtrue;
241}
242
243extern VALUE rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary);
244
245VALUE
246rb_yjit_rb_ary_subseq_length(VALUE ary, long beg)
247{
248 long len = RARRAY_LEN(ary);
249 return rb_ary_subseq(ary, beg, len);
250}
251
252// Checks to establish preconditions for rb_yjit_splat_varg_cfunc()
253VALUE
254rb_yjit_splat_varg_checks(VALUE *sp, VALUE splat_array, rb_control_frame_t *cfp)
255{
256 // We inserted a T_ARRAY guard before this call
257 long len = RARRAY_LEN(splat_array);
258
259 // Large splat arrays need a separate allocation
260 if (len < 0 || len > VM_ARGC_STACK_MAX) return Qfalse;
261
262 // Would we overflow if we put the contents of the array onto the stack?
263 if (sp + len > (VALUE *)(cfp - 2)) return Qfalse;
264
265 // Reject keywords hash since that requires duping it sometimes
266 if (len > 0) {
267 VALUE last_hash = RARRAY_AREF(splat_array, len - 1);
268 if (RB_TYPE_P(last_hash, T_HASH) &&
269 FL_TEST_RAW(last_hash, RHASH_PASS_AS_KEYWORDS)) {
270 return Qfalse;
271 }
272 }
273
274 return Qtrue;
275}
276
277// Push array elements to the stack for a C method that has a variable number
278// of parameters. Returns the number of arguments the splat array contributes.
279int
280rb_yjit_splat_varg_cfunc(VALUE *stack_splat_array)
281{
282 VALUE splat_array = *stack_splat_array;
283 int len;
284
285 // We already checked that length fits in `int`
286 RUBY_ASSERT(RB_TYPE_P(splat_array, T_ARRAY));
287 len = (int)RARRAY_LEN(splat_array);
288
289 // Push the contents of the array onto the stack
290 MEMCPY(stack_splat_array, RARRAY_CONST_PTR(splat_array), VALUE, len);
291
292 return len;
293}
294
295// Print the Ruby source location of some ISEQ for debugging purposes
296void
297rb_yjit_dump_iseq_loc(const rb_iseq_t *iseq, uint32_t insn_idx)
298{
299 char *ptr;
300 long len;
301 VALUE path = rb_iseq_path(iseq);
302 RSTRING_GETMEM(path, ptr, len);
303 fprintf(stderr, "%s %.*s:%u\n", __func__, (int)len, ptr, rb_iseq_line_no(iseq, insn_idx));
304}
305
306// Get the number of digits required to print an integer
307static int
308num_digits(int integer)
309{
310 int num = 1;
311 while (integer /= 10) {
312 num++;
313 }
314 return num;
315}
316
317// Allocate a C string that formats an ISEQ label like iseq_inspect()
318char *
319rb_yjit_iseq_inspect(const rb_iseq_t *iseq)
320{
321 const char *label = RSTRING_PTR(ISEQ_BODY(iseq)->location.label);
322 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
323 int lineno = ISEQ_BODY(iseq)->location.code_location.beg_pos.lineno;
324
325 const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
326 char *buf = ZALLOC_N(char, size);
327 snprintf(buf, size, "%s@%s:%d", label, path, lineno);
328 return buf;
329}
330
331// There are RSTRUCT_SETs in ruby/internal/core/rstruct.h and internal/struct.h
332// with different types (int vs long) for k. Here we use the one from ruby/internal/core/rstruct.h,
333// which takes an int.
334void
335rb_RSTRUCT_SET(VALUE st, int k, VALUE v)
336{
337 RSTRUCT_SET(st, k, v);
338}
339
340// Return the string encoding index
341int
342rb_ENCODING_GET(VALUE obj)
343{
344 return RB_ENCODING_GET(obj);
345}
346
347// For running write barriers from Rust. Required when we add a new edge in the
348// object graph from `old` to `young`.
349void
350rb_yjit_obj_written(VALUE old, VALUE young, const char *file, int line)
351{
352 rb_obj_written(old, Qundef, young, file, line);
353}
354
355void
356rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
357{
358 RB_VM_LOCKING() {
359 rb_vm_barrier();
360
361 // Compile a block version starting at the current instruction
362 uint8_t *rb_yjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception); // defined in Rust
363 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
364
365 if (jit_exception) {
366 ISEQ_BODY(iseq)->jit_exception = (rb_jit_func_t)code_ptr;
367 }
368 else {
369 ISEQ_BODY(iseq)->jit_entry = (rb_jit_func_t)code_ptr;
370 }
371 }
372}
373
374// GC root for interacting with the GC
376 bool unused; // empty structs are not legal in C99
377};
378
379// For dealing with refinements
380void
381rb_yjit_invalidate_all_method_lookup_assumptions(void)
382{
383 // It looks like Module#using actually doesn't need to invalidate all the
384 // method caches, so we do nothing here for now.
385}
386
387// Number of object shapes, which might be useful for investigating YJIT exit reasons.
388VALUE
389rb_object_shape_count(void)
390{
391 // next_shape_id starts from 0, so it's the same as the count
392 return ULONG2NUM((unsigned long)rb_shapes_count());
393}
394
395bool
396rb_yjit_shape_obj_complex_p(VALUE obj)
397{
398 return rb_obj_shape_complex_p(obj);
399}
400
401bool
402rb_yjit_shape_obj_embedded_p(VALUE obj)
403{
404 return rb_obj_shape_embedded_p(obj);
405}
406
407attr_index_t
408rb_yjit_shape_capacity(shape_id_t shape_id)
409{
410 return RSHAPE_CAPACITY(shape_id);
411}
412
413attr_index_t
414rb_yjit_shape_index(shape_id_t shape_id)
415{
416 return RSHAPE_INDEX(shape_id);
417}
418
419// The number of stack slots that vm_sendish() pops for send and invokesuper.
420size_t
421rb_yjit_sendish_sp_pops(const struct rb_callinfo *ci)
422{
423 return 1 - sp_inc_of_sendish(ci); // + 1 to ignore return value push
424}
425
426// The number of stack slots that vm_sendish() pops for invokeblock.
427size_t
428rb_yjit_invokeblock_sp_pops(const struct rb_callinfo *ci)
429{
430 return 1 - sp_inc_of_invokeblock(ci); // + 1 to ignore return value push
431}
432
433rb_serial_t
434rb_yjit_cme_ractor_serial(const rb_callable_method_entry_t *cme)
435{
436 return cme->def->body.bmethod.defined_ractor_id;
437}
438
439// Setup jit_return to avoid returning a non-Qundef value on a non-FINISH frame.
440// See [jit_compile_exception] for details.
441void
442rb_yjit_set_exception_return(rb_control_frame_t *cfp, void *leave_exit, void *leave_exception)
443{
444 if (VM_FRAME_FINISHED_P(cfp)) {
445 // If it's a FINISH frame, just normally exit with a non-Qundef value.
446 cfp->jit_return = leave_exit;
447 }
448 else if (cfp->jit_return) {
449 while (!VM_FRAME_FINISHED_P(cfp)) {
450 if (cfp->jit_return == leave_exit) {
451 // Unlike jit_exec(), leave_exit is not safe on a non-FINISH frame on
452 // jit_exec_exception(). See [jit_exec] and [jit_exec_exception] for
453 // details. Exit to the interpreter with Qundef to let it keep executing
454 // other Ruby frames.
455 cfp->jit_return = leave_exception;
456 return;
457 }
458 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
459 }
460 }
461 else {
462 // If the caller was not JIT code, exit to the interpreter with Qundef
463 // to keep executing Ruby frames with the interpreter.
464 cfp->jit_return = leave_exception;
465 }
466}
467
468// VM_INSTRUCTION_SIZE changes depending on if ZJIT is in the build. Since
469// bindgen can only grab one version of the constant and copy that to rust,
470// we make that the upper bound and this the accurate value.
471uint32_t
472rb_vm_instruction_size(void)
473{
474 return VM_INSTRUCTION_SIZE;
475}
476
477static int
478yjit_cdhash_all_fixnum_i(st_data_t key, st_data_t _val, st_data_t data)
479{
480 if (!FIXNUM_P((VALUE)key)) {
481 *((bool *)data) = false;
482 return ST_STOP;
483 }
484 return ST_CONTINUE;
485}
486
487bool
488rb_yjit_cdhash_all_fixnum_p(VALUE cdhash)
489{
490 bool all_fixnum = true;
491 st_foreach(rb_imemo_cdhash_tbl(cdhash), yjit_cdhash_all_fixnum_i, (st_data_t)&all_fixnum);
492 return all_fixnum;
493}
494
495int
496rb_yjit_cdhash_lookup(VALUE cdhash, st_data_t key, st_data_t *val)
497{
498 return st_lookup(rb_imemo_cdhash_tbl(cdhash), key, val);
499}
500
501// Primitives used by yjit.rb
502VALUE rb_yjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self);
503VALUE rb_yjit_print_stats_p(rb_execution_context_t *ec, VALUE self);
504VALUE rb_yjit_log_enabled_p(rb_execution_context_t *c, VALUE self);
505VALUE rb_yjit_print_log_p(rb_execution_context_t *c, VALUE self);
506VALUE rb_yjit_trace_exit_locations_enabled_p(rb_execution_context_t *ec, VALUE self);
507VALUE rb_yjit_get_stats(rb_execution_context_t *ec, VALUE self, VALUE key);
508VALUE rb_yjit_reset_stats_bang(rb_execution_context_t *ec, VALUE self);
509VALUE rb_yjit_get_log(rb_execution_context_t *ec, VALUE self);
510VALUE rb_yjit_disasm_iseq(rb_execution_context_t *ec, VALUE self, VALUE iseq);
511VALUE rb_yjit_insns_compiled(rb_execution_context_t *ec, VALUE self, VALUE iseq);
512VALUE rb_yjit_code_gc(rb_execution_context_t *ec, VALUE self);
513VALUE rb_yjit_simulate_oom_bang(rb_execution_context_t *ec, VALUE self);
514VALUE rb_yjit_get_exit_locations(rb_execution_context_t *ec, VALUE self);
515VALUE rb_yjit_enable(rb_execution_context_t *ec, VALUE self, VALUE gen_stats, VALUE print_stats, VALUE gen_compilation_log, VALUE print_compilation_log, VALUE mem_size, VALUE call_threshold);
516VALUE rb_yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self);
517
518// Allow YJIT_C_BUILTIN macro to force --yjit-c-builtin
519#ifdef YJIT_C_BUILTIN
520static VALUE yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self) { return Qtrue; }
521#else
522#define yjit_c_builtin_p rb_yjit_c_builtin_p
523#endif
524
525// Preprocessed yjit.rb generated during build
526#include "yjit.rbinc"
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
Definition assert.h:199
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
VALUE rb_profile_frame_absolute_path(VALUE frame)
Identical to rb_profile_frame_path(), except it tries to expand the returning path.
VALUE rb_profile_frame_path(VALUE frame)
Queries the path of the passed backtrace.
VALUE rb_profile_frame_first_lineno(VALUE frame)
Queries the first line of the method of the passed frame pointer.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
Definition event.h:44
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
Definition long.h:48
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
#define ULONG2NUM
Old name of RB_ULONG2NUM.
Definition long.h:60
#define SIZET2NUM
Old name of RB_SIZE2NUM.
Definition size_t.h:62
#define ZALLOC_N
Old name of RB_ZALLOC_N.
Definition memory.h:401
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:128
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
Definition int.h:43
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
Definition value_type.h:56
#define NIL_P
Old name of RB_NIL_P.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
static int RB_ENCODING_GET(VALUE obj)
Just another name of rb_enc_get_index.
Definition encoding.h:195
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Obtains a part of the passed array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
int len
Length of the buffer.
Definition io.h:8
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:50
#define RARRAY_AREF(a, i)
Definition rarray.h:402
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:51
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
Definition rstring.h:450
static VALUE RSTRUCT_SET(VALUE st, int k, VALUE v)
Resembles Struct#[]=.
Definition rstruct.h:92
#define RTEST
This is an old name of RB_TEST.
#define USE_FLONUM
Definition method.h:63
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:376