Ruby  2.1.10p492(2016-04-01revision54464)
variable.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  variable.c -
4 
5  $Author: usa $
6  created at: Tue Apr 19 23:55:15 JST 1994
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9  Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10  Copyright (C) 2000 Information-technology Promotion Agency, Japan
11 
12 **********************************************************************/
13 
14 #include "ruby/ruby.h"
15 #include "ruby/st.h"
16 #include "ruby/util.h"
17 #include "ruby/encoding.h"
18 #include "node.h"
19 #include "constant.h"
20 #include "internal.h"
21 #include "id.h"
22 
25 
26 void
28 {
30  CONST_ID(autoload, "__autoload__");
31  /* __classpath__: fully qualified class path */
32  CONST_ID(classpath, "__classpath__");
33  /* __tmp_classpath__: temporary class path which contains anonymous names */
34  CONST_ID(tmp_classpath, "__tmp_classpath__");
35  /* __classid__: name given to class/module under an anonymous namespace */
36  CONST_ID(classid, "__classid__");
37 }
38 
39 struct fc_result {
44  struct fc_result *prev;
45 };
46 
47 static VALUE
48 fc_path(struct fc_result *fc, ID name)
49 {
50  VALUE path, tmp;
51 
52  path = rb_id2str(name);
53  while (fc) {
54  st_data_t n;
55  if (fc->track == rb_cObject) break;
56  if (RCLASS_IV_TBL(fc->track) &&
58  tmp = rb_str_dup((VALUE)n);
59  rb_str_cat2(tmp, "::");
60  rb_str_append(tmp, path);
61  path = tmp;
62  break;
63  }
64  tmp = rb_str_dup(rb_id2str(fc->name));
65  rb_str_cat2(tmp, "::");
66  rb_str_append(tmp, path);
67  path = tmp;
68  fc = fc->prev;
69  }
71  return path;
72 }
73 
74 static int
76 {
77  ID key = (ID)k;
79  struct fc_result *res = (struct fc_result *)a;
80  VALUE value = ce->value;
81  if (!rb_is_const_id(key)) return ST_CONTINUE;
82 
83  if (value == res->klass && (!res->preferred || key == res->preferred)) {
84  res->path = fc_path(res, key);
85  return ST_STOP;
86  }
87  if (RB_TYPE_P(value, T_MODULE) || RB_TYPE_P(value, T_CLASS)) {
88  if (!RCLASS_CONST_TBL(value)) return ST_CONTINUE;
89  else {
90  struct fc_result arg;
91  struct fc_result *list;
92 
93  list = res;
94  while (list) {
95  if (list->track == value) return ST_CONTINUE;
96  list = list->prev;
97  }
98 
99  arg.name = key;
100  arg.preferred = res->preferred;
101  arg.path = 0;
102  arg.klass = res->klass;
103  arg.track = value;
104  arg.prev = res;
105  st_foreach(RCLASS_CONST_TBL(value), fc_i, (st_data_t)&arg);
106  if (arg.path) {
107  res->path = arg.path;
108  return ST_STOP;
109  }
110  }
111  }
112  return ST_CONTINUE;
113 }
114 
122 static VALUE
124 {
125  struct fc_result arg;
126 
127  arg.preferred = preferred;
128  arg.name = 0;
129  arg.path = 0;
130  arg.klass = klass;
131  arg.track = rb_cObject;
132  arg.prev = 0;
135  }
136  if (arg.path) {
137  st_data_t tmp = tmp_classpath;
138  if (!RCLASS_IV_TBL(klass)) {
140  }
142 
143  st_delete(RCLASS_IV_TBL(klass), &tmp, 0);
144  return arg.path;
145  }
146  return Qnil;
147 }
148 
156 static VALUE
157 classname(VALUE klass, int *permanent)
158 {
159  VALUE path = Qnil;
160  st_data_t n;
161 
162  if (!klass) klass = rb_cObject;
163  *permanent = 1;
164  if (RCLASS_IV_TBL(klass)) {
166  ID cid = 0;
168  cid = SYM2ID(n);
169  path = find_class_path(klass, cid);
170  }
171  if (NIL_P(path)) {
172  path = find_class_path(klass, (ID)0);
173  }
174  if (NIL_P(path)) {
175  if (!cid) {
176  return Qnil;
177  }
179  path = rb_id2str(cid);
180  return path;
181  }
182  *permanent = 0;
183  path = (VALUE)n;
184  return path;
185  }
186  }
187  else {
188  path = (VALUE)n;
189  }
190  if (!RB_TYPE_P(path, T_STRING)) {
191  rb_bug("class path is not set properly");
192  }
193  return path;
194  }
195  return find_class_path(klass, (ID)0);
196 }
197 
198 /*
199  * call-seq:
200  * mod.name -> string
201  *
202  * Returns the name of the module <i>mod</i>. Returns nil for anonymous modules.
203  */
204 
205 VALUE
207 {
208  int permanent;
209  VALUE path = classname(mod, &permanent);
210 
211  if (!NIL_P(path)) return rb_str_dup(path);
212  return path;
213 }
214 
216 
217 static VALUE
218 rb_tmp_class_path(VALUE klass, int *permanent, path_cache_func cache_path)
219 {
220  VALUE path = classname(klass, permanent);
221  st_data_t n = (st_data_t)path;
222 
223  if (!NIL_P(path)) {
224  return path;
225  }
227  (st_data_t)tmp_classpath, &n)) {
228  *permanent = 0;
229  return (VALUE)n;
230  }
231  else {
232  const char *s = "Class";
233 
234  if (RB_TYPE_P(klass, T_MODULE)) {
235  if (rb_obj_class(klass) == rb_cModule) {
236  s = "Module";
237  }
238  else {
239  int perm;
240  VALUE path;
241 
242  path = rb_tmp_class_path(RBASIC(klass)->klass, &perm, cache_path);
243  s = RSTRING_PTR(path);
244  }
245  }
246  path = rb_sprintf("#<%s:%p>", s, (void*)klass);
247  OBJ_FREEZE(path);
248 
249  cache_path(klass, tmp_classpath, path);
250  *permanent = 0;
251 
252  return path;
253  }
254 }
255 
256 VALUE
258 {
259  int permanent;
260  VALUE path = rb_tmp_class_path(klass, &permanent, rb_ivar_set);
261  if (!NIL_P(path)) path = rb_str_dup(path);
262  return path;
263 }
264 
265 static VALUE
267 {
268  return Qnil;
269 }
270 
271 VALUE
273 {
274  int permanent;
275  VALUE path = rb_tmp_class_path(klass, &permanent, null_cache);
276  if (!NIL_P(path)) path = rb_str_dup(path);
277  return path;
278 }
279 
280 VALUE
282 {
283  st_table *ivtbl = RCLASS_IV_TBL(klass);
284  st_data_t n;
285 
286  if (!ivtbl) return Qnil;
287  if (st_lookup(ivtbl, (st_data_t)classpath, &n)) return (VALUE)n;
288  if (st_lookup(ivtbl, (st_data_t)tmp_classpath, &n)) return (VALUE)n;
289  return Qnil;
290 }
291 
292 void
294 {
295  VALUE str;
296  ID pathid = classpath;
297 
298  if (under == rb_cObject) {
299  str = rb_str_new_frozen(name);
300  }
301  else {
302  int permanent;
303  str = rb_str_dup(rb_tmp_class_path(under, &permanent, rb_ivar_set));
304  rb_str_cat2(str, "::");
305  rb_str_append(str, name);
306  OBJ_FREEZE(str);
307  if (!permanent) {
308  pathid = tmp_classpath;
310  }
311  }
312  rb_ivar_set(klass, pathid, str);
313 }
314 
315 void
316 rb_set_class_path(VALUE klass, VALUE under, const char *name)
317 {
318  VALUE str;
319  ID pathid = classpath;
320 
321  if (under == rb_cObject) {
322  str = rb_str_new2(name);
323  }
324  else {
325  int permanent;
326  str = rb_str_dup(rb_tmp_class_path(under, &permanent, rb_ivar_set));
327  rb_str_cat2(str, "::");
328  rb_str_cat2(str, name);
329  if (!permanent) {
330  pathid = tmp_classpath;
332  }
333  }
334  OBJ_FREEZE(str);
335  rb_ivar_set(klass, pathid, str);
336 }
337 
338 VALUE
340 {
341  rb_encoding *enc = rb_enc_get(pathname);
342  const char *pbeg, *p, *path = RSTRING_PTR(pathname);
343  ID id;
344  VALUE c = rb_cObject;
345 
346  if (!rb_enc_asciicompat(enc)) {
347  rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
348  }
349  pbeg = p = path;
350  if (path[0] == '#') {
351  rb_raise(rb_eArgError, "can't retrieve anonymous class %"PRIsVALUE,
352  QUOTE(pathname));
353  }
354  while (*p) {
355  while (*p && *p != ':') p++;
356  id = rb_check_id_cstr(pbeg, p-pbeg, enc);
357  if (p[0] == ':') {
358  if (p[1] != ':') goto undefined_class;
359  p += 2;
360  pbeg = p;
361  }
362  if (!id || !rb_const_defined_at(c, id)) {
363  undefined_class:
364  rb_raise(rb_eArgError, "undefined class/module %.*"PRIsVALUE,
365  (int)(p-path), pathname);
366  }
367  c = rb_const_get_at(c, id);
368  if (!RB_TYPE_P(c, T_MODULE) && !RB_TYPE_P(c, T_CLASS)) {
369  rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
370  pathname);
371  }
372  }
373  RB_GC_GUARD(pathname);
374 
375  return c;
376 }
377 
378 VALUE
379 rb_path2class(const char *path)
380 {
382 }
383 
384 void
386 {
388 }
389 
390 VALUE
392 {
394 }
395 
396 const char *
398 {
399  int permanent;
401  if (NIL_P(path)) return NULL;
402  return RSTRING_PTR(path);
403 }
404 
405 const char *
407 {
408  return rb_class2name(CLASS_OF(obj));
409 }
410 
411 #define global_variable rb_global_variable
412 #define global_entry rb_global_entry
413 
414 #define gvar_getter_t rb_gvar_getter_t
415 #define gvar_setter_t rb_gvar_setter_t
416 #define gvar_marker_t rb_gvar_marker_t
417 
418 struct trace_var {
419  int removed;
420  void (*func)(VALUE arg, VALUE val);
422  struct trace_var *next;
423 };
424 
426  int counter;
427  void *data;
432  struct trace_var *trace;
433 };
434 
435 #define undef_getter rb_gvar_undef_getter
436 #define undef_setter rb_gvar_undef_setter
437 #define undef_marker rb_gvar_undef_marker
438 
439 #define val_getter rb_gvar_val_getter
440 #define val_setter rb_gvar_val_setter
441 #define val_marker rb_gvar_val_marker
442 
443 #define var_getter rb_gvar_var_getter
444 #define var_setter rb_gvar_var_setter
445 #define var_marker rb_gvar_var_marker
446 
447 #define readonly_setter rb_gvar_readonly_setter
448 
449 struct global_entry*
451 {
452  struct global_entry *entry;
453  st_data_t data;
454 
455  if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
456  struct global_variable *var;
457  entry = ALLOC(struct global_entry);
458  var = ALLOC(struct global_variable);
459  entry->id = id;
460  entry->var = var;
461  var->counter = 1;
462  var->data = 0;
463  var->getter = undef_getter;
464  var->setter = undef_setter;
465  var->marker = undef_marker;
466 
467  var->block_trace = 0;
468  var->trace = 0;
470  }
471  else {
472  entry = (struct global_entry *)data;
473  }
474  return entry;
475 }
476 
477 VALUE
478 undef_getter(ID id, void *data, struct global_variable *var)
479 {
480  rb_warning("global variable `%"PRIsVALUE"' not initialized", QUOTE_ID(id));
481 
482  return Qnil;
483 }
484 
485 void
486 undef_setter(VALUE val, ID id, void *data, struct global_variable *var)
487 {
488  var->getter = val_getter;
489  var->setter = val_setter;
490  var->marker = val_marker;
491 
492  var->data = (void*)val;
493 }
494 
495 void
497 {
498 }
499 
500 VALUE
501 val_getter(ID id, void *data, struct global_variable *var)
502 {
503  return (VALUE)data;
504 }
505 
506 void
507 val_setter(VALUE val, ID id, void *data, struct global_variable *var)
508 {
509  var->data = (void*)val;
510 }
511 
512 void
514 {
515  VALUE data = (VALUE)var;
516  if (data) rb_gc_mark_maybe(data);
517 }
518 
519 VALUE
520 var_getter(ID id, void *data, struct global_variable *gvar)
521 {
522  VALUE *var = data;
523  if (!var) return Qnil;
524  return *var;
525 }
526 
527 void
528 var_setter(VALUE val, ID id, void *data, struct global_variable *gvar)
529 {
530  *(VALUE *)data = val;
531 }
532 
533 void
535 {
536  if (var) rb_gc_mark_maybe(*var);
537 }
538 
539 void
540 readonly_setter(VALUE val, ID id, void *data, struct global_variable *gvar)
541 {
542  rb_name_error(id, "%"PRIsVALUE" is a read-only variable", QUOTE_ID(id));
543 }
544 
545 static int
547 {
548  struct global_entry *entry = (struct global_entry *)v;
549  struct trace_var *trace;
550  struct global_variable *var = entry->var;
551 
552  (*var->marker)(var->data);
553  trace = var->trace;
554  while (trace) {
556  trace = trace->next;
557  }
558  return ST_CONTINUE;
559 }
560 
561 void
563 {
564  if (rb_global_tbl)
566 }
567 
568 static ID
569 global_id(const char *name)
570 {
571  ID id;
572 
573  if (name[0] == '$') id = rb_intern(name);
574  else {
575  size_t len = strlen(name);
576  char *buf = ALLOCA_N(char, len+1);
577  buf[0] = '$';
578  memcpy(buf+1, name, len);
579  id = rb_intern2(buf, len+1);
580  }
581  return id;
582 }
583 
584 void
586  const char *name,
587  VALUE *var,
588  VALUE (*getter)(ANYARGS),
589  void (*setter)(ANYARGS))
590 {
591  volatile VALUE tmp = var ? *var : Qnil;
592  ID id = global_id(name);
593  struct global_variable *gvar = rb_global_entry(id)->var;
594 
595  gvar->data = (void*)var;
598  gvar->marker = var_marker;
599 
600  RB_GC_GUARD(tmp);
601 }
602 
603 void
604 rb_define_variable(const char *name, VALUE *var)
605 {
606  rb_define_hooked_variable(name, var, 0, 0);
607 }
608 
609 void
611 {
613 }
614 
615 void
617  const char *name,
618  VALUE (*getter)(ANYARGS),
619  void (*setter)(ANYARGS))
620 {
621  if (!getter) getter = val_getter;
622  if (!setter) setter = readonly_setter;
624 }
625 
626 static void
628 {
629  rb_eval_cmd(cmd, rb_ary_new3(1, val), 0);
630 }
631 
632 /*
633  * call-seq:
634  * trace_var(symbol, cmd ) -> nil
635  * trace_var(symbol) {|val| block } -> nil
636  *
637  * Controls tracing of assignments to global variables. The parameter
638  * +symbol_ identifies the variable (as either a string name or a
639  * symbol identifier). _cmd_ (which may be a string or a
640  * +Proc+ object) or block is executed whenever the variable
641  * is assigned. The block or +Proc+ object receives the
642  * variable's new value as a parameter. Also see
643  * <code>Kernel::untrace_var</code>.
644  *
645  * trace_var :$_, proc {|v| puts "$_ is now '#{v}'" }
646  * $_ = "hello"
647  * $_ = ' there'
648  *
649  * <em>produces:</em>
650  *
651  * $_ is now 'hello'
652  * $_ is now ' there'
653  */
654 
655 VALUE
657 {
658  VALUE var, cmd;
659  struct global_entry *entry;
660  struct trace_var *trace;
661 
662  if (rb_scan_args(argc, argv, "11", &var, &cmd) == 1) {
663  cmd = rb_block_proc();
664  }
665  if (NIL_P(cmd)) {
666  return rb_f_untrace_var(argc, argv);
667  }
668  entry = rb_global_entry(rb_to_id(var));
669  if (OBJ_TAINTED(cmd)) {
670  rb_raise(rb_eSecurityError, "Insecure: tainted variable trace");
671  }
672  trace = ALLOC(struct trace_var);
673  trace->next = entry->var->trace;
674  trace->func = rb_trace_eval;
675  trace->data = cmd;
676  trace->removed = 0;
677  entry->var->trace = trace;
678 
679  return Qnil;
680 }
681 
682 static void
684 {
685  struct trace_var *trace = var->trace;
686  struct trace_var t;
687  struct trace_var *next;
688 
689  t.next = trace;
690  trace = &t;
691  while (trace->next) {
692  next = trace->next;
693  if (next->removed) {
694  trace->next = next->next;
695  xfree(next);
696  }
697  else {
698  trace = next;
699  }
700  }
701  var->trace = t.next;
702 }
703 
704 /*
705  * call-seq:
706  * untrace_var(symbol [, cmd] ) -> array or nil
707  *
708  * Removes tracing for the specified command on the given global
709  * variable and returns +nil+. If no command is specified,
710  * removes all tracing for that variable and returns an array
711  * containing the commands actually removed.
712  */
713 
714 VALUE
716 {
717  VALUE var, cmd;
718  ID id;
719  struct global_entry *entry;
720  struct trace_var *trace;
721  st_data_t data;
722 
723  rb_scan_args(argc, argv, "11", &var, &cmd);
724  id = rb_check_id(&var);
725  if (!id) {
726  rb_name_error_str(var, "undefined global variable %"PRIsVALUE"", QUOTE(var));
727  }
728  if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
729  rb_name_error(id, "undefined global variable %"PRIsVALUE"", QUOTE_ID(id));
730  }
731 
732  trace = (entry = (struct global_entry *)data)->var->trace;
733  if (NIL_P(cmd)) {
734  VALUE ary = rb_ary_new();
735 
736  while (trace) {
737  struct trace_var *next = trace->next;
738  rb_ary_push(ary, (VALUE)trace->data);
739  trace->removed = 1;
740  trace = next;
741  }
742 
743  if (!entry->var->block_trace) remove_trace(entry->var);
744  return ary;
745  }
746  else {
747  while (trace) {
748  if (trace->data == cmd) {
749  trace->removed = 1;
750  if (!entry->var->block_trace) remove_trace(entry->var);
751  return rb_ary_new3(1, cmd);
752  }
753  trace = trace->next;
754  }
755  }
756  return Qnil;
757 }
758 
759 VALUE
760 rb_gvar_get(struct global_entry *entry)
761 {
762  struct global_variable *var = entry->var;
763  return (*var->getter)(entry->id, var->data, var);
764 }
765 
766 struct trace_data {
767  struct trace_var *trace;
769 };
770 
771 static VALUE
773 {
774  struct trace_var *trace = data->trace;
775 
776  while (trace) {
777  (*trace->func)(trace->data, data->val);
778  trace = trace->next;
779  }
780 
781  return Qnil;
782 }
783 
784 static VALUE
786 {
787  var->block_trace = 0;
788  remove_trace(var);
789  return Qnil; /* not reached */
790 }
791 
792 VALUE
794 {
795  struct trace_data trace;
796  struct global_variable *var = entry->var;
797 
798  (*var->setter)(val, entry->id, var->data, var);
799 
800  if (var->trace && !var->block_trace) {
801  var->block_trace = 1;
802  trace.trace = var->trace;
803  trace.val = val;
805  }
806  return val;
807 }
808 
809 VALUE
810 rb_gv_set(const char *name, VALUE val)
811 {
812  struct global_entry *entry;
813 
814  entry = rb_global_entry(global_id(name));
815  return rb_gvar_set(entry, val);
816 }
817 
818 VALUE
819 rb_gv_get(const char *name)
820 {
821  struct global_entry *entry;
822 
823  entry = rb_global_entry(global_id(name));
824  return rb_gvar_get(entry);
825 }
826 
827 VALUE
829 {
830  if (entry->var->getter == undef_getter) return Qfalse;
831  return Qtrue;
832 }
833 
834 static int
836 {
837  ID key = (ID)k;
838  VALUE ary = (VALUE)a;
839  rb_ary_push(ary, ID2SYM(key));
840  return ST_CONTINUE;
841 }
842 
843 /*
844  * call-seq:
845  * global_variables -> array
846  *
847  * Returns an array of the names of global variables.
848  *
849  * global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
850  */
851 
852 VALUE
854 {
855  VALUE ary = rb_ary_new();
856  char buf[2];
857  int i;
858 
860  buf[0] = '$';
861  for (i = 1; i <= 9; ++i) {
862  buf[1] = (char)(i + '0');
863  rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2)));
864  }
865  return ary;
866 }
867 
868 void
869 rb_alias_variable(ID name1, ID name2)
870 {
871  struct global_entry *entry1, *entry2;
872  st_data_t data1;
873 
874  entry2 = rb_global_entry(name2);
875  if (!st_lookup(rb_global_tbl, (st_data_t)name1, &data1)) {
876  entry1 = ALLOC(struct global_entry);
877  entry1->id = name1;
878  st_add_direct(rb_global_tbl, name1, (st_data_t)entry1);
879  }
880  else if ((entry1 = (struct global_entry *)data1)->var != entry2->var) {
881  struct global_variable *var = entry1->var;
882  if (var->block_trace) {
883  rb_raise(rb_eRuntimeError, "can't alias in tracer");
884  }
885  var->counter--;
886  if (var->counter == 0) {
887  struct trace_var *trace = var->trace;
888  while (trace) {
889  struct trace_var *next = trace->next;
890  xfree(trace);
891  trace = next;
892  }
893  xfree(var);
894  }
895  }
896  else {
897  return;
898  }
899  entry2->var->counter++;
900  entry1->var = entry2->var;
901 }
902 
903 static int special_generic_ivar = 0;
905 
906 st_table*
908 {
909  st_data_t tbl;
910 
911  if (!FL_TEST(obj, FL_EXIVAR)) return 0;
912  if (!generic_iv_tbl) return 0;
913  if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &tbl)) return 0;
914  return (st_table *)tbl;
915 }
916 
917 static VALUE
919 {
920  st_data_t tbl, val;
921 
922  if (generic_iv_tbl) {
923  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &tbl)) {
924  if (st_lookup((st_table *)tbl, (st_data_t)id, &val)) {
925  return (VALUE)val;
926  }
927  }
928  }
929  return undef;
930 }
931 
932 static void
934 {
935  st_table *tbl;
936  st_data_t data;
937 
938  if (rb_special_const_p(obj)) {
939  if (rb_obj_frozen_p(obj)) rb_error_frozen("object");
941  }
942  if (!generic_iv_tbl) {
944  }
945  if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) {
946  FL_SET(obj, FL_EXIVAR);
947  tbl = st_init_numtable();
949  st_add_direct(tbl, (st_data_t)id, (st_data_t)val);
950  if (FL_ABLE(obj)) RB_OBJ_WRITTEN(obj, Qundef, val);
951  return;
952  }
954  if (FL_ABLE(obj)) RB_OBJ_WRITTEN(obj, data, val);
955 }
956 
957 static VALUE
959 {
960  st_table *tbl;
961  st_data_t data;
962 
963  if (!generic_iv_tbl) return Qfalse;
964  if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) return Qfalse;
965  tbl = (st_table *)data;
966  if (st_lookup(tbl, (st_data_t)id, &data)) {
967  return Qtrue;
968  }
969  return Qfalse;
970 }
971 
972 static int
974 {
975  st_table *tbl;
976  st_data_t data, key = (st_data_t)id;
977  int status;
978 
979  if (!generic_iv_tbl) return 0;
980  if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) return 0;
981  tbl = (st_table *)data;
982  status = st_delete(tbl, &key, valp);
983  if (tbl->num_entries == 0) {
984  key = (st_data_t)obj;
987  }
988  return status;
989 }
990 
991 void
993 {
994  st_data_t tbl;
995 
996  if (!generic_iv_tbl) return;
997  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &tbl)) {
998  rb_mark_tbl((st_table *)tbl);
999  }
1000 }
1001 
1002 static int
1004 {
1005  VALUE value = (VALUE)v;
1006  rb_gc_mark(value);
1007  return ST_CONTINUE;
1008 }
1009 
1010 static int
1012 {
1013  VALUE obj = (VALUE)k;
1014  st_table *tbl = (st_table *)v;
1015  if (rb_special_const_p(obj)) {
1016  st_foreach_safe(tbl, givar_mark_i, 0);
1017  }
1018  return ST_CONTINUE;
1019 }
1020 
1021 void
1023 {
1024  if (!generic_iv_tbl) return;
1025  if (special_generic_ivar == 0) return;
1027 }
1028 
1029 void
1031 {
1032  st_data_t key = (st_data_t)obj, tbl;
1033 
1034  if (!generic_iv_tbl) return;
1035  if (st_delete(generic_iv_tbl, &key, &tbl))
1036  st_free_table((st_table *)tbl);
1037 }
1038 
1039 RUBY_FUNC_EXPORTED size_t
1041 {
1042  st_data_t tbl;
1043  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &tbl))
1044  return st_memsize((st_table *)tbl);
1045  return 0;
1046 }
1047 
1048 void
1050 {
1051  st_data_t data;
1052 
1053  if (!generic_iv_tbl) return;
1054  if (!FL_TEST(obj, FL_EXIVAR)) {
1055  clear:
1056  if (FL_TEST(clone, FL_EXIVAR)) {
1057  rb_free_generic_ivar(clone);
1058  FL_UNSET(clone, FL_EXIVAR);
1059  }
1060  return;
1061  }
1062  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) {
1063  st_table *tbl = (st_table *)data;
1064 
1065  if (tbl->num_entries == 0)
1066  goto clear;
1067 
1068  if (st_lookup(generic_iv_tbl, (st_data_t)clone, &data)) {
1071  }
1072  else {
1074  FL_SET(clone, FL_EXIVAR);
1075  }
1076  }
1077 }
1078 
1079 static VALUE
1080 rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
1081 {
1082  VALUE val, *ptr;
1083  struct st_table *iv_index_tbl;
1084  long len;
1085  st_data_t index;
1086 
1087  if (SPECIAL_CONST_P(obj)) goto generic;
1088  switch (BUILTIN_TYPE(obj)) {
1089  case T_OBJECT:
1090  len = ROBJECT_NUMIV(obj);
1091  ptr = ROBJECT_IVPTR(obj);
1092  iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
1093  if (!iv_index_tbl) break;
1094  if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
1095  if (len <= (long)index) break;
1096  val = ptr[index];
1097  if (val != Qundef)
1098  return val;
1099  break;
1100  case T_CLASS:
1101  case T_MODULE:
1102  if (RCLASS_IV_TBL(obj) && st_lookup(RCLASS_IV_TBL(obj), (st_data_t)id, &index))
1103  return (VALUE)index;
1104  break;
1105  default:
1106  generic:
1107  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj))
1108  return generic_ivar_get(obj, id, undef);
1109  break;
1110  }
1111  return undef;
1112 }
1113 
1114 VALUE
1116 {
1117  VALUE iv = rb_ivar_lookup(obj, id, Qundef);
1118 
1119  if (iv == Qundef) {
1120  rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
1121  iv = Qnil;
1122  }
1123  return iv;
1124 }
1125 
1126 VALUE
1128 {
1129  return rb_ivar_lookup(obj, id, Qnil);
1130 }
1131 
1132 VALUE
1134 {
1135  struct st_table *iv_index_tbl;
1136  st_data_t index;
1137  long i, len;
1138  int ivar_extended;
1139 
1140  rb_check_frozen(obj);
1141  if (SPECIAL_CONST_P(obj)) goto generic;
1142  switch (BUILTIN_TYPE(obj)) {
1143  case T_OBJECT:
1144  iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
1145  if (!iv_index_tbl) {
1146  VALUE klass = rb_obj_class(obj);
1147  iv_index_tbl = RCLASS_IV_INDEX_TBL(klass);
1148  if (!iv_index_tbl) {
1149  iv_index_tbl = RCLASS_IV_INDEX_TBL(klass) = st_init_numtable();
1150  }
1151  }
1152  ivar_extended = 0;
1153  if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
1154  index = iv_index_tbl->num_entries;
1155  st_add_direct(iv_index_tbl, (st_data_t)id, index);
1156  ivar_extended = 1;
1157  }
1158  len = ROBJECT_NUMIV(obj);
1159  if (len <= (long)index) {
1160  VALUE *ptr = ROBJECT_IVPTR(obj);
1161  if (index < ROBJECT_EMBED_LEN_MAX) {
1162  RBASIC(obj)->flags |= ROBJECT_EMBED;
1163  ptr = ROBJECT(obj)->as.ary;
1164  for (i = 0; i < ROBJECT_EMBED_LEN_MAX; i++) {
1165  ptr[i] = Qundef;
1166  }
1167  }
1168  else {
1169  VALUE *newptr;
1170  long newsize = (index+1) + (index+1)/4; /* (index+1)*1.25 */
1171  if (!ivar_extended &&
1172  iv_index_tbl->num_entries < (st_index_t)newsize) {
1173  newsize = iv_index_tbl->num_entries;
1174  }
1175  if (RBASIC(obj)->flags & ROBJECT_EMBED) {
1176  newptr = ALLOC_N(VALUE, newsize);
1177  MEMCPY(newptr, ptr, VALUE, len);
1178  RBASIC(obj)->flags &= ~ROBJECT_EMBED;
1179  ROBJECT(obj)->as.heap.ivptr = newptr;
1180  }
1181  else {
1182  REALLOC_N(ROBJECT(obj)->as.heap.ivptr, VALUE, newsize);
1183  newptr = ROBJECT(obj)->as.heap.ivptr;
1184  }
1185  for (; len < newsize; len++)
1186  newptr[len] = Qundef;
1187  ROBJECT(obj)->as.heap.numiv = newsize;
1188  ROBJECT(obj)->as.heap.iv_index_tbl = iv_index_tbl;
1189  }
1190  }
1191  RB_OBJ_WRITE(obj, &ROBJECT_IVPTR(obj)[index], val);
1192  break;
1193  case T_CLASS:
1194  case T_MODULE:
1195  if (!RCLASS_IV_TBL(obj)) RCLASS_IV_TBL(obj) = st_init_numtable();
1197  break;
1198  default:
1199  generic:
1200  generic_ivar_set(obj, id, val);
1201  break;
1202  }
1203  return val;
1204 }
1205 
1206 VALUE
1208 {
1209  VALUE val;
1210  struct st_table *iv_index_tbl;
1211  st_data_t index;
1212  if (SPECIAL_CONST_P(obj)) goto generic;
1213  switch (BUILTIN_TYPE(obj)) {
1214  case T_OBJECT:
1215  iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
1216  if (!iv_index_tbl) break;
1217  if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
1218  if (ROBJECT_NUMIV(obj) <= (long)index) break;
1219  val = ROBJECT_IVPTR(obj)[index];
1220  if (val != Qundef)
1221  return Qtrue;
1222  break;
1223  case T_CLASS:
1224  case T_MODULE:
1225  if (RCLASS_IV_TBL(obj) && st_lookup(RCLASS_IV_TBL(obj), (st_data_t)id, 0))
1226  return Qtrue;
1227  break;
1228  default:
1229  generic:
1230  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj))
1231  return generic_ivar_defined(obj, id);
1232  break;
1233  }
1234  return Qfalse;
1235 }
1236 
1239  int (*func)(ID key, VALUE val, st_data_t arg);
1241 };
1242 
1243 static int
1245 {
1246  struct obj_ivar_tag *data = (struct obj_ivar_tag *)arg;
1247  if ((long)index < ROBJECT_NUMIV(data->obj)) {
1248  VALUE val = ROBJECT_IVPTR(data->obj)[(long)index];
1249  if (val != Qundef) {
1250  return (data->func)((ID)key, val, data->arg);
1251  }
1252  }
1253  return ST_CONTINUE;
1254 }
1255 
1256 static void
1258 {
1259  st_table *tbl;
1260  struct obj_ivar_tag data;
1261 
1262  tbl = ROBJECT_IV_INDEX_TBL(obj);
1263  if (!tbl)
1264  return;
1265 
1266  data.obj = obj;
1267  data.func = (int (*)(ID key, VALUE val, st_data_t arg))func;
1268  data.arg = arg;
1269 
1270  st_foreach_safe(tbl, obj_ivar_i, (st_data_t)&data);
1271 }
1272 
1273 void
1275 {
1276  if (SPECIAL_CONST_P(obj)) goto generic;
1277  switch (BUILTIN_TYPE(obj)) {
1278  case T_OBJECT:
1279  obj_ivar_each(obj, func, arg);
1280  break;
1281  case T_CLASS:
1282  case T_MODULE:
1283  if (RCLASS_IV_TBL(obj)) {
1284  st_foreach_safe(RCLASS_IV_TBL(obj), func, arg);
1285  }
1286  break;
1287  default:
1288  generic:
1289  if (!generic_iv_tbl) break;
1290  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
1291  st_data_t tbl;
1292 
1293  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &tbl)) {
1294  st_foreach_safe((st_table *)tbl, func, arg);
1295  }
1296  }
1297  break;
1298  }
1299 }
1300 
1301 st_index_t
1303 {
1304  st_table *tbl;
1305  if (SPECIAL_CONST_P(obj)) goto generic;
1306  switch (BUILTIN_TYPE(obj)) {
1307  case T_OBJECT:
1308  if ((tbl = ROBJECT_IV_INDEX_TBL(obj)) != 0) {
1309  st_index_t i, count, num = tbl->num_entries;
1310  const VALUE *const ivptr = ROBJECT_IVPTR(obj);
1311  for (i = count = 0; i < num; ++i) {
1312  if (ivptr[i] != Qundef) {
1313  count++;
1314  }
1315  }
1316  return count;
1317  }
1318  break;
1319  case T_CLASS:
1320  case T_MODULE:
1321  if ((tbl = RCLASS_IV_TBL(obj)) != 0) {
1322  return tbl->num_entries;
1323  }
1324  break;
1325  default:
1326  generic:
1327  if (!generic_iv_tbl) break;
1328  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
1329  st_data_t data;
1330 
1331  if (st_lookup(generic_iv_tbl, (st_data_t)obj, &data) &&
1332  (tbl = (st_table *)data) != 0) {
1333  return tbl->num_entries;
1334  }
1335  }
1336  break;
1337  }
1338  return 0;
1339 }
1340 
1341 static int
1343 {
1344  ID key = (ID)k;
1345  VALUE ary = (VALUE)a;
1346 
1347  if (rb_is_instance_id(key)) {
1348  rb_ary_push(ary, ID2SYM(key));
1349  }
1350  return ST_CONTINUE;
1351 }
1352 
1353 /*
1354  * call-seq:
1355  * obj.instance_variables -> array
1356  *
1357  * Returns an array of instance variable names for the receiver. Note
1358  * that simply defining an accessor does not create the corresponding
1359  * instance variable.
1360  *
1361  * class Fred
1362  * attr_accessor :a1
1363  * def initialize
1364  * @iv = 3
1365  * end
1366  * end
1367  * Fred.new.instance_variables #=> [:@iv]
1368  */
1369 
1370 VALUE
1372 {
1373  VALUE ary;
1374 
1375  ary = rb_ary_new();
1376  rb_ivar_foreach(obj, ivar_i, ary);
1377  return ary;
1378 }
1379 
1380 /*
1381  * call-seq:
1382  * obj.remove_instance_variable(symbol) -> obj
1383  *
1384  * Removes the named instance variable from <i>obj</i>, returning that
1385  * variable's value.
1386  *
1387  * class Dummy
1388  * attr_reader :var
1389  * def initialize
1390  * @var = 99
1391  * end
1392  * def remove
1393  * remove_instance_variable(:@var)
1394  * end
1395  * end
1396  * d = Dummy.new
1397  * d.var #=> 99
1398  * d.remove #=> 99
1399  * d.var #=> nil
1400  */
1401 
1402 VALUE
1404 {
1405  VALUE val = Qnil;
1406  const ID id = rb_check_id(&name);
1407  st_data_t n, v;
1408  struct st_table *iv_index_tbl;
1409  st_data_t index;
1410 
1411  rb_check_frozen(obj);
1412  if (!id) {
1413  if (rb_is_instance_name(name)) {
1414  rb_name_error_str(name, "instance variable %"PRIsVALUE" not defined",
1415  name);
1416  }
1417  else {
1418  rb_name_error_str(name, "`%"PRIsVALUE"' is not allowed as an instance variable name",
1419  QUOTE(name));
1420  }
1421  }
1422  if (!rb_is_instance_id(id)) {
1423  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
1424  QUOTE_ID(id));
1425  }
1426 
1427  if (SPECIAL_CONST_P(obj)) goto generic;
1428  switch (BUILTIN_TYPE(obj)) {
1429  case T_OBJECT:
1430  iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
1431  if (!iv_index_tbl) break;
1432  if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
1433  if (ROBJECT_NUMIV(obj) <= (long)index) break;
1434  val = ROBJECT_IVPTR(obj)[index];
1435  if (val != Qundef) {
1436  ROBJECT_IVPTR(obj)[index] = Qundef;
1437  return val;
1438  }
1439  break;
1440  case T_CLASS:
1441  case T_MODULE:
1442  n = id;
1443  if (RCLASS_IV_TBL(obj) && st_delete(RCLASS_IV_TBL(obj), &n, &v)) {
1444  return (VALUE)v;
1445  }
1446  break;
1447  default:
1448  generic:
1449  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
1450  v = val;
1451  if (generic_ivar_remove(obj, (st_data_t)id, &v)) {
1452  return (VALUE)v;
1453  }
1454  }
1455  break;
1456  }
1457  rb_name_error(id, "instance variable %"PRIsVALUE" not defined", QUOTE_ID(id));
1458 
1459  UNREACHABLE;
1460 }
1461 
1462 NORETURN(static void uninitialized_constant(VALUE, ID));
1463 static void
1465 {
1466  if (klass && rb_class_real(klass) != rb_cObject)
1467  rb_name_error(id, "uninitialized constant %"PRIsVALUE"::%"PRIsVALUE"",
1468  rb_class_name(klass),
1469  QUOTE_ID(id));
1470  else {
1471  rb_name_error(id, "uninitialized constant %"PRIsVALUE"", QUOTE_ID(id));
1472  }
1473 }
1474 
1475 static VALUE
1477 {
1478  return rb_funcall(klass, rb_intern("const_missing"), 1, ID2SYM(id));
1479 }
1480 
1481 
1482 /*
1483  * call-seq:
1484  * mod.const_missing(sym) -> obj
1485  *
1486  * Invoked when a reference is made to an undefined constant in
1487  * <i>mod</i>. It is passed a symbol for the undefined constant, and
1488  * returns a value to be used for that constant. The
1489  * following code is an example of the same:
1490  *
1491  * def Foo.const_missing(name)
1492  * name # return the constant name as Symbol
1493  * end
1494  *
1495  * Foo::UNDEFINED_CONST #=> :UNDEFINED_CONST: symbol returned
1496  *
1497  * In the next example when a reference is made to an undefined constant,
1498  * it attempts to load a file whose name is the lowercase version of the
1499  * constant (thus class <code>Fred</code> is assumed to be in file
1500  * <code>fred.rb</code>). If found, it returns the loaded class. It
1501  * therefore implements an autoload feature similar to Kernel#autoload and
1502  * Module#autoload.
1503  *
1504  * def Object.const_missing(name)
1505  * @looked_for ||= {}
1506  * str_name = name.to_s
1507  * raise "Class not found: #{name}" if @looked_for[str_name]
1508  * @looked_for[str_name] = 1
1509  * file = str_name.downcase
1510  * require file
1511  * klass = const_get(name)
1512  * return klass if klass
1513  * raise "Class not found: #{name}"
1514  * end
1515  *
1516  */
1517 
1518 VALUE
1520 {
1523 
1524  UNREACHABLE;
1525 }
1526 
1527 static void
1528 autoload_mark(void *ptr)
1529 {
1530  rb_mark_tbl((st_table *)ptr);
1531 }
1532 
1533 static void
1534 autoload_free(void *ptr)
1535 {
1536  st_free_table((st_table *)ptr);
1537 }
1538 
1539 static size_t
1540 autoload_memsize(const void *ptr)
1541 {
1542  const st_table *tbl = ptr;
1543  return tbl ? st_memsize(tbl) : 0;
1544 }
1545 
1547  "autoload",
1550 };
1551 
1552 #define check_autoload_table(av) \
1553  (struct st_table *)rb_check_typeddata((av), &autoload_data_type)
1554 
1555 static VALUE
1557 {
1558  struct st_table *tbl;
1559  st_data_t val;
1560 
1561  if (!st_lookup(RCLASS_IV_TBL(mod), autoload, &val) ||
1562  !(tbl = check_autoload_table((VALUE)val)) || !st_lookup(tbl, (st_data_t)id, &val)) {
1563  return 0;
1564  }
1565  return (VALUE)val;
1566 }
1567 
1573 };
1574 
1575 static void
1577 {
1578  struct autoload_data_i *p = ptr;
1579  rb_gc_mark(p->feature);
1580  rb_gc_mark(p->thread);
1581  rb_gc_mark(p->value);
1582 }
1583 
1584 static void
1586 {
1587  struct autoload_data_i *p = ptr;
1588  xfree(p);
1589 }
1590 
1591 static size_t
1592 autoload_i_memsize(const void *ptr)
1593 {
1594  return sizeof(struct autoload_data_i);
1595 }
1596 
1598  "autoload_i",
1601 };
1602 
1603 #define check_autoload_data(av) \
1604  (struct autoload_data_i *)rb_check_typeddata((av), &autoload_data_i_type)
1605 
1606 void
1607 rb_autoload(VALUE mod, ID id, const char *file)
1608 {
1609  st_data_t av;
1610  VALUE ad, fn;
1611  struct st_table *tbl;
1612  struct autoload_data_i *ele;
1613 
1614  if (!rb_is_const_id(id)) {
1615  rb_raise(rb_eNameError, "autoload must be constant name: %"PRIsVALUE"",
1616  QUOTE_ID(id));
1617  }
1618  if (!file || !*file) {
1619  rb_raise(rb_eArgError, "empty file name");
1620  }
1621 
1622  if ((tbl = RCLASS_CONST_TBL(mod)) && st_lookup(tbl, (st_data_t)id, &av) && ((rb_const_entry_t*)av)->value != Qundef)
1623  return;
1624 
1625  rb_const_set(mod, id, Qundef);
1626  tbl = RCLASS_IV_TBL(mod);
1627  if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
1628  tbl = check_autoload_table((VALUE)av);
1629  }
1630  else {
1631  if (!tbl) tbl = RCLASS_IV_TBL(mod) = st_init_numtable();
1633  st_add_direct(tbl, (st_data_t)autoload, av);
1634  RB_OBJ_WRITTEN(mod, Qnil, av);
1635  DATA_PTR(av) = tbl = st_init_numtable();
1636  }
1637  fn = rb_str_new2(file);
1638  FL_UNSET(fn, FL_TAINT);
1639  OBJ_FREEZE(fn);
1640 
1641  ele = ALLOC(struct autoload_data_i);
1642  ele->feature = fn;
1643  ele->safe_level = rb_safe_level();
1644  ele->thread = Qnil;
1645  ele->value = Qundef;
1647  st_insert(tbl, (st_data_t)id, (st_data_t)ad);
1648 }
1649 
1650 static void
1652 {
1653  st_data_t val, load = 0, n = id;
1654  rb_const_entry_t *ce;
1655 
1657  ce = (rb_const_entry_t*)val;
1658  if (ce) xfree(ce);
1660  struct st_table *tbl = check_autoload_table((VALUE)val);
1661 
1662  st_delete(tbl, &n, &load);
1663 
1664  if (tbl->num_entries == 0) {
1665  n = autoload;
1666  st_delete(RCLASS_IV_TBL(mod), &n, &val);
1667  }
1668  }
1669 }
1670 
1671 static VALUE
1673 {
1674  const char **p = (const char **)arg;
1675  return rb_feature_provided(*p, p);
1676 }
1677 
1678 static VALUE
1680 {
1681  rb_set_safe_level_force((int)safe);
1682  return safe;
1683 }
1684 
1685 static VALUE
1686 check_autoload_required(VALUE mod, ID id, const char **loadingpath)
1687 {
1688  VALUE file, load;
1689  struct autoload_data_i *ele;
1690  const char *loading;
1691  int safe;
1692 
1693  if (!(load = autoload_data(mod, id)) || !(ele = check_autoload_data(load))) {
1694  return 0;
1695  }
1696  file = ele->feature;
1697  Check_Type(file, T_STRING);
1698  if (!RSTRING_PTR(file) || !*RSTRING_PTR(file)) {
1699  rb_raise(rb_eArgError, "empty file name");
1700  }
1701  loading = RSTRING_PTR(file);
1702  safe = rb_safe_level();
1704  if (!rb_ensure(autoload_provided, (VALUE)&loading, reset_safe, (VALUE)safe)) {
1705  return load;
1706  }
1707  if (loadingpath && loading) {
1708  *loadingpath = loading;
1709  return load;
1710  }
1711  return 0;
1712 }
1713 
1714 int
1716 {
1717  VALUE load;
1718  struct autoload_data_i *ele;
1719 
1720  if (!(load = autoload_data(mod, id)) || !(ele = check_autoload_data(load))) {
1721  return 0;
1722  }
1723  if (ele->thread == rb_thread_current()) {
1724  if (ele->value != Qundef) {
1725  if (value) {
1726  *value = ele->value;
1727  }
1728  return 1;
1729  }
1730  }
1731  return 0;
1732 }
1733 
1734 static int
1736 {
1737  struct st_table *tbl = RCLASS_CONST_TBL(mod);
1738  st_data_t val;
1739 
1740  if (!tbl || !st_lookup(tbl, (st_data_t)id, &val) || ((rb_const_entry_t*)val)->value != Qundef) {
1741  return 0;
1742  }
1743  return !rb_autoloading_value(mod, id, NULL);
1744 }
1745 
1750 };
1751 
1752 static VALUE
1754 {
1755  struct autoload_const_set_args* args = (struct autoload_const_set_args *)arg;
1756  autoload_delete(args->mod, args->id);
1757  rb_const_set(args->mod, args->id, args->value);
1758  return 0; /* ignored */
1759 }
1760 
1761 static VALUE
1763 {
1764  struct autoload_data_i *ele = (struct autoload_data_i *)arg;
1765  return rb_require_safe(ele->feature, ele->safe_level);
1766 }
1767 
1768 VALUE
1770 {
1771  VALUE load, result;
1772  const char *loading = 0, *src;
1773  struct autoload_data_i *ele;
1774  int state = 0;
1775 
1776  if (!autoload_defined_p(mod, id)) return Qfalse;
1777  load = check_autoload_required(mod, id, &loading);
1778  if (!load) return Qfalse;
1779  src = rb_sourcefile();
1780  if (src && loading && strcmp(src, loading) == 0) return Qfalse;
1781 
1782  /* set ele->thread for a marker of autoloading thread */
1783  if (!(ele = check_autoload_data(load))) {
1784  return Qfalse;
1785  }
1786  if (ele->thread == Qnil) {
1787  ele->thread = rb_thread_current();
1788  }
1789  /* autoload_data_i can be deleted by another thread while require */
1790  result = rb_protect(autoload_require, (VALUE)ele, &state);
1791  if (ele->thread == rb_thread_current()) {
1792  ele->thread = Qnil;
1793  }
1794  if (state) rb_jump_tag(state);
1795 
1796  if (RTEST(result)) {
1797  /* At the last, move a value defined in autoload to constant table */
1798  if (ele->value != Qundef) {
1799  int safe_backup;
1800  struct autoload_const_set_args args;
1801  args.mod = mod;
1802  args.id = id;
1803  args.value = ele->value;
1804  safe_backup = rb_safe_level();
1805  rb_set_safe_level_force(ele->safe_level);
1806  rb_ensure(autoload_const_set, (VALUE)&args, reset_safe, (VALUE)safe_backup);
1807  }
1808  }
1809  RB_GC_GUARD(load);
1810  return result;
1811 }
1812 
1813 VALUE
1815 {
1816  VALUE load;
1817  struct autoload_data_i *ele;
1818 
1819  while (!autoload_defined_p(mod, id)) {
1820  mod = RCLASS_SUPER(mod);
1821  if (!mod) return Qnil;
1822  }
1823  load = check_autoload_required(mod, id, 0);
1824  if (!load) return Qnil;
1825  return (ele = check_autoload_data(load)) ? ele->feature : Qnil;
1826 }
1827 
1828 static VALUE
1829 rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
1830 {
1831  VALUE value, tmp, av;
1832  int mod_retry = 0;
1833 
1834  tmp = klass;
1835  retry:
1836  while (RTEST(tmp)) {
1837  VALUE am = 0;
1838  st_data_t data;
1839  while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &data)) {
1840  rb_const_entry_t *ce = (rb_const_entry_t *)data;
1841  if (visibility && ce->flag == CONST_PRIVATE) {
1842  rb_name_error(id, "private constant %"PRIsVALUE"::%"PRIsVALUE" referenced",
1843  rb_class_name(klass), QUOTE_ID(id));
1844  }
1845  value = ce->value;
1846  if (value == Qundef) {
1847  if (am == tmp) break;
1848  am = tmp;
1849  if (rb_autoloading_value(tmp, id, &av)) return av;
1850  rb_autoload_load(tmp, id);
1851  continue;
1852  }
1853  if (exclude && tmp == rb_cObject && klass != rb_cObject) {
1854  rb_warn("toplevel constant %"PRIsVALUE" referenced by %"PRIsVALUE"::%"PRIsVALUE"",
1855  QUOTE_ID(id), rb_class_name(klass), QUOTE_ID(id));
1856  }
1857  return value;
1858  }
1859  if (!recurse) break;
1860  tmp = RCLASS_SUPER(tmp);
1861  }
1862  if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
1863  mod_retry = 1;
1864  tmp = rb_cObject;
1865  goto retry;
1866  }
1867 
1868  value = const_missing(klass, id);
1870  return value;
1871 }
1872 
1873 VALUE
1875 {
1876  return rb_const_get_0(klass, id, TRUE, TRUE, FALSE);
1877 }
1878 
1879 VALUE
1881 {
1882  return rb_const_get_0(klass, id, FALSE, TRUE, FALSE);
1883 }
1884 
1885 VALUE
1887 {
1888  return rb_const_get_0(klass, id, TRUE, FALSE, FALSE);
1889 }
1890 
1891 VALUE
1893 {
1894  return rb_const_get_0(klass, id, TRUE, TRUE, TRUE);
1895 }
1896 
1897 VALUE
1899 {
1900  return rb_const_get_0(klass, id, FALSE, TRUE, TRUE);
1901 }
1902 
1903 VALUE
1905 {
1906  return rb_const_get_0(klass, id, TRUE, FALSE, TRUE);
1907 }
1908 
1909 /*
1910  * call-seq:
1911  * remove_const(sym) -> obj
1912  *
1913  * Removes the definition of the given constant, returning that
1914  * constant's previous value. If that constant referred to
1915  * a module, this will not change that module's name and can lead
1916  * to confusion.
1917  */
1918 
1919 VALUE
1921 {
1922  const ID id = rb_check_id(&name);
1923 
1924  if (!id) {
1925  if (rb_is_const_name(name)) {
1926  rb_name_error_str(name, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined",
1927  rb_class_name(mod), name);
1928  }
1929  else {
1930  rb_name_error_str(name, "`%"PRIsVALUE"' is not allowed as a constant name",
1931  QUOTE(name));
1932  }
1933  }
1934  if (!rb_is_const_id(id)) {
1935  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a constant name",
1936  QUOTE_ID(id));
1937  }
1938  return rb_const_remove(mod, id);
1939 }
1940 
1941 VALUE
1943 {
1944  VALUE val;
1945  st_data_t v, n = id;
1946 
1948  if (!RCLASS_CONST_TBL(mod) || !st_delete(RCLASS_CONST_TBL(mod), &n, &v)) {
1949  if (rb_const_defined_at(mod, id)) {
1950  rb_name_error(id, "cannot remove %"PRIsVALUE"::%"PRIsVALUE"",
1951  rb_class_name(mod), QUOTE_ID(id));
1952  }
1953  rb_name_error(id, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined",
1954  rb_class_name(mod), QUOTE_ID(id));
1955  }
1956 
1958 
1959  val = ((rb_const_entry_t*)v)->value;
1960  if (val == Qundef) {
1961  autoload_delete(mod, id);
1962  val = Qnil;
1963  }
1964  xfree((rb_const_entry_t*)v);
1965  return val;
1966 }
1967 
1968 static int
1970 {
1971  ID key = (ID)k;
1973  st_table *tbl = (st_table *)a;
1974 
1975  if (rb_is_const_id(key)) {
1976  if (!st_lookup(tbl, (st_data_t)key, 0)) {
1977  st_insert(tbl, (st_data_t)key, (st_data_t)ce);
1978  }
1979  }
1980  return ST_CONTINUE;
1981 }
1982 
1983 static int
1984 rb_local_constants_i(st_data_t const_name, st_data_t const_value, st_data_t ary)
1985 {
1986  rb_ary_push((VALUE)ary, ID2SYM((ID)const_name));
1987  return ST_CONTINUE;
1988 }
1989 
1990 static VALUE
1992 {
1993  st_table *tbl = RCLASS_CONST_TBL(mod);
1994  VALUE ary;
1995 
1996  if (!tbl) return rb_ary_new2(0);
1997 
1998  ary = rb_ary_new2(tbl->num_entries);
1999  st_foreach(tbl, rb_local_constants_i, ary);
2000  return ary;
2001 }
2002 
2003 void*
2005 {
2006  st_table *tbl = data;
2007  if (!tbl) {
2008  tbl = st_init_numtable();
2009  }
2010  if (RCLASS_CONST_TBL(mod)) {
2012  }
2013  return tbl;
2014 }
2015 
2016 void*
2018 {
2019  VALUE tmp = mod;
2020  for (;;) {
2021  data = rb_mod_const_at(tmp, data);
2022  tmp = RCLASS_SUPER(tmp);
2023  if (!tmp) break;
2024  if (tmp == rb_cObject && mod != rb_cObject) break;
2025  }
2026  return data;
2027 }
2028 
2029 static int
2031 {
2032  ID sym = (ID)key;
2033  rb_const_entry_t *ce = (rb_const_entry_t *)value;
2034  if (ce->flag != CONST_PRIVATE) rb_ary_push(ary, ID2SYM(sym));
2035  return ST_CONTINUE;
2036 }
2037 
2038 VALUE
2039 rb_const_list(void *data)
2040 {
2041  st_table *tbl = data;
2042  VALUE ary;
2043 
2044  if (!tbl) return rb_ary_new2(0);
2045  ary = rb_ary_new2(tbl->num_entries);
2046  st_foreach_safe(tbl, list_i, ary);
2047  st_free_table(tbl);
2048 
2049  return ary;
2050 }
2051 
2052 /*
2053  * call-seq:
2054  * mod.constants(inherit=true) -> array
2055  *
2056  * Returns an array of the names of the constants accessible in
2057  * <i>mod</i>. This includes the names of constants in any included
2058  * modules (example at start of section), unless the <i>inherit</i>
2059  * parameter is set to <code>false</code>.
2060  *
2061  * The implementation makes no guarantees about the order in which the
2062  * constants are yielded.
2063  *
2064  * IO.constants.include?(:SYNC) #=> true
2065  * IO.constants(false).include?(:SYNC) #=> false
2066  *
2067  * Also see <code>Module::const_defined?</code>.
2068  */
2069 
2070 VALUE
2072 {
2073  VALUE inherit;
2074 
2075  if (argc == 0) {
2076  inherit = Qtrue;
2077  }
2078  else {
2079  rb_scan_args(argc, argv, "01", &inherit);
2080  }
2081 
2082  if (RTEST(inherit)) {
2083  return rb_const_list(rb_mod_const_of(mod, 0));
2084  }
2085  else {
2086  return rb_local_constants(mod);
2087  }
2088 }
2089 
2090 static int
2091 rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
2092 {
2093  st_data_t value;
2094  VALUE tmp;
2095  int mod_retry = 0;
2096 
2097  tmp = klass;
2098  retry:
2099  while (tmp) {
2100  if (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &value)) {
2101  rb_const_entry_t *ce = (rb_const_entry_t *)value;
2102  if (visibility && ce->flag == CONST_PRIVATE) {
2103  return (int)Qfalse;
2104  }
2105  if (ce->value == Qundef && !check_autoload_required(tmp, id, 0) && !rb_autoloading_value(tmp, id, 0))
2106  return (int)Qfalse;
2107  return (int)Qtrue;
2108  }
2109  if (!recurse) break;
2110  tmp = RCLASS_SUPER(tmp);
2111  }
2112  if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
2113  mod_retry = 1;
2114  tmp = rb_cObject;
2115  goto retry;
2116  }
2117  return (int)Qfalse;
2118 }
2119 
2120 int
2122 {
2123  return rb_const_defined_0(klass, id, TRUE, TRUE, FALSE);
2124 }
2125 
2126 int
2128 {
2129  return rb_const_defined_0(klass, id, FALSE, TRUE, FALSE);
2130 }
2131 
2132 int
2134 {
2135  return rb_const_defined_0(klass, id, TRUE, FALSE, FALSE);
2136 }
2137 
2138 int
2140 {
2141  return rb_const_defined_0(klass, id, TRUE, TRUE, TRUE);
2142 }
2143 
2144 int
2146 {
2147  return rb_const_defined_0(klass, id, FALSE, TRUE, TRUE);
2148 }
2149 
2150 int
2152 {
2153  return rb_const_defined_0(klass, id, TRUE, FALSE, TRUE);
2154 }
2155 
2156 static void
2157 check_before_mod_set(VALUE klass, ID id, VALUE val, const char *dest)
2158 {
2159  rb_check_frozen(klass);
2160 }
2161 
2162 void
2164 {
2165  rb_const_entry_t *ce;
2166  rb_const_flag_t visibility = CONST_PUBLIC;
2167 
2168  if (NIL_P(klass)) {
2169  rb_raise(rb_eTypeError, "no class/module to define constant %"PRIsVALUE"",
2170  QUOTE_ID(id));
2171  }
2172 
2173  check_before_mod_set(klass, id, val, "constant");
2174  if (!RCLASS_CONST_TBL(klass)) {
2176  }
2177  else {
2178  st_data_t value;
2179 
2180  if (st_lookup(RCLASS_CONST_TBL(klass), (st_data_t)id, &value)) {
2181  rb_const_entry_t *ce = (rb_const_entry_t*)value;
2182  if (ce->value == Qundef) {
2183  VALUE load;
2184  struct autoload_data_i *ele;
2185 
2186  load = autoload_data(klass, id);
2187  /* for autoloading thread, keep the defined value to autoloading storage */
2188  if (load && (ele = check_autoload_data(load)) && (ele->thread == rb_thread_current())) {
2190 
2191  ele->value = val; /* autoload_i is non-WB-protected */
2192  return;
2193  }
2194  /* otherwise, allow to override */
2195  autoload_delete(klass, id);
2196  }
2197  else {
2198  VALUE name = QUOTE_ID(id);
2199  visibility = ce->flag;
2200  if (klass == rb_cObject)
2201  rb_warn("already initialized constant %"PRIsVALUE"", name);
2202  else
2203  rb_warn("already initialized constant %"PRIsVALUE"::%"PRIsVALUE"",
2204  rb_class_name(klass), name);
2205  if (!NIL_P(ce->file) && ce->line) {
2207  "previous definition of %"PRIsVALUE" was here", name);
2208  }
2209  st_delete(RCLASS_CONST_TBL(klass), &id, 0);
2210  xfree(ce);
2211  }
2212  }
2213  }
2214 
2216 
2217 
2218  ce = ALLOC(rb_const_entry_t);
2219  MEMZERO(ce, rb_const_entry_t, 1);
2220  ce->flag = visibility;
2221  ce->line = rb_sourceline();
2222  st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
2223  RB_OBJ_WRITE(klass, &ce->value, val);
2224  RB_OBJ_WRITE(klass, &ce->file, rb_sourcefilename());
2225 }
2226 
2227 void
2228 rb_define_const(VALUE klass, const char *name, VALUE val)
2229 {
2230  ID id = rb_intern(name);
2231 
2232  if (!rb_is_const_id(id)) {
2233  rb_warn("rb_define_const: invalid name `%s' for constant", name);
2234  }
2235  rb_const_set(klass, id, val);
2236 }
2237 
2238 void
2240 {
2242 }
2243 
2244 static void
2246 {
2247  int i;
2248  st_data_t v;
2249  ID id;
2250 
2251  if (argc == 0) {
2252  rb_warning("%"PRIsVALUE" with no argument is just ignored",
2254  return;
2255  }
2256 
2257  for (i = 0; i < argc; i++) {
2258  VALUE val = argv[i];
2259  id = rb_check_id(&val);
2260  if (!id) {
2261  if (i > 0) {
2263  }
2264 
2265  rb_name_error_str(val, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined",
2266  rb_class_name(mod), QUOTE(val));
2267  }
2268  if (RCLASS_CONST_TBL(mod) &&
2269  st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
2270  ((rb_const_entry_t*)v)->flag = flag;
2271  }
2272  else {
2273  if (i > 0) {
2275  }
2276  rb_name_error(id, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined",
2277  rb_class_name(mod), QUOTE_ID(id));
2278  }
2279  }
2281 }
2282 
2283 /*
2284  * call-seq:
2285  * mod.private_constant(symbol, ...) => mod
2286  *
2287  * Makes a list of existing constants private.
2288  */
2289 
2290 VALUE
2292 {
2294  return obj;
2295 }
2296 
2297 /*
2298  * call-seq:
2299  * mod.public_constant(symbol, ...) => mod
2300  *
2301  * Makes a list of existing constants public.
2302  */
2303 
2304 VALUE
2306 {
2308  return obj;
2309 }
2310 
2311 static VALUE
2313 {
2314  if (RB_TYPE_P(c, T_ICLASS))
2315  return RBASIC(c)->klass;
2316  return c;
2317 }
2318 
2319 static int
2321 {
2322  if (!RCLASS_IV_TBL(klass)) return 0;
2323  return st_lookup(RCLASS_IV_TBL(klass), (st_data_t)id, v);
2324 }
2325 
2326 static VALUE
2328 {
2329  if (FL_TEST(klass, FL_SINGLETON)) {
2330  VALUE obj = rb_ivar_get(klass, id__attached__);
2331  if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
2332  return obj;
2333  }
2334  }
2335  return RCLASS_SUPER(klass);
2336 }
2337 
2338 #define CVAR_FOREACH_ANCESTORS(klass, v, r) \
2339  for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \
2340  if (cvar_lookup_at(klass, id, (v))) { \
2341  r; \
2342  } \
2343  }
2344 
2345 #define CVAR_LOOKUP(v,r) do {\
2346  if (cvar_lookup_at(klass, id, (v))) {r;}\
2347  CVAR_FOREACH_ANCESTORS(klass, v, r);\
2348 } while(0)
2349 
2350 void
2352 {
2353  VALUE tmp, front = 0, target = 0;
2354 
2355  tmp = klass;
2356  CVAR_LOOKUP(0, {if (!front) front = klass; target = klass;});
2357  if (target) {
2358  if (front && target != front) {
2359  st_data_t did = id;
2360 
2361  if (RTEST(ruby_verbose)) {
2362  rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
2363  QUOTE_ID(id), rb_class_name(original_module(front)),
2364  rb_class_name(original_module(target)));
2365  }
2366  if (BUILTIN_TYPE(front) == T_CLASS) {
2367  st_delete(RCLASS_IV_TBL(front),&did,0);
2368  }
2369  }
2370  }
2371  else {
2372  target = tmp;
2373  }
2374 
2375  check_before_mod_set(target, id, val, "class variable");
2376  if (!RCLASS_IV_TBL(target)) {
2377  RCLASS_IV_TBL(target) = st_init_numtable();
2378  }
2379 
2381 }
2382 
2383 VALUE
2385 {
2386  VALUE tmp, front = 0, target = 0;
2387  st_data_t value;
2388 
2389  tmp = klass;
2390  CVAR_LOOKUP(&value, {if (!front) front = klass; target = klass;});
2391  if (!target) {
2392  rb_name_error(id, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"",
2393  QUOTE_ID(id), rb_class_name(tmp));
2394  }
2395  if (front && target != front) {
2396  st_data_t did = id;
2397 
2398  if (RTEST(ruby_verbose)) {
2399  rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
2400  QUOTE_ID(id), rb_class_name(original_module(front)),
2401  rb_class_name(original_module(target)));
2402  }
2403  if (BUILTIN_TYPE(front) == T_CLASS) {
2404  st_delete(RCLASS_IV_TBL(front),&did,0);
2405  }
2406  }
2407  return (VALUE)value;
2408 }
2409 
2410 VALUE
2412 {
2413  if (!klass) return Qfalse;
2414  CVAR_LOOKUP(0,return Qtrue);
2415  return Qfalse;
2416 }
2417 
2418 void
2419 rb_cv_set(VALUE klass, const char *name, VALUE val)
2420 {
2421  ID id = rb_intern(name);
2422  if (!rb_is_class_id(id)) {
2423  rb_name_error(id, "wrong class variable name %s", name);
2424  }
2425  rb_cvar_set(klass, id, val);
2426 }
2427 
2428 VALUE
2429 rb_cv_get(VALUE klass, const char *name)
2430 {
2431  ID id = rb_intern(name);
2432  if (!rb_is_class_id(id)) {
2433  rb_name_error(id, "wrong class variable name %s", name);
2434  }
2435  return rb_cvar_get(klass, id);
2436 }
2437 
2438 void
2440 {
2441  ID id = rb_intern(name);
2442 
2443  if (!rb_is_class_id(id)) {
2444  rb_name_error(id, "wrong class variable name %s", name);
2445  }
2446  rb_cvar_set(klass, id, val);
2447 }
2448 
2449 static int
2451 {
2452  ID key = (ID)k;
2453  st_table *tbl = (st_table *)a;
2454 
2455  if (rb_is_class_id(key)) {
2456  if (!st_lookup(tbl, (st_data_t)key, 0)) {
2457  st_insert(tbl, (st_data_t)key, 0);
2458  }
2459  }
2460  return ST_CONTINUE;
2461 }
2462 
2463 static void*
2464 mod_cvar_at(VALUE mod, void *data)
2465 {
2466  st_table *tbl = data;
2467  if (!tbl) {
2468  tbl = st_init_numtable();
2469  }
2470  if (RCLASS_IV_TBL(mod)) {
2472  }
2473  return tbl;
2474 }
2475 
2476 static void*
2477 mod_cvar_of(VALUE mod, void *data)
2478 {
2479  VALUE tmp = mod;
2480  for (;;) {
2481  data = mod_cvar_at(tmp, data);
2482  tmp = RCLASS_SUPER(tmp);
2483  if (!tmp) break;
2484  }
2485  return data;
2486 }
2487 
2488 static int
2490 {
2491  ID sym = (ID)key;
2492  rb_ary_push(ary, ID2SYM(sym));
2493  return ST_CONTINUE;
2494 }
2495 
2496 static VALUE
2497 cvar_list(void *data)
2498 {
2499  st_table *tbl = data;
2500  VALUE ary;
2501 
2502  if (!tbl) return rb_ary_new2(0);
2503  ary = rb_ary_new2(tbl->num_entries);
2504  st_foreach_safe(tbl, cv_list_i, ary);
2505  st_free_table(tbl);
2506 
2507  return ary;
2508 }
2509 
2510 /*
2511  * call-seq:
2512  * mod.class_variables(inherit=true) -> array
2513  *
2514  * Returns an array of the names of class variables in <i>mod</i>.
2515  * This includes the names of class variables in any included
2516  * modules, unless the <i>inherit</i> parameter is set to
2517  * <code>false</code>.
2518  *
2519  * class One
2520  * @@var1 = 1
2521  * end
2522  * class Two < One
2523  * @@var2 = 2
2524  * end
2525  * One.class_variables #=> [:@@var1]
2526  * Two.class_variables #=> [:@@var2, :@@var1]
2527  * Two.class_variables(false) #=> [:@@var2]
2528  */
2529 
2530 VALUE
2532 {
2533  VALUE inherit;
2534  st_table *tbl;
2535 
2536  if (argc == 0) {
2537  inherit = Qtrue;
2538  }
2539  else {
2540  rb_scan_args(argc, argv, "01", &inherit);
2541  }
2542  if (RTEST(inherit)) {
2543  tbl = mod_cvar_of(mod, 0);
2544  }
2545  else {
2546  tbl = mod_cvar_at(mod, 0);
2547  }
2548  return cvar_list(tbl);
2549 }
2550 
2551 /*
2552  * call-seq:
2553  * remove_class_variable(sym) -> obj
2554  *
2555  * Removes the definition of the <i>sym</i>, returning that
2556  * constant's value.
2557  *
2558  * class Dummy
2559  * @@var = 99
2560  * puts @@var
2561  * remove_class_variable(:@@var)
2562  * p(defined? @@var)
2563  * end
2564  *
2565  * <em>produces:</em>
2566  *
2567  * 99
2568  * nil
2569  */
2570 
2571 VALUE
2573 {
2574  const ID id = rb_check_id(&name);
2575  st_data_t val, n = id;
2576 
2577  if (!id) {
2578  if (rb_is_class_name(name)) {
2579  rb_name_error_str(name, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"",
2580  name, rb_class_name(mod));
2581  }
2582  else {
2583  rb_name_error_str(name, "wrong class variable name %"PRIsVALUE"", QUOTE(name));
2584  }
2585  }
2586  if (!rb_is_class_id(id)) {
2587  rb_name_error(id, "wrong class variable name %"PRIsVALUE"", QUOTE_ID(id));
2588  }
2590  if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &val)) {
2591  return (VALUE)val;
2592  }
2593  if (rb_cvar_defined(mod, id)) {
2594  rb_name_error(id, "cannot remove %"PRIsVALUE" for %"PRIsVALUE"",
2595  QUOTE_ID(id), rb_class_name(mod));
2596  }
2597  rb_name_error(id, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"",
2598  QUOTE_ID(id), rb_class_name(mod));
2599 
2600  UNREACHABLE;
2601 }
2602 
2603 VALUE
2604 rb_iv_get(VALUE obj, const char *name)
2605 {
2606  ID id = rb_intern(name);
2607 
2608  return rb_ivar_get(obj, id);
2609 }
2610 
2611 VALUE
2612 rb_iv_set(VALUE obj, const char *name, VALUE val)
2613 {
2614  ID id = rb_intern(name);
2615 
2616  return rb_ivar_set(obj, id, val);
2617 }
2618 
2619 /* tbl = xx(obj); tbl[key] = value; */
2620 int
2622 {
2623  int result = st_insert(tbl, (st_data_t)key, (st_data_t)value);
2624  RB_OBJ_WRITTEN(obj, Qundef, value);
2625  return result;
2626 }
2627 
2628 static int
2630 {
2631  RB_OBJ_WRITTEN((VALUE)data, Qundef, (VALUE)value);
2632  return ST_CONTINUE;
2633 }
2634 
2635 st_table *
2636 rb_st_copy(VALUE obj, struct st_table *orig_tbl)
2637 {
2638  st_table *new_tbl = st_copy(orig_tbl);
2639  st_foreach(new_tbl, tbl_copy_i, (st_data_t)obj);
2640  return new_tbl;
2641 }
st_table * rb_st_copy(VALUE obj, struct st_table *orig_tbl)
Definition: variable.c:2636
void rb_mark_generic_ivar(VALUE obj)
Definition: variable.c:992
static VALUE classname(VALUE klass, int *permanent)
Returns +classpath+ of klass, if it is named, or +nil+ for anonymous +class+/+module+.
Definition: variable.c:157
static int givar_mark_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:1003
void rb_define_hooked_variable(const char *name, VALUE *var, VALUE(*getter)(ANYARGS), void(*setter)(ANYARGS))
Definition: variable.c:585
#define T_OBJECT
Definition: ruby.h:477
void rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
Definition: variable.c:293
NORETURN(static void uninitialized_constant(VALUE, ID))
static VALUE rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
Definition: variable.c:1829
static VALUE cvar_list(void *data)
Definition: variable.c:2497
#define FL_EXIVAR
Definition: ruby.h:1139
void rb_vm_inc_const_missing_count(void)
Definition: vm.c:111
void rb_bug(const char *fmt,...)
Definition: error.c:327
#define FALSE
Definition: nkf.h:174
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
int rb_is_class_name(VALUE name)
Definition: ripper.c:17436
size_t strlen(const char *)
VALUE rb_mod_const_missing(VALUE klass, VALUE name)
Definition: variable.c:1519
void * rb_mod_const_at(VALUE mod, void *data)
Definition: variable.c:2004
#define RCLASS_CONST_TBL(c)
Definition: internal.h:293
Definition: constant.h:19
Definition: st.h:69
VALUE rb_id2str(ID id)
Definition: ripper.c:17201
Definition: st.h:100
static void uninitialized_constant(VALUE klass, ID id)
Definition: variable.c:1464
VALUE rb_mod_class_variables(int argc, VALUE *argv, VALUE mod)
Definition: variable.c:2531
VALUE rb_f_global_variables(void)
Definition: variable.c:853
VALUE klass
Definition: variable.c:41
#define undef_getter
Definition: variable.c:435
int count
Definition: encoding.c:48
static VALUE generic_ivar_defined(VALUE obj, ID id)
Definition: variable.c:958
#define RB_OBJ_WRITTEN(a, oldv, b)
Definition: ruby.h:1222
st_table * rb_global_tbl
Definition: variable.c:23
static int autoload_defined_p(VALUE mod, ID id)
Definition: variable.c:1735
gvar_marker_t * marker
Definition: variable.c:430
static st_table * generic_iv_tbl
Definition: variable.c:904
void rb_define_const(VALUE klass, const char *name, VALUE val)
Definition: variable.c:2228
static int cv_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:2450
void rb_define_variable(const char *name, VALUE *var)
Definition: variable.c:604
VALUE path
Definition: variable.c:42
#define QUOTE_ID(id)
Definition: internal.h:718
#define FL_TAINT
Definition: ruby.h:1137
#define CLASS_OF(v)
Definition: ruby.h:440
#define T_MODULE
Definition: ruby.h:480
const VALUE file
Definition: constant.h:22
#define readonly_setter
Definition: variable.c:447
VALUE rb_ivar_defined(VALUE obj, ID id)
Definition: variable.c:1207
#define Qtrue
Definition: ruby.h:426
int st_insert(st_table *, st_data_t, st_data_t)
static VALUE autoload_require(VALUE arg)
Definition: variable.c:1762
static void remove_trace(struct global_variable *var)
Definition: variable.c:683
void rb_error_frozen(const char *what)
Definition: error.c:2077
#define TypedData_Wrap_Struct(klass, data_type, sval)
Definition: ruby.h:1027
static VALUE rb_tmp_class_path(VALUE klass, int *permanent, path_cache_func cache_path)
Definition: variable.c:218
const int id
Definition: nkf.c:209
#define gvar_setter_t
Definition: variable.c:415
static VALUE find_class_path(VALUE klass, ID preferred)
Traverse constant namespace and find +classpath+ for klass.
Definition: variable.c:123
VALUE rb_eTypeError
Definition: error.c:548
void rb_autoload(VALUE mod, ID id, const char *file)
Definition: variable.c:1607
#define UNREACHABLE
Definition: ruby.h:42
VALUE rb_autoload_p(VALUE mod, ID id)
Definition: variable.c:1814
void rb_define_virtual_variable(const char *name, VALUE(*getter)(ANYARGS), void(*setter)(ANYARGS))
Definition: variable.c:616
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:900
static int cvar_lookup_at(VALUE klass, ID id, st_data_t *v)
Definition: variable.c:2320
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
void st_free_table(st_table *)
Definition: st.c:334
VALUE rb_ivar_get(VALUE obj, ID id)
Definition: variable.c:1115
#define SYM2ID(x)
Definition: ruby.h:356
static VALUE trace_en(struct global_variable *var)
Definition: variable.c:785
VALUE rb_const_list(void *data)
Definition: variable.c:2039
void rb_define_global_const(const char *name, VALUE val)
Definition: variable.c:2239
const char * rb_class2name(VALUE klass)
Definition: variable.c:397
#define check_autoload_table(av)
Definition: variable.c:1552
VALUE rb_public_const_get_at(VALUE klass, ID id)
Definition: variable.c:1904
VALUE rb_mod_remove_const(VALUE mod, VALUE name)
Definition: variable.c:1920
static int obj_ivar_i(st_data_t key, st_data_t index, st_data_t arg)
Definition: variable.c:1244
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:781
#define val_setter
Definition: variable.c:440
void rb_gc_mark_global_tbl(void)
Definition: variable.c:562
static VALUE cvar_front_klass(VALUE klass)
Definition: variable.c:2327
#define ROBJECT_IV_INDEX_TBL(o)
Definition: ruby.h:782
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:807
static int givar_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:1011
VALUE rb_mod_name(VALUE mod)
Definition: variable.c:206
#define Check_Type(v, t)
Definition: ruby.h:532
VALUE rb_cv_get(VALUE klass, const char *name)
Definition: variable.c:2429
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
static int rb_local_constants_i(st_data_t const_name, st_data_t const_value, st_data_t ary)
Definition: variable.c:1984
static VALUE autoload_const_set(VALUE arg)
Definition: variable.c:1753
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:179
VALUE rb_path2class(const char *path)
Definition: variable.c:379
#define RB_GC_GUARD(v)
Definition: ruby.h:523
void rb_clear_constant_cache(void)
Definition: vm_method.c:60
int rb_public_const_defined(VALUE klass, ID id)
Definition: variable.c:2145
const VALUE value
Definition: constant.h:21
VALUE rb_eSecurityError
Definition: error.c:557
#define DATA_PTR(dta)
Definition: ruby.h:992
static VALUE autoload_provided(VALUE arg)
Definition: variable.c:1672
void rb_gc_mark(VALUE ptr)
Definition: gc.c:3607
int rb_feature_provided(const char *, const char **)
Definition: load.c:529
st_data_t st_index_t
Definition: st.h:48
#define ROBJECT_NUMIV(o)
Definition: ruby.h:774
static void set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag)
Definition: variable.c:2245
static int special_generic_ivar
Definition: variable.c:903
#define check_autoload_data(av)
Definition: variable.c:1603
VALUE rb_const_get(VALUE klass, ID id)
Definition: variable.c:1880
int rb_public_const_defined_at(VALUE klass, ID id)
Definition: variable.c:2151
VALUE rb_public_const_get(VALUE klass, ID id)
Definition: variable.c:1898
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
Definition: ripper.c:17365
#define gvar_marker_t
Definition: variable.c:416
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Definition: ripper.c:17407
VALUE rb_gvar_set(struct global_entry *entry, VALUE val)
Definition: variable.c:793
#define OBJ_TAINTED(x)
Definition: ruby.h:1182
static void rb_trace_eval(VALUE cmd, VALUE val)
Definition: variable.c:627
#define rb_ary_new2
Definition: intern.h:90
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:982
RUBY_FUNC_EXPORTED size_t rb_generic_ivar_memsize(VALUE obj)
Definition: variable.c:1040
#define undef_setter
Definition: variable.c:436
int line
Definition: constant.h:23
#define sym(x)
Definition: date_core.c:3695
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:967
void(* func)(VALUE arg, VALUE val)
Definition: variable.c:420
VALUE rb_autoload_load(VALUE mod, ID id)
Definition: variable.c:1769
rb_const_flag_t
Definition: constant.h:14
#define CVAR_LOOKUP(v, r)
Definition: variable.c:2345
static int list_i(st_data_t key, st_data_t value, VALUE ary)
Definition: variable.c:2030
rb_const_flag_t flag
Definition: constant.h:20
#define FL_SINGLETON
Definition: ruby.h:1133
int rb_is_const_id(ID id)
Definition: ripper.c:17312
int rb_is_instance_id(ID id)
Definition: ripper.c:17330
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1672
VALUE rb_eNameError
Definition: error.c:553
VALUE rb_cvar_defined(VALUE klass, ID id)
Definition: variable.c:2411
int st_lookup(st_table *, st_data_t, st_data_t *)
#define MEMZERO(p, type, n)
Definition: ruby.h:1359
void rb_const_set(VALUE klass, ID id, VALUE val)
Definition: variable.c:2163
#define FL_TEST(x, f)
Definition: ruby.h:1169
static void autoload_free(void *ptr)
Definition: variable.c:1534
st_data_t arg
Definition: variable.c:1240
static void autoload_delete(VALUE mod, ID id)
Definition: variable.c:1651
void rb_define_readonly_variable(const char *name, VALUE *var)
Definition: variable.c:610
static int cv_list_i(st_data_t key, st_data_t value, VALUE ary)
Definition: variable.c:2489
VALUE rb_class_path(VALUE klass)
Definition: variable.c:257
int t(void)
Definition: conftest.c:13
#define ROBJECT_IVPTR(o)
Definition: ruby.h:778
#define rb_intern_str(string)
Definition: generator.h:17
#define gvar_getter_t
Definition: variable.c:414
VALUE rb_gvar_get(struct global_entry *entry)
Definition: variable.c:760
#define ALLOC_N(type, n)
Definition: ruby.h:1341
struct fc_result * prev
Definition: variable.c:44
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1561
VALUE rb_eRuntimeError
Definition: error.c:547
VALUE rb_class_real(VALUE)
Definition: object.c:204
VALUE rb_str_cat2(VALUE, const char *)
Definition: string.c:2158
VALUE rb_ary_new(void)
Definition: array.c:499
VALUE rb_f_untrace_var(int argc, VALUE *argv)
Definition: variable.c:715
VALUE rb_mod_constants(int argc, VALUE *argv, VALUE mod)
Definition: variable.c:2071
VALUE rb_thread_current(void)
Definition: thread.c:2405
ID preferred
Definition: variable.c:40
#define NIL_P(v)
Definition: ruby.h:438
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
int st_delete(st_table *, st_data_t *, st_data_t *)
#define RCLASS_IV_TBL(c)
Definition: internal.h:292
int removed
Definition: variable.c:419
const char * rb_obj_classname(VALUE obj)
Definition: variable.c:406
#define var_setter
Definition: variable.c:444
int argc
Definition: ruby.c:131
#define Qfalse
Definition: ruby.h:425
#define rb_sourcefile()
Definition: tcltklib.c:98
VALUE rb_require_safe(VALUE, int)
Definition: load.c:945
#define ALLOCA_N(type, n)
Definition: ruby.h:1345
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1580
VALUE rb_gv_get(const char *name)
Definition: variable.c:819
void rb_cv_set(VALUE klass, const char *name, VALUE val)
Definition: variable.c:2419
#define RUBY_FUNC_EXPORTED
Definition: defines.h:246
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1360
#define rb_str_new2
Definition: intern.h:840
int rb_const_defined(VALUE klass, ID id)
Definition: variable.c:2127
union st_table::@120 as
#define OBJ_FREEZE(x)
Definition: ruby.h:1194
void rb_set_class_path(VALUE klass, VALUE under, const char *name)
Definition: variable.c:316
static ID global_id(const char *name)
Definition: variable.c:569
VALUE rb_f_trace_var(int argc, VALUE *argv)
Definition: variable.c:656
VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
Definition: variable.c:1133
int rb_public_const_defined_from(VALUE klass, ID id)
Definition: variable.c:2139
static VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
Definition: variable.c:1080
#define ALLOC(type)
Definition: ruby.h:1342
VALUE rb_class_name(VALUE klass)
Definition: variable.c:391
void st_foreach_safe(st_table *table, int(*func)(ANYARGS), st_data_t a)
Definition: hash.c:198
#define FL_ABLE(x)
Definition: ruby.h:1167
static VALUE generic_ivar_get(VALUE obj, ID id, VALUE undef)
Definition: variable.c:918
static void * mod_cvar_at(VALUE mod, void *data)
Definition: variable.c:2464
#define REALLOC_N(var, type, n)
Definition: ruby.h:1343
#define TRUE
Definition: nkf.h:175
int rb_const_defined_at(VALUE klass, ID id)
Definition: variable.c:2133
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
static void * mod_cvar_of(VALUE mod, void *data)
Definition: variable.c:2477
#define var_marker
Definition: variable.c:445
ID name
Definition: variable.c:40
VALUE rb_attr_get(VALUE obj, ID id)
Definition: variable.c:1127
VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name)
Definition: variable.c:1403
st_table * rb_generic_ivar_table(VALUE obj)
Definition: variable.c:907
#define val_getter
Definition: variable.c:439
VALUE rb_mod_public_constant(int argc, VALUE *argv, VALUE obj)
Definition: variable.c:2305
void Init_var_tables(void)
Definition: variable.c:27
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
void rb_vm_pop_cfunc_frame(void)
Definition: vm.c:281
#define PRIsVALUE
Definition: ruby.h:137
VALUE rb_const_get_at(VALUE klass, ID id)
Definition: variable.c:1886
unsigned long ID
Definition: ruby.h:89
#define val_marker
Definition: variable.c:441
static int ivar_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:1342
#define Qnil
Definition: ruby.h:427
static VALUE const_missing(VALUE klass, ID id)
Definition: variable.c:1476
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
int rb_autoloading_value(VALUE mod, ID id, VALUE *value)
Definition: variable.c:1715
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
#define RBASIC(obj)
Definition: ruby.h:1116
VALUE rb_public_const_get_from(VALUE klass, ID id)
Definition: variable.c:1892
void rb_mark_tbl(st_table *tbl)
Definition: gc.c:3522
VALUE val
Definition: variable.c:768
VALUE rb_gvar_defined(struct global_entry *entry)
Definition: variable.c:828
#define rb_ary_new3
Definition: intern.h:91
#define rb_enc_asciicompat(enc)
Definition: encoding.h:188
static int generic_ivar_remove(VALUE obj, ID id, st_data_t *valp)
Definition: variable.c:973
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:839
VALUE rb_str_new_cstr(const char *)
Definition: string.c:560
static const rb_data_type_t autoload_data_i_type
Definition: variable.c:1597
static int sv_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:1969
st_table * st_init_numtable(void)
Definition: st.c:272
static ID classid
Definition: variable.c:24
void rb_jump_tag(int tag)
Definition: eval.c:706
VALUE rb_str_dup(VALUE)
Definition: string.c:1062
gvar_getter_t * getter
Definition: variable.c:428
static void generic_ivar_set(VALUE obj, ID id, VALUE val)
Definition: variable.c:933
void rb_define_class_variable(VALUE klass, const char *name, VALUE val)
Definition: variable.c:2439
#define FL_UNSET(x, f)
Definition: ruby.h:1177
#define ROBJECT(obj)
Definition: ruby.h:1117
VALUE rb_mod_private_constant(int argc, VALUE *argv, VALUE obj)
Definition: variable.c:2291
void rb_set_safe_level_force(int)
Definition: safe.c:43
VALUE rb_obj_instance_variables(VALUE obj)
Definition: variable.c:1371
#define RSTRING_PTR(str)
Definition: ruby.h:845
static VALUE autoload_data(VALUE mod, ID id)
Definition: variable.c:1556
int rb_is_const_name(VALUE name)
Definition: ripper.c:17430
VALUE track
Definition: variable.c:43
gvar_setter_t * setter
Definition: variable.c:429
VALUE rb_class_path_cached(VALUE klass)
Definition: variable.c:281
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:832
static VALUE trace_ev(struct trace_data *data)
Definition: variable.c:772
st_index_t rb_ivar_count(VALUE obj)
Definition: variable.c:1302
#define RCLASS_SUPER(c)
Definition: classext.h:16
int rb_sourceline(void)
Definition: vm.c:1001
void rb_name_class(VALUE klass, ID id)
Definition: variable.c:385
#define var_getter
Definition: variable.c:443
#define global_entry
Definition: variable.c:412
ID rb_frame_callee(void)
Definition: eval.c:949
VALUE rb_block_proc(void)
Definition: proc.c:620
struct trace_var * trace
Definition: variable.c:432
VALUE(* path_cache_func)(VALUE obj, ID id, VALUE val)
Definition: variable.c:215
size_t st_memsize(const st_table *)
Definition: st.c:342
#define ROBJECT_EMBED_LEN_MAX
Definition: ruby.h:761
#define ANYARGS
Definition: defines.h:98
struct global_entry * rb_global_entry(ID id)
Definition: variable.c:450
void rb_ivar_foreach(VALUE obj, int(*func)(ANYARGS), st_data_t arg)
Definition: variable.c:1274
VALUE rb_iv_set(VALUE obj, const char *name, VALUE val)
Definition: variable.c:2612
VALUE rb_iv_get(VALUE obj, const char *name)
Definition: variable.c:2604
VALUE rb_cvar_get(VALUE klass, ID id)
Definition: variable.c:2384
VALUE rb_gv_set(const char *name, VALUE val)
Definition: variable.c:810
VALUE rb_obj_frozen_p(VALUE)
Definition: object.c:1096
VALUE rb_path_to_class(VALUE pathname)
Definition: variable.c:339
static const rb_data_type_t autoload_data_type
Definition: variable.c:1546
#define RCLASS_IV_INDEX_TBL(c)
Definition: internal.h:296
int rb_st_insert_id_and_value(VALUE obj, st_table *tbl, ID key, VALUE value)
Definition: variable.c:2621
VALUE rb_const_get_from(VALUE klass, ID id)
Definition: variable.c:1874
static void autoload_i_free(void *ptr)
Definition: variable.c:1585
uint8_t key[16]
Definition: random.c:1250
static int rb_special_const_p(VALUE obj)
Definition: ruby.h:1695
#define RTEST(v)
Definition: ruby.h:437
#define T_STRING
Definition: ruby.h:482
static VALUE fc_path(struct fc_result *fc, ID name)
Definition: variable.c:48
struct rb_encoding_entry * list
Definition: encoding.c:47
void rb_alias_variable(ID name1, ID name2)
Definition: variable.c:869
static int fc_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:75
static VALUE null_cache(VALUE obj, ID id, VALUE val)
Definition: variable.c:266
static ID classpath
Definition: variable.c:24
VALUE data
Definition: variable.c:421
VALUE rb_eval_cmd(VALUE, VALUE, int)
Definition: vm_eval.c:1471
void rb_cvar_set(VALUE klass, ID id, VALUE val)
Definition: variable.c:2351
static int rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
Definition: variable.c:2091
static int mark_global_entry(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:546
int rb_is_class_id(ID id)
Definition: ripper.c:17318
#define T_CLASS
Definition: ruby.h:478
VALUE rb_mod_remove_cvar(VALUE mod, VALUE name)
Definition: variable.c:2572
#define rb_safe_level()
Definition: tcltklib.c:95
#define ROBJECT_EMBED
Definition: ruby.h:773
void rb_gc_mark_maybe(VALUE obj)
Definition: gc.c:3540
static VALUE reset_safe(VALUE safe)
Definition: variable.c:1679
const char * name
Definition: nkf.c:208
static size_t autoload_memsize(const void *ptr)
Definition: variable.c:1540
#define FL_SET(x, f)
Definition: ruby.h:1175
#define ID2SYM(x)
Definition: ruby.h:355
static VALUE check_autoload_required(VALUE mod, ID id, const char **loadingpath)
Definition: variable.c:1686
int rb_is_instance_name(VALUE name)
Definition: ripper.c:17448
static void autoload_i_mark(void *ptr)
Definition: variable.c:1576
VALUE rb_str_new_frozen(VALUE)
Definition: string.c:833
st_table * st_copy(st_table *)
Definition: st.c:663
static int gvar_i(st_data_t k, st_data_t v, st_data_t a)
Definition: variable.c:835
static size_t autoload_i_memsize(const void *ptr)
Definition: variable.c:1592
void rb_warning(const char *fmt,...)
Definition: error.c:236
#define QUOTE(str)
Definition: internal.h:717
#define rb_check_frozen(obj)
Definition: intern.h:277
#define CONST_ID(var, str)
Definition: ruby.h:1436
static int tbl_copy_i(st_data_t key, st_data_t value, st_data_t data)
Definition: variable.c:2629
static void obj_ivar_each(VALUE obj, int(*func)(ANYARGS), st_data_t arg)
Definition: variable.c:1257
VALUE rb_class_path_no_cache(VALUE klass)
Definition: variable.c:272
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1165
struct trace_var * next
Definition: variable.c:422
static ID autoload
Definition: variable.c:24
void void xfree(void *)
#define rb_intern(str)
int(* func)(ID key, VALUE val, st_data_t arg)
Definition: variable.c:1239
#define mod(x, y)
Definition: date_strftime.c:28
ID rb_intern2(const char *name, long len)
Definition: ripper.c:17178
#define NULL
Definition: _sdbm.c:102
#define Qundef
Definition: ruby.h:428
#define T_ICLASS
Definition: ruby.h:479
static VALUE original_module(VALUE c)
Definition: variable.c:2312
void * rb_mod_const_of(VALUE mod, void *data)
Definition: variable.c:2017
struct trace_var * trace
Definition: variable.c:767
st_index_t num_entries
Definition: st.h:85
void rb_mark_generic_ivar_tbl(void)
Definition: variable.c:1022
static VALUE rb_local_constants(VALUE mod)
Definition: variable.c:1991
#define ruby_verbose
Definition: ruby.h:1483
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2297
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1034
VALUE rb_const_remove(VALUE mod, ID id)
Definition: variable.c:1942
void rb_warn(const char *fmt,...)
Definition: error.c:223
ID rb_to_id(VALUE)
Definition: string.c:8734
VALUE rb_eArgError
Definition: error.c:549
static void autoload_mark(void *ptr)
Definition: variable.c:1528
static void check_before_mod_set(VALUE klass, ID id, VALUE val, const char *dest)
Definition: variable.c:2157
void rb_free_generic_ivar(VALUE obj)
Definition: variable.c:1030
#define RB_OBJ_WRITE(a, slot, b)
Definition: ruby.h:1221
VALUE rb_sourcefilename(void)
Definition: vm.c:973
char ** argv
Definition: ruby.c:132
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
Definition: variable.c:1049
int rb_const_defined_from(VALUE klass, ID id)
Definition: variable.c:2121
#define undef_marker
Definition: variable.c:437
VALUE rb_obj_class(VALUE)
Definition: object.c:226
static ID tmp_classpath
Definition: variable.c:24