Ruby: vm_args.c Source File

Ruby 3.4.9p82 (2026-03-11 revision 76cca827ab52ab1d346a728f068d5b8da3e2952b)

vm_args.c
1/**********************************************************************
2
3 vm_args.c - process method call arguments.
4
5 $Author$
6
7 Copyright (C) 2014- Yukihiro Matsumoto
8
9**********************************************************************/
10
11NORETURN(static void raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc));
12NORETURN(static void argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc));
13NORETURN(static void argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const char *error, const VALUE keys));
14 VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
15static VALUE method_missing(rb_execution_context_t *ec, VALUE obj, ID id, int argc, const VALUE *argv,
16 enum method_missing_reason call_status, int kw_splat);
17const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
18
19 struct args_info {
20 /* basic args info */
21 VALUE *argv;
22 int argc;
23
24 /* additional args info */
25 int rest_index;
26 int rest_dupped;
27 const struct rb_callinfo_kwarg *kw_arg;
28 VALUE *kw_argv;
29 VALUE rest;
30};
31
32enum arg_setup_type {
33 arg_setup_method,
34 arg_setup_block
35};
36
37static inline void
38arg_rest_dup(struct args_info *args)
39{
40 if (!args->rest_dupped) {
41 args->rest = rb_ary_dup(args->rest);
42 args->rest_dupped = TRUE;
43 }
44}
45
46static inline int
47args_argc(struct args_info *args)
48{
49 if (args->rest == Qfalse) {
50 return args->argc;
51 }
52 else {
53 return args->argc + RARRAY_LENINT(args->rest) - args->rest_index;
54 }
55}
56
57static inline void
58args_extend(struct args_info *args, const int min_argc)
59{
60 int i;
61
62 if (args->rest) {
63 arg_rest_dup(args);
64 VM_ASSERT(args->rest_index == 0);
65 for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) {
66 rb_ary_push(args->rest, Qnil);
67 }
68 }
69 else {
70 for (i=args->argc; i<min_argc; i++) {
71 args->argv[args->argc++] = Qnil;
72 }
73 }
74}
75
76static inline void
77args_reduce(struct args_info *args, int over_argc)
78{
79 if (args->rest) {
80 const long len = RARRAY_LEN(args->rest);
81
82 if (len > over_argc) {
83 arg_rest_dup(args);
84 rb_ary_resize(args->rest, len - over_argc);
85 return;
86 }
87 else {
88 args->rest = Qfalse;
89 over_argc -= len;
90 }
91 }
92
93 VM_ASSERT(args->argc >= over_argc);
94 args->argc -= over_argc;
95}
96
97static inline int
98args_check_block_arg0(struct args_info *args)
99{
100 VALUE ary = Qnil;
101
102 if (args->rest && RARRAY_LEN(args->rest) == 1) {
103 VALUE arg0 = RARRAY_AREF(args->rest, 0);
104 ary = rb_check_array_type(arg0);
105 }
106 else if (args->argc == 1) {
107 VALUE arg0 = args->argv[0];
108 ary = rb_check_array_type(arg0);
109 args->argv[0] = arg0; /* see: https://bugs.ruby-lang.org/issues/8484 */
110 }
111
112 if (!NIL_P(ary)) {
113 args->rest = ary;
114 args->rest_index = 0;
115 args->argc = 0;
116 return TRUE;
117 }
118
119 return FALSE;
120}
121
122static inline void
123args_copy(struct args_info *args)
124{
125 if (args->rest != Qfalse) {
126 int argc = args->argc;
127 args->argc = 0;
128 arg_rest_dup(args);
129
130 /*
131 * argv: [m0, m1, m2, m3]
132 * rest: [a0, a1, a2, a3, a4, a5]
133 * ^
134 * rest_index
135 *
136 * #=> first loop
137 *
138 * argv: [m0, m1]
139 * rest: [m2, m3, a2, a3, a4, a5]
140 * ^
141 * rest_index
142 *
143 * #=> 2nd loop
144 *
145 * argv: [] (argc == 0)
146 * rest: [m0, m1, m2, m3, a2, a3, a4, a5]
147 * ^
148 * rest_index
149 */
150 while (args->rest_index > 0 && argc > 0) {
151 RARRAY_ASET(args->rest, --args->rest_index, args->argv[--argc]);
152 }
153 while (argc > 0) {
154 rb_ary_unshift(args->rest, args->argv[--argc]);
155 }
156 }
157 else if (args->argc > 0) {
158 args->rest = rb_ary_new_from_values(args->argc, args->argv);
159 args->rest_index = 0;
160 args->rest_dupped = TRUE;
161 args->argc = 0;
162 }
163}
164
165static inline const VALUE *
166args_rest_argv(struct args_info *args)
167{
168 return RARRAY_CONST_PTR(args->rest) + args->rest_index;
169}
170
171static inline VALUE
172args_rest_array(struct args_info *args)
173{
174 VALUE ary;
175
176 if (args->rest) {
177 ary = rb_ary_behead(args->rest, args->rest_index);
178 args->rest_index = 0;
179 args->rest = 0;
180 }
181 else {
182 ary = rb_ary_new();
183 }
184 return ary;
185}
186
187static int
188args_kw_argv_to_hash(struct args_info *args)
189{
190 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
191 const VALUE *const passed_keywords = kw_arg->keywords;
192 const int kw_len = kw_arg->keyword_len;
193 VALUE h = rb_hash_new_with_size(kw_len);
194 const int kw_start = args->argc - kw_len;
195 const VALUE * const kw_argv = args->argv + kw_start;
196 int i;
197
198 args->argc = kw_start + 1;
199 for (i=0; i<kw_len; i++) {
200 rb_hash_aset(h, passed_keywords[i], kw_argv[i]);
201 }
202
203 args->argv[args->argc - 1] = h;
204
205 return args->argc;
206}
207
208static inline void
209args_setup_lead_parameters(struct args_info *args, int argc, VALUE *locals)
210{
211 if (args->argc >= argc) {
212 /* do noting */
213 args->argc -= argc;
214 args->argv += argc;
215 }
216 else {
217 int i, j;
218 const VALUE *argv = args_rest_argv(args);
219
220 for (i=args->argc, j=0; i<argc; i++, j++) {
221 locals[i] = argv[j];
222 }
223 args->rest_index += argc - args->argc;
224 args->argc = 0;
225 }
226}
227
228static inline void
229args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
230{
231 long len;
232 len = RARRAY_LEN(args->rest);
233 MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc);
234 rb_ary_resize(args->rest, len - argc);
235}
236
237static inline int
238args_setup_opt_parameters(struct args_info *args, int opt_max, VALUE *locals)
239{
240 int i;
241
242 if (args->argc >= opt_max) {
243 args->argc -= opt_max;
244 args->argv += opt_max;
245 i = opt_max;
246 }
247 else {
248 int j;
249 i = args->argc;
250 args->argc = 0;
251
252 if (args->rest) {
253 int len = RARRAY_LENINT(args->rest);
254 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
255
256 for (; i<opt_max && args->rest_index < len; i++, args->rest_index++) {
257 locals[i] = argv[args->rest_index];
258 }
259 }
260
261 /* initialize by nil */
262 for (j=i; j<opt_max; j++) {
263 locals[j] = Qnil;
264 }
265 }
266
267 return i;
268}
269
270static inline void
271args_setup_rest_parameter(struct args_info *args, VALUE *locals)
272{
273 *locals = args_rest_array(args);
274}
275
276static VALUE
277make_unknown_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
278{
279 int i;
280 VALUE obj = rb_ary_hidden_new(1);
281
282 for (i=0; i<passed_keyword_len; i++) {
283 if (!UNDEF_P(kw_argv[i])) {
284 rb_ary_push(obj, passed_keywords[i]);
285 }
286 }
287 return obj;
288}
289
290static VALUE
291make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
292{
293 int i;
294 VALUE obj = rb_hash_new_with_size(passed_keyword_len);
295
296 for (i=0; i<passed_keyword_len; i++) {
297 if (!UNDEF_P(kw_argv[i])) {
298 rb_hash_aset(obj, passed_keywords[i], kw_argv[i]);
299 }
300 }
301 return obj;
302}
303
304static inline int
305args_setup_kw_parameters_lookup(const ID key, VALUE *ptr, const VALUE *const passed_keywords, VALUE *passed_values, const int passed_keyword_len)
306{
307 int i;
308 const VALUE keyname = ID2SYM(key);
309
310 for (i=0; i<passed_keyword_len; i++) {
311 if (keyname == passed_keywords[i]) {
312 *ptr = passed_values[i];
313 passed_values[i] = Qundef;
314 return TRUE;
315 }
316 }
317
318 return FALSE;
319}
320
321#define KW_SPECIFIED_BITS_MAX (32-1) /* TODO: 32 -> Fixnum's max bits */
322
323static void
324args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq,
325 VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
326 VALUE *const locals)
327{
328 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
329 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
330 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
331 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
332 VALUE missing = 0;
333 int i, di, found = 0;
334 int unspecified_bits = 0;
335 VALUE unspecified_bits_value = Qnil;
336
337 for (i=0; i<req_key_num; i++) {
338 ID key = acceptable_keywords[i];
339 if (args_setup_kw_parameters_lookup(key, &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
340 found++;
341 }
342 else {
343 if (!missing) missing = rb_ary_hidden_new(1);
344 rb_ary_push(missing, ID2SYM(key));
345 }
346 }
347
348 if (missing) argument_kw_error(ec, iseq, "missing", missing);
349
350 for (di=0; i<key_num; i++, di++) {
351 if (args_setup_kw_parameters_lookup(acceptable_keywords[i], &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
352 found++;
353 }
354 else {
355 if (UNDEF_P(default_values[di])) {
356 locals[i] = Qnil;
357
358 if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) {
359 unspecified_bits |= 0x01 << di;
360 }
361 else {
362 if (NIL_P(unspecified_bits_value)) {
363 /* fixnum -> hash */
364 int j;
365 unspecified_bits_value = rb_hash_new();
366
367 for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) {
368 if (unspecified_bits & (0x01 << j)) {
369 rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue);
370 }
371 }
372 }
373 rb_hash_aset(unspecified_bits_value, INT2FIX(di), Qtrue);
374 }
375 }
376 else {
377 locals[i] = default_values[di];
378 }
379 }
380 }
381
382 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
383 const int rest_hash_index = key_num + 1;
384 locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values);
385 }
386 else {
387 if (found != passed_keyword_len) {
388 VALUE keys = make_unknown_kw_hash(passed_keywords, passed_keyword_len, passed_values);
389 argument_kw_error(ec, iseq, "unknown", keys);
390 }
391 }
392
393 if (NIL_P(unspecified_bits_value)) {
394 unspecified_bits_value = INT2FIX(unspecified_bits);
395 }
396 locals[key_num] = unspecified_bits_value;
397}
398
399static void
400args_setup_kw_parameters_from_kwsplat(rb_execution_context_t *const ec, const rb_iseq_t *const iseq,
401 VALUE keyword_hash, VALUE *const locals, bool remove_hash_value)
402{
403 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
404 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
405 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
406 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
407 VALUE missing = 0;
408 int i, di;
409 int unspecified_bits = 0;
410 size_t keyword_size = RHASH_SIZE(keyword_hash);
411 VALUE unspecified_bits_value = Qnil;
412
413 for (i=0; i<req_key_num; i++) {
414 VALUE key = ID2SYM(acceptable_keywords[i]);
415 VALUE value;
416 if (remove_hash_value) {
417 value = rb_hash_delete_entry(keyword_hash, key);
418 }
419 else {
420 value = rb_hash_lookup2(keyword_hash, key, Qundef);
421 }
422
423 if (!UNDEF_P(value)) {
424 keyword_size--;
425 locals[i] = value;
426 }
427 else {
428 if (!missing) missing = rb_ary_hidden_new(1);
429 rb_ary_push(missing, key);
430 }
431 }
432
433 if (missing) argument_kw_error(ec, iseq, "missing", missing);
434
435 for (di=0; i<key_num; i++, di++) {
436 VALUE key = ID2SYM(acceptable_keywords[i]);
437 VALUE value;
438 if (remove_hash_value) {
439 value = rb_hash_delete_entry(keyword_hash, key);
440 }
441 else {
442 value = rb_hash_lookup2(keyword_hash, key, Qundef);
443 }
444
445 if (!UNDEF_P(value)) {
446 keyword_size--;
447 locals[i] = value;
448 }
449 else {
450 if (UNDEF_P(default_values[di])) {
451 locals[i] = Qnil;
452
453 if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) {
454 unspecified_bits |= 0x01 << di;
455 }
456 else {
457 if (NIL_P(unspecified_bits_value)) {
458 /* fixnum -> hash */
459 int j;
460 unspecified_bits_value = rb_hash_new();
461
462 for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) {
463 if (unspecified_bits & (0x01 << j)) {
464 rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue);
465 }
466 }
467 }
468 rb_hash_aset(unspecified_bits_value, INT2FIX(di), Qtrue);
469 }
470 }
471 else {
472 locals[i] = default_values[di];
473 }
474 }
475 }
476
477 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
478 const int rest_hash_index = key_num + 1;
479 locals[rest_hash_index] = keyword_hash;
480 }
481 else {
482 if (!remove_hash_value) {
483 if (keyword_size != 0) {
484 /* Recurse with duplicated keyword hash in remove mode.
485 * This is simpler than writing code to check which entries in the hash do not match.
486 * This will raise an exception, so the additional performance impact shouldn't be material.
487 */
488 args_setup_kw_parameters_from_kwsplat(ec, iseq, rb_hash_dup(keyword_hash), locals, true);
489 }
490 }
491 else if (!RHASH_EMPTY_P(keyword_hash)) {
492 argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash));
493 }
494 }
495
496 if (NIL_P(unspecified_bits_value)) {
497 unspecified_bits_value = INT2FIX(unspecified_bits);
498 }
499 locals[key_num] = unspecified_bits_value;
500}
501
502static inline void
503args_setup_kw_rest_parameter(VALUE keyword_hash, VALUE *locals, int kw_flag, bool anon_kwrest)
504{
505 if (NIL_P(keyword_hash)) {
506 if (!anon_kwrest) {
507 keyword_hash = rb_hash_new();
508 }
509 }
510 else if (!(kw_flag & VM_CALL_KW_SPLAT_MUT)) {
511 keyword_hash = rb_hash_dup(keyword_hash);
512 }
513 locals[0] = keyword_hash;
514}
515
516static inline void
517args_setup_block_parameter(const rb_execution_context_t *ec, struct rb_calling_info *calling, VALUE *locals)
518{
519 VALUE block_handler = calling->block_handler;
520 *locals = rb_vm_bh_to_procval(ec, block_handler);
521}
522
523static inline int
524ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq, unsigned int * kw_flag, VALUE * converted_keyword_hash)
525{
526 if (keyword_hash == Qnil) {
527 goto ignore;
528 }
529 else if (!RB_TYPE_P(keyword_hash, T_HASH)) {
530 keyword_hash = rb_to_hash_type(keyword_hash);
531 }
532 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_kwrest)) {
533 if (!ISEQ_BODY(iseq)->param.flags.has_kw) {
534 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
535 }
536 }
537
538 if (RHASH_EMPTY_P(keyword_hash) && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
539 goto ignore;
540 }
541
542 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT) &&
543 (ISEQ_BODY(iseq)->param.flags.has_kwrest ||
544 ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
545 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
546 keyword_hash = rb_hash_dup(keyword_hash);
547 }
548 *converted_keyword_hash = keyword_hash;
549
550 if (!(ISEQ_BODY(iseq)->param.flags.has_kw) &&
551 !(ISEQ_BODY(iseq)->param.flags.has_kwrest) &&
552 RHASH_EMPTY_P(keyword_hash)) {
553 ignore:
554 *kw_flag &= ~(VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
555 return 1;
556 }
557 else {
558 return 0;
559 }
560}
561
562static VALUE
563check_kwrestarg(VALUE keyword_hash, unsigned int *kw_flag)
564{
565 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT)) {
566 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
567 return rb_hash_dup(keyword_hash);
568 }
569 else {
570 return keyword_hash;
571 }
572}
573
574static void
575flatten_rest_args(rb_execution_context_t * const ec, struct args_info *args, VALUE * const locals, unsigned int *ci_flag)
576{
577 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
578 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest)-1;
579 args->argc += rest_len;
580 if (rest_len) {
581 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
582 for (j=0; rest_len > 0; rest_len--, i++, j++) {
583 locals[i] = argv[j];
584 }
585 }
586 args->rest = Qfalse;
587 *ci_flag &= ~VM_CALL_ARGS_SPLAT;
588}
589
590static int
591setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * const iseq,
592 struct rb_calling_info *const calling,
593 const struct rb_callinfo *ci,
594 VALUE * const locals, const enum arg_setup_type arg_setup_type)
595{
596 const int min_argc = ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.post_num;
597 const int max_argc = (ISEQ_BODY(iseq)->param.flags.has_rest == FALSE) ? min_argc + ISEQ_BODY(iseq)->param.opt_num : UNLIMITED_ARGUMENTS;
598 int given_argc;
599 unsigned int ci_flag = vm_ci_flag(ci);
600 unsigned int kw_flag = ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
601 int opt_pc = 0, allow_autosplat = !kw_flag;
602 struct args_info args_body, *args;
603 VALUE keyword_hash = Qnil;
604 VALUE * const orig_sp = ec->cfp->sp;
605 unsigned int i;
606 VALUE flag_keyword_hash = 0;
607 VALUE splat_flagged_keyword_hash = 0;
608 VALUE converted_keyword_hash = 0;
609 VALUE rest_last = 0;
610
611 vm_check_canary(ec, orig_sp);
612 /*
613 * Extend SP for GC.
614 *
615 * [pushed values] [uninitialized values]
616 * <- ci->argc -->
617 * <- ISEQ_BODY(iseq)->param.size------------>
618 * ^ locals ^ sp
619 *
620 * =>
621 * [pushed values] [initialized values ]
622 * <- ci->argc -->
623 * <- ISEQ_BODY(iseq)->param.size------------>
624 * ^ locals ^ sp
625 */
626 for (i=calling->argc; i<ISEQ_BODY(iseq)->param.size; i++) {
627 locals[i] = Qnil;
628 }
629 ec->cfp->sp = &locals[i];
630
631 /* setup args */
632 args = &args_body;
633 given_argc = args->argc = calling->argc;
634 args->argv = locals;
635 args->rest_dupped = ci_flag & VM_CALL_ARGS_SPLAT_MUT;
636
637 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest)) {
638 if ((ci_flag & VM_CALL_ARGS_SPLAT) &&
639 given_argc == ISEQ_BODY(iseq)->param.lead_num + (kw_flag ? 2 : 1) &&
640 !ISEQ_BODY(iseq)->param.flags.has_opt &&
641 !ISEQ_BODY(iseq)->param.flags.has_post &&
642 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
643 if (kw_flag) {
644 if (ISEQ_BODY(iseq)->param.flags.has_kw ||
645 ISEQ_BODY(iseq)->param.flags.has_kwrest) {
646 args->rest_dupped = true;
647 }
648 else if (kw_flag & VM_CALL_KW_SPLAT) {
649 VALUE kw_hash = locals[args->argc - 1];
650 if (kw_hash == Qnil ||
651 (RB_TYPE_P(kw_hash, T_HASH) && RHASH_EMPTY_P(kw_hash))) {
652 args->rest_dupped = true;
653 }
654 }
655
656 }
657 else if (!ISEQ_BODY(iseq)->param.flags.has_kw &&
658 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
659 !ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
660 args->rest_dupped = true;
661 }
662 }
663 }
664
665 if (kw_flag & VM_CALL_KWARG) {
666 args->kw_arg = vm_ci_kwarg(ci);
667
668 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
669 int kw_len = args->kw_arg->keyword_len;
670 /* copy kw_argv */
671 args->kw_argv = ALLOCA_N(VALUE, kw_len);
672 args->argc -= kw_len;
673 given_argc -= kw_len;
674 MEMCPY(args->kw_argv, locals + args->argc, VALUE, kw_len);
675 }
676 else {
677 args->kw_argv = NULL;
678 given_argc = args_kw_argv_to_hash(args);
679 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
680 }
681 }
682 else {
683 args->kw_arg = NULL;
684 args->kw_argv = NULL;
685 }
686
687 if ((ci_flag & VM_CALL_ARGS_SPLAT) && (ci_flag & VM_CALL_KW_SPLAT)) {
688 // f(*a, **kw)
689 args->rest_index = 0;
690 keyword_hash = locals[--args->argc];
691 args->rest = locals[--args->argc];
692
693 if (ignore_keyword_hash_p(keyword_hash, iseq, &kw_flag, &converted_keyword_hash)) {
694 keyword_hash = Qnil;
695 }
696 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
697 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
698 flag_keyword_hash = converted_keyword_hash;
699 arg_rest_dup(args);
700 rb_ary_push(args->rest, converted_keyword_hash);
701 keyword_hash = Qnil;
702 }
703 else if (!ISEQ_BODY(iseq)->param.flags.has_kwrest && !ISEQ_BODY(iseq)->param.flags.has_kw) {
704 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
705 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
706 arg_rest_dup(args);
707 rb_ary_push(args->rest, converted_keyword_hash);
708 keyword_hash = Qnil;
709 }
710 else {
711 // Avoid duping rest when not necessary
712 // Copy rest elements and converted keyword hash directly to VM stack
713 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
714 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest);
715 if (rest_len) {
716 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
717 given_argc += rest_len;
718 args->argc += rest_len;
719 for (j=0; rest_len > 0; rest_len--, i++, j++) {
720 locals[i] = argv[j];
721 }
722 }
723 locals[i] = converted_keyword_hash;
724 given_argc--;
725 args->argc++;
726 args->rest = Qfalse;
727 ci_flag &= ~(VM_CALL_ARGS_SPLAT|VM_CALL_KW_SPLAT);
728 keyword_hash = Qnil;
729 goto arg_splat_and_kw_splat_flattened;
730 }
731 }
732 else {
733 keyword_hash = converted_keyword_hash;
734 }
735
736 int len = RARRAY_LENINT(args->rest);
737 given_argc += len - 2;
738 }
739 else if (ci_flag & VM_CALL_ARGS_SPLAT) {
740 // f(*a)
741 args->rest_index = 0;
742 args->rest = locals[--args->argc];
743 int len = RARRAY_LENINT(args->rest);
744 given_argc += len - 1;
745
746 if (!kw_flag && len > 0) {
747 rest_last = RARRAY_AREF(args->rest, len - 1);
748 if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
749 // def f(**kw); a = [..., kw]; g(*a)
750 splat_flagged_keyword_hash = rest_last;
751 if (!(RHASH_EMPTY_P(rest_last) || ISEQ_BODY(iseq)->param.flags.has_kw) || (ISEQ_BODY(iseq)->param.flags.has_kwrest)) {
752 rest_last = rb_hash_dup(rest_last);
753 }
754 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
755
756 // Unset rest_dupped set by anon_rest as we may need to modify splat in this case
757 args->rest_dupped = false;
758
759 if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
760 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
761 // Only duplicate/modify splat array if it will be used
762 arg_rest_dup(args);
763 rb_ary_pop(args->rest);
764 }
765 else if (arg_setup_type == arg_setup_block && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
766 // Avoid hash allocation for empty hashes
767 // Copy rest elements except empty keyword hash directly to VM stack
768 flatten_rest_args(ec, args, locals, &ci_flag);
769 keyword_hash = Qnil;
770 kw_flag = 0;
771 }
772 given_argc--;
773 }
774 else if (!ISEQ_BODY(iseq)->param.flags.has_rest) {
775 // Avoid duping rest when not necessary
776 // Copy rest elements and converted keyword hash directly to VM stack
777 flatten_rest_args(ec, args, locals, &ci_flag);
778
779 if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
780 given_argc--;
781 keyword_hash = converted_keyword_hash;
782 }
783 else {
784 locals[args->argc] = converted_keyword_hash;
785 args->argc += 1;
786 keyword_hash = Qnil;
787 kw_flag = 0;
788 }
789 }
790 else {
791 if (rest_last != converted_keyword_hash) {
792 rest_last = converted_keyword_hash;
793 arg_rest_dup(args);
794 RARRAY_ASET(args->rest, len - 1, rest_last);
795 }
796
797 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords && rest_last) {
798 flag_keyword_hash = rest_last;
799 }
800 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
801 arg_rest_dup(args);
802 rb_ary_pop(args->rest);
803 given_argc--;
804 keyword_hash = rest_last;
805 }
806 }
807 }
808 }
809 }
810 else {
811 args->rest = Qfalse;
812
813 if (args->argc > 0 && (kw_flag & VM_CALL_KW_SPLAT)) {
814 // f(**kw)
815 VALUE last_arg = args->argv[args->argc-1];
816 if (ignore_keyword_hash_p(last_arg, iseq, &kw_flag, &converted_keyword_hash)) {
817 args->argc--;
818 given_argc--;
819 }
820 else {
821 if (!(kw_flag & VM_CALL_KW_SPLAT_MUT) && !ISEQ_BODY(iseq)->param.flags.has_kw) {
822 converted_keyword_hash = rb_hash_dup(converted_keyword_hash);
823 kw_flag |= VM_CALL_KW_SPLAT_MUT;
824 }
825
826 if (last_arg != converted_keyword_hash) {
827 last_arg = converted_keyword_hash;
828 args->argv[args->argc-1] = last_arg;
829 }
830
831 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
832 flag_keyword_hash = last_arg;
833 }
834 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
835 args->argc--;
836 given_argc--;
837 keyword_hash = last_arg;
838 }
839 }
840 }
841 }
842
843 if (flag_keyword_hash) {
844 FL_SET_RAW(flag_keyword_hash, RHASH_PASS_AS_KEYWORDS);
845 }
846
847 arg_splat_and_kw_splat_flattened:
848 if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
849 rb_raise(rb_eArgError, "no keywords accepted");
850 }
851
852 switch (arg_setup_type) {
853 case arg_setup_method:
854 break; /* do nothing special */
855 case arg_setup_block:
856 if (given_argc == 1 &&
857 allow_autosplat &&
858 !splat_flagged_keyword_hash &&
859 (min_argc > 0 || ISEQ_BODY(iseq)->param.opt_num > 1) &&
860 !ISEQ_BODY(iseq)->param.flags.ambiguous_param0 &&
861 !((ISEQ_BODY(iseq)->param.flags.has_kw ||
862 ISEQ_BODY(iseq)->param.flags.has_kwrest)
863 && max_argc == 1) &&
864 args_check_block_arg0(args)) {
865 given_argc = RARRAY_LENINT(args->rest);
866 }
867 break;
868 }
869
870 /* argc check */
871 if (given_argc < min_argc) {
872 if (arg_setup_type == arg_setup_block) {
873 CHECK_VM_STACK_OVERFLOW(ec->cfp, min_argc);
874 given_argc = min_argc;
875 args_extend(args, min_argc);
876 }
877 else {
878 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
879 }
880 }
881
882 if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
883 if (arg_setup_type == arg_setup_block) {
884 /* truncate */
885 args_reduce(args, given_argc - max_argc);
886 given_argc = max_argc;
887 }
888 else {
889 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
890 }
891 }
892
893 if (ISEQ_BODY(iseq)->param.flags.has_lead) {
894 args_setup_lead_parameters(args, ISEQ_BODY(iseq)->param.lead_num, locals + 0);
895 }
896
897 if (ISEQ_BODY(iseq)->param.flags.has_rest || ISEQ_BODY(iseq)->param.flags.has_post){
898 args_copy(args);
899 }
900
901 if (ISEQ_BODY(iseq)->param.flags.has_post) {
902 args_setup_post_parameters(args, ISEQ_BODY(iseq)->param.post_num, locals + ISEQ_BODY(iseq)->param.post_start);
903 }
904
905 if (ISEQ_BODY(iseq)->param.flags.has_opt) {
906 int opt = args_setup_opt_parameters(args, ISEQ_BODY(iseq)->param.opt_num, locals + ISEQ_BODY(iseq)->param.lead_num);
907 opt_pc = (int)ISEQ_BODY(iseq)->param.opt_table[opt];
908 }
909
910 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
911 args_setup_rest_parameter(args, locals + ISEQ_BODY(iseq)->param.rest_start);
912 VALUE ary = *(locals + ISEQ_BODY(iseq)->param.rest_start);
913 VALUE index = RARRAY_LEN(ary) - 1;
914 if (splat_flagged_keyword_hash &&
915 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords &&
916 !ISEQ_BODY(iseq)->param.flags.has_kw &&
917 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
918 RARRAY_AREF(ary, index) == splat_flagged_keyword_hash) {
919 ((struct RHash *)rest_last)->basic.flags &= ~RHASH_PASS_AS_KEYWORDS;
920 RARRAY_ASET(ary, index, rest_last);
921 }
922 }
923
924 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
925 VALUE * const klocals = locals + ISEQ_BODY(iseq)->param.keyword->bits_start - ISEQ_BODY(iseq)->param.keyword->num;
926
927 if (args->kw_argv != NULL) {
928 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
929 args_setup_kw_parameters(ec, iseq, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
930 }
931 else if (!NIL_P(keyword_hash)) {
932 bool remove_hash_value = false;
933 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
934 keyword_hash = check_kwrestarg(keyword_hash, &kw_flag);
935 remove_hash_value = true;
936 }
937 args_setup_kw_parameters_from_kwsplat(ec, iseq, keyword_hash, klocals, remove_hash_value);
938 }
939 else {
940#if VM_CHECK_MODE > 0
941 if (args_argc(args) != 0) {
942 VM_ASSERT(ci_flag & VM_CALL_ARGS_SPLAT);
943 VM_ASSERT(!(ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT)));
944 VM_ASSERT(!kw_flag);
945 VM_ASSERT(!ISEQ_BODY(iseq)->param.flags.has_rest);
946 VM_ASSERT(RARRAY_LENINT(args->rest) > 0);
947 VM_ASSERT(RB_TYPE_P(rest_last, T_HASH));
948 VM_ASSERT(FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS));
949 VM_ASSERT(args_argc(args) == 1);
950 }
951#endif
952 args_setup_kw_parameters(ec, iseq, NULL, 0, NULL, klocals);
953 }
954 }
955 else if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
956 args_setup_kw_rest_parameter(keyword_hash, locals + ISEQ_BODY(iseq)->param.keyword->rest_start,
957 kw_flag, ISEQ_BODY(iseq)->param.flags.anon_kwrest);
958 }
959 else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
960 argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash));
961 }
962
963 if (ISEQ_BODY(iseq)->param.flags.has_block) {
964 if (ISEQ_BODY(iseq)->local_iseq == iseq) {
965 /* Do nothing */
966 }
967 else {
968 args_setup_block_parameter(ec, calling, locals + ISEQ_BODY(iseq)->param.block_start);
969 }
970 }
971
972#if 0
973 {
974 int i;
975 for (i=0; i<ISEQ_BODY(iseq)->param.size; i++) {
976 ruby_debug_printf("local[%d] = %p\n", i, (void *)locals[i]);
977 }
978 }
979#endif
980
981 ec->cfp->sp = orig_sp;
982 return opt_pc;
983}
984
985static void
986raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc)
987{
988 VALUE at;
989
990 if (iseq) {
991 vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
992 VM_BLOCK_HANDLER_NONE /* specval*/, Qfalse /* me or cref */,
993 ISEQ_BODY(iseq)->iseq_encoded,
994 ec->cfp->sp, 0, 0 /* stack_max */);
995 at = rb_ec_backtrace_object(ec);
996 rb_backtrace_use_iseq_first_lineno_for_last_location(at);
997 rb_vm_pop_frame(ec);
998 }
999 else {
1000 at = rb_ec_backtrace_object(ec);
1001 }
1002
1003 rb_ivar_set(exc, idBt_locations, at);
1004 rb_exc_set_backtrace(exc, at);
1005 rb_exc_raise(exc);
1006}
1007
1008static void
1009argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc)
1010{
1011 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1012 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
1013 const struct rb_iseq_param_keyword *const kw = ISEQ_BODY(iseq)->param.keyword;
1014 const ID *keywords = kw->table;
1015 int req_key_num = kw->required_num;
1016 if (req_key_num > 0) {
1017 static const char required[] = "; required keywords";
1018 VALUE mesg = rb_attr_get(exc, idMesg);
1019 rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1020 rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1021 rb_str_cat_cstr(mesg, ":");
1022 do {
1023 rb_str_cat_cstr(mesg, " ");
1024 rb_str_append(mesg, rb_id2str(*keywords++));
1025 rb_str_cat_cstr(mesg, ",");
1026 } while (--req_key_num);
1027 RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1028 }
1029 }
1030 raise_argument_error(ec, iseq, exc);
1031}
1032
1033static void
1034argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const char *error, const VALUE keys)
1035{
1036 raise_argument_error(ec, iseq, rb_keyword_error_new(error, keys));
1037}
1038
1039static VALUE
1040vm_to_proc(VALUE proc)
1041{
1042 if (UNLIKELY(!rb_obj_is_proc(proc))) {
1043 VALUE b;
1044 const rb_callable_method_entry_t *me =
1045 rb_callable_method_entry_with_refinements(CLASS_OF(proc), idTo_proc, NULL);
1046
1047 if (me) {
1048 b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1049 }
1050 else {
1051 /* NOTE: calling method_missing */
1052 b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1053 }
1054
1055 if (NIL_P(b) || !rb_obj_is_proc(b)) {
1056 rb_raise(rb_eTypeError,
1057 "wrong argument type %s (expected Proc)",
1058 rb_obj_classname(proc));
1059 }
1060 return b;
1061 }
1062 else {
1063 return proc;
1064 }
1065}
1066
1067static VALUE
1068refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1069{
1070 VALUE obj;
1071 ID mid;
1072 const rb_callable_method_entry_t *me = 0; /* for hidden object case */
1073 rb_execution_context_t *ec;
1074 const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1075 const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1076 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1077 VALUE klass;
1078
1079 if (argc-- < 1) {
1080 rb_raise(rb_eArgError, "no receiver given");
1081 }
1082 obj = *argv++;
1083
1084 mid = SYM2ID(symbol);
1085 for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1086 me = rb_callable_method_entry(klass, mid);
1087 if (me) {
1088 me = rb_resolve_refined_method_callable(refinements, me);
1089 if (me) break;
1090 }
1091 }
1092
1093 ec = GET_EC();
1094 if (!NIL_P(blockarg)) {
1095 vm_passed_block_handler_set(ec, blockarg);
1096 }
1097 if (!me) {
1098 return method_missing(ec, obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1099 }
1100 return rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1101}
1102
1103static VALUE
1104vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1105 const struct rb_callinfo *ci, const rb_iseq_t *blockiseq, const int is_super)
1106{
1107 if (vm_ci_flag(ci) & VM_CALL_ARGS_BLOCKARG) {
1108 VALUE block_code = *(--reg_cfp->sp);
1109
1110 if (NIL_P(block_code)) {
1111 return VM_BLOCK_HANDLER_NONE;
1112 }
1113 else if (block_code == rb_block_param_proxy) {
1114 return VM_CF_BLOCK_HANDLER(reg_cfp);
1115 }
1116 else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1117 const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1118 if (cref && !NIL_P(cref->refinements)) {
1119 VALUE ref = cref->refinements;
1120 VALUE func = rb_hash_lookup(ref, block_code);
1121 if (NIL_P(func)) {
1122 /* TODO: limit cached funcs */
1123 VALUE callback_arg = rb_ary_hidden_new(2);
1124 rb_ary_push(callback_arg, block_code);
1125 rb_ary_push(callback_arg, ref);
1126 OBJ_FREEZE(callback_arg);
1127 func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 1, UNLIMITED_ARGUMENTS);
1128 rb_hash_aset(ref, block_code, func);
1129 }
1130 block_code = func;
1131 }
1132 return block_code;
1133 }
1134 else {
1135 return vm_to_proc(block_code);
1136 }
1137 }
1138 else if (blockiseq != NULL) { /* likely */
1139 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1140 captured->code.iseq = blockiseq;
1141 return VM_BH_FROM_ISEQ_BLOCK(captured);
1142 }
1143 else {
1144 if (is_super) {
1145 return GET_BLOCK_HANDLER();
1146 }
1147 else {
1148 return VM_BLOCK_HANDLER_NONE;
1149 }
1150 }
1151}
1152
1153static void vm_adjust_stack_forwarding(const struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, int argc, VALUE splat);
1154
1155static VALUE
1156vm_caller_setup_fwd_args(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1157 CALL_DATA cd, const rb_iseq_t *blockiseq, const int is_super,
1158 struct rb_forwarding_call_data *adjusted_cd, struct rb_callinfo *adjusted_ci)
1159{
1160 CALL_INFO site_ci = cd->ci;
1161 VALUE bh = Qundef;
1162
1163 RUBY_ASSERT(ISEQ_BODY(ISEQ_BODY(GET_ISEQ())->local_iseq)->param.flags.forwardable);
1164 CALL_INFO caller_ci = (CALL_INFO)TOPN(0);
1165
1166 unsigned int site_argc = vm_ci_argc(site_ci);
1167 unsigned int site_flag = vm_ci_flag(site_ci);
1168 ID site_mid = vm_ci_mid(site_ci);
1169
1170 unsigned int caller_argc = vm_ci_argc(caller_ci);
1171 unsigned int caller_flag = vm_ci_flag(caller_ci);
1172 const struct rb_callinfo_kwarg * kw = vm_ci_kwarg(caller_ci);
1173
1174 VALUE splat = Qfalse;
1175
1176 if (site_flag & VM_CALL_ARGS_SPLAT) {
1177 // If we're called with args_splat, the top 1 should be an array
1178 splat = TOPN(1);
1179 site_argc += (RARRAY_LEN(splat) - 1);
1180 }
1181
1182 // Need to setup the block in case of e.g. `super { :block }`
1183 if (is_super && blockiseq) {
1184 bh = vm_caller_setup_arg_block(ec, GET_CFP(), site_ci, blockiseq, is_super);
1185 }
1186 else {
1187 bh = VM_ENV_BLOCK_HANDLER(GET_LEP());
1188 }
1189
1190 vm_adjust_stack_forwarding(ec, GET_CFP(), caller_argc, splat);
1191
1192 *adjusted_ci = VM_CI_ON_STACK(
1193 site_mid,
1194 ((caller_flag & ~(VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL)) |
1195 (site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
1196 site_argc + caller_argc,
1197 kw
1198 );
1199
1200 adjusted_cd->cd.ci = adjusted_ci;
1201 adjusted_cd->cd.cc = cd->cc;
1202 adjusted_cd->caller_ci = caller_ci;
1203
1204 return bh;
1205}
RUBY_ASSERT
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
Qundef
#define Qundef
Old name of RUBY_Qundef.
Definition special_consts.h:62
INT2FIX
#define INT2FIX
Old name of RB_INT2FIX.
Definition long.h:48
ID2SYM
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
OBJ_FREEZE
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:135
SYM2ID
#define SYM2ID
Old name of RB_SYM2ID.
Definition symbol.h:45
T_DATA
#define T_DATA
Old name of RUBY_T_DATA.
Definition value_type.h:60
CLASS_OF
#define CLASS_OF
Old name of rb_class_of.
Definition globals.h:203
T_HASH
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
FL_TEST_RAW
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:132
Qtrue
#define Qtrue
Old name of RUBY_Qtrue.
Definition special_consts.h:61
Qnil
#define Qnil
Old name of RUBY_Qnil.
Definition special_consts.h:60
Qfalse
#define Qfalse
Old name of RUBY_Qfalse.
Definition special_consts.h:59
NIL_P
#define NIL_P
Old name of RB_NIL_P.
Definition special_consts.h:55
FL_SET_RAW
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
Definition fl_type.h:130
SYMBOL_P
#define SYMBOL_P
Old name of RB_SYMBOL_P.
Definition value_type.h:88
rb_eTypeError
VALUE rb_eTypeError
TypeError exception.
Definition error.c:1430
rb_cSymbol
VALUE rb_cSymbol
Symbol class.
Definition string.c:80
rb_ary_new
VALUE rb_ary_new(void)
Allocates a new, empty array.
Definition array.c:741
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
Definition error.h:35
rb_hash_new
VALUE rb_hash_new(void)
Creates a new, empty hash object.
Definition hash.c:1477
rb_obj_is_proc
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
Definition proc.c:120
rb_str_append
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
Definition string.c:3685
rb_str_cat
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
Definition string.c:3453
rb_str_cat_cstr
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1656
rb_ivar_set
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
Definition variable.c:1939
len
int len
Length of the buffer.
Definition io.h:8
RB_BLOCK_CALL_FUNC_ARGLIST
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
Definition iterator.h:58
MEMCPY
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
ALLOCA_N
#define ALLOCA_N(type, n)
Definition memory.h:292
RARRAY_LEN
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:51
RARRAY_LENINT
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
Definition rarray.h:281
RARRAY_ASET
static void RARRAY_ASET(VALUE ary, long i, VALUE v)
Assigns an object in an array.
Definition rarray.h:386
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition rarray.h:403
RARRAY_CONST_PTR
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:52
RCLASS_SUPER
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
Definition rclass.h:44
RHASH_SIZE
#define RHASH_SIZE(h)
Queries the size of the hash.
Definition rhash.h:69
RHASH_EMPTY_P
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
Definition rhash.h:79
rb_obj_classname
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
Definition variable.c:507
RB_PASS_CALLED_KEYWORDS
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
Definition scan_args.h:78
RB_NO_KEYWORDS
#define RB_NO_KEYWORDS
Do not pass keywords.
Definition scan_args.h:69
RHash
Definition hash.h:53
args_info
Definition vm_args.c:19
rb_callinfo_kwarg
Definition vm_callinfo.h:48
rb_callinfo
Definition vm_callinfo.h:65
rb_calling_info
Definition vm_core.h:306
rb_captured_block
Definition vm_core.h:867
rb_control_frame_struct
Definition vm_core.h:900
rb_execution_context_struct
Definition vm_core.h:1022
rb_forwarding_call_data
Definition vm_insnhelper.h:69
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
RB_TYPE_P
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