20 #include "ccan/list/list.h" 213 rb_bug(
"class path is not set properly");
246 path =
rb_sprintf(
"#<Module:%p>", (
void*)obj);
283 return cache_path(klass, path);
323 if (!ivtbl)
return Qnil;
401 if (path == pend || path[0] ==
'#') {
406 while (p < pend && *p !=
':') p++;
408 if (p < pend && p[0] ==
':') {
409 if ((
size_t)(pend - p) < 2 || p[1] !=
':')
goto undefined_class;
419 if (c ==
Qundef)
goto undefined_class;
523 var->
data = (
void*)val;
540 var->
data = (
void*)val;
554 if (!var)
return Qnil;
561 *(
VALUE *)data = val;
604 if (name[0] ==
'$')
id =
rb_intern(name);
626 gvar->
data = (
void*)var;
722 while (trace->
next) {
779 if (trace->
data == cmd) {
889 if (!
NIL_P(backref)) {
893 for (i = 1; i <= nmatch; ++i) {
897 buf[1] = (char)(i +
'0');
942 entry1->
var = entry2->
var;
984 if (!iv_index_tbl)
return 0;
989 if (!generic_iv_tbl_compat) {
1018 if (index < ivtbl->
numiv) {
1022 return ret ==
Qundef ? undef : ret;
1039 if (index < ivtbl->
numiv) {
1042 return ret ==
Qundef ? undef : ret;
1062 for (; len < n; len++) {
1071 gen_ivtbl_dup(
const struct gen_ivtbl *orig)
1086 uint32_t newsize = (index+1) + (index+1)/4;
1130 if (!iv_index_tbl)
return Qfalse;
1148 if (!iv_index_tbl)
return 0;
1149 if (!
st_lookup(iv_index_tbl, key, &index))
return 0;
1152 if (index < ivtbl->
numiv) {
1154 *valp = ivtbl->
ivptr[index];
1167 for (i = 0; i < ivtbl->
numiv; i++) {
1191 if (generic_iv_tbl_compat) {
1215 for (i = 0; i < ivtbl->
numiv; i++) {
1238 if (!iv_index_tbl)
break;
1240 if (len <= index)
break;
1249 return (
VALUE)index;
1292 if (!iv_index_tbl)
break;
1294 if (len <= index)
break;
1304 return (
VALUE)index;
1326 if (!iv_index_tbl) {
1330 return iv_index_tbl;
1358 ivup.u.ivtbl->ivptr[ivup.index] =
val;
1377 if (len <= ivup.
index) {
1393 RBASIC(obj)->flags &= ~ROBJECT_EMBED;
1394 ROBJECT(obj)->as.heap.ivptr = newptr;
1398 newptr =
ROBJECT(obj)->as.heap.ivptr;
1400 for (; len < newsize; len++)
1402 ROBJECT(obj)->as.heap.numiv = newsize;
1431 if (!iv_index_tbl)
break;
1464 return (data->
func)((
ID)key, val, data->
arg);
1501 return (arg->
func)((
ID)key, val, arg->
arg);
1513 if (!iv_index_tbl)
return;
1624 for (i = count = 0; i < num; ++i) {
1625 if (ivptr[i] !=
Qundef) {
1690 #define rb_is_constant_id rb_is_const_id 1691 #define rb_is_constant_name rb_is_const_name 1692 #define id_for_var(obj, name, part, type) \ 1693 id_for_var_message(obj, name, type, "`%1$s' is not allowed as "#part" "#type" variable name") 1694 #define id_for_var_message(obj, name, type, message) \ 1695 check_id_type(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message)) 1698 int (*valid_id_p)(
ID),
int (*valid_name_p)(
VALUE),
1699 const char *message,
size_t message_len)
1702 VALUE name = *pname;
1704 if (
id ? !valid_id_p(
id) : !valid_name_p(name)) {
1750 if (!iv_index_tbl)
break;
1872 #define check_autoload_table(av) \ 1873 (struct st_table *)rb_check_typeddata((av), &autoload_data_type) 1897 struct list_node node;
1898 struct list_head head;
1926 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1929 #define check_autoload_data(av) \ 1930 (struct autoload_data_i *)rb_check_typeddata((av), &autoload_data_i_type) 1935 if (!file || !*file) {
2010 const char **p = (
const char **)arg;
2026 const char *loading;
2054 if (loadingpath && loading) {
2055 *loadingpath = loading;
2073 *value = ele->
value;
2127 int need_wakeups = 0;
2140 args.
id = state->
id;
2201 const char *loading = 0, *src;
2207 if (!load)
return Qfalse;
2209 if (src && loading && strcmp(src, loading) == 0)
return Qfalse;
2221 ele->
state = &state;
2255 if (!mod)
return Qnil;
2258 if (!load)
return Qnil;
2280 if (c !=
Qundef)
return c;
2292 while (
RTEST(tmp)) {
2304 if (am == tmp)
break;
2316 if (!recurse)
break;
2535 if (
RTEST(inherit)) {
2562 if (!recurse)
break;
2701 visibility = ce->
flag;
2709 "previous definition of %"PRIsVALUE
" was here", name);
2728 ce->
flag = visibility;
2739 rb_warn(
"rb_define_const: invalid name `%s' for constant", name);
2765 for (i = 0; i <
argc; i++) {
2876 #define CVAR_FOREACH_ANCESTORS(klass, v, r) \ 2877 for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \ 2878 if (cvar_lookup_at(klass, id, (v))) { \ 2883 #define CVAR_LOOKUP(v,r) do {\ 2884 if (cvar_lookup_at(klass, id, (v))) {r;}\ 2885 CVAR_FOREACH_ANCESTORS(klass, v, r);\ 2891 VALUE tmp, front = 0, target = 0;
2894 CVAR_LOOKUP(0, {
if (!front) front = klass; target = klass;});
2896 if (front && target != front) {
2924 VALUE tmp, front = 0, target = 0;
2928 CVAR_LOOKUP(&value, {
if (!front) front = klass; target = klass;});
2933 if (front && target != front) {
2951 if (!klass)
return Qfalse;
3079 if (
RTEST(inherit)) {
st_table * rb_st_copy(VALUE obj, struct st_table *orig_tbl)
void rb_mark_generic_ivar(VALUE obj)
static VALUE classname(VALUE klass, int *permanent)
Returns +classpath+ of klass, if it is named, or +nil+ for anonymous +class+/+module+.
void rb_define_readonly_variable(const char *name, const VALUE *var)
void rb_define_hooked_variable(const char *name, VALUE *var, VALUE(*getter)(ANYARGS), void(*setter)(ANYARGS))
union autoload_state::@185 waitq
void rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
VALUE rb_gvar_defined(struct rb_global_entry *entry)
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
static enum rb_id_table_iterator_result mark_global_entry(VALUE v, void *ignored)
int rb_is_instance_id(ID id)
static VALUE rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
static VALUE cvar_list(void *data)
void rb_vm_inc_const_missing_count(void)
void rb_bug(const char *fmt,...)
rb_const_entry_t * rb_const_lookup(VALUE klass, ID id)
#define RUBY_TYPED_FREE_IMMEDIATELY
size_t strlen(const char *)
VALUE rb_mod_const_missing(VALUE klass, VALUE name)
void * rb_mod_const_at(VALUE mod, void *data)
VALUE rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *var)
#define RCLASS_CONST_TBL(c)
static st_table * iv_index_tbl_make(VALUE obj)
VALUE rb_f_global_variables(void)
ID rb_intern2(const char *, long)
static VALUE generic_ivar_defined(VALUE obj, ID id)
#define RB_OBJ_WRITTEN(a, oldv, b)
static int autoload_defined_p(VALUE mod, ID id)
static st_table * generic_iv_tbl
void rb_define_const(VALUE klass, const char *name, VALUE val)
static int cv_i(st_data_t k, st_data_t v, st_data_t a)
void rb_define_variable(const char *name, VALUE *var)
static enum rb_id_table_iterator_result gvar_i(ID key, VALUE val, void *a)
void rb_thread_sleep_deadly(void)
VALUE rb_fstring_cstr(const char *str)
#define RB_CONST_DEPRECATED_P(ce)
#define rb_name_err_raise_str(mesg, recv, name)
static VALUE rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility)
VALUE rb_ivar_defined(VALUE obj, ID id)
void rb_autoload_str(VALUE mod, ID id, VALUE file)
static int gen_ivar_copy(ID id, VALUE val, st_data_t arg)
static VALUE autoload_require(VALUE arg)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static VALUE rb_tmp_class_path(VALUE klass, int *permanent, path_cache_func cache_path)
void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data)
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
int rb_is_const_id(ID id)
rb_gvar_getter_t * getter
static VALUE find_class_path(VALUE klass, ID preferred)
Traverse constant namespace and find +classpath+ for klass.
static enum rb_id_table_iterator_result sv_i(ID key, VALUE v, void *a)
VALUE(* path_cache_func)(VALUE obj, VALUE name)
void rb_autoload(VALUE mod, ID id, const char *file)
VALUE rb_autoload_p(VALUE mod, ID id)
void rb_define_virtual_variable(const char *name, VALUE(*getter)(ANYARGS), void(*setter)(ANYARGS))
VALUE rb_ary_push(VALUE ary, VALUE item)
static int cvar_lookup_at(VALUE klass, ID id, st_data_t *v)
SSL_METHOD *(* func)(void)
int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp)
VALUE rb_ivar_get(VALUE obj, ID id)
VALUE rb_const_list(void *data)
void rb_define_global_const(const char *name, VALUE val)
const char * rb_class2name(VALUE klass)
const char * rb_sourcefile(void)
#define check_autoload_table(av)
VALUE rb_public_const_get_at(VALUE klass, ID id)
VALUE rb_mod_remove_const(VALUE mod, VALUE name)
static int obj_ivar_i(st_data_t key, st_data_t index, st_data_t arg)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_gc_mark_global_tbl(void)
static VALUE cvar_front_klass(VALUE klass)
#define ROBJECT_IV_INDEX_TBL(o)
VALUE rb_backref_get(void)
VALUE rb_mod_name(VALUE mod)
VALUE rb_cv_get(VALUE klass, const char *name)
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE autoload_const_set(VALUE arg)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
VALUE rb_path2class(const char *path)
rb_gvar_marker_t * marker
void rb_clear_constant_cache(void)
int rb_public_const_defined(VALUE klass, ID id)
static VALUE autoload_sleep_done(VALUE arg)
static VALUE autoload_provided(VALUE arg)
void rb_gc_mark(VALUE ptr)
int rb_feature_provided(const char *, const char **)
static void gen_ivar_each(VALUE obj, int(*func)(ANYARGS), st_data_t arg)
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
VALUE rb_gvar_get(struct rb_global_entry *entry)
#define check_autoload_data(av)
VALUE rb_const_get(VALUE klass, ID id)
int rb_public_const_defined_at(VALUE klass, ID id)
VALUE rb_public_const_get(VALUE klass, ID id)
struct rb_global_entry * rb_global_entry(ID id)
void rb_deprecate_constant(VALUE mod, const char *name)
VALUE rb_f_untrace_var(int argc, const VALUE *argv)
int(* func)(ID key, VALUE val, st_data_t arg)
int rb_match_count(VALUE match)
#define rb_name_err_raise(mesg, recv, name)
static void rb_trace_eval(VALUE cmd, VALUE val)
void rb_name_error_str(VALUE str, const char *fmt,...)
static int gen_ivar_each_i(st_data_t key, st_data_t index, st_data_t data)
RUBY_FUNC_EXPORTED size_t rb_generic_ivar_memsize(VALUE obj)
static VALUE autoload_reset(VALUE arg)
#define id_for_var(obj, name, part, type)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
void rb_name_error(ID id, const char *fmt,...)
void(* func)(VALUE arg, VALUE val)
VALUE rb_autoload_load(VALUE mod, ID id)
#define CVAR_LOOKUP(v, r)
static st_table * generic_iv_tbl_compat
static ID cv_intern(VALUE klass, const char *name)
static int list_i(st_data_t key, st_data_t value, VALUE ary)
static enum rb_id_table_iterator_result fc_i(ID key, VALUE v, void *a)
static VALUE ivar_cache(VALUE obj, VALUE name)
#define RB_TYPE_P(obj, type)
VALUE rb_gvar_val_getter(ID id, void *data, struct rb_global_variable *var)
VALUE rb_cvar_defined(VALUE klass, ID id)
void rb_const_set(VALUE klass, ID id, VALUE val)
#define id_for_var_message(obj, name, type, message)
static void autoload_free(void *ptr)
VALUE rb_search_class_path(VALUE klass)
static void autoload_delete(VALUE mod, ID id)
static int cv_list_i(st_data_t key, st_data_t value, VALUE ary)
VALUE rb_attr_delete(VALUE obj, ID id)
VALUE rb_class_path(VALUE klass)
VALUE rb_gvar_set(struct rb_global_entry *entry, VALUE val)
RUBY_EXTERN VALUE rb_cObject
int rb_is_class_id(ID id)
size_t st_memsize(const st_table *tab)
VALUE rb_str_cat2(VALUE, const char *)
union ivar_update::@184 u
static void uninitialized_constant(VALUE klass, VALUE name)
VALUE rb_thread_current(void)
int rb_id_table_delete(struct rb_id_table *tbl, ID id)
struct rb_id_table * rb_id_table_create(size_t size)
int rb_match_nth_defined(int nth, VALUE match)
const char * rb_obj_classname(VALUE obj)
static void setup_const_entry(rb_const_entry_t *, VALUE, VALUE, rb_const_flag_t)
int rb_class_ivar_set(VALUE obj, ID key, VALUE value)
#define ALLOCA_N(type, n)
RUBY_EXTERN VALUE rb_cModule
VALUE rb_gv_get(const char *name)
void rb_cv_set(VALUE klass, const char *name, VALUE val)
#define RUBY_FUNC_EXPORTED
#define MEMCPY(p1, p2, type, n)
int rb_const_defined(VALUE klass, ID id)
static int gen_ivar_compat_tbl_i(st_data_t id, st_data_t index, st_data_t arg)
void rb_set_class_path(VALUE klass, VALUE under, const char *name)
static void iv_index_tbl_extend(struct ivar_update *ivup, ID id)
static ID global_id(const char *name)
VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
VALUE rb_thread_wakeup_alive(VALUE)
int rb_public_const_defined_from(VALUE klass, ID id)
static int gen_ivtbl_get(VALUE obj, struct gen_ivtbl **ivtbl)
VALUE rb_gvar_getter_t(ID id, void *data, struct rb_global_variable *gvar)
VALUE rb_class_name(VALUE klass)
VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE mod)
void st_foreach_safe(st_table *table, int(*func)(ANYARGS), st_data_t a)
VALUE rb_str_subseq(VALUE, long, long)
static VALUE generic_ivar_get(VALUE obj, ID id, VALUE undef)
size_t rb_id_table_size(const struct rb_id_table *tbl)
static void remove_trace(struct rb_global_variable *var)
static void * mod_cvar_at(VALUE mod, void *data)
#define REALLOC_N(var, type, n)
VALUE rb_gvar_var_getter(ID id, void *data, struct rb_global_variable *gvar)
void rb_gvar_var_setter(VALUE val, ID id, void *data, struct rb_global_variable *g)
int rb_const_defined_at(VALUE klass, ID id)
static int generic_ivar_update(st_data_t *k, st_data_t *v, st_data_t u, int existing)
VALUE rb_sprintf(const char *format,...)
static void * mod_cvar_of(VALUE mod, void *data)
void rb_gvar_readonly_setter(VALUE v, ID id, void *d, struct rb_global_variable *g)
void rb_gvar_val_marker(VALUE *var)
VALUE rb_attr_get(VALUE obj, ID id)
static VALUE trace_en(struct rb_global_variable *var)
VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name)
st_table * rb_generic_ivar_table(VALUE obj)
void rb_gvar_val_setter(VALUE val, ID id, void *data, struct rb_global_variable *var)
void Init_var_tables(void)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_mod_deprecate_constant(int argc, const VALUE *argv, VALUE obj)
unsigned char buf[MIME_BUF_SIZE]
void rb_vm_pop_cfunc_frame(void)
VALUE rb_const_get_at(VALUE klass, ID id)
static int ivar_i(st_data_t k, st_data_t v, st_data_t a)
int rb_autoloading_value(VALUE mod, ID id, VALUE *value)
VALUE rb_vm_top_self(void)
static VALUE make_temporary_path(VALUE obj, VALUE klass)
#define RB_CONST_PRIVATE_P(ce)
VALUE rb_public_const_get_from(VALUE klass, ID id)
void rb_mark_tbl(st_table *tbl)
static size_t gen_ivtbl_bytes(size_t n)
struct autoload_data_i * ele
#define rb_enc_asciicompat(enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
VALUE rb_str_new_cstr(const char *)
void rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
static const rb_data_type_t autoload_data_i_type
static void generic_ivar_set(VALUE obj, ID id, VALUE val)
void rb_define_class_variable(VALUE klass, const char *name, VALUE val)
VALUE rb_fstring_new(const char *ptr, long len)
struct rb_global_variable * var
VALUE rb_class_real(VALUE cl)
static void check_before_mod_set(VALUE, ID, VALUE, const char *)
int rb_thread_to_be_killed(VALUE thread)
register unsigned int len
static VALUE generic_ivar_delete(VALUE obj, ID id, VALUE undef)
void rb_set_safe_level_force(int)
VALUE rb_obj_instance_variables(VALUE obj)
static VALUE autoload_data(VALUE mod, ID id)
VALUE rb_class_path_cached(VALUE klass)
rb_encoding * rb_enc_get(VALUE obj)
static VALUE trace_ev(struct trace_data *data)
st_index_t rb_ivar_count(VALUE obj)
void rb_name_class(VALUE klass, ID id)
VALUE rb_block_proc(void)
static VALUE autoload_sleep(VALUE arg)
static ID check_id_type(VALUE obj, VALUE *pname, int(*valid_id_p)(ID), int(*valid_name_p)(VALUE), const char *message, size_t message_len)
void rb_ivar_foreach(VALUE obj, int(*func)(ANYARGS), st_data_t arg)
static size_t gen_ivtbl_count(const struct gen_ivtbl *ivtbl)
VALUE rb_iv_set(VALUE obj, const char *name, VALUE val)
VALUE rb_iv_get(VALUE obj, const char *name)
VALUE rb_cvar_get(VALUE klass, ID id)
VALUE rb_gv_set(const char *name, VALUE val)
VALUE rb_path_to_class(VALUE pathname)
#define RB_CONST_PUBLIC_P(ce)
static const rb_data_type_t autoload_data_type
#define RCLASS_IV_INDEX_TBL(c)
VALUE rb_const_get_from(VALUE klass, ID id)
void rb_gvar_var_marker(VALUE *var)
void rb_gvar_marker_t(VALUE *var)
static VALUE fc_path(struct fc_result *fc, ID name)
static uint32_t iv_index_tbl_newsize(struct ivar_update *ivup)
struct rb_encoding_entry * list
void rb_alias_variable(ID name1, ID name2)
#define TypedData_Make_Struct(klass, type, data_type, sval)
rb_gvar_setter_t * setter
VALUE rb_const_missing(VALUE klass, VALUE name)
VALUE rb_eval_cmd(VALUE, VALUE, int)
void rb_cvar_set(VALUE klass, ID id, VALUE val)
struct autoload_state * state
static int cv_i_update(st_data_t *k, st_data_t *v, st_data_t a, int existing)
static int rb_const_defined_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
VALUE rb_mod_remove_cvar(VALUE mod, VALUE name)
static enum rb_id_table_iterator_result rb_local_constants_i(ID const_name, VALUE const_value, void *ary)
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE mod)
void rb_gc_mark_maybe(VALUE obj)
void rb_frozen_class_p(VALUE klass)
static VALUE reset_safe(VALUE safe)
static size_t autoload_memsize(const void *ptr)
static VALUE check_autoload_required(VALUE mod, ID id, const char **loadingpath)
static VALUE rb_ivar_delete(VALUE obj, ID id, VALUE undef)
static void set_const_visibility(VALUE mod, int argc, const VALUE *argv, rb_const_flag_t flag, rb_const_flag_t mask)
static void autoload_i_mark(void *ptr)
VALUE rb_str_new_frozen(VALUE)
static int generic_ivar_remove(VALUE obj, ID id, VALUE *valp)
VALUE rb_source_location(int *pline)
struct rb_id_table * rb_global_tbl
static size_t autoload_i_memsize(const void *ptr)
void rb_warning(const char *fmt,...)
void st_clear(st_table *)
#define rb_check_frozen(obj)
static void gen_ivtbl_mark(const struct gen_ivtbl *ivtbl)
VALUE rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj)
rb_id_table_iterator_result
#define RUBY_TYPED_DEFAULT_FREE
static int tbl_copy_i(st_data_t key, st_data_t value, st_data_t data)
VALUE rb_str_intern(VALUE)
#define rb_intern_const(str)
static void obj_ivar_each(VALUE obj, int(*func)(ANYARGS), st_data_t arg)
static VALUE never_cache(VALUE obj, VALUE name)
VALUE rb_class_path_no_cache(VALUE klass)
#define SPECIAL_CONST_P(x)
int(* func)(ID key, VALUE val, st_data_t arg)
VALUE rb_mod_public_constant(int argc, const VALUE *argv, VALUE obj)
void rb_gvar_setter_t(VALUE val, ID id, void *data, struct rb_global_variable *gvar)
static VALUE original_module(VALUE c)
void * rb_mod_const_of(VALUE mod, void *data)
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
VALUE rb_f_trace_var(int argc, const VALUE *argv)
static VALUE rb_local_constants(VALUE mod)
VALUE rb_str_append(VALUE, VALUE)
static void const_tbl_update(struct autoload_const_set_args *)
VALUE rb_const_remove(VALUE mod, ID id)
static VALUE null_cache(VALUE obj, VALUE name)
void rb_warn(const char *fmt,...)
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
static struct gen_ivtbl * gen_ivtbl_resize(struct gen_ivtbl *old, uint32_t n)
static void autoload_mark(void *ptr)
int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val)
void rb_free_generic_ivar(VALUE obj)
#define RB_OBJ_WRITE(a, slot, b)
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
void rb_gvar_undef_marker(VALUE *var)
int rb_const_defined_from(VALUE klass, ID id)
void rb_gvar_undef_setter(VALUE val, ID id, void *d, struct rb_global_variable *var)
NORETURN(static void uninitialized_constant(VALUE, VALUE))
VALUE rb_obj_class(VALUE)