Ruby: vm_args.c Source File

Ruby 4.0.5p0 (2026-05-20 revision 64336ffd0ee9e1f4c05891695a3d7b49cb709721)

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