14#include "internal/error.h"
15#include "internal/gc.h"
16#include "internal/hash.h"
17#include "internal/object.h"
18#include "internal/symbol.h"
19#include "internal/vm.h"
27#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
29# define USE_SYMBOL_GC 0
32# define USE_SYMBOL_GC 1
35# define SYMBOL_DEBUG 0
37#ifndef CHECK_ID_SERIAL
38# define CHECK_ID_SERIAL SYMBOL_DEBUG
41#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
43#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
46static ID register_static_symid_str(
ID,
VALUE);
47#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
50#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
52#define op_tbl_count numberof(op_tbl)
53STATIC_ASSERT(op_tbl_name_size,
sizeof(op_tbl[0].name) == 3);
54#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
62 for (i =
'!'; i <=
'~'; ++i) {
65 register_static_symid(i, &c, 1, enc);
68 for (i = 0; i < op_tbl_count; ++i) {
69 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
73static const int ID_ENTRY_UNIT = 512;
93 VALUE dsym_fstrs = rb_ident_hash_new();
94 symbols->dsymbol_fstr_hash = dsym_fstrs;
95 rb_gc_register_mark_object(dsym_fstrs);
98 symbols->str_sym = st_init_table_with_size(&symhash, 1000);
99 symbols->ids = rb_ary_hidden_new(0);
100 rb_gc_register_mark_object(symbols->ids);
108WARN_UNUSED_RESULT(
static ID lookup_str_id(
VALUE str));
110WARN_UNUSED_RESULT(
static VALUE lookup_str_sym(
const VALUE str));
111WARN_UNUSED_RESULT(
static VALUE lookup_id_str(
ID id));
112WARN_UNUSED_RESULT(
static ID intern_str(
VALUE str,
int mutable));
114#define GLOBAL_SYMBOLS_ENTER(symbols) rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()
115#define GLOBAL_SYMBOLS_LEAVE() RB_VM_LOCK_LEAVE()
123 if (!is_notop_id(
id)) {
125 case tAREF:
case tASET:
128 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
134 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
135 case ID_CONST:
case ID_CLASS:
case ID_JUNK:
141 if ((str = lookup_id_str(
id)) != 0) {
142 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
154 if (!(str = lookup_id_str(
id))) {
155 static const char id_types[][8] = {
165 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
166 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
170 sym = lookup_str_sym(str);
171 id = sym ?
rb_sym2id(sym) : intern_str(str, 1);
176is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
180 if (m >= e)
return 0;
181 if (is_global_name_punct(*m)) {
184 else if (*m ==
'-') {
185 if (++m >= e)
return 0;
186 if (is_identchar(m, e, enc)) {
188 m += rb_enc_mbclen(m, e, enc);
196 }
while (m < e &&
ISDIGIT(*m));
198 return m == e ? mb + 1 : 0;
214rb_sym_constant_char_p(
const char *name,
long nlen,
rb_encoding *enc)
217 const char *end = name + nlen;
219 if (nlen < 1)
return FALSE;
221 c = rb_enc_precise_mbclen(name, end, enc);
225 if (ONIGENC_IS_UNICODE(enc)) {
226 static int ctype_titlecase = 0;
229 if (!ctype_titlecase) {
230 static const UChar cname[] =
"titlecaseletter";
231 static const UChar *
const end = cname +
sizeof(cname) - 1;
232 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
238 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
239 const OnigUChar *beg = (
const OnigUChar *)name;
240 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
241 &beg, (
const OnigUChar *)end,
243 if (r > 0 && (r != len || memcmp(fold, name, r)))
249#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
250#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
253 const enum { invalid, stophere, needmore, } kind;
254 const enum ruby_id_types type;
258#define t struct enc_synmane_type_leading_chars_tag
261enc_synmane_type_leading_chars(const char *name,
long len,
rb_encoding *enc,
int allowed_attrset)
263 const char *m = name;
264 const char *e = m + len;
267 return (t) { invalid, 0, 0, };
270 return (t) { invalid, 0, 0, };
272 else if ( len <= 0 ) {
273 return (t) { invalid, 0, 0, };
277 return (t) { invalid, 0, 0, };
280 if (is_special_global_name(++m, e, enc)) {
281 return (t) { stophere, ID_GLOBAL, len, };
284 return (t) { needmore, ID_GLOBAL, 1, };
289 default:
return (t) { needmore, ID_INSTANCE, 1, };
290 case '@':
return (t) { needmore, ID_CLASS, 2, };
295 default:
return (t) { stophere, ID_JUNK, 1, };
296 case '<':
return (t) { stophere, ID_JUNK, 2, };
299 default:
return (t) { stophere, ID_JUNK, 2, };
300 case '>':
return (t) { stophere, ID_JUNK, 3, };
306 default:
return (t) { stophere, ID_JUNK, 1, };
307 case '>':
case '=':
return (t) { stophere, ID_JUNK, 2, };
312 default:
return (t) { invalid, 0, 1, };
313 case '~':
return (t) { stophere, ID_JUNK, 2, };
316 default:
return (t) { stophere, ID_JUNK, 2, };
317 case '=':
return (t) { stophere, ID_JUNK, 3, };
323 default:
return (t) { stophere, ID_JUNK, 1, };
324 case '*':
return (t) { stophere, ID_JUNK, 2, };
329 default:
return (t) { stophere, ID_JUNK, 1, };
330 case '@':
return (t) { stophere, ID_JUNK, 2, };
333 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
334 return (t) { stophere, ID_JUNK, 1, };
338 default:
return (t) { needmore, ID_JUNK, 0, };
341 default:
return (t) { stophere, ID_JUNK, 2, };
342 case '=':
return (t) { stophere, ID_JUNK, 3, };
348 case '=':
case '~':
return (t) { stophere, ID_JUNK, 2, };
350 if (allowed_attrset & (1U << ID_JUNK)) {
351 return (t) { needmore, ID_JUNK, 1, };
354 return (t) { stophere, ID_JUNK, 1, };
359 if (rb_sym_constant_char_p(name, len, enc)) {
360 return (t) { needmore, ID_CONST, 0, };
363 return (t) { needmore, ID_LOCAL, 0, };
370rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
373 enc_synmane_type_leading_chars(name, len, enc, allowed_attrset);
374 const char *m = name + f.nread;
375 const char *e = name + len;
376 int type = (int)f.type;
379 case invalid:
return -1;
380 case stophere:
break;
384 if (len > 1 && *(e-1) ==
'=') {
385 type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
386 if (allowed_attrset & (1U <<
type))
return ID_ATTRSET;
390 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
394 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
397 if (m + 1 < e || *m !=
'=')
break;
400 if (!(allowed_attrset & (1U <<
type)))
return -1;
407 return m == e ?
type : -1;
413 return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
417rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
421 int type = rb_enc_symname_type(ptr, len, rb_enc_get(name), allowed_attrset);
430 size_t idx = num / ID_ENTRY_UNIT;
432 VALUE ary, ids = symbols->ids;
433 if (idx >= (
size_t)
RARRAY_LEN(ids) ||
NIL_P(ary = rb_ary_entry(ids, (
long)idx))) {
434 ary = rb_ary_hidden_new(ID_ENTRY_UNIT * ID_ENTRY_SIZE);
435 rb_ary_store(ids, (
long)idx, ary);
437 idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
438 rb_ary_store(ary, (
long)idx + ID_ENTRY_STR, str);
439 rb_ary_store(ary, (
long)idx + ID_ENTRY_SYM, sym);
443get_id_serial_entry(rb_id_serial_t num,
ID id,
const enum id_entry_type t)
447 GLOBAL_SYMBOLS_ENTER(symbols);
449 if (num && num <= symbols->last_id) {
450 size_t idx = num / ID_ENTRY_UNIT;
451 VALUE ids = symbols->ids;
453 if (idx < (
size_t)
RARRAY_LEN(ids) && !
NIL_P(ary = rb_ary_entry(ids, (
long)idx))) {
454 long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
455 result = rb_ary_entry(ary, pos + t);
464 if (t != ID_ENTRY_SYM)
465 sym = rb_ary_entry(ary, pos + ID_ENTRY_SYM);
467 if (STATIC_SYM2ID(sym) !=
id) result = 0;
470 if (RSYMBOL(sym)->
id !=
id) result = 0;
478 GLOBAL_SYMBOLS_LEAVE();
484get_id_entry(
ID id,
const enum id_entry_type t)
486 return get_id_serial_entry(rb_id_to_serial(
id),
id, t);
490rb_static_id_valid_p(
ID id)
492 return STATIC_ID2SYM(
id) == get_id_entry(
id, ID_ENTRY_SYM);
496rb_id_serial_to_id(rb_id_serial_t num)
498 if (is_notop_id((
ID)num)) {
499 VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
500 if (sym)
return SYM2ID(sym);
501 return ((
ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
510register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
513 rb_fatal(
"symbol :% "PRIsVALUE
" is already registered with %"PRIxVALUE,
527 st_update(symbols->str_sym, (st_data_t)str,
528 register_sym_update_callback, (st_data_t)sym);
530 st_add_direct(symbols->str_sym, (st_data_t)str, (st_data_t)sym);
539 st_data_t str_data = (st_data_t)str;
540 if (!st_delete(symbols->str_sym, &str_data, NULL)) {
546register_static_symid(
ID id,
const char *name,
long len,
rb_encoding *enc)
549 return register_static_symid_str(
id, str);
553register_static_symid_str(
ID id,
VALUE str)
555 rb_id_serial_t num = rb_id_to_serial(
id);
556 VALUE sym = STATIC_ID2SYM(
id);
559 str = rb_fstring(str);
563 GLOBAL_SYMBOLS_ENTER(symbols)
565 register_sym(symbols, str, sym);
566 set_id_entry(symbols, num, str, sym);
568 GLOBAL_SYMBOLS_LEAVE();
574sym_check_asciionly(
VALUE str,
bool fake_str)
598must_be_dynamic_symbol(
VALUE x)
608 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
612 rb_bug(
"wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
626 rb_enc_set_index(dsym, rb_enc_to_index(enc));
629 RSYMBOL(dsym)->id =
type;
633 RSYMBOL(dsym)->hashval = RSHIFT((
long)hashval, 1);
634 register_sym(symbols, str, dsym);
635 rb_hash_aset(symbols->dsymbol_fstr_hash, str,
Qtrue);
636 RUBY_DTRACE_CREATE_HOOK(SYMBOL,
RSTRING_PTR(RSYMBOL(dsym)->fstr));
646 if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
647 const VALUE fstr = RSYMBOL(sym)->fstr;
648 const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
649 RSYMBOL(sym)->fstr = 0;
650 unregister_sym(symbols, fstr, sym);
651 return dsymbol_alloc(symbols,
rb_cSymbol, fstr, rb_enc_get(fstr),
type);
659lookup_str_id(
VALUE str)
664 GLOBAL_SYMBOLS_ENTER(symbols);
666 found = st_lookup(symbols->str_sym, (st_data_t)str, &sym_data);
668 GLOBAL_SYMBOLS_LEAVE();
674 return STATIC_SYM2ID(sym);
677 ID id = RSYMBOL(sym)->id;
678 if (
id & ~ID_SCOPE_MASK)
return id;
681 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
682 rb_builtin_class_name(sym), sym, str);
692 if (st_lookup(symbols->str_sym, (st_data_t)str, &sym_data)) {
695 sym = dsymbol_check(symbols, sym);
705lookup_str_sym(
const VALUE str)
709 GLOBAL_SYMBOLS_ENTER(symbols);
711 sym = lookup_str_sym_with_lock(symbols, str);
713 GLOBAL_SYMBOLS_LEAVE();
721 return get_id_entry(
id, ID_ENTRY_STR);
729 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
731 sym = lookup_str_sym(str);
734 return intern_str(str, 1);
741 rb_id_serial_t next_serial = symbols->last_id + 1;
743 if (next_serial == 0) {
747 const size_t num = ++symbols->last_id;
748 id = num << ID_SCOPE_SHIFT;
758 GLOBAL_SYMBOLS_ENTER(symbols);
760 id = next_id_base_with_lock(symbols);
762 GLOBAL_SYMBOLS_LEAVE();
767intern_str(
VALUE str,
int mutable)
772 id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
773 if (
id == (
ID)-1)
id = ID_JUNK;
774 if (sym_check_asciionly(str,
false)) {
776 rb_enc_associate(str, rb_usascii_encoding());
778 if ((nid = next_id_base()) == (
ID)-1) {
785 return register_static_symid_str(
id, str);
804 VALUE sym = lookup_str_sym(str);
810 return intern_str(str, 0);
814rb_gc_free_dsymbol(
VALUE sym)
816 VALUE str = RSYMBOL(sym)->fstr;
819 RSYMBOL(sym)->fstr = 0;
821 GLOBAL_SYMBOLS_ENTER(symbols);
823 unregister_sym(symbols, str, sym);
824 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, str);
826 GLOBAL_SYMBOLS_LEAVE();
855 GLOBAL_SYMBOLS_ENTER(symbols);
857 sym = lookup_str_sym_with_lock(symbols, str);
862 else if (USE_SYMBOL_GC) {
865 if (enc != ascii && sym_check_asciionly(str,
false)) {
867 rb_enc_associate(str, ascii);
875 str = rb_fstring(str);
876 int type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
881 ID id = intern_str(str, 0);
885 GLOBAL_SYMBOLS_LEAVE();
894 id = STATIC_SYM2ID(sym);
897 GLOBAL_SYMBOLS_ENTER(symbols);
899 sym = dsymbol_check(symbols, sym);
900 id = RSYMBOL(sym)->id;
902 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
903 VALUE fstr = RSYMBOL(sym)->fstr;
904 ID num = next_id_base_with_lock(symbols);
906 RSYMBOL(sym)->id =
id |= num;
909 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
910 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
913 GLOBAL_SYMBOLS_LEAVE();
917 rb_builtin_class_name(sym));
926 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
927 return get_id_entry(x, ID_ENTRY_SYM);
946 return RSYMBOL(sym)->fstr;
949 return rb_id2str(STATIC_SYM2ID(sym));
956 return lookup_id_str(
id);
962 VALUE str = rb_id2str(
id);
969rb_make_internal_id(
void)
971 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
975rb_make_temporary_id(
size_t n)
977 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
978 const ID id = max_id - (
ID)n;
979 if (
id <= ruby_global_symbols.last_id) {
982 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
986symbols_i(st_data_t key, st_data_t value, st_data_t arg)
992 rb_ary_push(
ary, sym);
998 else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
999 RSYMBOL(sym)->fstr = 0;
1003 rb_ary_push(
ary, sym);
1014 GLOBAL_SYMBOLS_ENTER(symbols);
1017 st_foreach(symbols->str_sym, symbols_i,
ary);
1019 GLOBAL_SYMBOLS_LEAVE();
1025rb_sym_immortal_count(
void)
1027 return (
size_t)ruby_global_symbols.last_id;
1033 return is_const_id(
id);
1039 return is_class_id(
id);
1045 return is_global_id(
id);
1051 return is_instance_id(
id);
1057 return is_attrset_id(
id);
1063 return is_local_id(
id);
1069 return is_junk_id(
id);
1073rb_is_const_sym(
VALUE sym)
1075 return is_const_sym(sym);
1079rb_is_attrset_sym(
VALUE sym)
1081 return is_attrset_sym(sym);
1088 VALUE name = *namep;
1091 return STATIC_SYM2ID(name);
1094 if (SYMBOL_PINNED_P(name)) {
1095 return RSYMBOL(name)->id;
1098 *namep = RSYMBOL(name)->fstr;
1112 sym_check_asciionly(name,
false);
1114 return lookup_str_id(name);
1119rb_get_symbol_id(
VALUE name)
1122 return STATIC_SYM2ID(name);
1125 if (SYMBOL_PINNED_P(name)) {
1126 return RSYMBOL(name)->id;
1134 return lookup_str_id(name);
1144 VALUE name = *namep;
1150 if (!SYMBOL_PINNED_P(name)) {
1151 GLOBAL_SYMBOLS_ENTER(symbols);
1153 name = dsymbol_check(symbols, name);
1155 GLOBAL_SYMBOLS_LEAVE();
1171 sym_check_asciionly(name,
false);
1173 if ((sym = lookup_str_sym(name)) != 0) {
1184 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1186 sym_check_asciionly(name,
true);
1188 return lookup_str_id(name);
1196 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1198 sym_check_asciionly(name,
true);
1200 if ((sym = lookup_str_sym(name)) != 0) {
1207#undef rb_sym_intern_ascii_cstr
1212FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii(
const char *
ptr,
long len));
1213FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii_cstr(
const char *
ptr));
1220 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1225rb_sym_intern_ascii(
const char *
ptr,
long len)
1227 return rb_sym_intern(
ptr,
len, rb_usascii_encoding());
1231rb_sym_intern_ascii_cstr(
const char *
ptr)
1233 return rb_sym_intern_ascii(
ptr, strlen(
ptr));
1237rb_to_symbol_type(
VALUE obj)
1239 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1243rb_is_const_name(
VALUE name)
1245 return rb_str_symname_type(name, 0) == ID_CONST;
1249rb_is_class_name(
VALUE name)
1251 return rb_str_symname_type(name, 0) == ID_CLASS;
1255rb_is_instance_name(
VALUE name)
1257 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1261rb_is_local_name(
VALUE name)
1263 return rb_str_symname_type(name, 0) == ID_LOCAL;
1266#include "id_table.c"
1267#include "symbol.rbinc"
#define RUBY_ASSERT_ALWAYS(expr)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
static bool rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isupper(), except it additionally takes an encoding.
static bool rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc)
Queries if the passed code point is of passed character type in the passed encoding.
static bool rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
Identical to rb_islower(), except it additionally takes an encoding.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define T_STRING
Old name of RUBY_T_STRING.
#define ISUPPER
Old name of rb_isupper.
#define ID2SYM
Old name of RB_ID2SYM.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define SYM2ID
Old name of RB_SYM2ID.
#define ISDIGIT
Old name of rb_isdigit.
#define STATIC_SYM_P
Old name of RB_STATIC_SYM_P.
#define MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
#define ISALPHA
Old name of rb_isalpha.
#define ISASCII
Old name of rb_isascii.
#define Qtrue
Old name of RUBY_Qtrue.
#define DYNAMIC_SYM_P
Old name of RB_DYNAMIC_SYM_P.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define ENC_CODERANGE_BROKEN
Old name of RUBY_ENC_CODERANGE_BROKEN.
#define NIL_P
Old name of RB_NIL_P.
#define MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
#define FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ISALNUM
Old name of rb_isalnum.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
VALUE rb_eTypeError
TypeError exception.
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
void rb_fatal(const char *fmt,...)
Raises the unsung "fatal" exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eEncodingError
EncodingError exception.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_cSymbol
Sumbol class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
static bool rb_enc_asciicompat(rb_encoding *enc)
Queries if the passed encoding is in some sense compatible with ASCII.
static OnigCodePoint rb_enc_mbc_to_codepoint(const char *p, const char *e, rb_encoding *enc)
Identical to rb_enc_codepoint(), except it assumes the passed character is not broken.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it additionally takes an encoding.
int rb_enc_symname_p(const char *str, rb_encoding *enc)
Identical to rb_symname_p(), except it additionally takes an encoding.
ID rb_intern3(const char *name, long len, rb_encoding *enc)
Identical to rb_intern2(), except it additionally takes an encoding.
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id_cstr(), except for the return type.
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
Identical to rb_enc_symname_p(), except it additionally takes the passed string's length.
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id(), except it takes a pointer to a memory region instead of Ruby's string.
VALUE rb_sym_all_symbols(void)
Collects every single bits of symbols that have ever interned in the entire history of the current pr...
int rb_is_global_id(ID id)
Classifies the given ID, then sees if it is a global variable.
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
int rb_is_junk_id(ID)
Classifies the given ID, then sees if it is a junk ID.
int rb_symname_p(const char *str)
Sees if the passed C string constructs a valid syntactic symbol.
ID rb_id_attrset(ID id)
Calculates an ID of attribute writer.
int rb_is_class_id(ID id)
Classifies the given ID, then sees if it is a class variable.
int rb_is_attrset_id(ID id)
Classifies the given ID, then sees if it is an attribute writer.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
int rb_str_hash_cmp(VALUE str1, VALUE str2)
Compares two strings.
VALUE rb_str_ellipsize(VALUE str, long len)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
ID rb_intern2(const char *name, long len)
Identical to rb_intern(), except it additionally takes the length of the string.
VALUE rb_check_symbol(volatile VALUE *namep)
Identical to rb_check_id(), except it returns an instance of rb_cSymbol instead.
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
const char * rb_id2name(ID id)
Retrieves the name mapped to the given id.
ID rb_intern_str(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RARRAY_LEN
Just another name of rb_array_len.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
long len
Length of the string, not including terminating NUL character.
char ary[RSTRING_EMBED_LEN_MAX+1]
When a string is short enough, it uses this area to store the contents themselves.
char * ptr
Pointer to the contents of the string.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.