Ruby: include/ruby/internal/symbol.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions
symbol.h File Reference

Defines rb_intern. More...

`#include "ruby/internal/config.h"`
`#include "ruby/internal/attr/nonnull.h"`
`#include "ruby/internal/attr/pure.h"`
`#include "ruby/internal/attr/noalias.h"`
`#include "ruby/internal/cast.h"`
`#include "ruby/internal/constant_p.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/has/builtin.h"`
`#include "ruby/internal/value.h"`

Go to the source code of this file.

## Macros
#define | RB_ID2SYM rb_id2sym
#define | RB_SYM2ID rb_sym2id
#define | ID2SYM RB_ID2SYM
#define | SYM2ID RB_SYM2ID
#define | CONST_ID_CACHE RUBY_CONST_ID_CACHE
#define | CONST_ID RUBY_CONST_ID
#define | RUBY_CONST_ID_CACHE(result, str)
#define | RUBY_CONST_ID(var, str)

## Functions
ID | rb_sym2id (VALUE)
VALUE | rb_id2sym (ID)
ID | rb_intern (const char *)
ID | rb_intern2 (const char *, long)
ID | rb_intern_str (VALUE str)
const char * | rb_id2name (ID)
ID | rb_check_id (volatile VALUE *)
| Returns ID for the given name if it is interned already, or 0. More...
ID | rb_to_id (VALUE)
VALUE | rb_id2str (ID)
VALUE | rb_sym2str (VALUE)
VALUE | rb_to_symbol (VALUE name)
VALUE | rb_check_symbol (volatile VALUE *namep)
| Returns Symbol for the given name if it is interned already, or nil. More...

## Detailed Description

Defines rb_intern.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file symbol.h.

## Macro Definition Documentation

## ◆ CONST_ID

#define CONST_ID RUBY_CONST_ID

Definition at line 47 of file symbol.h.

## ◆ CONST_ID_CACHE

#define CONST_ID_CACHE RUBY_CONST_ID_CACHE

Definition at line 46 of file symbol.h.

## ◆ ID2SYM

#define ID2SYM RB_ID2SYM

Definition at line 44 of file symbol.h.

## ◆ RB_ID2SYM

#define RB_ID2SYM rb_id2sym

Definition at line 42 of file symbol.h.

## ◆ RB_SYM2ID

#define RB_SYM2ID rb_sym2id

Definition at line 43 of file symbol.h.

## ◆ RUBY_CONST_ID

#define RUBY_CONST_ID | ( |  | var,
|  |  | str
| ) |  |

Value:
do { \
static ID rbimpl_id; \
(var) = rbimpl_intern_const(&rbimpl_id, (str)); \
} while (0)
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
ID
unsigned long ID
Definition: value.h:39

Definition at line 96 of file symbol.h.

## ◆ RUBY_CONST_ID_CACHE

#define RUBY_CONST_ID_CACHE | ( |  | result,
|  |  | str
| ) |  |

Value:
{ \
static ID rb_intern_id_cache; \
rbimpl_intern_const(&rb_intern_id_cache, (str)); \
result rb_intern_id_cache; \
}

Definition at line 90 of file symbol.h.

## ◆ SYM2ID

#define SYM2ID RB_SYM2ID

Definition at line 45 of file symbol.h.

## Function Documentation

## ◆ rb_check_id()

ID rb_check_id | ( | volatile VALUE * | namep | ) |

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

Parameters

  namep | the 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_symbol()

VALUE rb_check_symbol | ( | volatile VALUE * | namep | ) |

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

Parameters

  namep | the 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_id2name()

const char * rb_id2name | ( | ID | id | ) |

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().

## ◆ 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_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_intern_str()

ID rb_intern_str | ( | VALUE | str | ) |

Definition at line 791 of file symbol.c.

References str, sym, and SYM2ID.

## ◆ rb_sym2id()

ID rb_sym2id | ( | VALUE | sym | ) |

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().

## ◆ rb_sym2str()

VALUE rb_sym2str | ( | VALUE | sym | ) |

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().

## ◆ rb_to_id()

ID rb_to_id | ( | VALUE | name | ) |

Definition at line 11501 of file string.c.

References name, rb_intern_str, SYM2ID, and SYMBOL_P.

Referenced by rb_f_trace_var().

## ◆ rb_to_symbol()

VALUE rb_to_symbol | ( | VALUE | name | ) |

Definition at line 11511 of file string.c.

References name, rb_str_intern(), and SYMBOL_P.

Referenced by rb_fiddle_type_ensure().