Ruby 4.1.0dev (2026-09-27 revision 25f659ba9f8b541331b56d6959167a4805892a14)
vm_args.c (25f659ba9f8b541331b56d6959167a4805892a14)
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_capa(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_capa(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 inline void
324args_setup_kw_parameters_not_found(const VALUE *default_values, VALUE *locals, int i, int di,
325 int *unspecified_bits, VALUE *unspecified_bits_value)
326{
327 if (UNDEF_P(default_values[di])) {
328 locals[i] = Qnil;
329
330 if (LIKELY(i < VM_KW_SPECIFIED_BITS_MAX)) {
331 *unspecified_bits |= 0x01 << di;
332 }
333 else {
334 VALUE bits_value = *unspecified_bits_value;
335 if (NIL_P(bits_value)) {
336 /* fixnum -> hash */
337 int bits = *unspecified_bits;
338 *unspecified_bits_value = bits_value = rb_ident_set_new();
339
340 for (int j=0; j<VM_KW_SPECIFIED_BITS_MAX; j++) {
341 if (bits & (0x01 << j)) {
342 rb_set_add_no_check(bits_value, INT2FIX(j));
343 }
344 }
345 }
346 rb_set_add_no_check(bits_value, INT2FIX(di));
347 }
348 }
349 else {
350 locals[i] = default_values[di];
351 }
352}
353
354static void
355args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
356 VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
357 VALUE *const locals)
358{
359 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
360 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
361 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
362 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
363 VALUE missing = 0;
364 int i, di, found = 0;
365 int unspecified_bits = 0;
366 VALUE unspecified_bits_value = Qnil;
367
368 for (i=0; i<req_key_num; i++) {
369 ID key = acceptable_keywords[i];
370 if (args_setup_kw_parameters_lookup(key, &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
371 found++;
372 }
373 else {
374 if (!missing) missing = rb_ary_hidden_new(1);
375 rb_ary_push(missing, ID2SYM(key));
376 }
377 }
378
379 if (missing) argument_kw_error(ec, iseq, cme, "missing", missing);
380
381 for (di=0; i<key_num; i++, di++) {
382 if (args_setup_kw_parameters_lookup(acceptable_keywords[i], &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
383 found++;
384 }
385 else {
386 args_setup_kw_parameters_not_found(default_values, locals, i, di,
387 &unspecified_bits, &unspecified_bits_value);
388 }
389 }
390
391 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
392 const int rest_hash_index = key_num + 1;
393 locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values);
394 }
395 else {
396 if (found != passed_keyword_len) {
397 VALUE keys = make_unknown_kw_hash(passed_keywords, passed_keyword_len, passed_values);
398 argument_kw_error(ec, iseq, cme, "unknown", keys);
399 }
400 }
401
402 if (NIL_P(unspecified_bits_value)) {
403 unspecified_bits_value = INT2FIX(unspecified_bits);
404 }
405 locals[key_num] = unspecified_bits_value;
406}
407
408static void
409args_setup_kw_parameters_from_kwsplat(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
410 VALUE keyword_hash, VALUE *const locals, bool remove_hash_value)
411{
412 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
413 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
414 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
415 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
416 VALUE missing = 0;
417 int i, di;
418 int unspecified_bits = 0;
419 size_t keyword_size = RHASH_SIZE(keyword_hash);
420 VALUE unspecified_bits_value = Qnil;
421
422 for (i=0; i<req_key_num; i++) {
423 VALUE key = ID2SYM(acceptable_keywords[i]);
424 VALUE value;
425 if (remove_hash_value) {
426 value = rb_hash_delete_entry(keyword_hash, key);
427 }
428 else {
429 value = rb_hash_lookup2(keyword_hash, key, Qundef);
430 }
431
432 if (!UNDEF_P(value)) {
433 keyword_size--;
434 locals[i] = value;
435 }
436 else {
437 if (!missing) missing = rb_ary_hidden_new(1);
438 rb_ary_push(missing, key);
439 }
440 }
441
442 if (missing) argument_kw_error(ec, iseq, cme, "missing", missing);
443
444 for (di=0; i<key_num; i++, di++) {
445 VALUE key = ID2SYM(acceptable_keywords[i]);
446 VALUE value;
447 if (remove_hash_value) {
448 value = rb_hash_delete_entry(keyword_hash, key);
449 }
450 else {
451 value = rb_hash_lookup2(keyword_hash, key, Qundef);
452 }
453
454 if (!UNDEF_P(value)) {
455 keyword_size--;
456 locals[i] = value;
457 }
458 else {
459 args_setup_kw_parameters_not_found(default_values, locals, i, di,
460 &unspecified_bits, &unspecified_bits_value);
461 }
462 }
463
464 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
465 const int rest_hash_index = key_num + 1;
466 locals[rest_hash_index] = keyword_hash;
467 }
468 else {
469 if (!remove_hash_value) {
470 if (keyword_size != 0) {
471 /* Recurse with duplicated keyword hash in remove mode.
472 * This is simpler than writing code to check which entries in the hash do not match.
473 * This will raise an exception, so the additional performance impact shouldn't be material.
474 */
475 args_setup_kw_parameters_from_kwsplat(ec, iseq, cme, rb_hash_dup(keyword_hash), locals, true);
476 }
477 }
478 else if (!RHASH_EMPTY_P(keyword_hash)) {
479 argument_kw_error(ec, iseq, cme, "unknown", rb_hash_keys(keyword_hash));
480 }
481 }
482
483 if (NIL_P(unspecified_bits_value)) {
484 unspecified_bits_value = INT2FIX(unspecified_bits);
485 }
486 locals[key_num] = unspecified_bits_value;
487}
488
489static inline void
490args_setup_kw_rest_parameter(VALUE keyword_hash, VALUE *locals, int kw_flag, bool anon_kwrest)
491{
492 if (NIL_P(keyword_hash)) {
493 if (!anon_kwrest) {
494 keyword_hash = rb_hash_new();
495 }
496 }
497 else if (!(kw_flag & VM_CALL_KW_SPLAT_MUT)) {
498 keyword_hash = rb_hash_dup(keyword_hash);
499 }
500 locals[0] = keyword_hash;
501}
502
503static inline void
504args_setup_block_parameter(const rb_execution_context_t *ec, struct rb_calling_info *calling, VALUE *locals)
505{
506 VALUE block_handler = calling->block_handler;
507 *locals = rb_vm_bh_to_procval(ec, block_handler);
508}
509
510static inline int
511ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq, unsigned int * kw_flag, VALUE * converted_keyword_hash)
512{
513 if (keyword_hash == Qnil) {
514 goto ignore;
515 }
516 else if (!RB_TYPE_P(keyword_hash, T_HASH)) {
517 keyword_hash = rb_to_hash_type(keyword_hash);
518 }
519 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_kwrest)) {
520 if (!ISEQ_BODY(iseq)->param.flags.has_kw) {
521 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
522 }
523 }
524
525 if (RHASH_EMPTY_P(keyword_hash) && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
526 goto ignore;
527 }
528
529 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT) &&
530 (ISEQ_BODY(iseq)->param.flags.has_kwrest ||
531 ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
532 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
533 keyword_hash = rb_hash_dup(keyword_hash);
534 }
535 *converted_keyword_hash = keyword_hash;
536
537 if (!(ISEQ_BODY(iseq)->param.flags.has_kw) &&
538 !(ISEQ_BODY(iseq)->param.flags.has_kwrest) &&
539 RHASH_EMPTY_P(keyword_hash)) {
540 ignore:
541 *kw_flag &= ~(VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
542 return 1;
543 }
544 else {
545 return 0;
546 }
547}
548
549static VALUE
550check_kwrestarg(VALUE keyword_hash, unsigned int *kw_flag)
551{
552 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT)) {
553 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
554 return rb_hash_dup(keyword_hash);
555 }
556 else {
557 return keyword_hash;
558 }
559}
560
561static void
562flatten_rest_args(rb_execution_context_t * const ec, struct args_info *args, VALUE * const locals, unsigned int *ci_flag)
563{
564 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
565 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest)-1;
566 args->argc += rest_len;
567 if (rest_len) {
568 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
569 for (j=0; rest_len > 0; rest_len--, i++, j++) {
570 locals[i] = argv[j];
571 }
572 }
573 args->rest = Qfalse;
574 *ci_flag &= ~VM_CALL_ARGS_SPLAT;
575}
576
577static int
578setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * const iseq,
579 struct rb_calling_info *const calling,
580 const struct rb_callinfo *ci,
581 VALUE * const locals, const enum arg_setup_type arg_setup_type)
582{
583 const int min_argc = ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.post_num;
584 const int max_argc = (ISEQ_BODY(iseq)->param.flags.has_rest == FALSE) ? min_argc + ISEQ_BODY(iseq)->param.opt_num : UNLIMITED_ARGUMENTS;
585 int given_argc;
586 unsigned int ci_flag = vm_ci_flag(ci);
587 unsigned int kw_flag = ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
588 int opt_pc = 0, allow_autosplat = !kw_flag;
589 struct args_info args_body, *args;
590 VALUE keyword_hash = Qnil;
591 VALUE * const orig_sp = ec->cfp->sp;
592 unsigned int i;
593 VALUE flag_keyword_hash = 0;
594 VALUE splat_flagged_keyword_hash = 0;
595 VALUE converted_keyword_hash = 0;
596 VALUE rest_last = 0;
597 const rb_callable_method_entry_t *cme = calling->cc ? vm_cc_cme(calling->cc) : NULL;
598
599 vm_check_canary(ec, orig_sp);
600 /*
601 * Extend SP for GC.
602 *
603 * [pushed values] [uninitialized values]
604 * <- ci->argc -->
605 * <- ISEQ_BODY(iseq)->param.size------------>
606 * ^ locals ^ sp
607 *
608 * =>
609 * [pushed values] [initialized values ]
610 * <- ci->argc -->
611 * <- ISEQ_BODY(iseq)->param.size------------>
612 * ^ locals ^ sp
613 */
614 for (i=calling->argc; i<ISEQ_BODY(iseq)->param.size; i++) {
615 locals[i] = Qnil;
616 }
617 ec->cfp->sp = &locals[i];
618
619 /* setup args */
620 args = &args_body;
621 given_argc = args->argc = calling->argc;
622 args->argv = locals;
623 args->rest_dupped = ci_flag & VM_CALL_ARGS_SPLAT_MUT;
624
625 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest)) {
626 if ((ci_flag & VM_CALL_ARGS_SPLAT) &&
627 given_argc == ISEQ_BODY(iseq)->param.lead_num + (kw_flag ? 2 : 1) &&
628 !ISEQ_BODY(iseq)->param.flags.has_opt &&
629 !ISEQ_BODY(iseq)->param.flags.has_post &&
630 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
631 if (kw_flag) {
632 if (ISEQ_BODY(iseq)->param.flags.has_kw ||
633 ISEQ_BODY(iseq)->param.flags.has_kwrest) {
634 args->rest_dupped = true;
635 }
636 else if (kw_flag & VM_CALL_KW_SPLAT) {
637 VALUE kw_hash = locals[args->argc - 1];
638 if (kw_hash == Qnil ||
639 (RB_TYPE_P(kw_hash, T_HASH) && RHASH_EMPTY_P(kw_hash))) {
640 args->rest_dupped = true;
641 }
642 }
643
644 }
645 else if (!ISEQ_BODY(iseq)->param.flags.has_kw &&
646 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
647 !ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
648 args->rest_dupped = true;
649 }
650 }
651 }
652
653 if (kw_flag & VM_CALL_KWARG) {
654 args->kw_arg = vm_ci_kwarg(ci);
655
656 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
657 int kw_len = args->kw_arg->keyword_len;
658 /* copy kw_argv */
659 args->kw_argv = ALLOCA_N(VALUE, kw_len);
660 args->argc -= kw_len;
661 given_argc -= kw_len;
662 MEMCPY(args->kw_argv, locals + args->argc, VALUE, kw_len);
663 }
664 else {
665 args->kw_argv = NULL;
666 given_argc = args_kw_argv_to_hash(args);
667 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
668 }
669 }
670 else {
671 args->kw_arg = NULL;
672 args->kw_argv = NULL;
673 }
674
675 if ((ci_flag & VM_CALL_ARGS_SPLAT) && (ci_flag & VM_CALL_KW_SPLAT)) {
676 // f(*a, **kw)
677 args->rest_index = 0;
678 keyword_hash = locals[--args->argc];
679 args->rest = locals[--args->argc];
680
681 if (ignore_keyword_hash_p(keyword_hash, iseq, &kw_flag, &converted_keyword_hash)) {
682 keyword_hash = Qnil;
683 }
684 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
685 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
686 flag_keyword_hash = converted_keyword_hash;
687 arg_rest_dup(args);
688 rb_ary_push(args->rest, converted_keyword_hash);
689 keyword_hash = Qnil;
690 }
691 else if (!ISEQ_BODY(iseq)->param.flags.has_kwrest && !ISEQ_BODY(iseq)->param.flags.has_kw) {
692 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
693 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
694 arg_rest_dup(args);
695 rb_ary_push(args->rest, converted_keyword_hash);
696 keyword_hash = Qnil;
697 }
698 else {
699 // Avoid duping rest when not necessary
700 // Copy rest elements and converted keyword hash directly to VM stack
701 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
702 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest);
703 if (rest_len) {
704 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
705 given_argc += rest_len;
706 args->argc += rest_len;
707 for (j=0; rest_len > 0; rest_len--, i++, j++) {
708 locals[i] = argv[j];
709 }
710 }
711 locals[i] = converted_keyword_hash;
712 given_argc--;
713 args->argc++;
714 args->rest = Qfalse;
715 ci_flag &= ~(VM_CALL_ARGS_SPLAT|VM_CALL_KW_SPLAT);
716 keyword_hash = Qnil;
717 goto arg_splat_and_kw_splat_flattened;
718 }
719 }
720 else {
721 keyword_hash = converted_keyword_hash;
722 }
723
724 int len = RARRAY_LENINT(args->rest);
725 given_argc += len - 2;
726 }
727 else if (ci_flag & VM_CALL_ARGS_SPLAT) {
728 // f(*a)
729 args->rest_index = 0;
730 args->rest = locals[--args->argc];
731 int len = RARRAY_LENINT(args->rest);
732 given_argc += len - 1;
733
734 if (!kw_flag && len > 0) {
735 rest_last = RARRAY_AREF(args->rest, len - 1);
736 if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
737 // def f(**kw); a = [..., kw]; g(*a)
738 splat_flagged_keyword_hash = rest_last;
739 if (!(RHASH_EMPTY_P(rest_last) || ISEQ_BODY(iseq)->param.flags.has_kw) || (ISEQ_BODY(iseq)->param.flags.has_kwrest)) {
740 rest_last = rb_hash_dup(rest_last);
741 }
742 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
743
744 // Unset rest_dupped set by anon_rest as we may need to modify splat in this case
745 args->rest_dupped = false;
746
747 if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
748 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
749 // Only duplicate/modify splat array if it will be used
750 arg_rest_dup(args);
751 rb_ary_pop(args->rest);
752 }
753 else if (arg_setup_type == arg_setup_block && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
754 // Avoid hash allocation for empty hashes
755 // Copy rest elements except empty keyword hash directly to VM stack
756 flatten_rest_args(ec, args, locals, &ci_flag);
757 keyword_hash = Qnil;
758 kw_flag = 0;
759 }
760 given_argc--;
761 }
762 else if (!ISEQ_BODY(iseq)->param.flags.has_rest) {
763 // Avoid duping rest when not necessary
764 // Copy rest elements and converted keyword hash directly to VM stack
765 flatten_rest_args(ec, args, locals, &ci_flag);
766
767 if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
768 given_argc--;
769 keyword_hash = converted_keyword_hash;
770 }
771 else {
772 locals[args->argc] = converted_keyword_hash;
773 args->argc += 1;
774 keyword_hash = Qnil;
775 kw_flag = 0;
776 }
777 }
778 else {
779 if (rest_last != converted_keyword_hash) {
780 rest_last = converted_keyword_hash;
781 arg_rest_dup(args);
782 RARRAY_ASET(args->rest, len - 1, rest_last);
783 }
784
785 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords && rest_last) {
786 flag_keyword_hash = rest_last;
787 }
788 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
789 arg_rest_dup(args);
790 rb_ary_pop(args->rest);
791 given_argc--;
792 keyword_hash = rest_last;
793 }
794 }
795 }
796 }
797 }
798 else {
799 args->rest = Qfalse;
800
801 if (args->argc > 0 && (kw_flag & VM_CALL_KW_SPLAT)) {
802 // f(**kw)
803 VALUE last_arg = args->argv[args->argc-1];
804 if (ignore_keyword_hash_p(last_arg, iseq, &kw_flag, &converted_keyword_hash)) {
805 args->argc--;
806 given_argc--;
807 }
808 else {
809 if (!(kw_flag & VM_CALL_KW_SPLAT_MUT) && !ISEQ_BODY(iseq)->param.flags.has_kw) {
810 converted_keyword_hash = rb_hash_dup(converted_keyword_hash);
811 kw_flag |= VM_CALL_KW_SPLAT_MUT;
812 }
813
814 if (last_arg != converted_keyword_hash) {
815 last_arg = converted_keyword_hash;
816 args->argv[args->argc-1] = last_arg;
817 }
818
819 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
820 flag_keyword_hash = last_arg;
821 }
822 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
823 args->argc--;
824 given_argc--;
825 keyword_hash = last_arg;
826 }
827 }
828 }
829 }
830
831 if (flag_keyword_hash) {
832 FL_SET_RAW(flag_keyword_hash, RHASH_PASS_AS_KEYWORDS);
833 }
834
835 arg_splat_and_kw_splat_flattened:
836 if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
837 rb_raise(rb_eArgError, "no keywords accepted");
838 }
839
840 switch (arg_setup_type) {
841 case arg_setup_method:
842 break; /* do nothing special */
843 case arg_setup_block:
844 if (given_argc == 1 &&
845 allow_autosplat &&
846 !splat_flagged_keyword_hash &&
847 (min_argc > 0 || ISEQ_BODY(iseq)->param.opt_num > 1) &&
848 !ISEQ_BODY(iseq)->param.flags.ambiguous_param0 &&
849 !((ISEQ_BODY(iseq)->param.flags.has_kw ||
850 ISEQ_BODY(iseq)->param.flags.has_kwrest)
851 && max_argc == 1) &&
852 args_check_block_arg0(args)) {
853 given_argc = RARRAY_LENINT(args->rest);
854 }
855 break;
856 }
857
858 /* argc check */
859 if (given_argc < min_argc) {
860 if (arg_setup_type == arg_setup_block) {
861 CHECK_VM_STACK_OVERFLOW(ec->cfp, min_argc);
862 given_argc = min_argc;
863 args_extend(args, min_argc);
864 }
865 else {
866 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
867 }
868 }
869
870 if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
871 if (arg_setup_type == arg_setup_block) {
872 /* truncate */
873 args_reduce(args, given_argc - max_argc);
874 given_argc = max_argc;
875 }
876 else {
877 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
878 }
879 }
880
881 if (ISEQ_BODY(iseq)->param.flags.has_lead) {
882 args_setup_lead_parameters(args, ISEQ_BODY(iseq)->param.lead_num, locals + 0);
883 }
884
885 if (ISEQ_BODY(iseq)->param.flags.has_rest || ISEQ_BODY(iseq)->param.flags.has_post){
886 args_copy(args);
887 }
888
889 if (ISEQ_BODY(iseq)->param.flags.has_post) {
890 args_setup_post_parameters(args, ISEQ_BODY(iseq)->param.post_num, locals + ISEQ_BODY(iseq)->param.post_start);
891 }
892
893 if (ISEQ_BODY(iseq)->param.flags.has_opt) {
894 int opt = args_setup_opt_parameters(args, ISEQ_BODY(iseq)->param.opt_num, locals + ISEQ_BODY(iseq)->param.lead_num);
895 opt_pc = (int)ISEQ_BODY(iseq)->param.opt_table[opt];
896 }
897
898 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
899 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest && args->argc == 0 && !args->rest && !ISEQ_BODY(iseq)->param.flags.has_post)) {
900 *(locals + ISEQ_BODY(iseq)->param.rest_start) = args->rest = rb_cArray_empty_frozen;
901 args->rest_index = 0;
902 }
903 else {
904 args_setup_rest_parameter(args, locals + ISEQ_BODY(iseq)->param.rest_start);
905 VALUE ary = *(locals + ISEQ_BODY(iseq)->param.rest_start);
906 VALUE index = RARRAY_LEN(ary) - 1;
907 if (splat_flagged_keyword_hash &&
908 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords &&
909 !ISEQ_BODY(iseq)->param.flags.has_kw &&
910 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
911 RARRAY_AREF(ary, index) == splat_flagged_keyword_hash) {
912 ((struct RHash *)rest_last)->basic.flags &= ~RHASH_PASS_AS_KEYWORDS;
913 RARRAY_ASET(ary, index, rest_last);
914 }
915 }
916 }
917
918 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
919 VALUE * const klocals = locals + ISEQ_BODY(iseq)->param.keyword->bits_start - ISEQ_BODY(iseq)->param.keyword->num;
920
921 if (args->kw_argv != NULL) {
922 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
923 args_setup_kw_parameters(ec, iseq, cme, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
924 }
925 else if (!NIL_P(keyword_hash)) {
926 bool remove_hash_value = false;
927 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
928 keyword_hash = check_kwrestarg(keyword_hash, &kw_flag);
929 remove_hash_value = true;
930 }
931 args_setup_kw_parameters_from_kwsplat(ec, iseq, cme, keyword_hash, klocals, remove_hash_value);
932 }
933 else {
934#if VM_CHECK_MODE > 0
935 if (args_argc(args) != 0) {
936 VM_ASSERT(ci_flag & VM_CALL_ARGS_SPLAT);
937 VM_ASSERT(!(ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT)));
938 VM_ASSERT(!kw_flag);
939 VM_ASSERT(!ISEQ_BODY(iseq)->param.flags.has_rest);
940 VM_ASSERT(RARRAY_LENINT(args->rest) > 0);
941 VM_ASSERT(RB_TYPE_P(rest_last, T_HASH));
942 VM_ASSERT(FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS));
943 VM_ASSERT(args_argc(args) == 1);
944 }
945#endif
946 args_setup_kw_parameters(ec, iseq, cme, NULL, 0, NULL, klocals);
947 }
948 }
949 else if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
950 args_setup_kw_rest_parameter(keyword_hash, locals + ISEQ_BODY(iseq)->param.keyword->rest_start,
951 kw_flag, ISEQ_BODY(iseq)->param.flags.anon_kwrest);
952 }
953 else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
954 argument_kw_error(ec, iseq, cme, "unknown", rb_hash_keys(keyword_hash));
955 }
956
957 if (ISEQ_BODY(iseq)->param.flags.accepts_no_block) {
958 VALUE given_block;
959 args_setup_block_parameter(ec, calling, &given_block);
960 if (!NIL_P(given_block)) {
961 VALUE exc = rb_exc_new_cstr(rb_eArgError, "no block accepted");
962 rb_exc_raise(set_error_backtrace(ec, iseq, cme, exc));
963 }
964 }
965 else if (ISEQ_BODY(iseq)->param.flags.has_block) {
966 if (ISEQ_BODY(iseq)->local_iseq == iseq) {
967 /* Do nothing */
968 }
969 else {
970 args_setup_block_parameter(ec, calling, locals + ISEQ_BODY(iseq)->param.block_start);
971 }
972 }
973
974#if 0
975 {
976 int i;
977 for (i=0; i<ISEQ_BODY(iseq)->param.size; i++) {
978 ruby_debug_printf("local[%d] = %p\n", i, (void *)locals[i]);
979 }
980 }
981#endif
982
983 ec->cfp->sp = orig_sp;
984 return opt_pc;
985}
986
987static VALUE
988set_error_backtrace(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
989{
990 VALUE at;
991
992 if (iseq) {
993 vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
994 VM_BLOCK_HANDLER_NONE /* specval*/, (VALUE) cme /* me or cref */,
995 ISEQ_BODY(iseq)->iseq_encoded,
996 ec->cfp->sp, 0, 0 /* stack_max */);
997 at = rb_ec_backtrace_object(ec);
998 rb_vm_pop_frame(ec);
999 }
1000 else {
1001 at = rb_ec_backtrace_object(ec);
1002 }
1003
1004 rb_ivar_set(exc, idBt_locations, at);
1005 rb_exc_set_backtrace(exc, at);
1006 return exc;
1007}
1008
1009static void
1010raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
1011{
1012 set_error_backtrace(ec, iseq, cme, exc);
1013 rb_exc_raise(exc);
1014}
1015
1016static void
1017argument_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)
1018{
1019 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1020 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
1021 const struct rb_iseq_param_keyword *const kw = ISEQ_BODY(iseq)->param.keyword;
1022 const ID *keywords = kw->table;
1023 int req_key_num = kw->required_num;
1024 if (req_key_num > 0) {
1025 static const char required[] = "; required keywords";
1026 VALUE mesg = rb_attr_get(exc, idMesg);
1027 rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1028 rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1029 rb_str_cat_cstr(mesg, ":");
1030 do {
1031 rb_str_cat_cstr(mesg, " ");
1032 rb_str_append(mesg, rb_id2str(*keywords++));
1033 rb_str_cat_cstr(mesg, ",");
1034 } while (--req_key_num);
1035 RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1036 }
1037 }
1038 raise_argument_error(ec, iseq, cme, exc);
1039}
1040
1041static void
1042argument_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)
1043{
1044 raise_argument_error(ec, iseq, cme, rb_keyword_error_new(error, keys));
1045}
1046
1047static VALUE
1048vm_to_proc(VALUE proc)
1049{
1050 if (UNLIKELY(!rb_obj_is_proc(proc))) {
1051 VALUE b;
1052 const rb_callable_method_entry_t *me =
1053 rb_callable_method_entry_with_refinements(CLASS_OF(proc), idTo_proc, NULL);
1054
1055 if (me) {
1056 b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1057 }
1058 else {
1059 /* NOTE: calling method_missing */
1060 b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1061 }
1062
1063 if (NIL_P(b) || !rb_obj_is_proc(b)) {
1064 if (me) {
1065 rb_cant_convert_invalid_return(proc, "Proc", "to_proc", b);
1066 }
1067 else {
1068 rb_no_implicit_conversion(proc, "Proc");
1069 }
1070 }
1071 return b;
1072 }
1073 else {
1074 return proc;
1075 }
1076}
1077
1078static VALUE
1079refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1080{
1081 VALUE obj;
1082 ID mid;
1083 const rb_callable_method_entry_t *me = 0; /* for hidden object case */
1085 const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1086 const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1087 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1088 VALUE klass;
1089
1090 if (argc-- < 1) {
1091 rb_raise(rb_eArgError, "no receiver given");
1092 }
1093 obj = *argv++;
1094
1095 mid = SYM2ID(symbol);
1096 for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1097 me = rb_callable_method_entry(klass, mid);
1098 if (me) {
1099 me = rb_resolve_refined_method_callable(refinements, me);
1100 if (me) break;
1101 }
1102 }
1103
1104 ec = GET_EC();
1105 if (!NIL_P(blockarg)) {
1106 vm_passed_block_handler_set(ec, blockarg);
1107 }
1108 if (!me) {
1109 return method_missing(ec, obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1110 }
1111 return rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1112}
1113
1114static VALUE
1115vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1116 const struct rb_callinfo *ci, const rb_iseq_t *blockiseq, const int is_super)
1117{
1118 if (vm_ci_flag(ci) & VM_CALL_ARGS_BLOCKARG) {
1119 VALUE block_code = *(--reg_cfp->sp);
1120
1121 if (NIL_P(block_code)) {
1122 return VM_BLOCK_HANDLER_NONE;
1123 }
1124 else if (block_code == rb_block_param_proxy) {
1125 return VM_CF_BLOCK_HANDLER(reg_cfp);
1126 }
1127 else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1128 const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1129 if (cref && !NIL_P(cref->refinements)) {
1130 VALUE ref = cref->refinements;
1131 VALUE func = rb_hash_lookup(ref, block_code);
1132 if (NIL_P(func)) {
1133 /* TODO: limit cached funcs */
1134 VALUE callback_arg = rb_ary_hidden_new(2);
1135 rb_ary_push(callback_arg, block_code);
1136 rb_ary_push(callback_arg, ref);
1137 OBJ_FREEZE(callback_arg);
1138 func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 1, UNLIMITED_ARGUMENTS);
1139 /* the table is frozen when it belongs to a Proc#refined memo; skip the cache then */
1140 if (!OBJ_FROZEN(ref)) {
1141 rb_hash_aset(ref, block_code, func);
1142 }
1143 }
1144 block_code = func;
1145 }
1146 return block_code;
1147 }
1148 else {
1149 return vm_to_proc(block_code);
1150 }
1151 }
1152 else if (blockiseq != NULL) { /* likely */
1153 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1154 captured->code.iseq = blockiseq;
1155 return VM_BH_FROM_ISEQ_BLOCK(captured);
1156 }
1157 else {
1158 if (is_super) {
1159 return GET_BLOCK_HANDLER();
1160 }
1161 else {
1162 return VM_BLOCK_HANDLER_NONE;
1163 }
1164 }
1165}
1166
1167static void vm_adjust_stack_forwarding(const struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, int argc, VALUE splat);
1168
1169static VALUE
1170vm_caller_setup_fwd_args(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1171 CALL_DATA cd, const rb_iseq_t *blockiseq, const int is_super,
1172 struct rb_forwarding_call_data *adjusted_cd, struct rb_callinfo *adjusted_ci)
1173{
1174 CALL_INFO site_ci = cd->ci;
1175 VALUE bh = Qundef;
1176
1177 RUBY_ASSERT(ISEQ_BODY(ISEQ_BODY(CFP_ISEQ(reg_cfp))->local_iseq)->param.flags.forwardable);
1178 CALL_INFO caller_ci = (CALL_INFO)TOPN(0);
1179
1180 unsigned int site_argc = vm_ci_argc(site_ci);
1181 unsigned int site_flag = vm_ci_flag(site_ci);
1182 ID site_mid = vm_ci_mid(site_ci);
1183
1184 unsigned int caller_argc = vm_ci_argc(caller_ci);
1185 unsigned int caller_flag = vm_ci_flag(caller_ci);
1186 const struct rb_callinfo_kwarg * kw = vm_ci_kwarg(caller_ci);
1187
1188 VALUE splat = Qfalse;
1189
1190 if (site_flag & VM_CALL_ARGS_SPLAT) {
1191 // If we're called with args_splat, the top 1 should be an array
1192 splat = TOPN(1);
1193 site_argc += (RARRAY_LEN(splat) - 1);
1194 }
1195
1196 // Need to setup the block in case of e.g. `super { :block }`
1197 if (is_super && blockiseq) {
1198 bh = vm_caller_setup_arg_block(ec, GET_CFP(), site_ci, blockiseq, is_super);
1199 }
1200 else {
1201 bh = VM_ENV_BLOCK_HANDLER(GET_LEP());
1202 }
1203
1204 vm_adjust_stack_forwarding(ec, GET_CFP(), caller_argc, splat);
1205
1206 *adjusted_ci = VM_CI_ON_STACK(
1207 site_mid,
1208 ((caller_flag & ~(VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL)) |
1209 (site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
1210 site_argc + caller_argc,
1211 kw
1212 );
1213
1214 adjusted_cd->cd.ci = adjusted_ci;
1215 adjusted_cd->cd.cc = cd->cc;
1216 adjusted_cd->caller_ci = caller_ci;
1217
1218 return bh;
1219}
#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 OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
Definition fl_type.h:133
#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 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:678
VALUE rb_cSymbol
Symbol class.
Definition string.c:86
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:386
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:3898
#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:3666
#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:2141
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
Definition vm_method.c:3561
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:50
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
Definition rarray.h:280
static void RARRAY_ASET(VALUE ary, long i, VALUE v)
Assigns an object in an array.
Definition rarray.h:385
#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 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:54
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