Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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