13#include "internal/error.h"
14#include "internal/gc.h"
15#include "internal/hash.h"
16#include "internal/object.h"
17#include "internal/symbol.h"
18#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
34#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
36# define SYMBOL_DEBUG 1
39# define SYMBOL_DEBUG 0
41#ifndef CHECK_ID_SERIAL
42# define CHECK_ID_SERIAL SYMBOL_DEBUG
45#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
47#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
50static ID register_static_symid_str(
ID,
VALUE);
51#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
54#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
56#define op_tbl_count numberof(op_tbl)
57STATIC_ASSERT(op_tbl_name_size,
sizeof(op_tbl[0].name) == 3);
58#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
66 for (i =
'!'; i <=
'~'; ++i) {
69 register_static_symid(i, &c, 1, enc);
72 for (i = 0; i < op_tbl_count; ++i) {
73 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
77static const int ID_ENTRY_UNIT = 512;
97 VALUE dsym_fstrs = rb_ident_hash_new();
98 symbols->dsymbol_fstr_hash = dsym_fstrs;
101 symbols->str_sym = st_init_table_with_size(&symhash, 1000);
109rb_sym_global_symbols_mark(
void)
113 rb_gc_mark_movable(symbols->ids);
114 rb_gc_mark_movable(symbols->dsymbol_fstr_hash);
118rb_sym_global_symbols_update_references(
void)
122 symbols->ids = rb_gc_location(symbols->ids);
123 symbols->dsymbol_fstr_hash = rb_gc_location(symbols->dsymbol_fstr_hash);
128WARN_UNUSED_RESULT(
static ID lookup_str_id(
VALUE str));
130WARN_UNUSED_RESULT(
static VALUE lookup_str_sym(
const VALUE str));
131WARN_UNUSED_RESULT(
static VALUE lookup_id_str(
ID id));
132WARN_UNUSED_RESULT(
static ID intern_str(
VALUE str,
int mutable));
134#define GLOBAL_SYMBOLS_LOCKING(symbols) \
135 for (rb_symbols_t *symbols = &ruby_global_symbols, **locking = &symbols; \
146 if (!is_notop_id(
id)) {
148 case tAREF:
case tASET:
151 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
157 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
158 case ID_CONST:
case ID_CLASS:
case ID_JUNK:
164 if ((str = lookup_id_str(
id)) != 0) {
165 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
177 if (!(str = lookup_id_str(
id))) {
178 RBIMPL_ATTR_NONSTRING_ARRAY()
static const char id_types[][8] = {
188 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
189 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
193 sym = lookup_str_sym(str);
194 id = sym ?
rb_sym2id(sym) : intern_str(str, 1);
199is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
203 if (m >= e)
return 0;
204 if (is_global_name_punct(*m)) {
207 else if (*m ==
'-') {
208 if (++m >= e)
return 0;
209 if (is_identchar(m, e, enc)) {
211 m += rb_enc_mbclen(m, e, enc);
219 }
while (m < e &&
ISDIGIT(*m));
221 return m == e ? mb + 1 : 0;
237rb_sym_constant_char_p(
const char *name,
long nlen,
rb_encoding *enc)
240 const char *end = name + nlen;
242 if (nlen < 1)
return FALSE;
244 c = rb_enc_precise_mbclen(name, end, enc);
247 c = rb_enc_mbc_to_codepoint(name, end, enc);
250 if (ONIGENC_IS_UNICODE(enc)) {
251 static int ctype_titlecase = 0;
252 if (!ctype_titlecase) {
253 static const UChar cname[] =
"titlecaseletter";
254 static const UChar *
const end = cname +
sizeof(cname) - 1;
255 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
261 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
262 const OnigUChar *beg = (
const OnigUChar *)name;
263 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
264 &beg, (
const OnigUChar *)end,
266 if (r > 0 && (r !=
len || memcmp(fold, name, r)))
272#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
273#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
276 const enum { invalid, stophere, needmore, } kind;
277 const enum ruby_id_types type;
281#define t struct enc_synmane_type_leading_chars_tag
284enc_synmane_type_leading_chars(const char *name,
long len,
rb_encoding *enc,
int allowed_attrset)
286 const char *m = name;
287 const char *e = m +
len;
289 if (! rb_enc_asciicompat(enc)) {
290 return (t) { invalid, 0, 0, };
293 return (t) { invalid, 0, 0, };
295 else if (
len <= 0 ) {
296 return (t) { invalid, 0, 0, };
300 return (t) { invalid, 0, 0, };
303 if (is_special_global_name(++m, e, enc)) {
304 return (t) { stophere, ID_GLOBAL,
len, };
307 return (t) { needmore, ID_GLOBAL, 1, };
312 default:
return (t) { needmore, ID_INSTANCE, 1, };
313 case '@':
return (t) { needmore, ID_CLASS, 2, };
318 default:
return (t) { stophere, ID_JUNK, 1, };
319 case '<':
return (t) { stophere, ID_JUNK, 2, };
322 default:
return (t) { stophere, ID_JUNK, 2, };
323 case '>':
return (t) { stophere, ID_JUNK, 3, };
329 default:
return (t) { stophere, ID_JUNK, 1, };
330 case '>':
case '=':
return (t) { stophere, ID_JUNK, 2, };
335 default:
return (t) { invalid, 0, 1, };
336 case '~':
return (t) { stophere, ID_JUNK, 2, };
339 default:
return (t) { stophere, ID_JUNK, 2, };
340 case '=':
return (t) { stophere, ID_JUNK, 3, };
346 default:
return (t) { stophere, ID_JUNK, 1, };
347 case '*':
return (t) { stophere, ID_JUNK, 2, };
352 default:
return (t) { stophere, ID_JUNK, 1, };
353 case '@':
return (t) { stophere, ID_JUNK, 2, };
356 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
357 return (t) { stophere, ID_JUNK, 1, };
361 default:
return (t) { needmore, ID_JUNK, 0, };
364 default:
return (t) { stophere, ID_JUNK, 2, };
365 case '=':
return (t) { stophere, ID_JUNK, 3, };
371 case '=':
case '~':
return (t) { stophere, ID_JUNK, 2, };
373 if (allowed_attrset & (1U << ID_JUNK)) {
374 return (t) { needmore, ID_JUNK, 1, };
377 return (t) { stophere, ID_JUNK, 1, };
382 if (rb_sym_constant_char_p(name,
len, enc)) {
383 return (t) { needmore, ID_CONST, 0, };
386 return (t) { needmore, ID_LOCAL, 0, };
393rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
396 enc_synmane_type_leading_chars(name,
len, enc, allowed_attrset);
397 const char *m = name + f.nread;
398 const char *e = name +
len;
399 int type = (int)f.type;
402 case invalid:
return -1;
403 case stophere:
break;
407 if (
len > 1 && *(e-1) ==
'=') {
408 type = rb_enc_symname_type(name,
len-1, enc, allowed_attrset);
409 if (allowed_attrset & (1U <<
type))
return ID_ATTRSET;
413 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
417 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
420 if (m + 1 < e || *m !=
'=')
break;
423 if (!(allowed_attrset & (1U <<
type)))
return -1;
430 return m == e ?
type : -1;
436 return rb_enc_symname_type(name,
len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
440rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
443 long len = RSTRING_LEN(name);
444 int type = rb_enc_symname_type(ptr,
len, rb_enc_get(name), allowed_attrset);
456 size_t idx = num / ID_ENTRY_UNIT;
458 VALUE ary, ids = symbols->ids;
463 idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
469get_id_serial_entry(rb_id_serial_t num,
ID id,
const enum id_entry_type t)
473 GLOBAL_SYMBOLS_LOCKING(symbols) {
474 if (num && num <= symbols->last_id) {
475 size_t idx = num / ID_ENTRY_UNIT;
476 VALUE ids = symbols->ids;
479 long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
485 else if (CHECK_ID_SERIAL) {
488 if (t != ID_ENTRY_SYM)
491 if (STATIC_SYM2ID(sym) !=
id) result = 0;
494 if (RSYMBOL(sym)->
id !=
id) result = 0;
519get_id_entry(
ID id,
const enum id_entry_type t)
521 return get_id_serial_entry(rb_id_to_serial(
id),
id, t);
525rb_static_id_valid_p(
ID id)
527 return STATIC_ID2SYM(
id) == get_id_entry(
id, ID_ENTRY_SYM);
531rb_id_serial_to_id(rb_id_serial_t num)
533 if (is_notop_id((
ID)num)) {
534 VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
535 if (sym)
return SYM2ID(sym);
536 return ((
ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
544register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
547 rb_fatal(
"symbol :% "PRIsVALUE
" is already registered with %"PRIxVALUE,
560 st_update(symbols->str_sym, (st_data_t)str,
561 register_sym_update_callback, (st_data_t)sym);
564 st_add_direct(symbols->str_sym, (st_data_t)str, (st_data_t)sym);
569rb_free_static_symid_str(
void)
571 GLOBAL_SYMBOLS_LOCKING(symbols) {
572 st_free_table(symbols->str_sym);
581 st_data_t str_data = (st_data_t)str;
582 if (!st_delete(symbols->str_sym, &str_data, NULL)) {
583 rb_bug(
"%p can't remove str from str_id (%s)", (
void *)sym, RSTRING_PTR(str));
590 VALUE str = rb_enc_str_new(name,
len, enc);
591 return register_static_symid_str(
id, str);
595register_static_symid_str(
ID id,
VALUE str)
597 rb_id_serial_t num = rb_id_to_serial(
id);
598 VALUE sym = STATIC_ID2SYM(
id);
601 str = rb_fstring(str);
603 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
605 GLOBAL_SYMBOLS_LOCKING(symbols) {
606 register_sym(symbols, str, sym);
607 set_id_entry(symbols, num, str, sym);
614sym_check_asciionly(
VALUE str,
bool fake_str)
616 if (!rb_enc_asciicompat(rb_enc_get(str)))
return FALSE;
620 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
623 rb_enc_name(rb_enc_get(str)), str);
638must_be_dynamic_symbol(
VALUE x)
645 rb_bug(
"wrong argument: %s (inappropriate Symbol)", RSTRING_PTR(str));
648 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
652 rb_bug(
"wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
667 rb_enc_set_index((
VALUE)obj, rb_enc_to_index(enc));
674 obj->hashval = RSHIFT((
long)hashval, 1);
675 register_sym(symbols, str, (
VALUE)obj);
676 rb_hash_aset(symbols->dsymbol_fstr_hash, str,
Qtrue);
677 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
687 if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
688 const VALUE fstr = RSYMBOL(sym)->fstr;
689 const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
690 RSYMBOL(sym)->fstr = 0;
691 unregister_sym(symbols, fstr, sym);
692 return dsymbol_alloc(symbols,
rb_cSymbol, fstr, rb_enc_get(fstr),
type);
700lookup_str_id(
VALUE str)
705 GLOBAL_SYMBOLS_LOCKING(symbols) {
706 found = st_lookup(symbols->str_sym, (st_data_t)str, &sym_data);
713 return STATIC_SYM2ID(sym);
716 ID id = RSYMBOL(sym)->id;
717 if (
id & ~ID_SCOPE_MASK)
return id;
720 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
721 rb_builtin_class_name(sym), sym, str);
731 if (st_lookup(symbols->str_sym, (st_data_t)str, &sym_data)) {
734 sym = dsymbol_check(symbols, sym);
744lookup_str_sym(
const VALUE str)
748 GLOBAL_SYMBOLS_LOCKING(symbols) {
749 sym = lookup_str_sym_with_lock(symbols, str);
758 return get_id_entry(
id, ID_ENTRY_STR);
766 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
768 sym = lookup_str_sym(str);
770 str = rb_enc_str_new(name,
len, enc);
771 return intern_str(str, 1);
778 rb_id_serial_t next_serial = symbols->last_id + 1;
780 if (next_serial == 0) {
784 const size_t num = ++symbols->last_id;
785 id = num << ID_SCOPE_SHIFT;
795 GLOBAL_SYMBOLS_LOCKING(symbols) {
796 id = next_id_base_with_lock(symbols);
802intern_str(
VALUE str,
int mutable)
807 id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
808 if (
id == (
ID)-1)
id = ID_JUNK;
809 if (sym_check_asciionly(str,
false)) {
811 rb_enc_associate(str, rb_usascii_encoding());
813 if ((nid = next_id_base()) == (
ID)-1) {
820 return register_static_symid_str(
id, str);
824rb_intern2(
const char *name,
long len)
826 return rb_intern3(name,
len, rb_usascii_encoding());
831rb_intern(
const char *name)
833 return rb_intern2(name, strlen(name));
839 VALUE sym = lookup_str_sym(str);
845 return intern_str(str, 0);
849rb_gc_free_dsymbol(
VALUE sym)
851 VALUE str = RSYMBOL(sym)->fstr;
854 RSYMBOL(sym)->fstr = 0;
856 GLOBAL_SYMBOLS_LOCKING(symbols) {
857 unregister_sym(symbols, str, sym);
858 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, str);
888 GLOBAL_SYMBOLS_LOCKING(symbols) {
889 sym = lookup_str_sym_with_lock(symbols, str);
894 else if (USE_SYMBOL_GC) {
897 if (enc != ascii && sym_check_asciionly(str,
false)) {
899 rb_enc_associate(str, ascii);
907 str = rb_fstring(str);
908 int type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
913 ID id = intern_str(str, 0);
925 id = STATIC_SYM2ID(sym);
928 GLOBAL_SYMBOLS_LOCKING(symbols) {
929 sym = dsymbol_check(symbols, sym);
930 id = RSYMBOL(sym)->id;
932 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
933 VALUE fstr = RSYMBOL(sym)->fstr;
934 ID num = next_id_base_with_lock(symbols);
936 RSYMBOL(sym)->id =
id |= num;
939 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
940 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
945 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Symbol)",
946 rb_builtin_class_name(sym));
955 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
956 return get_id_entry(x, ID_ENTRY_SYM);
976 str = RSYMBOL(sym)->fstr;
980 str = rb_id2str(STATIC_SYM2ID(sym));
990 return lookup_id_str(
id);
996 VALUE str = rb_id2str(
id);
999 return RSTRING_PTR(str);
1003rb_make_internal_id(
void)
1005 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1009rb_make_temporary_id(
size_t n)
1011 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1012 const ID id = max_id - (
ID)n;
1013 if (
id <= ruby_global_symbols.last_id) {
1016 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1020symbols_i(st_data_t key, st_data_t value, st_data_t arg)
1030 rb_bug(
"invalid symbol: %s", RSTRING_PTR((
VALUE)key));
1032 else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
1033 RSYMBOL(sym)->fstr = 0;
1048 GLOBAL_SYMBOLS_LOCKING(symbols) {
1050 st_foreach(symbols->str_sym, symbols_i, ary);
1057rb_sym_immortal_count(
void)
1059 return (
size_t)ruby_global_symbols.last_id;
1065 return is_const_id(
id);
1071 return is_class_id(
id);
1077 return is_global_id(
id);
1083 return is_instance_id(
id);
1089 return is_attrset_id(
id);
1095 return is_local_id(
id);
1101 return is_junk_id(
id);
1105rb_is_const_sym(
VALUE sym)
1107 return is_const_sym(sym);
1111rb_is_attrset_sym(
VALUE sym)
1113 return is_attrset_sym(sym);
1120 VALUE name = *namep;
1123 return STATIC_SYM2ID(name);
1126 if (SYMBOL_PINNED_P(name)) {
1127 return RSYMBOL(name)->id;
1130 *namep = RSYMBOL(name)->fstr;
1137 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1144 sym_check_asciionly(name,
false);
1146 return lookup_str_id(name);
1151rb_get_symbol_id(
VALUE name)
1154 return STATIC_SYM2ID(name);
1157 if (SYMBOL_PINNED_P(name)) {
1158 return RSYMBOL(name)->id;
1165 return lookup_str_id(name);
1178 VALUE name = *namep;
1184 if (!SYMBOL_PINNED_P(name)) {
1185 GLOBAL_SYMBOLS_LOCKING(symbols) {
1186 name = dsymbol_check(symbols, name);
1196 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1203 sym_check_asciionly(name,
false);
1205 if ((sym = lookup_str_sym(name)) != 0) {
1216 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1218 sym_check_asciionly(name,
true);
1220 return lookup_str_id(name);
1228 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1230 sym_check_asciionly(name,
true);
1232 if ((sym = lookup_str_sym(name)) != 0) {
1239#undef rb_sym_intern_ascii_cstr
1244FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii(
const char *
ptr,
long len));
1245FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii_cstr(
const char *
ptr));
1252 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1257rb_sym_intern_ascii(
const char *
ptr,
long len)
1259 return rb_sym_intern(
ptr,
len, rb_usascii_encoding());
1263rb_sym_intern_ascii_cstr(
const char *
ptr)
1265 return rb_sym_intern_ascii(
ptr, strlen(
ptr));
1269rb_to_symbol_type(
VALUE obj)
1271 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1275rb_is_const_name(
VALUE name)
1277 return rb_str_symname_type(name, 0) == ID_CONST;
1281rb_is_class_name(
VALUE name)
1283 return rb_str_symname_type(name, 0) == ID_CLASS;
1287rb_is_instance_name(
VALUE name)
1289 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1293rb_is_local_name(
VALUE name)
1295 return rb_str_symname_type(name, 0) == ID_LOCAL;
1298#include "id_table.c"
1299#include "symbol.rbinc"
#define RUBY_ASSERT_BUILTIN_TYPE(obj, type)
A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or built-in type of obj is type.
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_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.
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
Symbol class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
int rb_enc_symname_p(const char *str, rb_encoding *enc)
Identical to rb_symname_p(), 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.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
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.
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.
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.
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
int len
Length of the buffer.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
Defines RBIMPL_ATTR_NONSTRING.
#define RARRAY_LEN
Just another name of rb_array_len.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
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.