Ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a25176072e02db9254f0e0c84c805cd)
Macros | Enumerations | Functions | Variables
symbol.c File Reference
#include "ruby/encoding.h"
#include "ruby/st.h"
#include "internal.h"
#include "symbol.h"
#include "gc.h"
#include "probes.h"
#include "id.c"
#include "id_table.c"

Go to the source code of this file.

Macros

#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   ruby_global_symbols
 
#define IDSET_ATTRSET_FOR_SYNTAX   ((1U<<ID_LOCAL)|(1U<<ID_CONST))
 
#define IDSET_ATTRSET_FOR_INTERN   (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
 

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(const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type))
 
 WARN_UNUSED_RESULT (static VALUE dsymbol_check(const VALUE sym))
 
 WARN_UNUSED_RESULT (static ID lookup_str_id(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 charrb_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)
 
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)
 
 FUNC_MINIMIZED (VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc))
 
 FUNC_MINIMIZED (VALUE rb_sym_intern_ascii(const char *ptr, long len))
 
 FUNC_MINIMIZED (VALUE rb_sym_intern_ascii_cstr(const char *ptr))
 
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 23 of file symbol.c.

◆ global_symbols

#define global_symbols   ruby_global_symbols

Definition at line 67 of file symbol.c.

◆ IDSET_ATTRSET_FOR_INTERN

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

Definition at line 230 of file symbol.c.

◆ IDSET_ATTRSET_FOR_SYNTAX

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

Definition at line 229 of file symbol.c.

◆ is_identchar

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

Definition at line 35 of file symbol.c.

◆ op_tbl_count

#define op_tbl_count   numberof(op_tbl)

Definition at line 37 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 39 of file symbol.c.

◆ REGISTER_SYMID

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

Definition at line 32 of file symbol.c.

◆ STATIC_SYM2ID

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

Definition at line 28 of file symbol.c.

◆ SYMBOL_DEBUG

#define SYMBOL_DEBUG   0

Definition at line 20 of file symbol.c.

◆ SYMBOL_PINNED_P

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

Definition at line 26 of file symbol.c.

Enumeration Type Documentation

◆ id_entry_type

Enumerator
ID_ENTRY_STR 
ID_ENTRY_SYM 
ID_ENTRY_SIZE 

Definition at line 60 of file symbol.c.

Function Documentation

◆ FUNC_MINIMIZED() [1/3]

FUNC_MINIMIZED ( VALUE   rb_sym_internconst char *ptr, long len, rb_encoding *enc)

◆ FUNC_MINIMIZED() [2/3]

FUNC_MINIMIZED ( VALUE   rb_sym_intern_asciiconst char *ptr, long len)

◆ FUNC_MINIMIZED() [3/3]

FUNC_MINIMIZED ( VALUE   rb_sym_intern_ascii_cstrconst char *ptr)

◆ Init_sym()

void Init_sym ( void  )

◆ rb_check_id_cstr()

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

Definition at line 988 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_cstr()

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

Definition at line 999 of file symbol.c.

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

◆ rb_enc_symname2_p()

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

Definition at line 339 of file symbol.c.

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

Referenced by rb_enc_symname_p().

◆ rb_enc_symname_p()

int rb_enc_symname_p ( const char name,
rb_encoding enc 
)

Definition at line 188 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 
)

Definition at line 233 of file symbol.c.

References ID_GLOBAL, ID_JUNK, len, name, and rb_enc_asciicompat.

Referenced by rb_enc_symname2_p().

◆ rb_gc_free_dsymbol()

void rb_gc_free_dsymbol ( VALUE  sym)

Definition at line 678 of file symbol.c.

References RSYMBOL, str, and sym.

◆ rb_id2sym()

VALUE rb_id2sym ( ID  x)

Definition at line 776 of file symbol.c.

References DYNAMIC_ID_P, and STATIC_ID2SYM.

◆ rb_id_attrset()

ID rb_id_attrset ( ID  id)

Definition at line 98 of file symbol.c.

References is_notop_id, PRIsVALUE, rb_id2str(), rb_name_error(), str, sym, tAREF, and tASET.

◆ rb_intern3()

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

Definition at line 603 of file symbol.c.

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

Referenced by rb_intern2().

◆ rb_is_attrset_id()

int rb_is_attrset_id ( ID  id)

Definition at line 878 of file symbol.c.

References is_attrset_id.

◆ rb_is_attrset_sym()

int rb_is_attrset_sym ( VALUE  sym)

Definition at line 902 of file symbol.c.

References is_attrset_sym, and sym.

◆ rb_is_class_id()

int rb_is_class_id ( ID  id)

Definition at line 860 of file symbol.c.

References is_class_id.

◆ rb_is_class_name()

int rb_is_class_name ( VALUE  name)

Definition at line 1056 of file symbol.c.

◆ rb_is_const_id()

int rb_is_const_id ( ID  id)

Definition at line 854 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 1050 of file symbol.c.

◆ rb_is_const_sym()

int rb_is_const_sym ( VALUE  sym)

Definition at line 896 of file symbol.c.

References is_const_sym, and sym.

◆ rb_is_global_id()

int rb_is_global_id ( ID  id)

Definition at line 866 of file symbol.c.

References is_global_id.

◆ rb_is_instance_id()

int rb_is_instance_id ( ID  id)

Definition at line 872 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 1062 of file symbol.c.

◆ rb_is_junk_id()

int rb_is_junk_id ( ID  id)

Definition at line 890 of file symbol.c.

References is_junk_id.

◆ rb_is_local_id()

int rb_is_local_id ( ID  id)

Definition at line 884 of file symbol.c.

References is_local_id.

◆ rb_is_local_name()

int rb_is_local_name ( VALUE  name)

Definition at line 1068 of file symbol.c.

◆ rb_make_internal_id()

ID rb_make_internal_id ( void  )

Definition at line 810 of file symbol.c.

◆ rb_str_intern()

VALUE rb_str_intern ( VALUE  str)

Definition at line 710 of file symbol.c.

References id, and sym.

Referenced by rb_sym_intern().

◆ rb_sym2id()

ID rb_sym2id ( VALUE  sym)

Definition at line 748 of file symbol.c.

References DYNAMIC_SYM_P, id, STATIC_SYM2ID, STATIC_SYM_P, and sym.

◆ rb_sym_all_symbols()

VALUE rb_sym_all_symbols ( void  )

Definition at line 840 of file symbol.c.

References RString::ary, global_symbols, rb_ary_new2, and st_foreach().

◆ rb_sym_immortal_count()

size_t rb_sym_immortal_count ( void  )

Definition at line 848 of file symbol.c.

References global_symbols.

◆ rb_sym_intern()

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

Definition at line 1024 of file symbol.c.

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

Referenced by rb_sym_intern_ascii().

◆ rb_sym_intern_ascii()

VALUE rb_sym_intern_ascii ( const char ptr,
long  len 
)

Definition at line 1032 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 1038 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 182 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 1044 of file symbol.c.

References idTo_sym, obj, 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/6]

WARN_UNUSED_RESULT ( static ID   intern_strVALUE str, int mutable)

◆ WARN_UNUSED_RESULT() [2/6]

WARN_UNUSED_RESULT ( static ID   lookup_str_idVALUE str)

◆ WARN_UNUSED_RESULT() [3/6]

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

◆ WARN_UNUSED_RESULT() [4/6]

WARN_UNUSED_RESULT ( static VALUE   dsymbol_checkconst VALUE sym)

◆ WARN_UNUSED_RESULT() [5/6]

WARN_UNUSED_RESULT ( static VALUE   lookup_id_strID id)

◆ WARN_UNUSED_RESULT() [6/6]

WARN_UNUSED_RESULT ( static VALUE   lookup_str_symconst VALUE str)

Variable Documentation

◆ ruby_global_symbols

rb_symbols_t ruby_global_symbols = {tNEXT_ID-1}

Definition at line 66 of file symbol.c.