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

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

variable.h
Go to the documentation of this file.
1#ifndef RBIMPL_INTERN_VARIABLE_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_INTERN_VARIABLE_H
23#include "ruby/internal/attr/nonnull.h"
24#include "ruby/internal/attr/noreturn.h"
25#include "ruby/internal/dllexport.h"
26#include "ruby/internal/value.h"
27#include "ruby/st.h"
28
29 RBIMPL_SYMBOL_EXPORT_BEGIN()
30
31/* variable.c */
32
33
40 VALUE rb_mod_name(VALUE mod);
41
49 VALUE rb_class_path(VALUE mod);
50
58 VALUE rb_class_path_cached(VALUE mod);
59
60 RBIMPL_ATTR_NONNULL(())
69void rb_set_class_path(VALUE klass, VALUE space, const char *name);
70
80void rb_set_class_path_string(VALUE klass, VALUE space, VALUE name);
81
91 VALUE rb_path_to_class(VALUE path);
92
93 RBIMPL_ATTR_NONNULL(())
102 VALUE rb_path2class(const char *path);
103
110 VALUE rb_class_name(VALUE obj);
111
130 VALUE rb_autoload_load(VALUE space, ID name);
131
140 VALUE rb_autoload_p(VALUE space, ID name);
141
154 VALUE rb_f_trace_var(int argc, const VALUE *argv);
155
169 VALUE rb_f_untrace_var(int argc, const VALUE *argv);
170
180 VALUE rb_f_global_variables(void);
181
201void rb_alias_variable(ID dst, ID src);
202
217void rb_free_generic_ivar(VALUE obj);
218
228 VALUE rb_ivar_get(VALUE obj, ID name);
229
243 VALUE rb_ivar_set(VALUE obj, ID name, VALUE val);
244
254 VALUE rb_ivar_defined(VALUE obj, ID name);
255
263 void rb_ivar_foreach(VALUE obj, int (*func)(ID name, VALUE val, st_data_t arg), st_data_t arg);
264
271st_index_t rb_ivar_count(VALUE obj);
272
285 VALUE rb_attr_get(VALUE obj, ID name);
286
295 VALUE rb_obj_instance_variables(VALUE obj);
296
305 VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name);
306
316void *rb_mod_const_at(VALUE, void*);
317
323void *rb_mod_const_of(VALUE, void*);
324
331 VALUE rb_const_list(void*);
332
346 VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv);
347
360 VALUE rb_mod_remove_const(VALUE space, VALUE name);
361
375int rb_const_defined(VALUE space, ID name);
376
393int rb_const_defined_at(VALUE space, ID name);
394
411int rb_const_defined_from(VALUE space, ID name);
412
425 VALUE rb_const_get(VALUE space, ID name);
426
441 VALUE rb_const_get_at(VALUE space, ID name);
442
457 VALUE rb_const_get_from(VALUE space, ID name);
458
473void rb_const_set(VALUE space, ID name, VALUE val);
474
488 VALUE rb_const_remove(VALUE space, ID name);
489
490#if 0 /* EXPERIMENTAL: remove if no problem */
491 RBIMPL_ATTR_NORETURN()
499 VALUE rb_mod_const_missing(VALUE space, VALUE name);
500#endif
501
515 VALUE rb_cvar_defined(VALUE klass, ID name);
516
529void rb_cvar_set(VALUE klass, ID name, VALUE val);
530
544 VALUE rb_cvar_get(VALUE klass, ID name);
545
546 RBIMPL_ATTR_NONNULL(())
565 VALUE rb_cvar_find(VALUE klass, ID name, VALUE *front);
566
567 RBIMPL_ATTR_NONNULL(())
576void rb_cv_set(VALUE klass, const char *name, VALUE val);
577
578 RBIMPL_ATTR_NONNULL(())
588 VALUE rb_cv_get(VALUE klass, const char *name);
589
590 RBIMPL_ATTR_NONNULL(())
598void rb_define_class_variable(VALUE, const char*, VALUE);
599
614 VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE recv);
615
624 VALUE rb_mod_remove_cvar(VALUE mod, VALUE name);
625
626 RBIMPL_SYMBOL_EXPORT_END()
627
628#endif /* RBIMPL_INTERN_VARIABLE_H */
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
rb_mod_remove_cvar
VALUE rb_mod_remove_cvar(VALUE mod, VALUE name)
Resembles Module#remove_class_variable.
Definition variable.c:4548
rb_obj_instance_variables
VALUE rb_obj_instance_variables(VALUE obj)
Resembles Object#instance_variables.
Definition variable.c:2478
rb_f_untrace_var
VALUE rb_f_untrace_var(int argc, const VALUE *argv)
Deletes the passed tracer from the passed global variable, or if omitted, deletes everything.
Definition variable.c:924
rb_const_get
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
Definition variable.c:3505
rb_const_list
VALUE rb_const_list(void *)
This is another mysterious API that comes with no documents at all.
Definition variable.c:3749
rb_path2class
VALUE rb_path2class(const char *path)
Resolves a Q::W::E::R-style path string to the actual class it points.
Definition variable.c:494
rb_autoload_p
VALUE rb_autoload_p(VALUE space, ID name)
Queries if an autoload is defined at a point.
Definition variable.c:3373
rb_set_class_path
void rb_set_class_path(VALUE klass, VALUE space, const char *name)
Names a class.
Definition variable.c:441
rb_ivar_set
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
Definition variable.c:2030
rb_mod_remove_const
VALUE rb_mod_remove_const(VALUE space, VALUE name)
Resembles Module#remove_const.
Definition variable.c:3610
rb_class_path_cached
VALUE rb_class_path_cached(VALUE mod)
Just another name of rb_mod_name.
Definition variable.c:389
rb_f_trace_var
VALUE rb_f_trace_var(int argc, const VALUE *argv)
Traces a global variable.
Definition variable.c:878
rb_cvar_set
void rb_cvar_set(VALUE klass, ID name, VALUE val)
Assigns a value to a class variable.
Definition variable.c:4305
rb_cvar_get
VALUE rb_cvar_get(VALUE klass, ID name)
Obtains a value from a class variable.
Definition variable.c:4383
rb_mod_constants
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv)
Resembles Module#constants.
Definition variable.c:3781
rb_cvar_find
VALUE rb_cvar_find(VALUE klass, ID name, VALUE *front)
Identical to rb_cvar_get(), except it takes additional "front" pointer.
Definition variable.c:4368
rb_path_to_class
VALUE rb_path_to_class(VALUE path)
Identical to rb_path2class(), except it accepts the path as Ruby's string instead of C's.
Definition variable.c:449
rb_ivar_get
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
Definition variable.c:1505
rb_ivar_foreach
void rb_ivar_foreach(VALUE obj, int(*func)(ID name, VALUE val, st_data_t arg), st_data_t arg)
Iterates over an object's instance variables.
rb_const_set
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
Definition variable.c:3983
rb_autoload_load
VALUE rb_autoload_load(VALUE space, ID name)
Kicks the autoload procedure as if it was "touched".
Definition variable.c:3335
rb_mod_name
VALUE rb_mod_name(VALUE mod)
Queries the name of a module.
Definition variable.c:136
rb_class_name
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
Definition variable.c:500
rb_const_get_at
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
Definition variable.c:3511
rb_set_class_path_string
void rb_set_class_path_string(VALUE klass, VALUE space, VALUE name)
Identical to rb_set_class_path(), except it accepts the name as Ruby's string instead of C's.
Definition variable.c:423
rb_alias_variable
void rb_alias_variable(ID dst, ID src)
Aliases a global variable.
Definition variable.c:1166
rb_define_class_variable
void rb_define_class_variable(VALUE, const char *, VALUE)
Just another name of rb_cv_set.
Definition variable.c:4423
rb_obj_remove_instance_variable
VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name)
Resembles Object#remove_instance_variable.
Definition variable.c:2532
rb_mod_const_of
void * rb_mod_const_of(VALUE, void *)
This is a variant of rb_mod_const_at().
Definition variable.c:3727
rb_ivar_count
st_index_t rb_ivar_count(VALUE obj)
Number of instance variables defined on an object.
Definition variable.c:2390
rb_mod_const_at
void * rb_mod_const_at(VALUE, void *)
This API is mysterious.
Definition variable.c:3712
rb_const_remove
VALUE rb_const_remove(VALUE space, ID name)
Identical to rb_mod_remove_const(), except it takes the name as ID instead of VALUE.
Definition variable.c:3623
rb_const_get_from
VALUE rb_const_get_from(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
Definition variable.c:3499
rb_ivar_defined
VALUE rb_ivar_defined(VALUE obj, ID name)
Queries if the instance variable is defined at the object.
Definition variable.c:2109
rb_cv_get
VALUE rb_cv_get(VALUE klass, const char *name)
Identical to rb_cvar_get(), except it accepts C's string instead of ID.
Definition variable.c:4416
rb_const_defined_at
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
Definition variable.c:3843
rb_cv_set
void rb_cv_set(VALUE klass, const char *name, VALUE val)
Identical to rb_cvar_set(), except it accepts C's string instead of ID.
Definition variable.c:4409
rb_mod_class_variables
VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE recv)
Resembles Module#class_variables.
Definition variable.c:4513
rb_f_global_variables
VALUE rb_f_global_variables(void)
Queries the list of global variables.
Definition variable.c:1133
rb_cvar_defined
VALUE rb_cvar_defined(VALUE klass, ID name)
Queries if the given class has the given class variable.
Definition variable.c:4390
rb_class_path
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
Definition variable.c:380
rb_const_defined_from
int rb_const_defined_from(VALUE space, ID name)
Identical to rb_const_defined(), except it returns false for private constants.
Definition variable.c:3831
rb_const_defined
int rb_const_defined(VALUE space, ID name)
Queries if the constant is defined at the namespace.
Definition variable.c:3837
rb_free_generic_ivar
void rb_free_generic_ivar(VALUE obj)
Frees the list of instance variables.
Definition variable.c:1308
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull)).
Definition nonnull.h:30
noreturn.h
Defines RBIMPL_ATTR_NORETURN.
RBIMPL_ATTR_NORETURN
#define RBIMPL_ATTR_NORETURN()
Wraps (or simulates) [[noreturn]].
Definition noreturn.h:38
value.h
Defines VALUE and ID.
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40