Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
|
#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 } |
Variables | |
rb_symbols_t | ruby_global_symbols = {tNEXT_ID-1} |
#define CHECK_ID_SERIAL SYMBOL_DEBUG |
#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_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET)) |
#define STATIC_SYM2ID | ( | sym | ) | RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT) |
#define SYMBOL_PINNED_P | ( | sym | ) | (RSYMBOL(sym)->id&~ID_SCOPE_MASK) |
#define t struct enc_synmane_type_leading_chars_tag |
enum id_entry_type |
void Init_sym | ( | void | ) |
Definition at line 84 of file symbol.c.
References rb_symbols_t::dsymbol_fstr_hash, rb_symbols_t::ids, rb_ary_tmp_new(), rb_gc_register_mark_object(), rb_ident_hash_new(), rb_obj_hide(), ruby_global_symbols, st_init_table_with_size, and rb_symbols_t::str_sym.
Returns ID for the given name if it is interned already, or 0.
namep | the pointer to the name object |
namep
must be a Symbol or a String, or possible to convert with to_str method. 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().
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().
Returns Symbol for the given name if it is interned already, or nil.
namep | the pointer to the name object |
namep
must be a Symbol or a String, or possible to convert with to_str method. 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.
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().
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().
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().
int rb_enc_symname_type | ( | const char * | name, |
long | len, | ||
rb_encoding * | enc, | ||
unsigned int | allowed_attrset | ||
) |
Definition at line 365 of file symbol.c.
References f, ID_ATTRSET, ID_CLASS, ID_GLOBAL, ID_INSTANCE, ID_JUNK, int(), enc_synmane_type_leading_chars_tag::invalid, is_identchar, ISALPHA, ISASCII, len, name, enc_synmane_type_leading_chars_tag::needmore, rb_enc_mbclen(), rb_enc_symname_type(), and enc_synmane_type_leading_chars_tag::stophere.
Referenced by rb_enc_symname2_p(), and rb_enc_symname_type().
void rb_gc_free_dsymbol | ( | VALUE | sym | ) |
Definition at line 803 of file symbol.c.
References rb_symbols_t::dsymbol_fstr_hash, GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, rb_hash_delete_entry(), RSYMBOL, str, and sym.
Definition at line 944 of file symbol.c.
References rb_id2str, RSTRING_PTR, and str.
Referenced by rb_dtrace_setup(), rb_raw_obj_info(), rb_undef(), rsock_inspect_sockaddr(), rsock_revlookup_flag(), and ruby_debug_print_id().
Definition at line 919 of file symbol.c.
References DYNAMIC_ID_P, ID_ENTRY_SYM, and STATIC_ID2SYM.
Definition at line 113 of file symbol.c.
References id, ID_ATTRSET, ID_CLASS, ID_CONST, ID_GLOBAL, ID_INSTANCE, ID_JUNK, ID_LOCAL, id_types, is_notop_id, PRIsVALUE, PRIxVALUE, Qnil, rb_id2str, rb_name_error(), rb_name_error_str(), rb_str_cat(), rb_str_dup(), rb_sym2id(), str, sym, tAREF, and tASET.
Referenced by rb_attr().
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().
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().
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().
Definition at line 1028 of file symbol.c.
References is_attrset_id.
Definition at line 1052 of file symbol.c.
References is_attrset_sym, and sym.
Definition at line 1010 of file symbol.c.
References is_class_id.
Definition at line 1004 of file symbol.c.
References is_const_id.
Referenced by rb_autoload_str(), and rb_define_const().
Definition at line 1046 of file symbol.c.
References is_const_sym, and sym.
Definition at line 1016 of file symbol.c.
References is_global_id.
Definition at line 1022 of file symbol.c.
References is_instance_id.
Referenced by rb_ivar_set_internal().
Definition at line 1229 of file symbol.c.
References ID_INSTANCE, and name.
Definition at line 1040 of file symbol.c.
References is_junk_id.
Definition at line 1034 of file symbol.c.
References is_local_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().
Definition at line 840 of file symbol.c.
References GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, id, ID2SYM, ID_JUNK, IDSET_ATTRSET_FOR_INTERN, OBJ_FREEZE, rb_cSymbol, rb_enc_associate(), rb_enc_get(), rb_fstring(), rb_str_dup(), rb_usascii_encoding(), str, and sym.
Referenced by Init_String(), rb_f_global_variables(), rb_sym_intern(), and rb_to_symbol().
Definition at line 885 of file symbol.c.
References rb_symbols_t::dsymbol_fstr_hash, DYNAMIC_SYM_P, GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, id, ID_SCOPE_MASK, num, rb_builtin_class_name(), rb_eTypeError, rb_hash_delete_entry(), rb_raise(), RSYMBOL, STATIC_SYM2ID, STATIC_SYM_P, sym, and UNLIKELY.
Referenced by rb_fiddle_type_ensure(), rb_id_attrset(), and rb_intern3().
Definition at line 927 of file symbol.c.
References DYNAMIC_SYM_P, rb_id2str, RSYMBOL, STATIC_SYM2ID, and sym.
Referenced by Init_String(), rb_enc_get_index(), rb_num_get_rounding_option(), rb_reg_match_p(), rb_str_format(), and rb_sym_to_s().
VALUE rb_sym_all_symbols | ( | void | ) |
Definition at line 983 of file symbol.c.
References RString::ary, GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, st_table::num_entries, rb_ary_new2, st_foreach, and rb_symbols_t::str_sym.
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.
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().
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().
Definition at line 1205 of file symbol.c.
References ptr, rb_sym_intern_ascii(), and strlen().
Definition at line 197 of file symbol.c.
References name, rb_ascii8bit_encoding(), and rb_enc_symname_p().
Definition at line 1211 of file symbol.c.
References rb_convert_type_with_id(), and T_SYMBOL.
STATIC_ASSERT | ( | op_tbl_name_size | , |
sizeof(op_tbl[0].name) | = =3 |
||
) |
WARN_UNUSED_RESULT | ( | static ID | intern_strVALUE str, int mutable | ) |
WARN_UNUSED_RESULT | ( | static ID | lookup_str_idVALUE str | ) |
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 | ( | static VALUE | dsymbol_checkrb_symbols_t *symbols, const VALUE sym | ) |
WARN_UNUSED_RESULT | ( | static VALUE | lookup_id_strID id | ) |
WARN_UNUSED_RESULT | ( | static VALUE | lookup_str_symconst VALUE str | ) |
WARN_UNUSED_RESULT | ( | static VALUE | lookup_str_sym_with_lockrb_symbols_t *symbols, const VALUE str | ) |
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().