Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Enumerations | Functions
symbol.c File Reference
#include "internal.h"
#include "ruby/st.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.

Data Structures

struct  symbols
 

Macros

#define SYMBOL_DEBUG   0
 
#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 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 attrsetname_to_attr(VALUE name))
 
 WARN_UNUSED_RESULT (static ID intern_str(VALUE str, int mutable))
 
ID rb_id_attrset (ID id)
 
ID rb_id_attrget (ID id)
 
int rb_symname_p (const char *name)
 
int rb_enc_symname_p (const char *name, rb_encoding *enc)
 
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_class_sym (VALUE sym)
 
int rb_is_global_sym (VALUE sym)
 
int rb_is_instance_sym (VALUE sym)
 
int rb_is_attrset_sym (VALUE sym)
 
int rb_is_local_sym (VALUE sym)
 
int rb_is_junk_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_cstr(const char *ptr, 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_cstr (const char *ptr, rb_encoding *enc)
 
VALUE rb_sym_intern_ascii (const char *ptr, long len)
 
VALUE rb_sym_intern_ascii_cstr (const char *ptr)
 
int rb_is_const_name (VALUE name)
 
int rb_is_class_name (VALUE name)
 
int rb_is_global_name (VALUE name)
 
int rb_is_instance_name (VALUE name)
 
int rb_is_attrset_name (VALUE name)
 
int rb_is_local_name (VALUE name)
 
int rb_is_method_name (VALUE name)
 
int rb_is_junk_name (VALUE name)
 

Macro Definition Documentation

◆ IDSET_ATTRSET_FOR_INTERN

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

Definition at line 202 of file symbol.c.

◆ IDSET_ATTRSET_FOR_SYNTAX

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

Definition at line 201 of file symbol.c.

◆ is_identchar

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

Definition at line 31 of file symbol.c.

◆ op_tbl_count

#define op_tbl_count   numberof(op_tbl)

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

◆ REGISTER_SYMID

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

Definition at line 28 of file symbol.c.

◆ STATIC_SYM2ID

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

Definition at line 24 of file symbol.c.

Referenced by rb_check_id(), rb_sym2id(), and rb_sym2str().

◆ SYMBOL_DEBUG

#define SYMBOL_DEBUG   0

Definition at line 19 of file symbol.c.

◆ SYMBOL_PINNED_P

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

Definition at line 22 of file symbol.c.

Referenced by rb_check_id(), and rb_check_symbol().

Enumeration Type Documentation

◆ id_entry_type

Enumerator
ID_ENTRY_STR 
ID_ENTRY_SYM 
ID_ENTRY_SIZE 

Definition at line 56 of file symbol.c.

Function Documentation

◆ FUNC_MINIMIZED() [1/4]

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

◆ FUNC_MINIMIZED() [2/4]

FUNC_MINIMIZED ( VALUE   rb_sym_intern_cstrconst char *ptr, rb_encoding *enc)

◆ FUNC_MINIMIZED() [3/4]

FUNC_MINIMIZED ( VALUE   rb_sym_intern_asciiconst char *ptr, long len)

◆ FUNC_MINIMIZED() [4/4]

FUNC_MINIMIZED ( VALUE   rb_sym_intern_ascii_cstrconst char *ptr)

◆ Init_sym()

void Init_sym ( void  )

Definition at line 75 of file symbol.c.

References rb_ident_hash_new().

◆ 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 915 of file symbol.c.

References DYNAMIC_SYM_P, name, NIL_P, PRIsVALUE, rb_check_string_type(), rb_eTypeError, rb_raise(), RB_TYPE_P, 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 984 of file symbol.c.

References rb_setup_fake_str().

Referenced by rb_deprecate_constant(), and rb_path_to_class().

◆ rb_check_symbol()

VALUE rb_check_symbol ( volatile VALUE namep)

Definition at line 948 of file symbol.c.

References DYNAMIC_SYM_P, name, STATIC_SYM_P, sym, and SYMBOL_PINNED_P.

◆ rb_check_symbol_cstr()

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

Definition at line 995 of file symbol.c.

References 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 311 of file symbol.c.

Referenced by rb_enc_symname_p().

◆ rb_enc_symname_p()

int rb_enc_symname_p ( const char *  name,
rb_encoding enc 
)

Definition at line 196 of file symbol.c.

References rb_enc_symname2_p(), and strlen().

Referenced by rb_symname_p().

◆ rb_gc_free_dsymbol()

void rb_gc_free_dsymbol ( VALUE  sym)

Definition at line 629 of file symbol.c.

References RSYMBOL.

◆ rb_id2name()

const char* rb_id2name ( ID  id)

Definition at line 751 of file symbol.c.

References rb_id2str(), and RSTRING_PTR.

Referenced by rb_undef(), rsock_inspect_sockaddr(), and ruby_debug_print_id().

◆ rb_id2str()

VALUE rb_id2str ( ID  id)

Definition at line 745 of file symbol.c.

Referenced by rb_id2name(), rb_id_attrset(), and rb_sym2str().

◆ rb_id2sym()

VALUE rb_id2sym ( ID  x)

Definition at line 726 of file symbol.c.

References DYNAMIC_ID_P, and STATIC_ID2SYM.

◆ rb_id_attrget()

ID rb_id_attrget ( ID  id)

Definition at line 158 of file symbol.c.

◆ rb_id_attrset()

ID rb_id_attrset ( ID  id)

Definition at line 100 of file symbol.c.

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

◆ rb_intern()

ID rb_intern ( const char *  name)

Definition at line 611 of file symbol.c.

References rb_intern2(), and strlen().

◆ rb_intern2()

ID rb_intern2 ( const char *  name,
long  len 
)

Definition at line 604 of file symbol.c.

References rb_intern3(), and rb_usascii_encoding().

Referenced by Init_load(), and rb_intern().

◆ rb_intern3()

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

Definition at line 554 of file symbol.c.

References OBJ_FREEZE, rb_setup_fake_str(), and sym.

Referenced by rb_intern2().

◆ rb_intern_str()

ID rb_intern_str ( VALUE  str)

Definition at line 617 of file symbol.c.

◆ rb_is_attrset_id()

int rb_is_attrset_id ( ID  id)

Definition at line 844 of file symbol.c.

References is_attrset_id.

◆ rb_is_attrset_name()

int rb_is_attrset_name ( VALUE  name)

Definition at line 1100 of file symbol.c.

◆ rb_is_attrset_sym()

int rb_is_attrset_sym ( VALUE  sym)

Definition at line 886 of file symbol.c.

References is_attrset_sym.

◆ rb_is_class_id()

int rb_is_class_id ( ID  id)

Definition at line 826 of file symbol.c.

References is_class_id.

◆ rb_is_class_name()

int rb_is_class_name ( VALUE  name)

Definition at line 1082 of file symbol.c.

◆ rb_is_class_sym()

int rb_is_class_sym ( VALUE  sym)

Definition at line 868 of file symbol.c.

References is_class_sym.

◆ rb_is_const_id()

int rb_is_const_id ( ID  id)

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

◆ rb_is_const_sym()

int rb_is_const_sym ( VALUE  sym)

Definition at line 862 of file symbol.c.

References is_const_sym.

◆ rb_is_global_id()

int rb_is_global_id ( ID  id)

Definition at line 832 of file symbol.c.

References is_global_id.

◆ rb_is_global_name()

int rb_is_global_name ( VALUE  name)

Definition at line 1088 of file symbol.c.

◆ rb_is_global_sym()

int rb_is_global_sym ( VALUE  sym)

Definition at line 874 of file symbol.c.

References is_global_sym.

◆ rb_is_instance_id()

int rb_is_instance_id ( ID  id)

Definition at line 838 of file symbol.c.

References is_instance_id.

◆ rb_is_instance_name()

int rb_is_instance_name ( VALUE  name)

Definition at line 1094 of file symbol.c.

◆ rb_is_instance_sym()

int rb_is_instance_sym ( VALUE  sym)

Definition at line 880 of file symbol.c.

References is_instance_sym.

◆ rb_is_junk_id()

int rb_is_junk_id ( ID  id)

Definition at line 856 of file symbol.c.

References is_junk_id.

◆ rb_is_junk_name()

int rb_is_junk_name ( VALUE  name)

Definition at line 1122 of file symbol.c.

◆ rb_is_junk_sym()

int rb_is_junk_sym ( VALUE  sym)

Definition at line 898 of file symbol.c.

References is_junk_sym.

◆ rb_is_local_id()

int rb_is_local_id ( ID  id)

Definition at line 850 of file symbol.c.

References is_local_id.

◆ rb_is_local_name()

int rb_is_local_name ( VALUE  name)

Definition at line 1106 of file symbol.c.

◆ rb_is_local_sym()

int rb_is_local_sym ( VALUE  sym)

Definition at line 892 of file symbol.c.

References is_local_sym.

◆ rb_is_method_name()

int rb_is_method_name ( VALUE  name)

Definition at line 1112 of file symbol.c.

◆ rb_make_internal_id()

ID rb_make_internal_id ( void  )

Definition at line 760 of file symbol.c.

◆ rb_str_intern()

VALUE rb_str_intern ( VALUE  str)

Definition at line 661 of file symbol.c.

References id.

Referenced by rb_sym_intern().

◆ rb_sym2id()

ID rb_sym2id ( VALUE  sym)

Definition at line 698 of file symbol.c.

References DYNAMIC_SYM_P, id, STATIC_SYM2ID, and STATIC_SYM_P.

◆ rb_sym2str()

VALUE rb_sym2str ( VALUE  sym)

Definition at line 734 of file symbol.c.

References DYNAMIC_SYM_P, rb_id2str(), RSYMBOL, and STATIC_SYM2ID.

◆ rb_sym_all_symbols()

VALUE rb_sym_all_symbols ( void  )

Definition at line 806 of file symbol.c.

References RString::ary, and rb_ary_new2.

◆ rb_sym_immortal_count()

size_t rb_sym_immortal_count ( void  )

Definition at line 814 of file symbol.c.

◆ rb_sym_intern()

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

Definition at line 1022 of file symbol.c.

References rb_setup_fake_str(), and rb_str_intern().

Referenced by rb_sym_intern_ascii(), and rb_sym_intern_cstr().

◆ rb_sym_intern_ascii()

VALUE rb_sym_intern_ascii ( const char *  ptr,
long  len 
)

Definition at line 1036 of file symbol.c.

References 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 1042 of file symbol.c.

References rb_sym_intern_ascii(), and strlen().

Referenced by rb_catch(), and rb_throw().

◆ rb_sym_intern_cstr()

VALUE rb_sym_intern_cstr ( const char *  ptr,
rb_encoding enc 
)

Definition at line 1030 of file symbol.c.

References rb_sym_intern(), and strlen().

◆ rb_symname_p()

int rb_symname_p ( const char *  name)

Definition at line 190 of file symbol.c.

References rb_ascii8bit_encoding(), and rb_enc_symname_p().

◆ STATIC_ASSERT()

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

◆ WARN_UNUSED_RESULT() [1/7]

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

◆ WARN_UNUSED_RESULT() [2/7]

WARN_UNUSED_RESULT ( static VALUE   dsymbol_checkconst VALUE sym)

◆ WARN_UNUSED_RESULT() [3/7]

WARN_UNUSED_RESULT ( static ID   lookup_str_idVALUE str)

◆ WARN_UNUSED_RESULT() [4/7]

WARN_UNUSED_RESULT ( static VALUE   lookup_str_symconst VALUE str)

◆ WARN_UNUSED_RESULT() [5/7]

WARN_UNUSED_RESULT ( static VALUE   lookup_id_strID id)

◆ WARN_UNUSED_RESULT() [6/7]

WARN_UNUSED_RESULT ( static ID   attrsetname_to_attrVALUE name)

◆ WARN_UNUSED_RESULT() [7/7]

WARN_UNUSED_RESULT ( static ID   intern_strVALUE str, int mutable)