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