Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
class.c
Go to the documentation of this file.
1/**********************************************************************
2
3 class.c -
4
5 $Author$
6 created at: Tue Aug 10 15:05:44 JST 1993
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10**********************************************************************/
11
26#include "internal.h"
27#include "ruby/st.h"
28#include "constant.h"
29#include "vm_core.h"
30#include "id_table.h"
31#include <ctype.h>
32
33#define id_attached id__attached__
34
35#define METACLASS_OF(k) RBASIC(k)->klass
36#define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
37
38void
40{
41 rb_subclass_entry_t *entry, *head;
42
43 if (super && super != Qundef) {
45 entry->klass = klass;
46 entry->next = NULL;
47
48 head = RCLASS_EXT(super)->subclasses;
49 if (head) {
50 entry->next = head;
51 RCLASS_EXT(head->klass)->parent_subclasses = &entry->next;
52 }
53
54 RCLASS_EXT(super)->subclasses = entry;
55 RCLASS_EXT(klass)->parent_subclasses = &RCLASS_EXT(super)->subclasses;
56 }
57}
58
59static void
60rb_module_add_to_subclasses_list(VALUE module, VALUE iclass)
61{
62 rb_subclass_entry_t *entry, *head;
63
65 entry->klass = iclass;
66 entry->next = NULL;
67
68 head = RCLASS_EXT(module)->subclasses;
69 if (head) {
70 entry->next = head;
71 RCLASS_EXT(head->klass)->module_subclasses = &entry->next;
72 }
73
74 RCLASS_EXT(module)->subclasses = entry;
75 RCLASS_EXT(iclass)->module_subclasses = &RCLASS_EXT(module)->subclasses;
76}
77
78void
80{
82
83 if (RCLASS_EXT(klass)->parent_subclasses) {
84 entry = *RCLASS_EXT(klass)->parent_subclasses;
85
86 *RCLASS_EXT(klass)->parent_subclasses = entry->next;
87 if (entry->next) {
88 RCLASS_EXT(entry->next->klass)->parent_subclasses = RCLASS_EXT(klass)->parent_subclasses;
89 }
90 xfree(entry);
91 }
92
93 RCLASS_EXT(klass)->parent_subclasses = NULL;
94}
95
96void
98{
100
101 if (RCLASS_EXT(klass)->module_subclasses) {
102 entry = *RCLASS_EXT(klass)->module_subclasses;
103 *RCLASS_EXT(klass)->module_subclasses = entry->next;
104
105 if (entry->next) {
106 RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
107 }
108
109 xfree(entry);
110 }
111
112 RCLASS_EXT(klass)->module_subclasses = NULL;
113}
114
115void
117{
118 rb_subclass_entry_t *cur = RCLASS_EXT(klass)->subclasses;
119
120 /* do not be tempted to simplify this loop into a for loop, the order of
121 operations is important here if `f` modifies the linked list */
122 while (cur) {
123 VALUE curklass = cur->klass;
124 cur = cur->next;
125 f(curklass, arg);
126 }
127}
128
129static void
130class_detach_subclasses(VALUE klass, VALUE arg)
131{
133}
134
135void
137{
138 rb_class_foreach_subclass(klass, class_detach_subclasses, Qnil);
139}
140
141static void
142class_detach_module_subclasses(VALUE klass, VALUE arg)
143{
145}
146
147void
149{
150 rb_class_foreach_subclass(klass, class_detach_module_subclasses, Qnil);
151}
152
165static VALUE
166class_alloc(VALUE flags, VALUE klass)
167{
168 NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0));
169 obj->ptr = ZALLOC(rb_classext_t);
170 /* ZALLOC
171 RCLASS_IV_TBL(obj) = 0;
172 RCLASS_CONST_TBL(obj) = 0;
173 RCLASS_M_TBL(obj) = 0;
174 RCLASS_IV_INDEX_TBL(obj) = 0;
175 RCLASS_SET_SUPER((VALUE)obj, 0);
176 RCLASS_EXT(obj)->subclasses = NULL;
177 RCLASS_EXT(obj)->parent_subclasses = NULL;
178 RCLASS_EXT(obj)->module_subclasses = NULL;
179 */
180 RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
183 RCLASS_EXT(obj)->allocator = 0;
184
185 return (VALUE)obj;
186}
187
188static void
189RCLASS_M_TBL_INIT(VALUE c)
190{
192}
193
203VALUE
205{
206 VALUE klass = class_alloc(T_CLASS, rb_cClass);
207
208 RCLASS_SET_SUPER(klass, super);
209 RCLASS_M_TBL_INIT(klass);
210
211 return (VALUE)klass;
212}
213
214
221void
223{
224 if (!RB_TYPE_P(super, T_CLASS)) {
225 rb_raise(rb_eTypeError, "superclass must be a Class (%"PRIsVALUE" given)",
226 rb_obj_class(super));
227 }
228 if (RBASIC(super)->flags & FL_SINGLETON) {
229 rb_raise(rb_eTypeError, "can't make subclass of singleton class");
230 }
231 if (super == rb_cClass) {
232 rb_raise(rb_eTypeError, "can't make subclass of Class");
233 }
234}
235
236
243VALUE
245{
246 Check_Type(super, T_CLASS);
248 return rb_class_boot(super);
249}
250
251static void
252clone_method(VALUE old_klass, VALUE new_klass, ID mid, const rb_method_entry_t *me)
253{
254 if (me->def->type == VM_METHOD_TYPE_ISEQ) {
255 rb_cref_t *new_cref;
256 rb_vm_rewrite_cref(me->def->body.iseq.cref, old_klass, new_klass, &new_cref);
257 rb_add_method_iseq(new_klass, mid, me->def->body.iseq.iseqptr, new_cref, METHOD_ENTRY_VISI(me));
258 }
259 else {
260 rb_method_entry_set(new_klass, mid, me, METHOD_ENTRY_VISI(me));
261 }
262}
263
267};
268
270clone_method_i(ID key, VALUE value, void *data)
271{
272 const struct clone_method_arg *arg = (struct clone_method_arg *)data;
273 clone_method(arg->old_klass, arg->new_klass, key, (const rb_method_entry_t *)value);
274 return ID_TABLE_CONTINUE;
275}
276
280};
281
282static int
283clone_const(ID key, const rb_const_entry_t *ce, struct clone_const_arg *arg)
284{
286 MEMCPY(nce, ce, rb_const_entry_t, 1);
287 RB_OBJ_WRITTEN(arg->klass, Qundef, ce->value);
288 RB_OBJ_WRITTEN(arg->klass, Qundef, ce->file);
289
290 rb_id_table_insert(arg->tbl, key, (VALUE)nce);
291 return ID_TABLE_CONTINUE;
292}
293
295clone_const_i(ID key, VALUE value, void *data)
296{
297 return clone_const(key, (const rb_const_entry_t *)value, data);
298}
299
300static void
301class_init_copy_check(VALUE clone, VALUE orig)
302{
303 if (orig == rb_cBasicObject) {
304 rb_raise(rb_eTypeError, "can't copy the root class");
305 }
306 if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
307 rb_raise(rb_eTypeError, "already initialized class");
308 }
309 if (FL_TEST(orig, FL_SINGLETON)) {
310 rb_raise(rb_eTypeError, "can't copy singleton class");
311 }
312}
313
314/* :nodoc: */
315VALUE
317{
318 /* cloned flag is refer at constant inline cache
319 * see vm_get_const_key_cref() in vm_insnhelper.c
320 */
321 FL_SET(clone, RCLASS_CLONED);
322 FL_SET(orig , RCLASS_CLONED);
323
324 if (RB_TYPE_P(clone, T_CLASS)) {
325 class_init_copy_check(clone, orig);
326 }
327 if (!OBJ_INIT_COPY(clone, orig)) return clone;
328 if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
331 }
332 RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig));
333 RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
334 if (RCLASS_IV_TBL(clone)) {
336 RCLASS_IV_TBL(clone) = 0;
337 }
338 if (RCLASS_CONST_TBL(clone)) {
340 RCLASS_CONST_TBL(clone) = 0;
341 }
342 RCLASS_M_TBL(clone) = 0;
343 if (RCLASS_IV_TBL(orig)) {
345
346 rb_iv_tbl_copy(clone, orig);
347 CONST_ID(id, "__tmp_classpath__");
348 st_delete(RCLASS_IV_TBL(clone), &id, 0);
349 CONST_ID(id, "__classpath__");
350 st_delete(RCLASS_IV_TBL(clone), &id, 0);
351 CONST_ID(id, "__classid__");
352 st_delete(RCLASS_IV_TBL(clone), &id, 0);
353 }
354 if (RCLASS_CONST_TBL(orig)) {
355 struct clone_const_arg arg;
356
357 arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
358 arg.klass = clone;
359 rb_id_table_foreach(RCLASS_CONST_TBL(orig), clone_const_i, &arg);
360 }
361 if (RCLASS_M_TBL(orig)) {
362 struct clone_method_arg arg;
363 arg.old_klass = orig;
364 arg.new_klass = clone;
365 RCLASS_M_TBL_INIT(clone);
366 rb_id_table_foreach(RCLASS_M_TBL(orig), clone_method_i, &arg);
367 }
368
369 return clone;
370}
371
372VALUE
374{
376}
377
378// Clone and return the singleton class of `obj` if it has been created and is attached to `obj`.
379VALUE
381{
382 const VALUE klass = RBASIC(obj)->klass;
383
384 // Note that `rb_singleton_class()` can create situations where `klass` is
385 // attached to an object other than `obj`. In which case `obj` does not have
386 // a material singleton class attached yet and there is no singleton class
387 // to clone.
389 // nothing to clone
390 return klass;
391 }
392 else {
393 /* copy singleton(unnamed) class */
394 bool klass_of_clone_is_new;
395 VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
396
397 if (BUILTIN_TYPE(obj) == T_CLASS) {
398 klass_of_clone_is_new = true;
399 RBASIC_SET_CLASS(clone, clone);
400 }
401 else {
402 VALUE klass_metaclass_clone = rb_singleton_class_clone(klass);
403 // When `METACLASS_OF(klass) == klass_metaclass_clone`, it means the
404 // recursive call did not clone `METACLASS_OF(klass)`.
405 klass_of_clone_is_new = (METACLASS_OF(klass) != klass_metaclass_clone);
406 RBASIC_SET_CLASS(clone, klass_metaclass_clone);
407 }
408
409 RCLASS_SET_SUPER(clone, RCLASS_SUPER(klass));
410 RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator;
411 if (RCLASS_IV_TBL(klass)) {
412 rb_iv_tbl_copy(clone, klass);
413 }
414 if (RCLASS_CONST_TBL(klass)) {
415 struct clone_const_arg arg;
416 arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
417 arg.klass = clone;
419 }
420 if (attach != Qundef) {
421 rb_singleton_class_attached(clone, attach);
422 }
423 RCLASS_M_TBL_INIT(clone);
424 {
425 struct clone_method_arg arg;
426 arg.old_klass = klass;
427 arg.new_klass = clone;
428 rb_id_table_foreach(RCLASS_M_TBL(klass), clone_method_i, &arg);
429 }
430 if (klass_of_clone_is_new) {
432 }
433 FL_SET(clone, FL_SINGLETON);
434
435 return clone;
436 }
437}
438
443void
445{
446 if (FL_TEST(klass, FL_SINGLETON)) {
447 if (!RCLASS_IV_TBL(klass)) {
449 }
451 }
452}
453
459#define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
460
461static int
462rb_singleton_class_has_metaclass_p(VALUE sklass)
463{
464 return rb_attr_get(METACLASS_OF(sklass), id_attached) == sklass;
465}
466
467int
469{
470 return (RB_TYPE_P(rb_attr_get(sklass, id_attached), T_CLASS) &&
471 !rb_singleton_class_has_metaclass_p(sklass));
472}
473
479#define HAVE_METACLASS_P(k) \
480 (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
481 rb_singleton_class_has_metaclass_p(k))
482
490#define ENSURE_EIGENCLASS(klass) \
491 (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
492
493
503static inline VALUE
504make_metaclass(VALUE klass)
505{
506 VALUE super;
507 VALUE metaclass = rb_class_boot(Qundef);
508
509 FL_SET(metaclass, FL_SINGLETON);
511
513 SET_METACLASS_OF(klass, metaclass);
514 SET_METACLASS_OF(metaclass, metaclass);
515 }
516 else {
517 VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
518 SET_METACLASS_OF(klass, metaclass);
519 SET_METACLASS_OF(metaclass, ENSURE_EIGENCLASS(tmp));
520 }
521
522 super = RCLASS_SUPER(klass);
523 while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
524 RCLASS_SET_SUPER(metaclass, super ? ENSURE_EIGENCLASS(super) : rb_cClass);
525
526 return metaclass;
527}
528
535static inline VALUE
536make_singleton_class(VALUE obj)
537{
538 VALUE orig_class = RBASIC(obj)->klass;
539 VALUE klass = rb_class_boot(orig_class);
540
544
546 return klass;
547}
548
549
550static VALUE
551boot_defclass(const char *name, VALUE super)
552{
553 VALUE obj = rb_class_boot(super);
554 ID id = rb_intern(name);
555
558 return obj;
559}
560
561void
563{
564 rb_cBasicObject = boot_defclass("BasicObject", 0);
565 rb_cObject = boot_defclass("Object", rb_cBasicObject);
567
568 /* resolve class name ASAP for order-independence */
570
571 rb_cModule = boot_defclass("Module", rb_cObject);
572 rb_cClass = boot_defclass("Class", rb_cModule);
573
579}
580
581
592VALUE
594{
595 if (BUILTIN_TYPE(obj) == T_CLASS) {
596 return make_metaclass(obj);
597 }
598 else {
599 return make_singleton_class(obj);
600 }
601}
602
603
614VALUE
616{
617 VALUE klass;
618
619 if (!super) super = rb_cObject;
620 klass = rb_class_new(super);
622
623 return klass;
624}
625
626
637{
638 ID inherited;
639 if (!super) super = rb_cObject;
640 CONST_ID(inherited, "inherited");
641 return rb_funcall(super, inherited, 1, klass);
642}
643
644
645
661VALUE
662rb_define_class(const char *name, VALUE super)
663{
664 VALUE klass;
665 ID id;
666
667 id = rb_intern(name);
668 if (rb_const_defined(rb_cObject, id)) {
670 if (!RB_TYPE_P(klass, T_CLASS)) {
671 rb_raise(rb_eTypeError, "%s is not a class (%"PRIsVALUE")",
673 }
674 if (rb_class_real(RCLASS_SUPER(klass)) != super) {
675 rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
676 }
677
678 /* Class may have been defined in Ruby and not pin-rooted */
680 return klass;
681 }
682 if (!super) {
683 rb_raise(rb_eArgError, "no super class for `%s'", name);
684 }
685 klass = rb_define_class_id(id, super);
689
690 return klass;
691}
692
693
710VALUE
711rb_define_class_under(VALUE outer, const char *name, VALUE super)
712{
713 return rb_define_class_id_under(outer, rb_intern(name), super);
714}
715
716
733VALUE
735{
736 VALUE klass;
737
738 if (rb_const_defined_at(outer, id)) {
739 klass = rb_const_get_at(outer, id);
740 if (!RB_TYPE_P(klass, T_CLASS)) {
741 rb_raise(rb_eTypeError, "%"PRIsVALUE"::%"PRIsVALUE" is not a class"
742 " (%"PRIsVALUE")",
743 outer, rb_id2str(id), rb_obj_class(klass));
744 }
745 if (rb_class_real(RCLASS_SUPER(klass)) != super) {
746 rb_raise(rb_eTypeError, "superclass mismatch for class "
747 "%"PRIsVALUE"::%"PRIsVALUE""
748 " (%"PRIsVALUE" is given but was %"PRIsVALUE")",
749 outer, rb_id2str(id), RCLASS_SUPER(klass), super);
750 }
751 /* Class may have been defined in Ruby and not pin-rooted */
753
754 return klass;
755 }
756 if (!super) {
757 rb_raise(rb_eArgError, "no super class for `%"PRIsVALUE"::%"PRIsVALUE"'",
758 rb_class_path(outer), rb_id2str(id));
759 }
760 klass = rb_define_class_id(id, super);
762 rb_const_set(outer, id, klass);
766
767 return klass;
768}
769
770VALUE
772{
773 VALUE mdl = class_alloc(T_MODULE, rb_cModule);
774 RCLASS_M_TBL_INIT(mdl);
775 return (VALUE)mdl;
776}
777
778VALUE
780{
781 return rb_module_new();
782}
783
784VALUE
786{
787 VALUE module;
788 ID id;
789
790 id = rb_intern(name);
791 if (rb_const_defined(rb_cObject, id)) {
792 module = rb_const_get(rb_cObject, id);
793 if (!RB_TYPE_P(module, T_MODULE)) {
794 rb_raise(rb_eTypeError, "%s is not a module (%"PRIsVALUE")",
795 name, rb_obj_class(module));
796 }
797 /* Module may have been defined in Ruby and not pin-rooted */
798 rb_vm_add_root_module(id, module);
799 return module;
800 }
801 module = rb_define_module_id(id);
802 rb_vm_add_root_module(id, module);
804 rb_const_set(rb_cObject, id, module);
805
806 return module;
807}
808
809VALUE
811{
813}
814
815VALUE
817{
818 VALUE module;
819
820 if (rb_const_defined_at(outer, id)) {
821 module = rb_const_get_at(outer, id);
822 if (!RB_TYPE_P(module, T_MODULE)) {
823 rb_raise(rb_eTypeError, "%"PRIsVALUE"::%"PRIsVALUE" is not a module"
824 " (%"PRIsVALUE")",
825 outer, rb_id2str(id), rb_obj_class(module));
826 }
827 return module;
828 }
829 module = rb_define_module_id(id);
830 rb_const_set(outer, id, module);
831 rb_set_class_path_string(module, outer, rb_id2str(id));
833
834 return module;
835}
836
837VALUE
839{
840 VALUE klass = class_alloc(T_ICLASS, rb_cClass);
841
843 RCLASS_M_TBL(OBJ_WB_UNPROTECT(module)); /* TODO: unprotected? */
844
845 RCLASS_SET_ORIGIN(klass, module == RCLASS_ORIGIN(module) ? klass : RCLASS_ORIGIN(module));
846 if (BUILTIN_TYPE(module) == T_ICLASS) {
847 module = RBASIC(module)->klass;
848 }
849 if (!RCLASS_IV_TBL(module)) {
851 }
852 if (!RCLASS_CONST_TBL(module)) {
854 }
857
858 RCLASS_SET_SUPER(klass, super);
859 if (RB_TYPE_P(module, T_ICLASS)) {
861 }
862 else {
863 RBASIC_SET_CLASS(klass, module);
864 }
865
866 return (VALUE)klass;
867}
868
869static int include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super);
870
871static void
872ensure_includable(VALUE klass, VALUE module)
873{
875 Check_Type(module, T_MODULE);
877 rb_raise(rb_eArgError, "refinement module is not allowed");
878 }
879}
880
881void
883{
884 int changed = 0;
885
886 ensure_includable(klass, module);
887
888 changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module, TRUE);
889 if (changed < 0)
890 rb_raise(rb_eArgError, "cyclic include detected");
891}
892
894add_refined_method_entry_i(ID key, VALUE value, void *data)
895{
897 return ID_TABLE_CONTINUE;
898}
899
900static void ensure_origin(VALUE klass);
901
902static int
903include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
904{
905 VALUE p, iclass;
906 int method_changed = 0, constant_changed = 0;
907 struct rb_id_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
908
909 if (FL_TEST(module, RCLASS_REFINED_BY_ANY)) {
910 ensure_origin(module);
911 }
912
913 while (module) {
914 int origin_seen = FALSE;
915 int superclass_seen = FALSE;
916 struct rb_id_table *tbl;
917
918 if (klass == c)
919 origin_seen = TRUE;
920 if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
921 return -1;
922 /* ignore if the module included already in superclasses */
923 for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
924 int type = BUILTIN_TYPE(p);
925 if (c == p)
926 origin_seen = TRUE;
927 if (type == T_ICLASS) {
928 if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
929 if (!superclass_seen && origin_seen) {
930 c = p; /* move insertion point */
931 }
932 goto skip;
933 }
934 }
935 else if (type == T_CLASS) {
936 if (!search_super) break;
937 superclass_seen = TRUE;
938 }
939 }
940 iclass = rb_include_class_new(module, RCLASS_SUPER(c));
941 c = RCLASS_SET_SUPER(c, iclass);
942 RCLASS_SET_INCLUDER(iclass, klass);
943
944 {
945 VALUE m = module;
946 if (BUILTIN_TYPE(m) == T_ICLASS) m = RBASIC(m)->klass;
947 rb_module_add_to_subclasses_list(m, iclass);
948 }
949
951 VALUE refined_class =
953
954 rb_id_table_foreach(RMODULE_M_TBL(module), add_refined_method_entry_i, (void *)refined_class);
956 }
957
958 tbl = RMODULE_M_TBL(module);
959 if (tbl && rb_id_table_size(tbl)) method_changed = 1;
960
961 tbl = RMODULE_CONST_TBL(module);
962 if (tbl && rb_id_table_size(tbl)) constant_changed = 1;
963 skip:
964 module = RCLASS_SUPER(module);
965 }
966
967 if (method_changed) rb_clear_method_cache_by_class(klass);
968 if (constant_changed) rb_clear_constant_cache();
969
970 return method_changed;
971}
972
974move_refined_method(ID key, VALUE value, void *data)
975{
977 VALUE klass = (VALUE)data;
978 struct rb_id_table *tbl = RCLASS_M_TBL(klass);
979
981 if (me->def->body.refined.orig_me) {
982 const rb_method_entry_t *orig_me = me->def->body.refined.orig_me, *new_me;
984 new_me = rb_method_entry_clone(me);
985 rb_id_table_insert(tbl, key, (VALUE)new_me);
986 RB_OBJ_WRITTEN(klass, Qundef, new_me);
987 rb_method_entry_copy(me, orig_me);
988 return ID_TABLE_CONTINUE;
989 }
990 else {
992 return ID_TABLE_DELETE;
993 }
994 }
995 else {
996 return ID_TABLE_CONTINUE;
997 }
998}
999
1000static void
1001ensure_origin(VALUE klass)
1002{
1003 VALUE origin = RCLASS_ORIGIN(klass);
1004 if (origin == klass) {
1005 origin = class_alloc(T_ICLASS, klass);
1006 OBJ_WB_UNPROTECT(origin); /* TODO: conservative shading. Need more survey. */
1007 RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass));
1008 RCLASS_SET_SUPER(klass, origin);
1009 RCLASS_SET_ORIGIN(klass, origin);
1010 RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
1011 RCLASS_M_TBL_INIT(klass);
1012 rb_id_table_foreach(RCLASS_M_TBL(origin), move_refined_method, (void *)klass);
1013 }
1014}
1015
1016void
1018{
1019 int changed = 0;
1020
1021 ensure_includable(klass, module);
1022 ensure_origin(klass);
1023 changed = include_modules_at(klass, klass, module, FALSE);
1024 if (changed < 0)
1025 rb_raise(rb_eArgError, "cyclic prepend detected");
1026 if (changed) {
1028 }
1029}
1030
1031/*
1032 * call-seq:
1033 * mod.included_modules -> array
1034 *
1035 * Returns the list of modules included in <i>mod</i>.
1036 *
1037 * module Mixin
1038 * end
1039 *
1040 * module Outer
1041 * include Mixin
1042 * end
1043 *
1044 * Mixin.included_modules #=> []
1045 * Outer.included_modules #=> [Mixin]
1046 */
1047
1048VALUE
1050{
1051 VALUE ary = rb_ary_new();
1052 VALUE p;
1053 VALUE origin = RCLASS_ORIGIN(mod);
1054
1055 for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
1056 if (p != origin && BUILTIN_TYPE(p) == T_ICLASS) {
1057 VALUE m = RBASIC(p)->klass;
1058 if (RB_TYPE_P(m, T_MODULE))
1059 rb_ary_push(ary, m);
1060 }
1061 }
1062 return ary;
1063}
1064
1065/*
1066 * call-seq:
1067 * mod.include?(module) -> true or false
1068 *
1069 * Returns <code>true</code> if <i>module</i> is included in
1070 * <i>mod</i> or one of <i>mod</i>'s ancestors.
1071 *
1072 * module A
1073 * end
1074 * class B
1075 * include A
1076 * end
1077 * class C < B
1078 * end
1079 * B.include?(A) #=> true
1080 * C.include?(A) #=> true
1081 * A.include?(A) #=> false
1082 */
1083
1084VALUE
1086{
1087 VALUE p;
1088
1089 Check_Type(mod2, T_MODULE);
1090 for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
1091 if (BUILTIN_TYPE(p) == T_ICLASS) {
1092 if (RBASIC(p)->klass == mod2) return Qtrue;
1093 }
1094 }
1095 return Qfalse;
1096}
1097
1098/*
1099 * call-seq:
1100 * mod.ancestors -> array
1101 *
1102 * Returns a list of modules included/prepended in <i>mod</i>
1103 * (including <i>mod</i> itself).
1104 *
1105 * module Mod
1106 * include Math
1107 * include Comparable
1108 * prepend Enumerable
1109 * end
1110 *
1111 * Mod.ancestors #=> [Enumerable, Mod, Comparable, Math]
1112 * Math.ancestors #=> [Math]
1113 * Enumerable.ancestors #=> [Enumerable]
1114 */
1115
1116VALUE
1118{
1119 VALUE p, ary = rb_ary_new();
1120
1121 for (p = mod; p; p = RCLASS_SUPER(p)) {
1122 if (p != RCLASS_ORIGIN(p)) continue;
1123 if (BUILTIN_TYPE(p) == T_ICLASS) {
1124 rb_ary_push(ary, RBASIC(p)->klass);
1125 }
1126 else {
1127 rb_ary_push(ary, p);
1128 }
1129 }
1130 return ary;
1131}
1132
1133static void
1134ins_methods_push(st_data_t name, st_data_t ary)
1135{
1136 rb_ary_push((VALUE)ary, ID2SYM((ID)name));
1137}
1138
1139static int
1140ins_methods_i(st_data_t name, st_data_t type, st_data_t ary)
1141{
1142 switch ((rb_method_visibility_t)type) {
1143 case METHOD_VISI_UNDEF:
1145 break;
1146 default: /* everything but private */
1147 ins_methods_push(name, ary);
1148 break;
1149 }
1150 return ST_CONTINUE;
1151}
1152
1153static int
1154ins_methods_prot_i(st_data_t name, st_data_t type, st_data_t ary)
1155{
1157 ins_methods_push(name, ary);
1158 }
1159 return ST_CONTINUE;
1160}
1161
1162static int
1163ins_methods_priv_i(st_data_t name, st_data_t type, st_data_t ary)
1164{
1166 ins_methods_push(name, ary);
1167 }
1168 return ST_CONTINUE;
1169}
1170
1171static int
1172ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
1173{
1175 ins_methods_push(name, ary);
1176 }
1177 return ST_CONTINUE;
1178}
1179
1183};
1184
1186method_entry_i(ID key, VALUE value, void *data)
1187{
1188 const rb_method_entry_t *me = (const rb_method_entry_t *)value;
1189 struct method_entry_arg *arg = (struct method_entry_arg *)data;
1191
1192 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1193 VALUE owner = me->owner;
1195 if (!me) return ID_TABLE_CONTINUE;
1196 if (!arg->recur && me->owner != owner) return ID_TABLE_CONTINUE;
1197 }
1198 if (!st_is_member(arg->list, key)) {
1200 type = METHOD_VISI_UNDEF; /* none */
1201 }
1202 else {
1204 }
1206 }
1207 return ID_TABLE_CONTINUE;
1208}
1209
1210static void
1211add_instance_method_list(VALUE mod, struct method_entry_arg *me_arg)
1212{
1213 struct rb_id_table *m_tbl = RCLASS_M_TBL(mod);
1214 if (!m_tbl) return;
1215 rb_id_table_foreach(m_tbl, method_entry_i, me_arg);
1216}
1217
1218static bool
1219particular_class_p(VALUE mod)
1220{
1221 if (!mod) return false;
1222 if (FL_TEST(mod, FL_SINGLETON)) return true;
1223 if (BUILTIN_TYPE(mod) == T_ICLASS) return true;
1224 return false;
1225}
1226
1227static VALUE
1228class_instance_method_list(int argc, const VALUE *argv, VALUE mod, int obj, int (*func) (st_data_t, st_data_t, st_data_t))
1229{
1230 VALUE ary;
1231 int recur = TRUE, prepended = 0;
1232 struct method_entry_arg me_arg;
1233
1234 if (rb_check_arity(argc, 0, 1)) recur = RTEST(argv[0]);
1235
1236 me_arg.list = st_init_numtable();
1237 me_arg.recur = recur;
1238
1239 if (obj) {
1240 for (; particular_class_p(mod); mod = RCLASS_SUPER(mod)) {
1241 add_instance_method_list(mod, &me_arg);
1242 }
1243 }
1244
1245 if (!recur && RCLASS_ORIGIN(mod) != mod) {
1247 prepended = 1;
1248 }
1249
1250 for (; mod; mod = RCLASS_SUPER(mod)) {
1251 add_instance_method_list(mod, &me_arg);
1252 if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
1253 if (!recur) break;
1254 }
1255 ary = rb_ary_new2(me_arg.list->num_entries);
1256 st_foreach(me_arg.list, func, ary);
1257 st_free_table(me_arg.list);
1258
1259 return ary;
1260}
1261
1262/*
1263 * call-seq:
1264 * mod.instance_methods(include_super=true) -> array
1265 *
1266 * Returns an array containing the names of the public and protected instance
1267 * methods in the receiver. For a module, these are the public and protected methods;
1268 * for a class, they are the instance (not singleton) methods. If the optional
1269 * parameter is <code>false</code>, the methods of any ancestors are not included.
1270 *
1271 * module A
1272 * def method1() end
1273 * end
1274 * class B
1275 * include A
1276 * def method2() end
1277 * end
1278 * class C < B
1279 * def method3() end
1280 * end
1281 *
1282 * A.instance_methods(false) #=> [:method1]
1283 * B.instance_methods(false) #=> [:method2]
1284 * B.instance_methods(true).include?(:method1) #=> true
1285 * C.instance_methods(false) #=> [:method3]
1286 * C.instance_methods.include?(:method2) #=> true
1287 */
1288
1289VALUE
1291{
1292 return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1293}
1294
1295/*
1296 * call-seq:
1297 * mod.protected_instance_methods(include_super=true) -> array
1298 *
1299 * Returns a list of the protected instance methods defined in
1300 * <i>mod</i>. If the optional parameter is <code>false</code>, the
1301 * methods of any ancestors are not included.
1302 */
1303
1304VALUE
1306{
1307 return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1308}
1309
1310/*
1311 * call-seq:
1312 * mod.private_instance_methods(include_super=true) -> array
1313 *
1314 * Returns a list of the private instance methods defined in
1315 * <i>mod</i>. If the optional parameter is <code>false</code>, the
1316 * methods of any ancestors are not included.
1317 *
1318 * module Mod
1319 * def method1() end
1320 * private :method1
1321 * def method2() end
1322 * end
1323 * Mod.instance_methods #=> [:method2]
1324 * Mod.private_instance_methods #=> [:method1]
1325 */
1326
1327VALUE
1329{
1330 return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1331}
1332
1333/*
1334 * call-seq:
1335 * mod.public_instance_methods(include_super=true) -> array
1336 *
1337 * Returns a list of the public instance methods defined in <i>mod</i>.
1338 * If the optional parameter is <code>false</code>, the methods of
1339 * any ancestors are not included.
1340 */
1341
1342VALUE
1344{
1345 return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1346}
1347
1348/*
1349 * call-seq:
1350 * obj.methods(regular=true) -> array
1351 *
1352 * Returns a list of the names of public and protected methods of
1353 * <i>obj</i>. This will include all the methods accessible in
1354 * <i>obj</i>'s ancestors.
1355 * If the optional parameter is <code>false</code>, it
1356 * returns an array of <i>obj</i>'s public and protected singleton methods,
1357 * the array will not include methods in modules included in <i>obj</i>.
1358 *
1359 * class Klass
1360 * def klass_method()
1361 * end
1362 * end
1363 * k = Klass.new
1364 * k.methods[0..9] #=> [:klass_method, :nil?, :===,
1365 * # :==~, :!, :eql?
1366 * # :hash, :<=>, :class, :singleton_class]
1367 * k.methods.length #=> 56
1368 *
1369 * k.methods(false) #=> []
1370 * def k.singleton_method; end
1371 * k.methods(false) #=> [:singleton_method]
1372 *
1373 * module M123; def m123; end end
1374 * k.extend M123
1375 * k.methods(false) #=> [:singleton_method]
1376 */
1377
1378VALUE
1380{
1381 rb_check_arity(argc, 0, 1);
1382 if (argc > 0 && !RTEST(argv[0])) {
1384 }
1385 return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
1386}
1387
1388/*
1389 * call-seq:
1390 * obj.protected_methods(all=true) -> array
1391 *
1392 * Returns the list of protected methods accessible to <i>obj</i>. If
1393 * the <i>all</i> parameter is set to <code>false</code>, only those methods
1394 * in the receiver will be listed.
1395 */
1396
1397VALUE
1399{
1400 return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
1401}
1402
1403/*
1404 * call-seq:
1405 * obj.private_methods(all=true) -> array
1406 *
1407 * Returns the list of private methods accessible to <i>obj</i>. If
1408 * the <i>all</i> parameter is set to <code>false</code>, only those methods
1409 * in the receiver will be listed.
1410 */
1411
1412VALUE
1414{
1415 return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
1416}
1417
1418/*
1419 * call-seq:
1420 * obj.public_methods(all=true) -> array
1421 *
1422 * Returns the list of public methods accessible to <i>obj</i>. If
1423 * the <i>all</i> parameter is set to <code>false</code>, only those methods
1424 * in the receiver will be listed.
1425 */
1426
1427VALUE
1429{
1430 return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
1431}
1432
1433/*
1434 * call-seq:
1435 * obj.singleton_methods(all=true) -> array
1436 *
1437 * Returns an array of the names of singleton methods for <i>obj</i>.
1438 * If the optional <i>all</i> parameter is true, the list will include
1439 * methods in modules included in <i>obj</i>.
1440 * Only public and protected singleton methods are returned.
1441 *
1442 * module Other
1443 * def three() end
1444 * end
1445 *
1446 * class Single
1447 * def Single.four() end
1448 * end
1449 *
1450 * a = Single.new
1451 *
1452 * def a.one()
1453 * end
1454 *
1455 * class << a
1456 * include Other
1457 * def two()
1458 * end
1459 * end
1460 *
1461 * Single.singleton_methods #=> [:four]
1462 * a.singleton_methods(false) #=> [:two, :one]
1463 * a.singleton_methods #=> [:two, :one, :three]
1464 */
1465
1466VALUE
1468{
1469 VALUE ary, klass, origin;
1470 struct method_entry_arg me_arg;
1471 struct rb_id_table *mtbl;
1472 int recur = TRUE;
1473
1474 if (rb_check_arity(argc, 0, 1)) recur = RTEST(argv[0]);
1477 }
1478 klass = CLASS_OF(obj);
1479 origin = RCLASS_ORIGIN(klass);
1480 me_arg.list = st_init_numtable();
1481 me_arg.recur = recur;
1482 if (klass && FL_TEST(klass, FL_SINGLETON)) {
1483 if ((mtbl = RCLASS_M_TBL(origin)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
1485 }
1486 if (recur) {
1487 while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
1488 if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
1490 }
1491 }
1492 ary = rb_ary_new2(me_arg.list->num_entries);
1493 st_foreach(me_arg.list, ins_methods_i, ary);
1494 st_free_table(me_arg.list);
1495
1496 return ary;
1497}
1498
1556#ifdef rb_define_method_id
1557#undef rb_define_method_id
1558#endif
1559void
1561{
1563}
1564
1565#ifdef rb_define_method
1566#undef rb_define_method
1567#endif
1568void
1569rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1570{
1572}
1573
1574#ifdef rb_define_protected_method
1575#undef rb_define_protected_method
1576#endif
1577void
1579{
1581}
1582
1583#ifdef rb_define_private_method
1584#undef rb_define_private_method
1585#endif
1586void
1588{
1590}
1591
1592void
1594{
1596}
1597
1599undef_method_i(ID name, VALUE value, void *data)
1600{
1601 VALUE klass = (VALUE)data;
1603 return ID_TABLE_CONTINUE;
1604}
1605
1606void
1608{
1609 struct rb_id_table *mtbl = RCLASS_M_TBL(super);
1610 if (mtbl) {
1611 rb_id_table_foreach(mtbl, undef_method_i, (void *)klass);
1612 }
1613}
1614
1623#define SPECIAL_SINGLETON(x,c) do {\
1624 if (obj == (x)) {\
1625 return (c);\
1626 }\
1627} while (0)
1628
1629static inline VALUE
1630special_singleton_class_of(VALUE obj)
1631{
1635 return Qnil;
1636}
1637
1638VALUE
1640{
1641 return special_singleton_class_of(obj);
1642}
1643
1653static VALUE
1654singleton_class_of(VALUE obj)
1655{
1656 VALUE klass;
1657
1658 if (FIXNUM_P(obj) || FLONUM_P(obj) || STATIC_SYM_P(obj)) {
1659 no_singleton:
1660 rb_raise(rb_eTypeError, "can't define singleton");
1661 }
1662 if (SPECIAL_CONST_P(obj)) {
1663 klass = special_singleton_class_of(obj);
1664 if (NIL_P(klass))
1665 rb_bug("unknown immediate %p", (void *)obj);
1666 return klass;
1667 }
1668 else {
1669 switch (BUILTIN_TYPE(obj)) {
1670 case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
1671 goto no_singleton;
1672 case T_STRING:
1673 if (FL_TEST_RAW(obj, RSTRING_FSTR)) goto no_singleton;
1674 break;
1675 }
1676 }
1677
1678 klass = RBASIC(obj)->klass;
1679 if (!(FL_TEST(klass, FL_SINGLETON) &&
1683 RCLASS_SERIAL(klass) = serial;
1684 }
1685
1687
1688 return klass;
1689}
1690
1691void
1693{
1694 /* should not propagate to meta-meta-class, and so on */
1695 if (!(RBASIC(x)->flags & FL_SINGLETON)) {
1697 if (klass && (klass = RCLASS_ORIGIN(klass)) != 0 &&
1700 }
1701 }
1702}
1703
1711VALUE
1713{
1714 VALUE klass;
1715
1716 if (SPECIAL_CONST_P(obj)) {
1718 }
1719 klass = RBASIC(obj)->klass;
1720 if (!FL_TEST(klass, FL_SINGLETON)) return Qnil;
1721 if (rb_ivar_get(klass, id_attached) != obj) return Qnil;
1722 return klass;
1723}
1724
1742VALUE
1744{
1745 VALUE klass = singleton_class_of(obj);
1746
1747 /* ensures an exposed class belongs to its own eigenclass */
1749
1750 return klass;
1751}
1752
1762#ifdef rb_define_singleton_method
1763#undef rb_define_singleton_method
1764#endif
1772void
1774{
1775 rb_define_method(singleton_class_of(obj), name, func, argc);
1776}
1777
1778#ifdef rb_define_module_function
1779#undef rb_define_module_function
1780#endif
1788void
1789rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
1790{
1791 rb_define_private_method(module, name, func, argc);
1792 rb_define_singleton_method(module, name, func, argc);
1793}
1794
1795#ifdef rb_define_global_function
1796#undef rb_define_global_function
1797#endif
1804void
1806{
1808}
1809
1810
1817void
1818rb_define_alias(VALUE klass, const char *name1, const char *name2)
1819{
1820 rb_alias(klass, rb_intern(name1), rb_intern(name2));
1821}
1822
1830void
1831rb_define_attr(VALUE klass, const char *name, int read, int write)
1832{
1834}
1835
1838{
1839 long i = 0, len = RARRAY_LEN(keys);
1840 VALUE error_message = rb_sprintf("%s keyword%.*s", error, len > 1, "s");
1841
1842 if (len > 0) {
1843 rb_str_cat_cstr(error_message, ": ");
1844 while (1) {
1845 const VALUE k = RARRAY_AREF(keys, i);
1846 rb_str_append(error_message, rb_inspect(k));
1847 if (++i >= len) break;
1848 rb_str_cat_cstr(error_message, ", ");
1849 }
1850 }
1851
1852 return rb_exc_new_str(rb_eArgError, error_message);
1853}
1854
1855NORETURN(static void rb_keyword_error(const char *error, VALUE keys));
1856static void
1857rb_keyword_error(const char *error, VALUE keys)
1858{
1860}
1861
1862NORETURN(static void unknown_keyword_error(VALUE hash, const ID *table, int keywords));
1863static void
1864unknown_keyword_error(VALUE hash, const ID *table, int keywords)
1865{
1866 int i;
1867 for (i = 0; i < keywords; i++) {
1868 st_data_t key = ID2SYM(table[i]);
1870 }
1871 rb_keyword_error("unknown", rb_hash_keys(hash));
1872}
1873
1874
1875static int
1876separate_symbol(st_data_t key, st_data_t value, st_data_t arg)
1877{
1878 VALUE *kwdhash = (VALUE *)arg;
1879 if (!SYMBOL_P(key)) kwdhash++;
1880 if (!*kwdhash) *kwdhash = rb_hash_new();
1881 rb_hash_aset(*kwdhash, (VALUE)key, (VALUE)value);
1882 return ST_CONTINUE;
1883}
1884
1885VALUE
1887{
1888 VALUE parthash[2] = {0, 0};
1889 VALUE hash = *orighash;
1890
1891 if (RHASH_EMPTY_P(hash)) {
1892 *orighash = 0;
1893 return hash;
1894 }
1895 rb_hash_foreach(hash, separate_symbol, (st_data_t)&parthash);
1896 *orighash = parthash[1];
1897 if (parthash[1] && RBASIC_CLASS(hash) != rb_cHash) {
1898 RBASIC_SET_CLASS(parthash[1], RBASIC_CLASS(hash));
1899 }
1900 return parthash[0];
1901}
1902
1903int
1904rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
1905{
1906 int i = 0, j;
1907 int rest = 0;
1908 VALUE missing = Qnil;
1909 st_data_t key;
1910
1911#define extract_kwarg(keyword, val) \
1912 (key = (st_data_t)(keyword), values ? \
1913 (rb_hash_stlike_delete(keyword_hash, &key, &(val)) || ((val) = Qundef, 0)) : \
1914 rb_hash_stlike_lookup(keyword_hash, key, NULL))
1915
1916 if (NIL_P(keyword_hash)) keyword_hash = 0;
1917
1918 if (optional < 0) {
1919 rest = 1;
1920 optional = -1-optional;
1921 }
1922 if (required) {
1923 for (; i < required; i++) {
1924 VALUE keyword = ID2SYM(table[i]);
1925 if (keyword_hash) {
1926 if (extract_kwarg(keyword, values[i])) {
1927 continue;
1928 }
1929 }
1930 if (NIL_P(missing)) missing = rb_ary_tmp_new(1);
1931 rb_ary_push(missing, keyword);
1932 }
1933 if (!NIL_P(missing)) {
1934 rb_keyword_error("missing", missing);
1935 }
1936 }
1937 j = i;
1938 if (optional && keyword_hash) {
1939 for (i = 0; i < optional; i++) {
1940 if (extract_kwarg(ID2SYM(table[required+i]), values[required+i])) {
1941 j++;
1942 }
1943 }
1944 }
1945 if (!rest && keyword_hash) {
1946 if (RHASH_SIZE(keyword_hash) > (unsigned int)(values ? 0 : j)) {
1947 unknown_keyword_error(keyword_hash, table, required+optional);
1948 }
1949 }
1950 if (values && !keyword_hash) {
1951 for (i = 0; i < required + optional; i++) {
1952 values[i] = Qundef;
1953 }
1954 }
1955 return j;
1956#undef extract_kwarg
1957}
1958
1960 int argc;
1961 const VALUE *argv;
1970 int argi;
1975};
1976
1977static void
1978rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, struct rb_scan_args_t *arg)
1979{
1980 const char *p = fmt;
1981 VALUE *tmp_buffer = arg->tmp_buffer;
1982 int keyword_given = 0;
1983 int empty_keyword_given = 0;
1984 int last_hash_keyword = 0;
1985
1986 memset(arg, 0, sizeof(*arg));
1987 arg->last_idx = -1;
1988 arg->hash = Qnil;
1989
1990 switch (kw_flag) {
1992 if (!(keyword_given = rb_keyword_given_p())) {
1993 empty_keyword_given = rb_empty_keyword_given_p();
1994 }
1995 break;
1997 keyword_given = 1;
1998 break;
2000 empty_keyword_given = 1;
2001 break;
2003 last_hash_keyword = 1;
2004 break;
2005 }
2006
2007 if (ISDIGIT(*p)) {
2008 arg->n_lead = *p - '0';
2009 p++;
2010 if (ISDIGIT(*p)) {
2011 arg->n_opt = *p - '0';
2012 p++;
2013 }
2014 }
2015 if (*p == '*') {
2016 arg->f_var = 1;
2017 p++;
2018 }
2019 if (ISDIGIT(*p)) {
2020 arg->n_trail = *p - '0';
2021 p++;
2022 }
2023 if (*p == ':') {
2024 arg->f_hash = 1;
2025 p++;
2026 }
2027 if (*p == '&') {
2028 arg->f_block = 1;
2029 p++;
2030 }
2031 if (*p != '\0') {
2032 rb_fatal("bad scan arg format: %s", fmt);
2033 }
2034 arg->n_mand = arg->n_lead + arg->n_trail;
2035
2036 /* capture an option hash - phase 1: pop */
2037 /* Ignore final positional hash if empty keywords given */
2038 if (argc > 0 && !(arg->f_hash && empty_keyword_given)) {
2039 VALUE last = argv[argc - 1];
2040
2041 if (arg->f_hash && arg->n_mand < argc) {
2042 if (keyword_given) {
2043 if (!RB_TYPE_P(last, T_HASH)) {
2044 rb_warn("Keyword flag set when calling rb_scan_args, but last entry is not a hash");
2045 }
2046 else {
2047 arg->hash = last;
2048 }
2049 }
2050 else if (NIL_P(last)) {
2051 /* For backwards compatibility, nil is taken as an empty
2052 option hash only if it is not ambiguous; i.e. '*' is
2053 not specified and arguments are given more than sufficient.
2054 This will be removed in Ruby 3. */
2055 if (!arg->f_var && arg->n_mand + arg->n_opt < argc) {
2056 rb_warn("The last argument is nil, treating as empty keywords");
2057 argc--;
2058 }
2059 }
2060 else {
2061 arg->hash = rb_check_hash_type(last);
2062 }
2063
2064 /* Ruby 3: Remove if branch, as it will not attempt to split hashes */
2065 if (!NIL_P(arg->hash)) {
2066 VALUE opts = rb_extract_keywords(&arg->hash);
2067
2068 if (!(arg->last_hash = arg->hash)) {
2069 if (!keyword_given && !last_hash_keyword) {
2070 /* Warn if treating positional as keyword, as in Ruby 3,
2071 this will be an error */
2072 rb_warn("Using the last argument as keyword parameters is deprecated");
2073 }
2074 argc--;
2075 }
2076 else {
2077 /* Warn if splitting either positional hash to keywords or keywords
2078 to positional hash, as in Ruby 3, no splitting will be done */
2079 rb_warn("The last argument is split into positional and keyword parameters");
2080 arg->last_idx = argc - 1;
2081 }
2082 arg->hash = opts ? opts : Qnil;
2083 }
2084 }
2085 else if (arg->f_hash && keyword_given && arg->n_mand == argc) {
2086 /* Warn if treating keywords as positional, as in Ruby 3, this will be an error */
2087 rb_warn("Passing the keyword argument as the last hash parameter is deprecated");
2088 }
2089 }
2090 if (arg->f_hash && arg->n_mand == argc+1 && empty_keyword_given) {
2091 VALUE *ptr = rb_alloc_tmp_buffer2(tmp_buffer, argc+1, sizeof(VALUE));
2092 memcpy(ptr, argv, sizeof(VALUE)*argc);
2093 ptr[argc] = rb_hash_new();
2094 argc++;
2095 *(&argv) = ptr;
2096 rb_warn("Passing the keyword argument as the last hash parameter is deprecated");
2097 }
2098
2099 arg->argc = argc;
2100 arg->argv = argv;
2101}
2102
2103static int
2104rb_scan_args_assign(struct rb_scan_args_t *arg, va_list vargs)
2105{
2106 int argi = 0;
2107 int i;
2108 VALUE *var;
2109
2110 if (arg->argc < arg->n_mand) {
2111 return 1;
2112 }
2113
2114 /* capture leading mandatory arguments */
2115 for (i = arg->n_lead; i-- > 0; ) {
2116 var = va_arg(vargs, VALUE *);
2117 if (var) *var = (argi == arg->last_idx) ? arg->last_hash : arg->argv[argi];
2118 argi++;
2119 }
2120 /* capture optional arguments */
2121 for (i = arg->n_opt; i-- > 0; ) {
2122 var = va_arg(vargs, VALUE *);
2123 if (argi < arg->argc - arg->n_trail) {
2124 if (var) *var = (argi == arg->last_idx) ? arg->last_hash : arg->argv[argi];
2125 argi++;
2126 }
2127 else {
2128 if (var) *var = Qnil;
2129 }
2130 }
2131 /* capture variable length arguments */
2132 if (arg->f_var) {
2133 int n_var = arg->argc - argi - arg->n_trail;
2134
2135 var = va_arg(vargs, VALUE *);
2136 if (0 < n_var) {
2137 if (var) {
2138 int f_last = (arg->last_idx + 1 == arg->argc - arg->n_trail);
2139 *var = rb_ary_new4(n_var - f_last, &arg->argv[argi]);
2140 if (f_last) rb_ary_push(*var, arg->last_hash);
2141 }
2142 argi += n_var;
2143 }
2144 else {
2145 if (var) *var = rb_ary_new();
2146 }
2147 }
2148 /* capture trailing mandatory arguments */
2149 for (i = arg->n_trail; i-- > 0; ) {
2150 var = va_arg(vargs, VALUE *);
2151 if (var) *var = (argi == arg->last_idx) ? arg->last_hash : arg->argv[argi];
2152 argi++;
2153 }
2154 /* capture an option hash - phase 2: assignment */
2155 if (arg->f_hash) {
2156 var = va_arg(vargs, VALUE *);
2157 if (var) *var = arg->hash;
2158 }
2159 /* capture iterator block */
2160 if (arg->f_block) {
2161 var = va_arg(vargs, VALUE *);
2162 if (rb_block_given_p()) {
2163 *var = rb_block_proc();
2164 }
2165 else {
2166 *var = Qnil;
2167 }
2168 }
2169
2170 if (argi < arg->argc) return 1;
2171
2172 return 0;
2173}
2174
2175#undef rb_scan_args
2176int
2177rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
2178{
2179 int error;
2180 va_list vargs;
2181 VALUE tmp_buffer = 0;
2182 struct rb_scan_args_t arg;
2183 arg.tmp_buffer = &tmp_buffer;
2184 rb_scan_args_parse(RB_SCAN_ARGS_PASS_CALLED_KEYWORDS, argc, argv, fmt, &arg);
2186 error = rb_scan_args_assign(&arg, vargs);
2187 va_end(vargs);
2188 if (tmp_buffer) {
2190 }
2191 if (error) {
2192 rb_error_arity(arg.argc, arg.n_mand, arg.f_var ? UNLIMITED_ARGUMENTS : arg.n_mand + arg.n_opt);
2193 }
2194 return arg.argc;
2195}
2196
2197int
2198rb_scan_args_kw(int kw_flag, int argc, const VALUE *argv, const char *fmt, ...)
2199{
2200 int error;
2201 va_list vargs;
2202 VALUE tmp_buffer = 0;
2203 struct rb_scan_args_t arg;
2204 arg.tmp_buffer = &tmp_buffer;
2205 rb_scan_args_parse(kw_flag, argc, argv, fmt, &arg);
2207 error = rb_scan_args_assign(&arg, vargs);
2208 va_end(vargs);
2209 if (tmp_buffer) {
2211 }
2212 if (error) {
2213 rb_error_arity(arg.argc, arg.n_mand, arg.f_var ? UNLIMITED_ARGUMENTS : arg.n_mand + arg.n_opt);
2214 }
2215 return arg.argc;
2216}
2217
2218int
2220{
2221 return rb_id_table_size(RCLASS_M_TBL(c)) == 0 ? FALSE : TRUE;
2222}
2223
#define extract_kwarg(keyword, val)
#define mod(x, y)
Definition: date_strftime.c:28
#define recur(fmt)
struct RIMemo * ptr
Definition: debug.c:65
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod)
Definition: class.c:1305
#define SET_METACLASS_OF(k, cls)
Definition: class.c:36
void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE, VALUE), VALUE arg)
Definition: class.c:116
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:882
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:662
VALUE rb_class_new(VALUE super)
Creates a new class.
Definition: class.c:244
VALUE rb_singleton_class_clone(VALUE obj)
Definition: class.c:373
VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj)
Definition: class.c:1413
void rb_class_subclass_add(VALUE super, VALUE klass)
Definition: class.c:39
VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj)
Definition: class.c:1379
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:1017
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1743
void rb_class_detach_subclasses(VALUE klass)
Definition: class.c:136
void Init_class_hierarchy(void)
Definition: class.c:562
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:711
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
Definition: class.c:380
#define METACLASS_OF(k)
Definition: class.c:35
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:838
VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj)
Definition: class.c:1398
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
Definition: class.c:1467
VALUE rb_module_new(void)
Definition: class.c:771
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
Definition: class.c:459
int rb_singleton_class_internal_p(VALUE sklass)
Definition: class.c:468
#define SPECIAL_SINGLETON(x, c)
Definition: class.c:1623
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod)
Definition: class.c:1290
MJIT_FUNC_EXPORTED VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:636
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
Definition: class.c:222
#define id_attached
Definition: class.c:33
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod)
Definition: class.c:1343
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
Definition: class.c:204
VALUE rb_define_module(const char *name)
Definition: class.c:785
void rb_class_modify_check(VALUE)
Asserts that klass is not a frozen class.
Definition: eval.c:438
void rb_class_detach_module_subclasses(VALUE klass)
Definition: class.c:148
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1639
VALUE rb_define_module_id_under(VALUE outer, ID id)
Definition: class.c:816
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
Definition: class.c:444
void rb_freeze_singleton_class(VALUE x)
Definition: class.c:1692
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:1049
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:734
VALUE rb_mod_ancestors(VALUE mod)
Definition: class.c:1117
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Definition: class.c:1085
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod)
Definition: class.c:1328
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
Definition: class.c:490
void rb_class_remove_from_module_subclasses(VALUE klass)
Definition: class.c:97
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
Definition: class.c:316
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:810
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
Definition: class.c:1712
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:593
VALUE rb_define_module_id(ID id)
Definition: class.c:779
VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj)
Definition: class.c:1428
VALUE rb_define_class_id(ID id, VALUE super)
Defines a new class.
Definition: class.c:615
void rb_class_remove_from_super_subclasses(VALUE klass)
Definition: class.c:79
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1569
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1578
VALUE rb_extract_keywords(VALUE *orighash)
Definition: class.c:1886
int rb_class_has_methods(VALUE c)
Definition: class.c:2219
MJIT_FUNC_EXPORTED VALUE rb_keyword_error_new(const char *error, VALUE keys)
Definition: class.c:1837
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines (a) public accessor method(s) for an attribute.
Definition: class.c:1831
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1587
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1593
int rb_scan_args_kw(int kw_flag, int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:2198
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1818
void rb_undef_methods_from(VALUE klass, VALUE super)
Definition: class.c:1607
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:2177
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1773
NORETURN(static void rb_keyword_error(const char *error, VALUE keys))
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1805
int rb_block_given_p(void)
Determines if the current method is given a block.
Definition: eval.c:898
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1560
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Definition: class.c:1904
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1789
VALUE rb_cTrueClass
TrueClass class.
Definition: ruby.h:2051
VALUE rb_cNilClass
NilClass class.
Definition: ruby.h:2038
VALUE rb_mKernel
Kernel module.
Definition: ruby.h:2000
VALUE rb_cClass
Class class.
Definition: ruby.h:2018
VALUE rb_cBasicObject
BasicObject class.
Definition: ruby.h:2011
VALUE rb_cObject
Object class.
Definition: ruby.h:2012
VALUE rb_cHash
Definition: hash.c:92
VALUE rb_cFalseClass
FalseClass class.
Definition: ruby.h:2024
@ RSTRING_FSTR
Definition: ruby.h:983
VALUE rb_cModule
Module class.
Definition: ruby.h:2036
@ RMODULE_IS_REFINEMENT
Definition: ruby.h:956
@ RMODULE_INCLUDED_INTO_REFINEMENT
Definition: ruby.h:957
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2671
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:668
void rb_bug(const char *fmt,...)
Definition: error.c:636
VALUE rb_eTypeError
Definition: error.c:924
void rb_fatal(const char *fmt,...)
Definition: error.c:2722
void rb_warn(const char *fmt,...)
Definition: error.c:315
VALUE rb_exc_new_str(VALUE, VALUE)
Definition: error.c:974
VALUE rb_eArgError
Definition: error.c:925
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
Definition: object.c:551
VALUE rb_class_real(VALUE cl)
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.
Definition: object.c:202
int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val)
Definition: id_table.c:256
size_t rb_id_table_size(const struct rb_id_table *tbl)
Definition: id_table.c:117
struct rb_id_table * rb_id_table_create(size_t capa)
Definition: id_table.c:95
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
Definition: id_table.c:292
rb_id_table_iterator_result
Definition: id_table.h:8
@ ID_TABLE_DELETE
Definition: id_table.h:11
@ ID_TABLE_CONTINUE
Definition: id_table.h:9
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
const char * name
Definition: nkf.c:208
unsigned int last
Definition: nkf.c:4324
#define RARRAY_LEN(a)
const rb_method_entry_t * rb_method_entry_clone(const rb_method_entry_t *me)
Definition: vm_method.c:406
#define MEMCPY(p1, p2, type, n)
void rb_hash_foreach(VALUE, int(*)(VALUE, VALUE, VALUE), VALUE)
#define NULL
#define FL_SINGLETON
#define UNLIMITED_ARGUMENTS
#define OBJ_WB_UNPROTECT(x)
#define NEWOBJ_OF(obj, type, klass, flags)
#define RTEST(v)
void rb_set_class_path_string(VALUE, VALUE, VALUE)
Definition: variable.c:198
#define OBJ_INIT_COPY(obj, orig)
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:2391
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:1180
#define RCLASS_SUPER(c)
#define FL_TEST(x, f)
unsigned long st_data_t
#define RBASIC(obj)
int rb_empty_keyword_given_p(void)
Definition: eval.c:919
#define T_STRING
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
Definition: vm_method.c:685
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(), int argc, rb_method_visibility_t visi)
const rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me)
Definition: vm_method.c:989
#define xfree
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
Definition: vm_method.c:675
#define T_MASK
#define Qundef
#define RMODULE_CONST_TBL(m)
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1070
int rb_hash_stlike_delete(VALUE hash, st_data_t *pkey, st_data_t *pval)
Definition: hash.c:2310
const VALUE VALUE obj
#define FL_SET(x, f)
#define T_FLOAT
#define st_is_member(table, key)
void rb_gc_register_mark_object(VALUE)
Definition: gc.c:7079
const rb_iseq_t const char * error
#define RCLASS_SERIAL(c)
#define T_BIGNUM
void rb_clear_constant_cache(void)
Definition: vm_method.c:87
void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src)
Definition: vm_method.c:451
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:491
#define NIL_P(v)
#define RCLASS_CLONED
const rb_callable_method_entry_t * me
#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
#define ID2SYM(x)
#define rb_intern_const(str)
unsigned long VALUE
VALUE rb_ary_push(VALUE, VALUE)
Definition: array.c:1195
#define RB_SCAN_ARGS_KEYWORDS
#define rb_ary_new4
#define RB_OBJ_FROZEN_RAW(x)
const rb_iseq_t const char const VALUE keys
@ METHOD_VISI_PROTECTED
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2692
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex)
Definition: vm_method.c:714
#define STATIC_SYM_P(x)
#define T_MODULE
#define RB_SCAN_ARGS_EMPTY_KEYWORDS
uint32_t i
#define rb_fstring_lit(str)
__inline__ const void *__restrict__ size_t len
const VALUE int int int int int int VALUE char * fmt
VALUE rb_class_path(VALUE)
Definition: variable.c:153
#define FL_TEST_RAW(x, f)
VALUE rb_block_proc(void)
Definition: proc.c:837
#define ZALLOC(type)
#define RCLASS_IV_TBL(c)
#define RB_OBJ_WRITE(a, slot, b)
#define va_end(v)
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:2397
#define FLONUM_P(x)
#define T_ICLASS
#define T_HASH
__gnuc_va_list va_list
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1598
@ VM_METHOD_TYPE_REFINED
@ VM_METHOD_TYPE_UNDEF
void rb_iv_tbl_copy(VALUE dst, VALUE src)
Definition: variable.c:3343
#define RB_SCAN_ARGS_LAST_HASH_KEYWORDS
void rb_vm_check_redefinition_by_prepend(VALUE klass)
Definition: vm.c:1631
int rb_vm_add_root_module(ID id, VALUE module)
Definition: vm.c:2312
#define PRIsVALUE
unsigned long long rb_serial_t
void * memset(void *, int, size_t)
rb_serial_t rb_next_class_serial(void)
Definition: vm.c:358
#define RCLASS_ORIGIN(c)
VALUE rb_ary_tmp_new(long)
Definition: array.c:768
#define rb_funcall(recv, mid, argc,...)
VALUE rb_ary_new(void)
Definition: array.c:723
#define rb_str_cat_cstr(str, ptr)
#define rb_intern(str)
#define va_arg(v, l)
#define RCLASS_CONST_TBL(c)
#define va_start(v, l)
#define RCLASS_EXT(c)
#define CONST_ID(var, str)
#define TRUE
#define FALSE
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2756
#define RHASH_SIZE(h)
#define UNDEFINED_METHOD_ENTRY_P(me)
VALUE rb_hash_keys(VALUE hash)
Definition: hash.c:3409
void void rb_free_tmp_buffer(volatile VALUE *store)
Definition: gc.c:10290
#define Qtrue
#define RGENGC_WB_PROTECTED_CLASS
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2965
#define RCLASS_M_TBL(c)
#define ISDIGIT(c)
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1084
#define Qnil
#define Qfalse
void * memcpy(void *__restrict__, const void *__restrict__, size_t)
#define OBJ_FREEZE_RAW(x)
int rb_class_ivar_set(VALUE klass, ID vid, VALUE value)
Definition: variable.c:3327
#define RCLASS_REFINED_CLASS(c)
VALUE rb_check_hash_type(VALUE)
Definition: hash.c:1852
#define RB_TYPE_P(obj, type)
#define FL_WB_PROTECTED
#define SPECIAL_CONST_P(x)
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1481
#define ALLOC(type)
#define T_SYMBOL
#define MJIT_FUNC_EXPORTED
const VALUE * argv
#define SYMBOL_P(x)
#define FIXNUM_P(f)
#define T_CLASS
#define CLASS_OF(v)
void rb_free_const_table(struct rb_id_table *tbl)
Definition: gc.c:2506
#define Check_Type(v, t)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
Definition: hash.c:2852
void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr)
#define rb_check_arity
#define FL_PROMOTED1
#define FL_FREEZE
VALUE rb_sprintf(const char *,...) __attribute__((format(printf
#define RBASIC_CLASS(obj)
unsigned long ID
#define RHASH_EMPTY_P(h)
int rb_keyword_given_p(void)
Definition: eval.c:911
#define RB_FL_SET_RAW(x, f)
VALUE ID id
#define RBASIC_SET_CLASS(obj, cls)
#define rb_ary_new2
void rb_clear_method_cache_by_class(VALUE)
Definition: vm_method.c:93
#define RARRAY_AREF(a, i)
#define BUILTIN_TYPE(x)
#define RMODULE_M_TBL(m)
VALUE rb_hash_new(void)
Definition: hash.c:1523
#define RB_OBJ_WRITTEN(a, oldv, b)
#define RCLASS_REFINED_BY_ANY
#define ANYARGS
_ssize_t write(int __fd, const void *__buf, size_t __nbyte)
int rb_const_defined(VALUE, ID)
Definition: variable.c:2686
_ssize_t read(int __fd, void *__buf, size_t __nbyte)
#define METHOD_ENTRY_VISI(me)
#define f
void st_free_table(st_table *tab)
Definition: st.c:709
int st_delete(st_table *tab, st_data_t *key, st_data_t *value)
Definition: st.c:1418
void st_add_direct(st_table *tab, st_data_t key, st_data_t value)
Definition: st.c:1251
st_table * st_init_numtable(void)
Definition: st.c:653
int st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
Definition: st.c:1717
VALUE klass
Definition: class.c:278
struct rb_id_table * tbl
Definition: class.c:279
VALUE old_klass
Definition: class.c:266
VALUE new_klass
Definition: class.c:265
Definition: class.c:1180
int recur
Definition: class.c:1182
st_table * list
Definition: class.c:1181
Definition: gc.c:90
struct rb_method_definition_struct *const def
const VALUE owner
VALUE value
VALUE file
CREF (Class REFerence)
union rb_method_definition_struct::@41 body
rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
struct rb_method_entry_struct * orig_me
VALUE last_hash
Definition: class.c:1973
VALUE hash
Definition: class.c:1972
va_list vargs
Definition: class.c:1962
int last_idx
Definition: class.c:1971
const VALUE * argv
Definition: class.c:1961
VALUE * tmp_buffer
Definition: class.c:1974
rb_subclass_entry_t * next
VALUE klass
#define rb_id2str(id)
Definition: vm_backtrace.c:30
MJIT_STATIC void rb_error_arity(int argc, int min, int max)