Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
Data Structures | Macros | Enumerations | Functions | Variables
symbol.c File Reference
#include "gc.h"
#include "internal.h"
#include "internal/error.h"
#include "internal/gc.h"
#include "internal/hash.h"
#include "internal/object.h"
#include "internal/symbol.h"
#include "internal/vm.h"
#include "probes.h"
#include "ruby/encoding.h"
#include "ruby/st.h"
#include "symbol.h"
#include "vm_sync.h"
#include "id.c"
#include "id_table.c"

Go to the source code of this file.

Data Structures

struct  enc_synmane_type_leading_chars_tag
 

Macros

#define USE_SYMBOL_GC   1
 
#define SYMBOL_DEBUG   0
 
#define CHECK_ID_SERIAL   SYMBOL_DEBUG
 
#define SYMBOL_PINNED_P(sym)   (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
 
#define STATIC_SYM2ID(sym)   RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT)
 
#define REGISTER_SYMID(id, name)   register_static_symid((id), (name), strlen(name), enc)
 
#define is_identchar(p, e, enc)   (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
 
#define op_tbl_count   numberof(op_tbl)
 
#define op_tbl_len(i)   (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
 
#define GLOBAL_SYMBOLS_ENTER(symbols)   rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()
 
#define GLOBAL_SYMBOLS_LEAVE()   RB_VM_LOCK_LEAVE()
 
#define IDSET_ATTRSET_FOR_SYNTAX   ((1U<<ID_LOCAL)|(1U<<ID_CONST))
 
#define IDSET_ATTRSET_FOR_INTERN   (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
 
#define t   struct enc_synmane_type_leading_chars_tag
 

Enumerations

enum  id_entry_type { ID_ENTRY_STR , ID_ENTRY_SYM , ID_ENTRY_SIZE }
 

Functions

 STATIC_ASSERT (op_tbl_name_size, sizeof(op_tbl[0].name)==3)
 
void Init_sym (void)
 
 WARN_UNUSED_RESULT (static VALUE dsymbol_alloc(rb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type))
 
 WARN_UNUSED_RESULT (static VALUE dsymbol_check(rb_symbols_t *symbols, const VALUE sym))
 
 WARN_UNUSED_RESULT (static ID lookup_str_id(VALUE str))
 
 WARN_UNUSED_RESULT (static VALUE lookup_str_sym_with_lock(rb_symbols_t *symbols, const VALUE str))
 
 WARN_UNUSED_RESULT (static VALUE lookup_str_sym(const VALUE str))
 
 WARN_UNUSED_RESULT (static VALUE lookup_id_str(ID id))
 
 WARN_UNUSED_RESULT (static ID intern_str(VALUE str, int mutable))
 
ID rb_id_attrset (ID id)
 
int rb_symname_p (const char *name)
 
int rb_enc_symname_p (const char *name, rb_encoding *enc)
 
int rb_enc_symname_type (const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
 
int rb_enc_symname2_p (const char *name, long len, rb_encoding *enc)
 
ID rb_intern3 (const char *name, long len, rb_encoding *enc)
 
ID rb_intern2 (const char *name, long len)
 
ID rb_intern (const char *name)
 
ID rb_intern_str (VALUE str)
 
void rb_gc_free_dsymbol (VALUE sym)
 
VALUE rb_str_intern (VALUE str)
 
ID rb_sym2id (VALUE sym)
 
VALUE rb_id2sym (ID x)
 
VALUE rb_sym2str (VALUE sym)
 
VALUE rb_id2str (ID id)
 
const char * rb_id2name (ID id)
 
ID rb_make_internal_id (void)
 
VALUE rb_sym_all_symbols (void)
 
size_t rb_sym_immortal_count (void)
 
int rb_is_const_id (ID id)
 
int rb_is_class_id (ID id)
 
int rb_is_global_id (ID id)
 
int rb_is_instance_id (ID id)
 
int rb_is_attrset_id (ID id)
 
int rb_is_local_id (ID id)
 
int rb_is_junk_id (ID id)
 
int rb_is_const_sym (VALUE sym)
 
int rb_is_attrset_sym (VALUE sym)
 
ID rb_check_id (volatile VALUE *namep)
 Returns ID for the given name if it is interned already, or 0. More...
 
VALUE rb_check_symbol (volatile VALUE *namep)
 Returns Symbol for the given name if it is interned already, or nil. More...
 
ID rb_check_id_cstr (const char *ptr, long len, rb_encoding *enc)
 
VALUE rb_check_symbol_cstr (const char *ptr, long len, rb_encoding *enc)
 
VALUE rb_sym_intern (const char *ptr, long len, rb_encoding *enc)
 
VALUE rb_sym_intern_ascii (const char *ptr, long len)
 
VALUE rb_sym_intern_ascii_cstr (const char *ptr)
 
VALUE rb_to_symbol_type (VALUE obj)
 
int rb_is_const_name (VALUE name)
 
int rb_is_class_name (VALUE name)
 
int rb_is_instance_name (VALUE name)
 
int rb_is_local_name (VALUE name)
 

Variables

rb_symbols_t ruby_global_symbols = {tNEXT_ID-1}
 

Macro Definition Documentation

◆ CHECK_ID_SERIAL

#define CHECK_ID_SERIAL   SYMBOL_DEBUG

Definition at line 33 of file symbol.c.

◆ GLOBAL_SYMBOLS_ENTER

#define GLOBAL_SYMBOLS_ENTER (   symbols)    rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()

Definition at line 109 of file symbol.c.

◆ GLOBAL_SYMBOLS_LEAVE

#define GLOBAL_SYMBOLS_LEAVE ( )    RB_VM_LOCK_LEAVE()

Definition at line 110 of file symbol.c.

◆ IDSET_ATTRSET_FOR_INTERN

#define IDSET_ATTRSET_FOR_INTERN   (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))

Definition at line 245 of file symbol.c.

◆ IDSET_ATTRSET_FOR_SYNTAX

#define IDSET_ATTRSET_FOR_SYNTAX   ((1U<<ID_LOCAL)|(1U<<ID_CONST))

Definition at line 244 of file symbol.c.

◆ is_identchar

#define is_identchar (   p,
  e,
  enc 
)    (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))

Definition at line 45 of file symbol.c.

◆ op_tbl_count

#define op_tbl_count   numberof(op_tbl)

Definition at line 47 of file symbol.c.

◆ op_tbl_len

#define op_tbl_len (   i)    (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)

Definition at line 49 of file symbol.c.

◆ REGISTER_SYMID

#define REGISTER_SYMID (   id,
  name 
)    register_static_symid((id), (name), strlen(name), enc)

Definition at line 42 of file symbol.c.

◆ STATIC_SYM2ID

#define STATIC_SYM2ID (   sym)    RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT)

Definition at line 38 of file symbol.c.

◆ SYMBOL_DEBUG

#define SYMBOL_DEBUG   0

Definition at line 30 of file symbol.c.

◆ SYMBOL_PINNED_P

#define SYMBOL_PINNED_P (   sym)    (RSYMBOL(sym)->id&~ID_SCOPE_MASK)

Definition at line 36 of file symbol.c.

◆ t

#define t   struct enc_synmane_type_leading_chars_tag

Definition at line 253 of file symbol.c.

◆ USE_SYMBOL_GC

#define USE_SYMBOL_GC   1

Definition at line 27 of file symbol.c.

Enumeration Type Documentation

◆ id_entry_type

Enumerator
ID_ENTRY_STR 
ID_ENTRY_SYM 
ID_ENTRY_SIZE 

Definition at line 70 of file symbol.c.

Function Documentation

◆ Init_sym()

void Init_sym ( void  )

◆ rb_check_id()

ID rb_check_id ( volatile VALUE namep)

Returns ID for the given name if it is interned already, or 0.

Parameters
namepthe pointer to the name object
Returns
the ID for *namep
Precondition
the object referred by namep must be a Symbol or a String, or possible to convert with to_str method.
Postcondition
the object referred by namep is a Symbol or a String if non-zero value is returned, or is a String if 0 is returned.

Definition at line 1069 of file symbol.c.

References DYNAMIC_SYM_P, name, NIL_P, PRIsVALUE, rb_check_string_type(), rb_eTypeError, rb_raise(), RSYMBOL, STATIC_SYM2ID, STATIC_SYM_P, SYMBOL_PINNED_P, and T_STRING.

Referenced by rb_execarg_addopt(), rb_f_untrace_var(), and rb_obj_singleton_method().

◆ rb_check_id_cstr()

ID rb_check_id_cstr ( const char *  ptr,
long  len,
rb_encoding enc 
)

Definition at line 1155 of file symbol.c.

References len, name, ptr, and rb_setup_fake_str().

Referenced by rb_deprecate_constant(), rb_iv_get(), and rb_path_to_class().

◆ rb_check_symbol()

VALUE rb_check_symbol ( volatile VALUE namep)

Returns Symbol for the given name if it is interned already, or nil.

Parameters
namepthe pointer to the name object
Returns
the Symbol for *namep
Precondition
the object referred by namep must be a Symbol or a String, or possible to convert with to_str method.
Postcondition
the object referred by namep is a Symbol or a String if non-nil value is returned, or is a String if nil is returned.

Definition at line 1114 of file symbol.c.

References DYNAMIC_SYM_P, GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, name, NIL_P, PRIsVALUE, Qnil, rb_check_string_type(), rb_eTypeError, rb_raise(), STATIC_SYM_P, sym, SYMBOL_PINNED_P, and T_STRING.

◆ rb_check_symbol_cstr()

VALUE rb_check_symbol_cstr ( const char *  ptr,
long  len,
rb_encoding enc 
)

Definition at line 1166 of file symbol.c.

References len, name, ptr, Qnil, rb_setup_fake_str(), and sym.

Referenced by rb_str_format().

◆ rb_enc_symname2_p()

int rb_enc_symname2_p ( const char *  name,
long  len,
rb_encoding enc 
)

Definition at line 407 of file symbol.c.

References IDSET_ATTRSET_FOR_SYNTAX, len, name, and rb_enc_symname_type().

Referenced by rb_enc_symname_p(), and rb_str_symname_p().

◆ rb_enc_symname_p()

int rb_enc_symname_p ( const char *  name,
rb_encoding enc 
)

Definition at line 203 of file symbol.c.

References name, rb_enc_symname2_p(), and strlen().

Referenced by rb_symname_p().

◆ rb_enc_symname_type()

int rb_enc_symname_type ( const char *  name,
long  len,
rb_encoding enc,
unsigned int  allowed_attrset 
)

◆ rb_gc_free_dsymbol()

void rb_gc_free_dsymbol ( VALUE  sym)

◆ rb_id2name()

const char * rb_id2name ( ID  id)

◆ rb_id2str()

VALUE rb_id2str ( ID  id)

Definition at line 938 of file symbol.c.

◆ rb_id2sym()

VALUE rb_id2sym ( ID  x)

Definition at line 919 of file symbol.c.

References DYNAMIC_ID_P, ID_ENTRY_SYM, and STATIC_ID2SYM.

◆ rb_id_attrset()

ID rb_id_attrset ( ID  id)

◆ rb_intern()

ID rb_intern ( const char *  name)

Definition at line 785 of file symbol.c.

References name, rb_intern2(), and strlen().

Referenced by asn1time_to_time(), create_win32ole_param(), create_win32ole_variable(), default_inspect(), DupConfigPtr(), EVENTSINK_Invoke(), Init_bubblebabble(), Init_console(), Init_digest(), Init_fiddle(), Init_fiddle_pointer(), Init_GC(), Init_generator(), Init_objspace(), Init_openssl(), Init_ossl_asn1(), Init_ossl_ec(), Init_ossl_pkcs12(), Init_ossl_pkcs7(), Init_ossl_pkey(), Init_ossl_x509ext(), Init_ossl_x509name(), Init_ossl_x509store(), Init_parser(), Init_Proc(), Init_psych_emitter(), Init_psych_parser(), Init_Random(), Init_readline(), Init_socket(), Init_stringio(), Init_strscan(), Init_Struct(), Init_syslog(), Init_transcode(), Init_win32ole_event(), Init_win32ole_variant(), Init_zlib(), InitVM_pathname(), olerecord_set_ivar(), ossl_obj2bio(), ossl_time_split(), rb_big_remainder(), rb_callable_receiver(), rb_define_alias(), rb_define_attr(), rb_define_class(), rb_define_class_under(), rb_define_const(), rb_define_method(), rb_define_module(), rb_define_module_under(), rb_define_private_method(), rb_define_protected_method(), rb_enc_get_index(), rb_fiddle_generic_to_value(), rb_gvar_ractor_local(), rb_iseq_add_local_tracepoint_recursively(), rb_iseq_load_iseq(), rb_iv_set(), rb_range_values(), rb_rational_cmp(), rb_rational_pow(), rb_remove_method(), rb_resolve_feature_path(), rb_time_zone_abbreviation(), rb_undef_method(), rsock_init_addrinfo(), rsock_init_ancdata(), and rsock_init_socket_init().

◆ rb_intern2()

ID rb_intern2 ( const char *  name,
long  len 
)

Definition at line 778 of file symbol.c.

References len, name, rb_intern3(), and rb_usascii_encoding().

Referenced by Init_load(), rb_f_global_variables(), rb_intern(), and yyparse().

◆ rb_intern3()

ID rb_intern3 ( const char *  name,
long  len,
rb_encoding enc 
)

Definition at line 714 of file symbol.c.

References len, name, OBJ_FREEZE, rb_enc_str_new(), rb_setup_fake_str(), rb_sym2id(), str, and sym.

Referenced by rb_intern2().

◆ rb_intern_str()

ID rb_intern_str ( VALUE  str)

Definition at line 791 of file symbol.c.

References str, sym, and SYM2ID.

◆ rb_is_attrset_id()

int rb_is_attrset_id ( ID  id)

Definition at line 1028 of file symbol.c.

References is_attrset_id.

◆ rb_is_attrset_sym()

int rb_is_attrset_sym ( VALUE  sym)

Definition at line 1052 of file symbol.c.

References is_attrset_sym, and sym.

◆ rb_is_class_id()

int rb_is_class_id ( ID  id)

Definition at line 1010 of file symbol.c.

References is_class_id.

◆ rb_is_class_name()

int rb_is_class_name ( VALUE  name)

Definition at line 1223 of file symbol.c.

References ID_CLASS, and name.

◆ rb_is_const_id()

int rb_is_const_id ( ID  id)

Definition at line 1004 of file symbol.c.

References is_const_id.

Referenced by rb_autoload_str(), and rb_define_const().

◆ rb_is_const_name()

int rb_is_const_name ( VALUE  name)

Definition at line 1217 of file symbol.c.

References ID_CONST, and name.

◆ rb_is_const_sym()

int rb_is_const_sym ( VALUE  sym)

Definition at line 1046 of file symbol.c.

References is_const_sym, and sym.

◆ rb_is_global_id()

int rb_is_global_id ( ID  id)

Definition at line 1016 of file symbol.c.

References is_global_id.

◆ rb_is_instance_id()

int rb_is_instance_id ( ID  id)

Definition at line 1022 of file symbol.c.

References is_instance_id.

Referenced by rb_ivar_set_internal().

◆ rb_is_instance_name()

int rb_is_instance_name ( VALUE  name)

Definition at line 1229 of file symbol.c.

References ID_INSTANCE, and name.

◆ rb_is_junk_id()

int rb_is_junk_id ( ID  id)

Definition at line 1040 of file symbol.c.

References is_junk_id.

◆ rb_is_local_id()

int rb_is_local_id ( ID  id)

Definition at line 1034 of file symbol.c.

References is_local_id.

◆ rb_is_local_name()

int rb_is_local_name ( VALUE  name)

Definition at line 1235 of file symbol.c.

References ID_LOCAL, and name.

◆ rb_make_internal_id()

ID rb_make_internal_id ( void  )

Definition at line 953 of file symbol.c.

References ID_INTERNAL, and ID_STATIC_SYM.

Referenced by Init_Exception(), Init_Hash(), and Init_pack().

◆ rb_str_intern()

VALUE rb_str_intern ( VALUE  str)

◆ rb_sym2id()

ID rb_sym2id ( VALUE  sym)

◆ rb_sym2str()

VALUE rb_sym2str ( VALUE  sym)

◆ rb_sym_all_symbols()

VALUE rb_sym_all_symbols ( void  )

◆ rb_sym_immortal_count()

size_t rb_sym_immortal_count ( void  )

Definition at line 998 of file symbol.c.

References rb_symbols_t::last_id, and ruby_global_symbols.

◆ rb_sym_intern()

VALUE rb_sym_intern ( const char *  ptr,
long  len,
rb_encoding enc 
)

Definition at line 1191 of file symbol.c.

References len, name, ptr, rb_setup_fake_str(), and rb_str_intern().

Referenced by rb_str_format(), and rb_sym_intern_ascii().

◆ rb_sym_intern_ascii()

VALUE rb_sym_intern_ascii ( const char *  ptr,
long  len 
)

Definition at line 1199 of file symbol.c.

References len, ptr, rb_sym_intern(), and rb_usascii_encoding().

Referenced by rb_sym_intern_ascii_cstr().

◆ rb_sym_intern_ascii_cstr()

VALUE rb_sym_intern_ascii_cstr ( const char *  ptr)

Definition at line 1205 of file symbol.c.

References ptr, rb_sym_intern_ascii(), and strlen().

◆ rb_symname_p()

int rb_symname_p ( const char *  name)

Definition at line 197 of file symbol.c.

References name, rb_ascii8bit_encoding(), and rb_enc_symname_p().

◆ rb_to_symbol_type()

VALUE rb_to_symbol_type ( VALUE  obj)

Definition at line 1211 of file symbol.c.

References rb_convert_type_with_id(), and T_SYMBOL.

◆ STATIC_ASSERT()

STATIC_ASSERT ( op_tbl_name_size  ,
sizeof(op_tbl[0].name = =3 
)

◆ WARN_UNUSED_RESULT() [1/7]

WARN_UNUSED_RESULT ( static ID   intern_strVALUE str, int mutable)

◆ WARN_UNUSED_RESULT() [2/7]

WARN_UNUSED_RESULT ( static ID   lookup_str_idVALUE str)

◆ WARN_UNUSED_RESULT() [3/7]

WARN_UNUSED_RESULT ( static VALUE   dsymbol_allocrb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type)

◆ WARN_UNUSED_RESULT() [4/7]

WARN_UNUSED_RESULT ( static VALUE   dsymbol_checkrb_symbols_t *symbols, const VALUE sym)

◆ WARN_UNUSED_RESULT() [5/7]

WARN_UNUSED_RESULT ( static VALUE   lookup_id_strID id)

◆ WARN_UNUSED_RESULT() [6/7]

WARN_UNUSED_RESULT ( static VALUE   lookup_str_symconst VALUE str)

◆ WARN_UNUSED_RESULT() [7/7]

WARN_UNUSED_RESULT ( static VALUE   lookup_str_sym_with_lockrb_symbols_t *symbols, const VALUE str)

Variable Documentation

◆ ruby_global_symbols

rb_symbols_t ruby_global_symbols = {tNEXT_ID-1}

Definition at line 76 of file symbol.c.

Referenced by Init_sym(), and rb_sym_immortal_count().