Ruby 4.1.0dev (2026-05-19 revision 7e8d94dec00d75f51cbd931d6744d5bb9b19b289)
vm_args.c (7e8d94dec00d75f51cbd931d6744d5bb9b19b289)
1/**********************************************************************
2
3 vm_args.c - process method call arguments. Included into vm.c.
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 rb_callable_method_entry_t *cme, const VALUE exc));
12NORETURN(static void argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, 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 rb_callable_method_entry_t *cme, const char *error, const VALUE keys));
14VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
15static VALUE set_error_backtrace(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc);
16
17static VALUE method_missing(rb_execution_context_t *ec, VALUE obj, ID id, int argc, const VALUE *argv,
18 enum method_missing_reason call_status, int kw_splat);
19const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
20
21struct args_info {
22 /* basic args info */
23 VALUE *argv;
24 int argc;
25
26 /* additional args info */
27 int rest_index;
28 int rest_dupped;
29 const struct rb_callinfo_kwarg *kw_arg;
30 VALUE *kw_argv;
31 VALUE rest;
32};
33
34enum arg_setup_type {
35 arg_setup_method,
36 arg_setup_block
37};
38
39static inline void
40arg_rest_dup(struct args_info *args)
41{
42 if (!args->rest_dupped) {
43 args->rest = rb_ary_dup(args->rest);
44 args->rest_dupped = TRUE;
45 }
46}
47
48static inline int
49args_argc(struct args_info *args)
50{
51 if (args->rest == Qfalse) {
52 return args->argc;
53 }
54 else {
55 return args->argc + RARRAY_LENINT(args->rest) - args->rest_index;
56 }
57}
58
59static inline void
60args_extend(struct args_info *args, const int min_argc)
61{
62 int i;
63
64 if (args->rest) {
65 arg_rest_dup(args);
66 VM_ASSERT(args->rest_index == 0);
67 for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) {
68 rb_ary_push(args->rest, Qnil);
69 }
70 }
71 else {
72 for (i=args->argc; i<min_argc; i++) {
73 args->argv[args->argc++] = Qnil;
74 }
75 }
76}
77
78static inline void
79args_reduce(struct args_info *args, int over_argc)
80{
81 if (args->rest) {
82 const long len = RARRAY_LEN(args->rest);
83
84 if (len > over_argc) {
85 arg_rest_dup(args);
86 rb_ary_resize(args->rest, len - over_argc);
87 return;
88 }
89 else {
90 args->rest = Qfalse;
91 over_argc -= len;
92 }
93 }
94
95 VM_ASSERT(args->argc >= over_argc);
96 args->argc -= over_argc;
97}
98
99static inline int
100args_check_block_arg0(struct args_info *args)
101{
102 VALUE ary = Qnil;
103
104 if (args->rest && RARRAY_LEN(args->rest) == 1) {
105 VALUE arg0 = RARRAY_AREF(args->rest, 0);
106 ary = rb_check_array_type(arg0);
107 }
108 else if (args->argc == 1) {
109 VALUE arg0 = args->argv[0];
110 ary = rb_check_array_type(arg0);
111 args->argv[0] = arg0; /* see: https://bugs.ruby-lang.org/issues/8484 */
112 }
113
114 if (!NIL_P(ary)) {
115 args->rest = ary;
116 args->rest_index = 0;
117 args->argc = 0;
118 return TRUE;
119 }
120
121 return FALSE;
122}
123
124static inline void
125args_copy(struct args_info *args)
126{
127 if (args->rest != Qfalse) {
128 int argc = args->argc;
129 args->argc = 0;
130 arg_rest_dup(args);
131
132 /*
133 * argv: [m0, m1, m2, m3]
134 * rest: [a0, a1, a2, a3, a4, a5]
135 * ^
136 * rest_index
137 *
138 * #=> first loop
139 *
140 * argv: [m0, m1]
141 * rest: [m2, m3, a2, a3, a4, a5]
142 * ^
143 * rest_index
144 *
145 * #=> 2nd loop
146 *
147 * argv: [] (argc == 0)
148 * rest: [m0, m1, m2, m3, a2, a3, a4, a5]
149 * ^
150 * rest_index
151 */
152 while (args->rest_index > 0 && argc > 0) {
153 RARRAY_ASET(args->rest, --args->rest_index, args->argv[--argc]);
154 }
155 while (argc > 0) {
156 rb_ary_unshift(args->rest, args->argv[--argc]);
157 }
158 }
159 else if (args->argc > 0) {
160 args->rest = rb_ary_new_from_values(args->argc, args->argv);
161 args->rest_index = 0;
162 args->rest_dupped = TRUE;
163 args->argc = 0;
164 }
165}
166
167static inline const VALUE *
168args_rest_argv(struct args_info *args)
169{
170 return RARRAY_CONST_PTR(args->rest) + args->rest_index;
171}
172
173static inline VALUE
174args_rest_array(struct args_info *args)
175{
176 VALUE ary;
177
178 if (args->rest) {
179 ary = rb_ary_behead(args->rest, args->rest_index);
180 args->rest_index = 0;
181 args->rest = 0;
182 }
183 else {
184 ary = rb_ary_new();
185 }
186 return ary;
187}
188
189static int
190args_kw_argv_to_hash(struct args_info *args)
191{
192 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
193 const VALUE *const passed_keywords = kw_arg->keywords;
194 const int kw_len = kw_arg->keyword_len;
195 VALUE h = rb_hash_new_with_size(kw_len);
196 const int kw_start = args->argc - kw_len;
197 const VALUE * const kw_argv = args->argv + kw_start;
198 int i;
199
200 args->argc = kw_start + 1;
201 for (i=0; i<kw_len; i++) {
202 rb_hash_aset(h, passed_keywords[i], kw_argv[i]);
203 }
204
205 args->argv[args->argc - 1] = h;
206
207 return args->argc;
208}
209
210static inline void
211args_setup_lead_parameters(struct args_info *args, int argc, VALUE *locals)
212{
213 if (args->argc >= argc) {
214 /* do noting */
215 args->argc -= argc;
216 args->argv += argc;
217 }
218 else {
219 int i, j;
220 const VALUE *argv = args_rest_argv(args);
221
222 for (i=args->argc, j=0; i<argc; i++, j++) {
223 locals[i] = argv[j];
224 }
225 args->rest_index += argc - args->argc;
226 args->argc = 0;
227 }
228}
229
230static inline void
231args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
232{
233 long len;
234 len = RARRAY_LEN(args->rest);
235 MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc);
236 rb_ary_resize(args->rest, len - argc);
237}
238
239static inline int
240args_setup_opt_parameters(struct args_info *args, int opt_max, VALUE *locals)
241{
242 int i;
243
244 if (args->argc >= opt_max) {
245 args->argc -= opt_max;
246 args->argv += opt_max;
247 i = opt_max;
248 }
249 else {
250 int j;
251 i = args->argc;
252 args->argc = 0;
253
254 if (args->rest) {
255 int len = RARRAY_LENINT(args->rest);
256 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
257
258 for (; i<opt_max && args->rest_index < len; i++, args->rest_index++) {
259 locals[i] = argv[args->rest_index];
260 }
261 }
262
263 /* initialize by nil */
264 for (j=i; j<opt_max; j++) {
265 locals[j] = Qnil;
266 }
267 }
268
269 return i;
270}
271
272static inline void
273args_setup_rest_parameter(struct args_info *args, VALUE *locals)
274{
275 *locals = args_rest_array(args);
276}
277
278static VALUE
279make_unknown_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
280{
281 int i;
282 VALUE obj = rb_ary_hidden_new(1);
283
284 for (i=0; i<passed_keyword_len; i++) {
285 if (!UNDEF_P(kw_argv[i])) {
286 rb_ary_push(obj, passed_keywords[i]);
287 }
288 }
289 return obj;
290}
291
292static VALUE
293make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
294{
295 int i;
296 VALUE obj = rb_hash_new_with_size(passed_keyword_len);
297
298 for (i=0; i<passed_keyword_len; i++) {
299 if (!UNDEF_P(kw_argv[i])) {
300 rb_hash_aset(obj, passed_keywords[i], kw_argv[i]);
301 }
302 }
303 return obj;
304}
305
306static inline int
307args_setup_kw_parameters_lookup(const ID key, VALUE *ptr, const VALUE *const passed_keywords, VALUE *passed_values, const int passed_keyword_len)
308{
309 int i;
310 const VALUE keyname = ID2SYM(key);
311
312 for (i=0; i<passed_keyword_len; i++) {
313 if (keyname == passed_keywords[i]) {
314 *ptr = passed_values[i];
315 passed_values[i] = Qundef;
316 return TRUE;
317 }
318 }
319
320 return FALSE;
321}
322
323static void
324args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
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, cme, "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 < VM_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<VM_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, cme, "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, const rb_callable_method_entry_t *cme,
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, cme, "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 < VM_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<VM_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, cme, rb_hash_dup(keyword_hash), locals, true);
489 }
490 }
491 else if (!RHASH_EMPTY_P(keyword_hash)) {
492 argument_kw_error(ec, iseq, cme, "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 const rb_callable_method_entry_t *cme = calling->cc ? vm_cc_cme(calling->cc) : NULL;
611
612 vm_check_canary(ec, orig_sp);
613 /*
614 * Extend SP for GC.
615 *
616 * [pushed values] [uninitialized values]
617 * <- ci->argc -->
618 * <- ISEQ_BODY(iseq)->param.size------------>
619 * ^ locals ^ sp
620 *
621 * =>
622 * [pushed values] [initialized values ]
623 * <- ci->argc -->
624 * <- ISEQ_BODY(iseq)->param.size------------>
625 * ^ locals ^ sp
626 */
627 for (i=calling->argc; i<ISEQ_BODY(iseq)->param.size; i++) {
628 locals[i] = Qnil;
629 }
630 ec->cfp->sp = &locals[i];
631
632 /* setup args */
633 args = &args_body;
634 given_argc = args->argc = calling->argc;
635 args->argv = locals;
636 args->rest_dupped = ci_flag & VM_CALL_ARGS_SPLAT_MUT;
637
638 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest)) {
639 if ((ci_flag & VM_CALL_ARGS_SPLAT) &&
640 given_argc == ISEQ_BODY(iseq)->param.lead_num + (kw_flag ? 2 : 1) &&
641 !ISEQ_BODY(iseq)->param.flags.has_opt &&
642 !ISEQ_BODY(iseq)->param.flags.has_post &&
643 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
644 if (kw_flag) {
645 if (ISEQ_BODY(iseq)->param.flags.has_kw ||
646 ISEQ_BODY(iseq)->param.flags.has_kwrest) {
647 args->rest_dupped = true;
648 }
649 else if (kw_flag & VM_CALL_KW_SPLAT) {
650 VALUE kw_hash = locals[args->argc - 1];
651 if (kw_hash == Qnil ||
652 (RB_TYPE_P(kw_hash, T_HASH) && RHASH_EMPTY_P(kw_hash))) {
653 args->rest_dupped = true;
654 }
655 }
656
657 }
658 else if (!ISEQ_BODY(iseq)->param.flags.has_kw &&
659 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
660 !ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
661 args->rest_dupped = true;
662 }
663 }
664 }
665
666 if (kw_flag & VM_CALL_KWARG) {
667 args->kw_arg = vm_ci_kwarg(ci);
668
669 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
670 int kw_len = args->kw_arg->keyword_len;
671 /* copy kw_argv */
672 args->kw_argv = ALLOCA_N(VALUE, kw_len);
673 args->argc -= kw_len;
674 given_argc -= kw_len;
675 MEMCPY(args->kw_argv, locals + args->argc, VALUE, kw_len);
676 }
677 else {
678 args->kw_argv = NULL;
679 given_argc = args_kw_argv_to_hash(args);
680 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
681 }
682 }
683 else {
684 args->kw_arg = NULL;
685 args->kw_argv = NULL;
686 }
687
688 if ((ci_flag & VM_CALL_ARGS_SPLAT) && (ci_flag & VM_CALL_KW_SPLAT)) {
689 // f(*a, **kw)
690 args->rest_index = 0;
691 keyword_hash = locals[--args->argc];
692 args->rest = locals[--args->argc];
693
694 if (ignore_keyword_hash_p(keyword_hash, iseq, &kw_flag, &converted_keyword_hash)) {
695 keyword_hash = Qnil;
696 }
697 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
698 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
699 flag_keyword_hash = converted_keyword_hash;
700 arg_rest_dup(args);
701 rb_ary_push(args->rest, converted_keyword_hash);
702 keyword_hash = Qnil;
703 }
704 else if (!ISEQ_BODY(iseq)->param.flags.has_kwrest && !ISEQ_BODY(iseq)->param.flags.has_kw) {
705 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
706 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
707 arg_rest_dup(args);
708 rb_ary_push(args->rest, converted_keyword_hash);
709 keyword_hash = Qnil;
710 }
711 else {
712 // Avoid duping rest when not necessary
713 // Copy rest elements and converted keyword hash directly to VM stack
714 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
715 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest);
716 if (rest_len) {
717 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
718 given_argc += rest_len;
719 args->argc += rest_len;
720 for (j=0; rest_len > 0; rest_len--, i++, j++) {
721 locals[i] = argv[j];
722 }
723 }
724 locals[i] = converted_keyword_hash;
725 given_argc--;
726 args->argc++;
727 args->rest = Qfalse;
728 ci_flag &= ~(VM_CALL_ARGS_SPLAT|VM_CALL_KW_SPLAT);
729 keyword_hash = Qnil;
730 goto arg_splat_and_kw_splat_flattened;
731 }
732 }
733 else {
734 keyword_hash = converted_keyword_hash;
735 }
736
737 int len = RARRAY_LENINT(args->rest);
738 given_argc += len - 2;
739 }
740 else if (ci_flag & VM_CALL_ARGS_SPLAT) {
741 // f(*a)
742 args->rest_index = 0;
743 args->rest = locals[--args->argc];
744 int len = RARRAY_LENINT(args->rest);
745 given_argc += len - 1;
746
747 if (!kw_flag && len > 0) {
748 rest_last = RARRAY_AREF(args->rest, len - 1);
749 if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
750 // def f(**kw); a = [..., kw]; g(*a)
751 splat_flagged_keyword_hash = rest_last;
752 if (!(RHASH_EMPTY_P(rest_last) || ISEQ_BODY(iseq)->param.flags.has_kw) || (ISEQ_BODY(iseq)->param.flags.has_kwrest)) {
753 rest_last = rb_hash_dup(rest_last);
754 }
755 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
756
757 // Unset rest_dupped set by anon_rest as we may need to modify splat in this case
758 args->rest_dupped = false;
759
760 if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
761 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
762 // Only duplicate/modify splat array if it will be used
763 arg_rest_dup(args);
764 rb_ary_pop(args->rest);
765 }
766 else if (arg_setup_type == arg_setup_block && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
767 // Avoid hash allocation for empty hashes
768 // Copy rest elements except empty keyword hash directly to VM stack
769 flatten_rest_args(ec, args, locals, &ci_flag);
770 keyword_hash = Qnil;
771 kw_flag = 0;
772 }
773 given_argc--;
774 }
775 else if (!ISEQ_BODY(iseq)->param.flags.has_rest) {
776 // Avoid duping rest when not necessary
777 // Copy rest elements and converted keyword hash directly to VM stack
778 flatten_rest_args(ec, args, locals, &ci_flag);
779
780 if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
781 given_argc--;
782 keyword_hash = converted_keyword_hash;
783 }
784 else {
785 locals[args->argc] = converted_keyword_hash;
786 args->argc += 1;
787 keyword_hash = Qnil;
788 kw_flag = 0;
789 }
790 }
791 else {
792 if (rest_last != converted_keyword_hash) {
793 rest_last = converted_keyword_hash;
794 arg_rest_dup(args);
795 RARRAY_ASET(args->rest, len - 1, rest_last);
796 }
797
798 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords && rest_last) {
799 flag_keyword_hash = rest_last;
800 }
801 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
802 arg_rest_dup(args);
803 rb_ary_pop(args->rest);
804 given_argc--;
805 keyword_hash = rest_last;
806 }
807 }
808 }
809 }
810 }
811 else {
812 args->rest = Qfalse;
813
814 if (args->argc > 0 && (kw_flag & VM_CALL_KW_SPLAT)) {
815 // f(**kw)
816 VALUE last_arg = args->argv[args->argc-1];
817 if (ignore_keyword_hash_p(last_arg, iseq, &kw_flag, &converted_keyword_hash)) {
818 args->argc--;
819 given_argc--;
820 }
821 else {
822 if (!(kw_flag & VM_CALL_KW_SPLAT_MUT) && !ISEQ_BODY(iseq)->param.flags.has_kw) {
823 converted_keyword_hash = rb_hash_dup(converted_keyword_hash);
824 kw_flag |= VM_CALL_KW_SPLAT_MUT;
825 }
826
827 if (last_arg != converted_keyword_hash) {
828 last_arg = converted_keyword_hash;
829 args->argv[args->argc-1] = last_arg;
830 }
831
832 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
833 flag_keyword_hash = last_arg;
834 }
835 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
836 args->argc--;
837 given_argc--;
838 keyword_hash = last_arg;
839 }
840 }
841 }
842 }
843
844 if (flag_keyword_hash) {
845 FL_SET_RAW(flag_keyword_hash, RHASH_PASS_AS_KEYWORDS);
846 }
847
848 arg_splat_and_kw_splat_flattened:
849 if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
850 rb_raise(rb_eArgError, "no keywords accepted");
851 }
852
853 switch (arg_setup_type) {
854 case arg_setup_method:
855 break; /* do nothing special */
856 case arg_setup_block:
857 if (given_argc == 1 &&
858 allow_autosplat &&
859 !splat_flagged_keyword_hash &&
860 (min_argc > 0 || ISEQ_BODY(iseq)->param.opt_num > 1) &&
861 !ISEQ_BODY(iseq)->param.flags.ambiguous_param0 &&
862 !((ISEQ_BODY(iseq)->param.flags.has_kw ||
863 ISEQ_BODY(iseq)->param.flags.has_kwrest)
864 && max_argc == 1) &&
865 args_check_block_arg0(args)) {
866 given_argc = RARRAY_LENINT(args->rest);
867 }
868 break;
869 }
870
871 /* argc check */
872 if (given_argc < min_argc) {
873 if (arg_setup_type == arg_setup_block) {
874 CHECK_VM_STACK_OVERFLOW(ec->cfp, min_argc);
875 given_argc = min_argc;
876 args_extend(args, min_argc);
877 }
878 else {
879 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
880 }
881 }
882
883 if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
884 if (arg_setup_type == arg_setup_block) {
885 /* truncate */
886 args_reduce(args, given_argc - max_argc);
887 given_argc = max_argc;
888 }
889 else {
890 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
891 }
892 }
893
894 if (ISEQ_BODY(iseq)->param.flags.has_lead) {
895 args_setup_lead_parameters(args, ISEQ_BODY(iseq)->param.lead_num, locals + 0);
896 }
897
898 if (ISEQ_BODY(iseq)->param.flags.has_rest || ISEQ_BODY(iseq)->param.flags.has_post){
899 args_copy(args);
900 }
901
902 if (ISEQ_BODY(iseq)->param.flags.has_post) {
903 args_setup_post_parameters(args, ISEQ_BODY(iseq)->param.post_num, locals + ISEQ_BODY(iseq)->param.post_start);
904 }
905
906 if (ISEQ_BODY(iseq)->param.flags.has_opt) {
907 int opt = args_setup_opt_parameters(args, ISEQ_BODY(iseq)->param.opt_num, locals + ISEQ_BODY(iseq)->param.lead_num);
908 opt_pc = (int)ISEQ_BODY(iseq)->param.opt_table[opt];
909 }
910
911 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
912 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest && args->argc == 0 && !args->rest && !ISEQ_BODY(iseq)->param.flags.has_post)) {
913 *(locals + ISEQ_BODY(iseq)->param.rest_start) = args->rest = rb_cArray_empty_frozen;
914 args->rest_index = 0;
915 }
916 else {
917 args_setup_rest_parameter(args, locals + ISEQ_BODY(iseq)->param.rest_start);
918 VALUE ary = *(locals + ISEQ_BODY(iseq)->param.rest_start);
919 VALUE index = RARRAY_LEN(ary) - 1;
920 if (splat_flagged_keyword_hash &&
921 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords &&
922 !ISEQ_BODY(iseq)->param.flags.has_kw &&
923 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
924 RARRAY_AREF(ary, index) == splat_flagged_keyword_hash) {
925 ((struct RHash *)rest_last)->basic.flags &= ~RHASH_PASS_AS_KEYWORDS;
926 RARRAY_ASET(ary, index, rest_last);
927 }
928 }
929 }
930
931 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
932 VALUE * const klocals = locals + ISEQ_BODY(iseq)->param.keyword->bits_start - ISEQ_BODY(iseq)->param.keyword->num;
933
934 if (args->kw_argv != NULL) {
935 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
936 args_setup_kw_parameters(ec, iseq, cme, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
937 }
938 else if (!NIL_P(keyword_hash)) {
939 bool remove_hash_value = false;
940 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
941 keyword_hash = check_kwrestarg(keyword_hash, &kw_flag);
942 remove_hash_value = true;
943 }
944 args_setup_kw_parameters_from_kwsplat(ec, iseq, cme, keyword_hash, klocals, remove_hash_value);
945 }
946 else {
947#if VM_CHECK_MODE > 0
948 if (args_argc(args) != 0) {
949 VM_ASSERT(ci_flag & VM_CALL_ARGS_SPLAT);
950 VM_ASSERT(!(ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT)));
951 VM_ASSERT(!kw_flag);
952 VM_ASSERT(!ISEQ_BODY(iseq)->param.flags.has_rest);
953 VM_ASSERT(RARRAY_LENINT(args->rest) > 0);
954 VM_ASSERT(RB_TYPE_P(rest_last, T_HASH));
955 VM_ASSERT(FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS));
956 VM_ASSERT(args_argc(args) == 1);
957 }
958#endif
959 args_setup_kw_parameters(ec, iseq, cme, NULL, 0, NULL, klocals);
960 }
961 }
962 else if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
963 args_setup_kw_rest_parameter(keyword_hash, locals + ISEQ_BODY(iseq)->param.keyword->rest_start,
964 kw_flag, ISEQ_BODY(iseq)->param.flags.anon_kwrest);
965 }
966 else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
967 argument_kw_error(ec, iseq, cme, "unknown", rb_hash_keys(keyword_hash));
968 }
969
970 if (ISEQ_BODY(iseq)->param.flags.accepts_no_block) {
971 VALUE given_block;
972 args_setup_block_parameter(ec, calling, &given_block);
973 if (!NIL_P(given_block)) {
974 VALUE exc = rb_exc_new_cstr(rb_eArgError, "no block accepted");
975 rb_exc_raise(set_error_backtrace(ec, iseq, cme, exc));
976 }
977 }
978 else if (ISEQ_BODY(iseq)->param.flags.has_block) {
979 if (ISEQ_BODY(iseq)->local_iseq == iseq) {
980 /* Do nothing */
981 }
982 else {
983 args_setup_block_parameter(ec, calling, locals + ISEQ_BODY(iseq)->param.block_start);
984 }
985 }
986
987#if 0
988 {
989 int i;
990 for (i=0; i<ISEQ_BODY(iseq)->param.size; i++) {
991 ruby_debug_printf("local[%d] = %p\n", i, (void *)locals[i]);
992 }
993 }
994#endif
995
996 ec->cfp->sp = orig_sp;
997 return opt_pc;
998}
999
1000static VALUE
1001set_error_backtrace(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
1002{
1003 VALUE at;
1004
1005 if (iseq) {
1006 vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
1007 VM_BLOCK_HANDLER_NONE /* specval*/, (VALUE) cme /* me or cref */,
1008 ISEQ_BODY(iseq)->iseq_encoded,
1009 ec->cfp->sp, 0, 0 /* stack_max */);
1010 at = rb_ec_backtrace_object(ec);
1011 rb_vm_pop_frame(ec);
1012 }
1013 else {
1014 at = rb_ec_backtrace_object(ec);
1015 }
1016
1017 rb_ivar_set(exc, idBt_locations, at);
1018 rb_exc_set_backtrace(exc, at);
1019 return exc;
1020}
1021
1022static void
1023raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
1024{
1025 set_error_backtrace(ec, iseq, cme, exc);
1026 rb_exc_raise(exc);
1027}
1028
1029static void
1030argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const int miss_argc, const int min_argc, const int max_argc)
1031{
1032 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1033 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
1034 const struct rb_iseq_param_keyword *const kw = ISEQ_BODY(iseq)->param.keyword;
1035 const ID *keywords = kw->table;
1036 int req_key_num = kw->required_num;
1037 if (req_key_num > 0) {
1038 static const char required[] = "; required keywords";
1039 VALUE mesg = rb_attr_get(exc, idMesg);
1040 rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1041 rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1042 rb_str_cat_cstr(mesg, ":");
1043 do {
1044 rb_str_cat_cstr(mesg, " ");
1045 rb_str_append(mesg, rb_id2str(*keywords++));
1046 rb_str_cat_cstr(mesg, ",");
1047 } while (--req_key_num);
1048 RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1049 }
1050 }
1051 raise_argument_error(ec, iseq, cme, exc);
1052}
1053
1054static void
1055argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const char *error, const VALUE keys)
1056{
1057 raise_argument_error(ec, iseq, cme, rb_keyword_error_new(error, keys));
1058}
1059
1060static VALUE
1061vm_to_proc(VALUE proc)
1062{
1063 if (UNLIKELY(!rb_obj_is_proc(proc))) {
1064 VALUE b;
1065 const rb_callable_method_entry_t *me =
1066 rb_callable_method_entry_with_refinements(CLASS_OF(proc), idTo_proc, NULL);
1067
1068 if (me) {
1069 b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1070 }
1071 else {
1072 /* NOTE: calling method_missing */
1073 b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1074 }
1075
1076 if (NIL_P(b) || !rb_obj_is_proc(b)) {
1077 if (me) {
1078 rb_cant_convert_invalid_return(proc, "Proc", "to_proc", b);
1079 }
1080 else {
1081 rb_no_implicit_conversion(proc, "Proc");
1082 }
1083 }
1084 return b;
1085 }
1086 else {
1087 return proc;
1088 }
1089}
1090
1091static VALUE
1092refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1093{
1094 VALUE obj;
1095 ID mid;
1096 const rb_callable_method_entry_t *me = 0; /* for hidden object case */
1098 const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1099 const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1100 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1101 VALUE klass;
1102
1103 if (argc-- < 1) {
1104 rb_raise(rb_eArgError, "no receiver given");
1105 }
1106 obj = *argv++;
1107
1108 mid = SYM2ID(symbol);
1109 for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1110 me = rb_callable_method_entry(klass, mid);
1111 if (me) {
1112 me = rb_resolve_refined_method_callable(refinements, me);
1113 if (me) break;
1114 }
1115 }
1116
1117 ec = GET_EC();
1118 if (!NIL_P(blockarg)) {
1119 vm_passed_block_handler_set(ec, blockarg);
1120 }
1121 if (!me) {
1122 return method_missing(ec, obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1123 }
1124 return rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1125}
1126
1127static VALUE
1128vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1129 const struct rb_callinfo *ci, const rb_iseq_t *blockiseq, const int is_super)
1130{
1131 if (vm_ci_flag(ci) & VM_CALL_ARGS_BLOCKARG) {
1132 VALUE block_code = *(--reg_cfp->sp);
1133
1134 if (NIL_P(block_code)) {
1135 return VM_BLOCK_HANDLER_NONE;
1136 }
1137 else if (block_code == rb_block_param_proxy) {
1138 return VM_CF_BLOCK_HANDLER(reg_cfp);
1139 }
1140 else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1141 const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1142 if (cref && !NIL_P(cref->refinements)) {
1143 VALUE ref = cref->refinements;
1144 VALUE func = rb_hash_lookup(ref, block_code);
1145 if (NIL_P(func)) {
1146 /* TODO: limit cached funcs */
1147 VALUE callback_arg = rb_ary_hidden_new(2);
1148 rb_ary_push(callback_arg, block_code);
1149 rb_ary_push(callback_arg, ref);
1150 OBJ_FREEZE(callback_arg);
1151 func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 1, UNLIMITED_ARGUMENTS);
1152 rb_hash_aset(ref, block_code, func);
1153 }
1154 block_code = func;
1155 }
1156 return block_code;
1157 }
1158 else {
1159 return vm_to_proc(block_code);
1160 }
1161 }
1162 else if (blockiseq != NULL) { /* likely */
1163 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1164 captured->code.iseq = blockiseq;
1165 return VM_BH_FROM_ISEQ_BLOCK(captured);
1166 }
1167 else {
1168 if (is_super) {
1169 return GET_BLOCK_HANDLER();
1170 }
1171 else {
1172 return VM_BLOCK_HANDLER_NONE;
1173 }
1174 }
1175}
1176
1177static void vm_adjust_stack_forwarding(const struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, int argc, VALUE splat);
1178
1179static VALUE
1180vm_caller_setup_fwd_args(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1181 CALL_DATA cd, const rb_iseq_t *blockiseq, const int is_super,
1182 struct rb_forwarding_call_data *adjusted_cd, struct rb_callinfo *adjusted_ci)
1183{
1184 CALL_INFO site_ci = cd->ci;
1185 VALUE bh = Qundef;
1186
1187 RUBY_ASSERT(ISEQ_BODY(ISEQ_BODY(GET_ISEQ())->local_iseq)->param.flags.forwardable);
1188 CALL_INFO caller_ci = (CALL_INFO)TOPN(0);
1189
1190 unsigned int site_argc = vm_ci_argc(site_ci);
1191 unsigned int site_flag = vm_ci_flag(site_ci);
1192 ID site_mid = vm_ci_mid(site_ci);
1193
1194 unsigned int caller_argc = vm_ci_argc(caller_ci);
1195 unsigned int caller_flag = vm_ci_flag(caller_ci);
1196 const struct rb_callinfo_kwarg * kw = vm_ci_kwarg(caller_ci);
1197
1198 VALUE splat = Qfalse;
1199
1200 if (site_flag & VM_CALL_ARGS_SPLAT) {
1201 // If we're called with args_splat, the top 1 should be an array
1202 splat = TOPN(1);
1203 site_argc += (RARRAY_LEN(splat) - 1);
1204 }
1205
1206 // Need to setup the block in case of e.g. `super { :block }`
1207 if (is_super && blockiseq) {
1208 bh = vm_caller_setup_arg_block(ec, GET_CFP(), site_ci, blockiseq, is_super);
1209 }
1210 else {
1211 bh = VM_ENV_BLOCK_HANDLER(GET_LEP());
1212 }
1213
1214 vm_adjust_stack_forwarding(ec, GET_CFP(), caller_argc, splat);
1215
1216 *adjusted_ci = VM_CI_ON_STACK(
1217 site_mid,
1218 ((caller_flag & ~(VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL)) |
1219 (site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
1220 site_argc + caller_argc,
1221 kw
1222 );
1223
1224 adjusted_cd->cd.ci = adjusted_ci;
1225 adjusted_cd->cd.cc = cd->cc;
1226 adjusted_cd->caller_ci = caller_ci;
1227
1228 return bh;
1229}
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
#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 OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:131
#define SYM2ID
Old name of RB_SYM2ID.
Definition symbol.h:45
#define T_DATA
Old name of RUBY_T_DATA.
Definition value_type.h:60
#define CLASS_OF
Old name of rb_class_of.
Definition globals.h:205
#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 Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
Definition fl_type.h:126
#define SYMBOL_P
Old name of RB_SYMBOL_P.
Definition value_type.h:88
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition eval.c:661
VALUE rb_cSymbol
Symbol class.
Definition string.c:82
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_resize(VALUE ary, long len)
Expands or shrinks the passed array to the passed length.
VALUE rb_ary_pop(VALUE ary)
Destructively deletes an element from the end of the passed array and returns what was deleted.
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
Definition error.h:35
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
Definition proc.c:122
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:3836
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1671
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
Definition string.c:3604
#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:1657
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:2064
int len
Length of the buffer.
Definition io.h:8
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
Definition iterator.h:58
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
#define ALLOCA_N(type, n)
Definition memory.h:292
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:51
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
Definition rarray.h:281
static void RARRAY_ASET(VALUE ary, long i, VALUE v)
Assigns an object in an array.
Definition rarray.h:386
#define RARRAY_AREF(a, i)
Definition rarray.h:403
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:52
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
Definition rclass.h:44
#define RHASH_SIZE(h)
Queries the size of the hash.
Definition rhash.h:69
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
Definition rhash.h:79
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
Definition scan_args.h:78
#define RB_NO_KEYWORDS
Do not pass keywords.
Definition scan_args.h:69
Definition hash.h:53
Definition method.h:63
CREF (Class REFerence)
Definition method.h:45
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