Ruby: include/ruby/internal/intern/variable.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Functions
variable.h File Reference

Public APIs related to names inside of a Ruby program. More...

`#include "ruby/internal/attr/noreturn.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/st.h"`

Go to the source code of this file.

## Functions
VALUE | rb_mod_name (VALUE)
VALUE | rb_class_path (VALUE)
VALUE | rb_class_path_cached (VALUE)
void | rb_set_class_path (VALUE, VALUE, const char *)
void | rb_set_class_path_string (VALUE, VALUE, VALUE)
VALUE | rb_path_to_class (VALUE)
VALUE | rb_path2class (const char *)
VALUE | rb_class_name (VALUE)
VALUE | rb_autoload_load (VALUE, ID)
VALUE | rb_autoload_p (VALUE, ID)
VALUE | rb_f_trace_var (int, const VALUE *)
VALUE | rb_f_untrace_var (int, const VALUE *)
VALUE | rb_f_global_variables (void)
void | rb_alias_variable (ID, ID)
void | rb_copy_generic_ivar (VALUE, VALUE)
void | rb_free_generic_ivar (VALUE)
VALUE | rb_ivar_get (VALUE, ID)
VALUE | rb_ivar_set (VALUE, ID, VALUE)
VALUE | rb_ivar_defined (VALUE, ID)
void | rb_ivar_foreach (VALUE, int(*)(ID, VALUE, st_data_t), st_data_t)
st_index_t | rb_ivar_count (VALUE)
VALUE | rb_attr_get (VALUE, ID)
VALUE | rb_obj_instance_variables (VALUE)
VALUE | rb_obj_remove_instance_variable (VALUE, VALUE)
void * | rb_mod_const_at (VALUE, void *)
void * | rb_mod_const_of (VALUE, void *)
VALUE | rb_const_list (void *)
VALUE | rb_mod_constants (int, const VALUE *, VALUE)
VALUE | rb_mod_remove_const (VALUE, VALUE)
int | rb_const_defined (VALUE, ID)
int | rb_const_defined_at (VALUE, ID)
int | rb_const_defined_from (VALUE, ID)
VALUE | rb_const_get (VALUE, ID)
VALUE | rb_const_get_at (VALUE, ID)
VALUE | rb_const_get_from (VALUE, ID)
void | rb_const_set (VALUE, ID, VALUE)
VALUE | rb_const_remove (VALUE, ID)
VALUE | rb_cvar_defined (VALUE, ID)
void | rb_cvar_set (VALUE, ID, VALUE)
VALUE | rb_cvar_get (VALUE, ID)
void | rb_cv_set (VALUE, const char *, VALUE)
VALUE | rb_cv_get (VALUE, const char *)
void | rb_define_class_variable (VALUE, const char *, VALUE)
VALUE | rb_mod_class_variables (int, const VALUE *, VALUE)
VALUE | rb_mod_remove_cvar (VALUE, VALUE)

## Detailed Description

Public APIs related to names inside of a Ruby program.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file variable.h.

## Function Documentation

## ◆ rb_alias_variable()

void rb_alias_variable | ( | ID | name1,
|  | ID | name2
| ) |  |

Definition at line 843 of file variable.c.

References ALLOC, rb_global_variable::block_trace, rb_global_variable::counter, rb_global_entry::id, trace_var::next, rb_eRactorIsolationError, rb_eRuntimeError, rb_id_table_insert(), rb_id_table_lookup(), rb_raise(), rb_global_variable::trace, rb_global_entry::var, and xfree.

Referenced by Init_load().

## ◆ rb_attr_get()

VALUE rb_attr_get | ( | VALUE | obj,
|  | ID | id
| ) |  |

Definition at line 1242 of file variable.c.

References Qnil, and rb_ivar_lookup().

Referenced by ossl_asn1_get_asn1type(), rb_dtrace_setup(), rb_error_frozen_object(), rb_refinement_module_get_refined_class(), rb_singleton_class_clone_and_attach(), rb_singleton_class_get(), rb_singleton_class_internal_p(), and rb_syntax_error_append().

## ◆ rb_autoload_load()

VALUE rb_autoload_load | ( | VALUE | mod,
|  | ID | id
| ) |  |

Definition at line 2452 of file variable.c.

References autoload_state::ac, CONST_DEPRECATED, CONST_VISIBILITY_MASK, rb_const_entry_struct::flag, autoload_data_i::fork_gen, load(), mod, Qfalse, rb_const_lookup(), rb_ensure(), RB_GC_GUARD, rb_sourcefile(), rb_thread_current(), autoload_state::result, autoload_data_i::state, autoload_state::thread, and autoload_state::waitq.

## ◆ rb_autoload_p()

VALUE rb_autoload_p | ( | VALUE | mod,
|  | ID | id
| ) |  |

Definition at line 2511 of file variable.c.

References mod, rb_autoload_at_p(), and TRUE.

## ◆ rb_class_name()

VALUE rb_class_name | ( | VALUE | klass | ) |

Definition at line 293 of file variable.c.

References rb_class_path(), and rb_class_real().

Referenced by rb_any_to_s(), and rb_const_warn_if_deprecated().

## ◆ rb_class_path()

VALUE rb_class_path | ( | VALUE | klass | ) |

Definition at line 169 of file variable.c.

References NIL_P, and rb_str_dup().

Referenced by rb_class_name(), rb_define_class_id_under(), rb_dtrace_setup(), rb_dump_literal(), and rb_profile_frame_classpath().

## ◆ rb_class_path_cached()

VALUE rb_class_path_cached | ( | VALUE | klass | ) |

Definition at line 178 of file variable.c.

Referenced by rb_raw_obj_info().

## ◆ rb_const_defined()

int rb_const_defined | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2928 of file variable.c.

References FALSE, and TRUE.

Referenced by Init_cparse(), Init_fiddle(), Init_strscan(), rb_define_class(), and rb_define_module().

## ◆ rb_const_defined_at()

int rb_const_defined_at | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2934 of file variable.c.

References FALSE, and TRUE.

Referenced by rb_const_remove(), rb_define_class_id_under(), and rb_define_module_id_under().

## ◆ rb_const_defined_from()

int rb_const_defined_from | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2922 of file variable.c.

References FALSE, and TRUE.

## ◆ rb_const_get()

VALUE rb_const_get | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2624 of file variable.c.

References FALSE, and TRUE.

Referenced by Init_cparse(), Init_objspace(), Init_parser(), rb_define_class(), rb_define_module(), and rb_fiddle_generic_to_value().

## ◆ rb_const_get_at()

VALUE rb_const_get_at | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2630 of file variable.c.

References FALSE, and TRUE.

Referenced by Init_cparse(), rb_define_class_id_under(), and rb_define_module_id_under().

## ◆ rb_const_get_from()

VALUE rb_const_get_from | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 2618 of file variable.c.

References FALSE, and TRUE.

## ◆ rb_const_list()

VALUE rb_const_list | ( | void * | data | ) |

Definition at line 2840 of file variable.c.

References st_table::num_entries, rb_ary_new2, st_foreach_safe, and st_free_table.

Referenced by rb_mod_constants().

## ◆ rb_const_remove()

VALUE rb_const_remove | ( | VALUE | mod,
|  | ID | id
| ) |  |

Definition at line 2727 of file variable.c.

References ID2SYM, mod, Qnil, Qundef, rb_check_frozen, rb_clear_constant_cache(), rb_const_defined_at(), rb_const_lookup(), rb_id_table_delete(), RCLASS_CONST_TBL, rb_const_entry_struct::value, and xfree.

Referenced by Init_fiddle(), and rb_mod_remove_const().

## ◆ rb_const_set()

void rb_const_set | ( | VALUE | klass,
|  | ID | id,
|  | VALUE | val
| ) |  |

Definition at line 3003 of file variable.c.

References CONST_PUBLIC, id, autoload_const::mod, NIL_P, PRIsVALUE, rb_clear_constant_cache(), rb_cObject, rb_eRactorIsolationError, rb_eTypeError, rb_id2str, rb_id_table_create(), rb_id_table_insert(), rb_ivar_set(), rb_raise(), RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, RCLASS_CONST_TBL, and ZALLOC.

Referenced by Init_class_hierarchy(), Init_strscan(), InitVM_Random(), rb_autoload_str(), rb_define_class(), rb_define_class_id_under(), rb_define_const(), rb_define_module(), rb_define_module_id_under(), and ruby_init_loadpath().

## ◆ rb_copy_generic_ivar()

void rb_copy_generic_ivar | ( | VALUE | clone,
|  | VALUE | obj
| ) |  |

Definition at line 1638 of file variable.c.

References FL_EXIVAR, FL_SET, FL_TEST, FL_UNSET, givar_copy::iv_index_tbl, gen_ivtbl::ivptr, givar_copy::ivtbl, givar_copy::klass, gen_ivtbl::numiv, givar_copy::obj, Qundef, rb_check_frozen, rb_free_generic_ivar(), rb_obj_class(), RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, and st_insert.

Referenced by rb_hash_dup().

## ◆ rb_cv_get()

VALUE rb_cv_get | ( | VALUE | klass,
|  | const char * | name
| ) |  |

Definition at line 3413 of file variable.c.

References name, and rb_cvar_get().

## ◆ rb_cv_set()

void rb_cv_set | ( | VALUE | klass,
|  | const char * | name,
|  | VALUE | val
| ) |  |

Definition at line 3406 of file variable.c.

References name, and rb_cvar_set().

## ◆ rb_cvar_defined()

VALUE rb_cvar_defined | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 3387 of file variable.c.

References CVAR_LOOKUP, Qfalse, and Qtrue.

Referenced by rb_mod_remove_cvar().

## ◆ rb_cvar_get()

VALUE rb_cvar_get | ( | VALUE | klass,
|  | ID | id
| ) |  |

Definition at line 3371 of file variable.c.

References CVAR_LOOKUP, and ID2SYM.

Referenced by rb_cv_get().

## ◆ rb_cvar_set()

void rb_cvar_set | ( | VALUE | klass,
|  | ID | id,
|  | VALUE | val
| ) |  |

Definition at line 3346 of file variable.c.

References CVAR_LOOKUP, rb_class_ivar_set(), RBASIC, RCLASS_IV_TBL, st_init_numtable, and T_ICLASS.

Referenced by rb_cv_set(), and rb_define_class_variable().

## ◆ rb_define_class_variable()

void rb_define_class_variable | ( | VALUE | klass,
|  | const char * | name,
|  | VALUE | val
| ) |  |

Definition at line 3420 of file variable.c.

References name, and rb_cvar_set().

## ◆ rb_f_global_variables()

VALUE rb_f_global_variables | ( | void |  | ) |

Definition at line 811 of file variable.c.

References ID2SYM, NIL_P, rb_ary_new(), rb_ary_push(), rb_backref_get(), rb_eRactorIsolationError, rb_id_table_foreach(), rb_intern2(), rb_match_count(), rb_match_nth_defined(), rb_raise(), rb_sprintf(), rb_str_intern(), and sym.

## ◆ rb_f_trace_var()

VALUE rb_f_trace_var | ( | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 610 of file variable.c.

References ALLOC, argc, argv, trace_var::data, trace_var::func, trace_var::next, NIL_P, Qnil, rb_block_proc(), rb_f_untrace_var(), rb_scan_args(), rb_to_id(), trace_var::removed, rb_global_variable::trace, and rb_global_entry::var.

## ◆ rb_f_untrace_var()

VALUE rb_f_untrace_var | ( | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 656 of file variable.c.

References argc, argv, rb_global_variable::block_trace, trace_var::data, id, trace_var::next, NIL_P, NULL, PRIsVALUE, Qnil, rb_ary_new(), rb_ary_new3, rb_ary_push(), rb_check_id(), rb_name_error(), rb_name_error_str(), rb_scan_args(), trace_var::removed, rb_global_variable::trace, and rb_global_entry::var.

Referenced by rb_f_trace_var().

## ◆ rb_free_generic_ivar()

void rb_free_generic_ivar | ( | VALUE | obj | ) |

Definition at line 1157 of file variable.c.

References key, st_delete, and xfree.

Referenced by rb_copy_generic_ivar().

## ◆ rb_ivar_count()

st_index_t rb_ivar_count | ( | VALUE | obj | ) |

Definition at line 1733 of file variable.c.

References BUILTIN_TYPE, count, FL_EXIVAR, FL_TEST, gen_ivtbl::ivptr, num, st_table::num_entries, Qundef, RCLASS_IV_TBL, ROBJECT_IV_INDEX_TBL, SPECIAL_CONST_P, T_CLASS, T_MODULE, and T_OBJECT.

## ◆ rb_ivar_defined()

VALUE rb_ivar_defined | ( | VALUE | obj,
|  | ID | id
| ) |  |

Definition at line 1510 of file variable.c.

References BUILTIN_TYPE, FL_EXIVAR, FL_TEST, Qfalse, Qtrue, Qundef, RCLASS_IV_TBL, ROBJECT_IV_INDEX_TBL, SPECIAL_CONST_P, st_is_member, T_CLASS, T_MODULE, and T_OBJECT.

## ◆ rb_ivar_foreach()

void rb_ivar_foreach | ( | VALUE | ,
|  | int(*)(ID, VALUE, st_data_t) | ,
|  | st_data_t |
| ) |  |

## ◆ rb_ivar_get()

VALUE rb_ivar_get | ( | VALUE | obj,
|  | ID | id
| ) |  |

Definition at line 1234 of file variable.c.

References Qnil, RB_DEBUG_COUNTER_INC, and rb_ivar_lookup().

Referenced by EVENTSINK_Invoke(), rb_class_modify_check(), rb_iv_get(), rb_method_name_error(), and rb_profile_frame_classpath().

## ◆ rb_ivar_set()

VALUE rb_ivar_set | ( | VALUE | obj,
|  | ID | id,
|  | VALUE | val
| ) |  |

Definition at line 1493 of file variable.c.

References rb_check_frozen.

Referenced by create_win32ole_param(), create_win32ole_variable(), olerecord_set_ivar(), rb_arith_seq_new(), rb_const_set(), rb_ec_setup_exception(), rb_error_frozen_object(), rb_frozen_error_raise(), rb_iv_set(), rb_key_err_new(), rb_memory_view_register(), rb_set_class_path_string(), and ruby_init_loadpath().

## ◆ rb_mod_class_variables()

VALUE rb_mod_class_variables | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | mod
| ) |  |

Definition at line 3512 of file variable.c.

References argc, argv, mod, rb_check_arity, and RTEST.

## ◆ rb_mod_const_at()

void * rb_mod_const_at | ( | VALUE | mod,
|  | void * | data
| ) |  |

Definition at line 2801 of file variable.c.

References mod, rb_id_table_foreach(), RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, RCLASS_CONST_TBL, and st_init_numtable.

Referenced by rb_mod_const_of().

## ◆ rb_mod_const_of()

void * rb_mod_const_of | ( | VALUE | mod,
|  | void * | data
| ) |  |

Definition at line 2818 of file variable.c.

References mod, rb_cObject, rb_mod_const_at(), and RCLASS_SUPER.

Referenced by rb_mod_constants().

## ◆ rb_mod_constants()

VALUE rb_mod_constants | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | mod
| ) |  |

Definition at line 2872 of file variable.c.

References argc, argv, mod, rb_check_arity, rb_const_list(), rb_mod_const_of(), and RTEST.

## ◆ rb_mod_name()

VALUE rb_mod_name | ( | VALUE | mod | ) |

Definition at line 118 of file variable.c.

References mod.

## ◆ rb_mod_remove_const()

VALUE rb_mod_remove_const | ( | VALUE | mod,
|  | VALUE | name
| ) |  |

Definition at line 2716 of file variable.c.

References id_for_var, mod, name, and rb_const_remove().

## ◆ rb_mod_remove_cvar()

VALUE rb_mod_remove_cvar | ( | VALUE | mod,
|  | VALUE | name
| ) |  |

Definition at line 3547 of file variable.c.

References id, ID2SYM, id_for_var_message, mod, name, Qundef, rb_check_frozen, rb_cvar_defined(), RCLASS_IV_TBL, st_delete, and UNREACHABLE_RETURN.

## ◆ rb_obj_instance_variables()

VALUE rb_obj_instance_variables | ( | VALUE | obj | ) |

Definition at line 1801 of file variable.c.

References rb_ary_new(), and rb_ivar_foreach().

## ◆ rb_obj_remove_instance_variable()

VALUE rb_obj_remove_instance_variable | ( | VALUE | obj,
|  | VALUE | name
| ) |  |

Definition at line 1856 of file variable.c.

References BUILTIN_TYPE, FL_EXIVAR, FL_TEST, id, id_for_var, name, Qnil, Qundef, rb_check_frozen, RCLASS_IV_TBL, ROBJECT_IV_INDEX_TBL, st_delete, T_CLASS, T_MODULE, T_OBJECT, and UNREACHABLE_RETURN.

## ◆ rb_path2class()

VALUE rb_path2class | ( | const char * | path | ) |

Definition at line 287 of file variable.c.

References rb_path_to_class(), and rb_str_new_cstr.

Referenced by Init_bubblebabble(), Init_generator(), Init_md5(), Init_ossl_digest(), Init_parser(), Init_rmd160(), Init_sha1(), and Init_sha2().

## ◆ rb_path_to_class()

VALUE rb_path_to_class | ( | VALUE | pathname | ) |

Definition at line 242 of file variable.c.

References FALSE, id, PRIsVALUE, Qundef, rb_check_id_cstr(), rb_cObject, rb_eArgError, rb_enc_asciicompat, rb_enc_get(), rb_eTypeError, RB_GC_GUARD, rb_raise(), rb_str_subseq(), RSTRING_LEN, RSTRING_PTR, TRUE, and UNREACHABLE_RETURN.

Referenced by rb_path2class().

## ◆ rb_set_class_path()

void rb_set_class_path | ( | VALUE | klass,
|  | VALUE | under,
|  | const char * | name
| ) |  |

Definition at line 234 of file variable.c.

References name, OBJ_FREEZE, rb_set_class_path_string(), rb_str_new2, and str.

Referenced by Init_IO(), and Init_VM().

## ◆ rb_set_class_path_string()

void rb_set_class_path_string | ( | VALUE | klass,
|  | VALUE | under,
|  | VALUE | name
| ) |  |

Definition at line 214 of file variable.c.

References name, rb_cObject, rb_ivar_set(), rb_str_new_frozen(), and str.

Referenced by Init_class_hierarchy(), rb_define_class_id_under(), rb_define_module_id_under(), and rb_set_class_path().