14#include "internal/concurrent_set.h"
15#include "internal/error.h"
16#include "internal/gc.h"
17#include "internal/hash.h"
18#include "internal/object.h"
19#include "internal/symbol.h"
20#include "internal/vm.h"
30#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
32# define USE_SYMBOL_GC 0
35# define USE_SYMBOL_GC 1
37#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
39# define SYMBOL_DEBUG 1
42# define SYMBOL_DEBUG 0
44#ifndef CHECK_ID_SERIAL
45# define CHECK_ID_SERIAL SYMBOL_DEBUG
48#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
49#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
51#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
53#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
56#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
59#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
61#define op_tbl_count numberof(op_tbl)
62STATIC_ASSERT(op_tbl_name_size,
sizeof(op_tbl[0].name) == 3);
63#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
66#define GLOBAL_SYMBOLS_LOCKING(symbols) \
67 for (rb_symbols_t *symbols = &ruby_global_symbols, **locking = &symbols; \
78 for (i =
'!'; i <=
'~'; ++i) {
81 register_static_symid(i, &c, 1, enc);
84 for (i = 0; i < op_tbl_count; ++i) {
85 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
89static const int ID_ENTRY_UNIT = 512;
107#define SYM_SET_SYM_STATIC_TAG 1
110sym_set_sym_static_p(
VALUE sym)
112 return sym & SYM_SET_SYM_STATIC_TAG;
118 VALUE value = (
VALUE)sym | SYM_SET_SYM_STATIC_TAG;
126sym_set_static_sym_untag(
VALUE sym)
134sym_set_sym_get_str(
VALUE sym)
137 if (sym_set_sym_static_p(sym)) {
138 str = sym_set_static_sym_untag(sym)->str;
142 str = RSYMBOL(sym)->fstr;
151sym_set_hash(
VALUE sym)
153 if (sym_set_sym_static_p(sym)) {
157 return (
VALUE)RSYMBOL(sym)->hashval;
164 return rb_str_hash_cmp(sym_set_sym_get_str(a), sym_set_sym_get_str(b)) ==
false;
173sym_id_entry_list_mark(
void *ptr)
178 rb_darray_foreach(ary, i, entry) {
181 rb_gc_mark(entry->sym);
182 rb_gc_mark_movable(entry->str);
187sym_id_entry_list_free(
void *ptr)
193sym_id_entry_list_memsize(
const void *ptr)
197 return rb_darray_memsize(ary);
201sym_id_entry_list_compact(
void *ptr)
206 rb_darray_foreach(ary, i, entry) {
207 entry->str = rb_gc_location(entry->str);
212 "symbol_id_entry_list",
214 sym_id_entry_list_mark,
215 sym_id_entry_list_free,
216 sym_id_entry_list_memsize,
217 sym_id_entry_list_compact,
223sym_check_asciionly(
VALUE str,
bool fake_str)
225 if (!rb_enc_asciicompat(rb_enc_get(str)))
return FALSE;
229 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
232 rb_enc_name(rb_enc_get(str)), str);
240dup_string_for_create(
VALUE str)
244 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), enc);
247 if (enc != ascii && sym_check_asciionly(str,
false)) {
248 rb_enc_associate(str, ascii);
252 str = rb_fstring(str);
257rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
260 long len = RSTRING_LEN(name);
261 int type = rb_enc_symname_type(ptr,
len, rb_enc_get(name), allowed_attrset);
271 return (
ID)serial << ID_SCOPE_SHIFT;
281 size_t idx = num / ID_ENTRY_UNIT;
283 VALUE id_entry_list, ids = symbols->ids;
286 rb_darray_make(&entries, ID_ENTRY_UNIT);
291 entries = RTYPEDDATA_GET_DATA(id_entry_list);
294 idx = num % ID_ENTRY_UNIT;
295 struct sym_id_entry *entry = rb_darray_ref(entries, idx);
304sym_set_create(
VALUE sym,
void *data)
306 bool create_dynamic_symbol = (bool)data;
310 VALUE str = dup_string_for_create(static_sym_entry->str);
312 if (create_dynamic_symbol) {
316 rb_enc_set_index((
VALUE)obj, rb_enc_to_index(enc));
318 RB_OBJ_SET_FROZEN_SHAREABLE((
VALUE)obj);
320 int id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
321 if (
id < 0)
id = ID_INTERNAL;
325 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
331 new_static_sym_entry->str = str;
333 VALUE static_sym = static_sym_entry->sym;
334 if (static_sym == 0) {
335 ID id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
336 if (
id == (
ID)-1)
id = ID_INTERNAL;
338 id |= next_id_base();
341 static_sym = STATIC_ID2SYM(
id);
343 new_static_sym_entry->sym = static_sym;
346 set_id_entry(&ruby_global_symbols, rb_id_to_serial(STATIC_SYM2ID(static_sym)), str, static_sym);
349 return sym_set_static_sym_tag(new_static_sym_entry);
354sym_set_free(
VALUE sym)
356 if (sym_set_sym_static_p(sym)) {
357 xfree(sym_set_static_sym_untag(sym));
362 .hash = sym_set_hash,
364 .create = sym_set_create,
365 .free = sym_set_free,
369sym_set_entry_to_sym(
VALUE entry)
371 if (sym_set_sym_static_p(entry)) {
374 if (!
STATIC_SYM_P(sym_set_static_sym_untag(entry)->sym)) rb_bug(
"not sym");
376 return sym_set_static_sym_untag(entry)->sym;
392 return sym_set_entry_to_sym(
393 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
true)
403 return sym_set_entry_to_sym(
404 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
false)
412 .sym = STATIC_ID2SYM(
id),
415 return sym_set_entry_to_sym(
416 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
false)
425 symbols->sym_set = rb_concurrent_set_new(&sym_set_funcs, 1024);
433rb_sym_global_symbols_mark_and_move(
void)
437 rb_gc_mark_and_move(&symbols->sym_set);
438 rb_gc_mark_and_move(&symbols->ids);
442rb_free_global_symbol_table_i(
VALUE *sym_ptr,
void *data)
444 sym_set_free(*sym_ptr);
450rb_free_global_symbol_table(
void)
452 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_free_global_symbol_table_i, NULL);
455WARN_UNUSED_RESULT(
static ID lookup_str_id(
VALUE str));
456WARN_UNUSED_RESULT(
static VALUE get_id_str(
ID id));
463 if (!is_notop_id(
id)) {
465 case tAREF:
case tASET:
468 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
474 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
475 case ID_CONST:
case ID_CLASS:
case ID_INTERNAL:
481 VALUE str = get_id_str(
id);
483 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
496 VALUE str = get_id_str(
id);
500 if (sym_check_asciionly(str,
false)) {
501 rb_enc_associate(str, rb_usascii_encoding());
504 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
512 RBIMPL_ATTR_NONSTRING_ARRAY()
static const char id_types[][8] = {
522 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
523 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
530is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
534 if (m >= e)
return 0;
535 if (is_global_name_punct(*m)) {
538 else if (*m ==
'-') {
539 if (++m >= e)
return 0;
540 if (is_identchar(m, e, enc)) {
542 m += rb_enc_mbclen(m, e, enc);
550 }
while (m < e &&
ISDIGIT(*m));
552 return m == e ? mb + 1 : 0;
568rb_sym_constant_char_p(
const char *name,
long nlen,
rb_encoding *enc)
571 const char *end = name + nlen;
573 if (nlen < 1)
return FALSE;
575 c = rb_enc_precise_mbclen(name, end, enc);
578 c = rb_enc_mbc_to_codepoint(name, end, enc);
581 if (ONIGENC_IS_UNICODE(enc)) {
582 static int ctype_titlecase = 0;
583 if (!ctype_titlecase) {
584 static const UChar cname[] =
"titlecaseletter";
585 static const UChar *
const end = cname +
sizeof(cname) - 1;
586 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
592 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
593 const OnigUChar *beg = (
const OnigUChar *)name;
594 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
595 &beg, (
const OnigUChar *)end,
597 if (r > 0 && (r !=
len || memcmp(fold, name, r)))
604 const enum { invalid, stophere, needmore, } kind;
605 const enum ruby_id_types
type;
609#define t struct enc_synmane_type_leading_chars_tag
612enc_synmane_type_leading_chars(const char *name,
long len,
rb_encoding *enc,
int allowed_attrset)
614 const char *m = name;
615 const char *e = m +
len;
617 if (! rb_enc_asciicompat(enc)) {
618 return (t) { invalid, 0, 0, };
621 return (t) { invalid, 0, 0, };
623 else if (
len <= 0 ) {
624 return (t) { invalid, 0, 0, };
628 return (t) { invalid, 0, 0, };
631 if (is_special_global_name(++m, e, enc)) {
632 return (t) { stophere, ID_GLOBAL,
len, };
635 return (t) { needmore, ID_GLOBAL, 1, };
640 default:
return (t) { needmore, ID_INSTANCE, 1, };
641 case '@':
return (t) { needmore, ID_CLASS, 2, };
646 default:
return (t) { stophere, ID_INTERNAL, 1, };
647 case '<':
return (t) { stophere, ID_INTERNAL, 2, };
650 default:
return (t) { stophere, ID_INTERNAL, 2, };
651 case '>':
return (t) { stophere, ID_INTERNAL, 3, };
657 default:
return (t) { stophere, ID_INTERNAL, 1, };
658 case '>':
case '=':
return (t) { stophere, ID_INTERNAL, 2, };
663 default:
return (t) { invalid, 0, 1, };
664 case '~':
return (t) { stophere, ID_INTERNAL, 2, };
667 default:
return (t) { stophere, ID_INTERNAL, 2, };
668 case '=':
return (t) { stophere, ID_INTERNAL, 3, };
674 default:
return (t) { stophere, ID_INTERNAL, 1, };
675 case '*':
return (t) { stophere, ID_INTERNAL, 2, };
680 default:
return (t) { stophere, ID_INTERNAL, 1, };
681 case '@':
return (t) { stophere, ID_INTERNAL, 2, };
684 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
685 return (t) { stophere, ID_INTERNAL, 1, };
689 default:
return (t) { needmore, ID_INTERNAL, 0, };
692 default:
return (t) { stophere, ID_INTERNAL, 2, };
693 case '=':
return (t) { stophere, ID_INTERNAL, 3, };
699 case '=':
case '~':
return (t) { stophere, ID_INTERNAL, 2, };
701 if (allowed_attrset & (1U << ID_INTERNAL)) {
702 return (t) { needmore, ID_INTERNAL, 1, };
705 return (t) { stophere, ID_INTERNAL, 1, };
710 if (rb_sym_constant_char_p(name,
len, enc)) {
711 return (t) { needmore, ID_CONST, 0, };
714 return (t) { needmore, ID_LOCAL, 0, };
721rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
724 enc_synmane_type_leading_chars(name,
len, enc, allowed_attrset);
725 const char *m = name + f.nread;
726 const char *e = name +
len;
727 int type = (int)f.type;
730 case invalid:
return -1;
731 case stophere:
break;
735 if (
len > 1 && *(e-1) ==
'=') {
736 type = rb_enc_symname_type(name,
len-1, enc, allowed_attrset);
737 if (allowed_attrset & (1U <<
type))
return ID_ATTRSET;
741 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
745 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
748 if (m + 1 < e || *m !=
'=')
break;
751 if (!(allowed_attrset & (1U <<
type)))
return -1;
758 return m == e ?
type : -1;
764 return rb_enc_symname_type(name,
len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
768get_id_serial_entry(rb_id_serial_t num)
772 GLOBAL_SYMBOLS_LOCKING(symbols) {
774 size_t idx = num / ID_ENTRY_UNIT;
775 VALUE ids = symbols->ids;
778 rb_darray(
struct sym_id_entry) entries = RTYPEDDATA_GET_DATA(id_entry_list);
780 size_t pos = (size_t)(num % ID_ENTRY_UNIT);
782 entry = rb_darray_ref(entries, pos);
793 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(
id));
794 return entry ? entry->sym : 0;
800 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(
id));
801 return entry ? entry->str : 0;
805rb_static_id_valid_p(
ID id)
807 return STATIC_ID2SYM(
id) == get_id_sym(
id);
811rb_id_serial_to_id(rb_id_serial_t num)
813 if (is_notop_id((
ID)num)) {
815 if (entry && entry->sym != 0) {
816 return SYM2ID(entry->sym);
819 return ((
ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
830 VALUE str = rb_enc_str_new(name,
len, enc);
832 str = rb_fstring(str);
834 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
836 sym_find_or_insert_static_symbol_id(&ruby_global_symbols, str,
id);
849 sym = rb_concurrent_set_find(&ruby_global_symbols.sym_set, sym_set_static_sym_tag(&static_sym));
852 return sym_set_entry_to_sym(sym);
860lookup_str_id(
VALUE str)
862 VALUE sym = sym_find(str);
869 return STATIC_SYM2ID(sym);
872 ID id = RSYMBOL(sym)->id;
873 if (
id & ~ID_SCOPE_MASK)
return id;
876 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
877 rb_builtin_class_name(sym), sym, str);
886 struct RString fake_str = {RBASIC_INIT};
887 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
890 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
895rb_intern2(
const char *name,
long len)
897 return rb_intern3(name,
len, rb_usascii_encoding());
902rb_intern(
const char *name)
904 return rb_intern2(name, strlen(name));
910 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
915rb_obj_is_symbol_table(
VALUE obj)
917 return obj == ruby_global_symbols.sym_set;
921 int (*callback)(
VALUE *key,
void *data);
926rb_sym_global_symbol_table_foreach_weak_reference_i(
VALUE *key,
void *d)
931 if (sym_set_sym_static_p(sym)) {
934 return data->callback(&static_sym->str, data->data);
937 return data->callback(key, data->data);
942rb_sym_global_symbol_table_foreach_weak_reference(
int (*callback)(
VALUE *key,
void *data),
void *data)
944 if (!ruby_global_symbols.sym_set)
return;
947 .callback = callback,
951 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_sym_global_symbol_table_foreach_weak_reference_i, &foreach_data);
955rb_gc_free_dsymbol(
VALUE sym)
957 VALUE str = RSYMBOL(sym)->fstr;
960 rb_concurrent_set_delete_by_identity(ruby_global_symbols.sym_set, sym);
962 RSYMBOL(sym)->fstr = 0;
977 return sym_find_or_insert_dynamic_symbol(&ruby_global_symbols, str);
985 id = STATIC_SYM2ID(sym);
988 GLOBAL_SYMBOLS_LOCKING(symbols) {
990 id = RSYMBOL(sym)->id;
992 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
993 VALUE fstr = RSYMBOL(sym)->fstr;
994 ID num = next_id_base();
996 RSYMBOL(sym)->id =
id |= num;
999 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
1004 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Symbol)",
1005 rb_builtin_class_name(sym));
1014 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
1015 return get_id_sym(x);
1035 str = RSYMBOL(sym)->fstr;
1039 str = rb_id2str(STATIC_SYM2ID(sym));
1049 return get_id_str(
id);
1055 VALUE str = rb_id2str(
id);
1058 return RSTRING_PTR(str);
1062rb_make_internal_id(
void)
1064 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1068rb_make_temporary_id(
size_t n)
1070 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1071 const ID id = max_id - (
ID)n;
1075 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1079symbols_i(
VALUE *key,
void *data)
1084 if (sym_set_sym_static_p(sym)) {
1085 rb_ary_push(ary, sym_set_static_sym_untag(sym)->sym);
1087 else if (rb_objspace_garbage_object_p(sym)) {
1102 GLOBAL_SYMBOLS_LOCKING(symbols) {
1103 ary =
rb_ary_new2(rb_concurrent_set_size(symbols->sym_set));
1104 rb_concurrent_set_foreach_with_replace(symbols->sym_set, symbols_i, (
void *)ary);
1111rb_sym_immortal_count(
void)
1119 return is_const_id(
id);
1125 return is_class_id(
id);
1131 return is_global_id(
id);
1137 return is_instance_id(
id);
1143 return is_attrset_id(
id);
1149 return is_local_id(
id);
1155 return is_internal_id(
id);
1159rb_is_const_sym(
VALUE sym)
1161 return is_const_sym(sym);
1165rb_is_attrset_sym(
VALUE sym)
1167 return is_attrset_sym(sym);
1174 VALUE name = *namep;
1177 return STATIC_SYM2ID(name);
1180 if (SYMBOL_PINNED_P(name)) {
1181 return RSYMBOL(name)->id;
1184 *namep = RSYMBOL(name)->fstr;
1191 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1198 sym_check_asciionly(name,
false);
1200 return lookup_str_id(name);
1205rb_get_symbol_id(
VALUE name)
1208 return STATIC_SYM2ID(name);
1211 if (SYMBOL_PINNED_P(name)) {
1212 return RSYMBOL(name)->id;
1219 return lookup_str_id(name);
1232 VALUE name = *namep;
1244 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1251 sym_check_asciionly(name,
false);
1253 if ((sym = sym_find(name)) != 0) {
1263 struct RString fake_str = {RBASIC_INIT};
1264 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1266 sym_check_asciionly(name,
true);
1268 return lookup_str_id(name);
1275 struct RString fake_str = {RBASIC_INIT};
1276 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1278 sym_check_asciionly(name,
true);
1280 if ((sym = sym_find(name)) != 0) {
1287#undef rb_sym_intern_ascii_cstr
1292FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii(
const char *
ptr,
long len));
1293FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii_cstr(
const char *
ptr));
1299 struct RString fake_str = {RBASIC_INIT};
1300 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1305rb_sym_intern_ascii(
const char *
ptr,
long len)
1307 return rb_sym_intern(
ptr,
len, rb_usascii_encoding());
1311rb_sym_intern_ascii_cstr(
const char *
ptr)
1313 return rb_sym_intern_ascii(
ptr, strlen(
ptr));
1317rb_to_symbol_type(
VALUE obj)
1319 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1323rb_is_const_name(
VALUE name)
1325 return rb_str_symname_type(name, 0) == ID_CONST;
1329rb_is_class_name(
VALUE name)
1331 return rb_str_symname_type(name, 0) == ID_CLASS;
1335rb_is_instance_name(
VALUE name)
1337 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1341rb_is_local_name(
VALUE name)
1343 return rb_str_symname_type(name, 0) == ID_LOCAL;
1346#include "id_table.c"
1347#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.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
#define RUBY_ATOMIC_FETCH_ADD(var, val)
Atomically replaces the value pointed by var with the result of addition of val to the old value of v...
#define RUBY_ATOMIC_LOAD(var)
Atomic load.
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 xfree
Old name of ruby_xfree.
#define ISUPPER
Old name of rb_isupper.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define SYM2ID
Old name of RB_SYM2ID.
#define xmalloc
Old name of ruby_xmalloc.
#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 DYNAMIC_SYM_P
Old name of RB_DYNAMIC_SYM_P.
#define Qnil
Old name of RUBY_Qnil.
#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 IMMEDIATE_P
Old name of RB_IMMEDIATE_P.
#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_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_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*.
#define RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
char * ptr
Pointer to the contents of the string.
This is the struct that holds necessary info for a struct.
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.