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"
32#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
34# define SYMBOL_DEBUG 1
37# define SYMBOL_DEBUG 0
39#ifndef CHECK_ID_SERIAL
40# define CHECK_ID_SERIAL SYMBOL_DEBUG
43#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
44#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
46#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
49#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
52#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
54#define op_tbl_count numberof(op_tbl)
55STATIC_ASSERT(op_tbl_name_size,
sizeof(op_tbl[0].name) == 3);
56#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
59#define GLOBAL_SYMBOLS_LOCKING(symbols) \
60 for (rb_symbols_t *symbols = &ruby_global_symbols, **locking = &symbols; \
71 for (i =
'!'; i <=
'~'; ++i) {
74 register_static_symid(i, &c, 1, enc);
77 for (i = 0; i < op_tbl_count; ++i) {
78 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
82static const int ID_ENTRY_UNIT = 512;
100#define SYM_SET_SYM_STATIC_TAG 1
103sym_set_sym_static_p(
VALUE sym)
105 return sym & SYM_SET_SYM_STATIC_TAG;
111 VALUE value = (
VALUE)sym | SYM_SET_SYM_STATIC_TAG;
119sym_set_static_sym_untag(
VALUE sym)
127sym_set_sym_get_str(
VALUE sym)
130 if (sym_set_sym_static_p(sym)) {
131 str = sym_set_static_sym_untag(sym)->str;
135 str = RSYMBOL(sym)->fstr;
144sym_set_hash(
VALUE sym)
146 if (sym_set_sym_static_p(sym)) {
150 return (
VALUE)RSYMBOL(sym)->hashval;
157 return rb_str_hash_cmp(sym_set_sym_get_str(a), sym_set_sym_get_str(b)) ==
false;
166sym_id_entry_list_mark(
void *ptr)
171 rb_darray_foreach(ary, i, entry) {
174 rb_gc_mark(entry->sym);
175 rb_gc_mark_movable(entry->str);
180sym_id_entry_list_free(
void *ptr)
186sym_id_entry_list_memsize(
const void *ptr)
190 return rb_darray_memsize(ary);
194sym_id_entry_list_compact(
void *ptr)
199 rb_darray_foreach(ary, i, entry) {
200 rb_gc_update_moved(&entry->str);
205 "symbol_id_entry_list",
207 sym_id_entry_list_mark,
208 sym_id_entry_list_free,
209 sym_id_entry_list_memsize,
210 sym_id_entry_list_compact,
212 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED
223id_entry_dir_mark(
void *ptr)
226 for (
long i = 0; i < dir->capa; i++) {
227 if (dir->entries[i]) {
228 rb_gc_mark_movable(dir->entries[i]);
234id_entry_dir_free(
void *ptr)
237 SIZED_FREE_N(dir->entries, dir->capa);
242id_entry_dir_memsize(
const void *ptr)
249id_entry_dir_compact(
void *ptr)
252 for (
long i = 0; i < dir->capa; i++) {
253 if (dir->entries[i]) {
254 rb_gc_update_moved(&dir->entries[i]);
260 "symbol_id_entry_directory",
264 id_entry_dir_memsize,
265 id_entry_dir_compact,
267 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED
270static const long ID_ENTRY_DIR_INITIAL_CAPA = 16;
273id_entry_dir_new(
long capa)
284sym_check_asciionly(
VALUE str,
bool fake_str)
286 if (!rb_enc_asciicompat(rb_enc_get(str)))
return FALSE;
287 switch (rb_enc_str_coderange(str)) {
290 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
293 rb_enc_name(rb_enc_get(str)), str);
301dup_string_for_create(
VALUE str)
305 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), enc);
308 if (enc != ascii && sym_check_asciionly(str,
false)) {
309 rb_enc_associate(str, ascii);
313 str = rb_fstring(str);
318rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
321 long len = RSTRING_LEN(name);
322 int type = rb_enc_symname_type(ptr,
len, rb_enc_get(name), allowed_attrset);
332 return (
ID)serial << ID_SCOPE_SHIFT;
340 long new_capa = old_dir->capa ? old_dir->capa * 2 : ID_ENTRY_DIR_INITIAL_CAPA;
341 while ((
size_t)new_capa <= min_idx) new_capa *= 2;
345 VALUE new_obj = id_entry_dir_new(new_capa);
346 struct id_entry_dir *new_dir = RTYPEDDATA_GET_DATA(new_obj);
348 memcpy(new_dir->entries, old_dir->entries, old_dir->capa *
sizeof(
VALUE));
349 rb_gc_writebarrier_remember(new_obj);
354 rbimpl_atomic_value_store(&symbols->ids, new_obj, RBIMPL_ATOMIC_RELEASE);
368 size_t idx = num / ID_ENTRY_UNIT;
370 struct id_entry_dir *dir = RTYPEDDATA_GET_DATA(symbols->ids);
371 if (idx >= (
size_t)dir->capa) {
372 dir = id_entry_dir_grow(symbols, dir, idx);
375 VALUE bucket = dir->entries[idx];
378 rb_darray_make(&entries, ID_ENTRY_UNIT);
383 rbimpl_atomic_value_store(&dir->entries[idx], bucket, RBIMPL_ATOMIC_RELEASE);
387 entries = RTYPEDDATA_GET_DATA(bucket);
390 idx = num % ID_ENTRY_UNIT;
391 struct sym_id_entry *entry = rb_darray_ref(entries, idx);
400sym_set_create(
VALUE sym,
void *data)
402 bool create_dynamic_symbol = (bool)data;
406 VALUE str = dup_string_for_create(static_sym_entry->str);
408 if (create_dynamic_symbol) {
412 rb_enc_set_index((
VALUE)obj, rb_enc_to_index(enc));
416 int id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
417 if (
id < 0)
id = ID_INTERNAL;
421 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
427 new_static_sym_entry->str = str;
429 VALUE static_sym = static_sym_entry->sym;
430 if (static_sym == 0) {
431 ID id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
432 if (
id == (
ID)-1)
id = ID_INTERNAL;
434 id |= next_id_base();
437 static_sym = STATIC_ID2SYM(
id);
439 new_static_sym_entry->sym = static_sym;
442 set_id_entry(&ruby_global_symbols, rb_id_to_serial(STATIC_SYM2ID(static_sym)), str, static_sym);
445 return sym_set_static_sym_tag(new_static_sym_entry);
450sym_set_free(
VALUE sym)
452 if (sym_set_sym_static_p(sym)) {
453 xfree(sym_set_static_sym_untag(sym));
458 .hash = sym_set_hash,
460 .create = sym_set_create,
461 .free = sym_set_free,
465sym_set_entry_to_sym(
VALUE entry)
467 if (sym_set_sym_static_p(entry)) {
470 if (!
STATIC_SYM_P(sym_set_static_sym_untag(entry)->sym)) rb_bug(
"not sym");
472 return sym_set_static_sym_untag(entry)->sym;
488 return sym_set_entry_to_sym(
489 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
true)
499 return sym_set_entry_to_sym(
500 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
false)
508 .sym = STATIC_ID2SYM(
id),
511 return sym_set_entry_to_sym(
512 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (
void *)
false)
521 symbols->sym_set = rb_concurrent_set_new(&sym_set_funcs, 1024);
522 symbols->ids = id_entry_dir_new(ID_ENTRY_DIR_INITIAL_CAPA);
529rb_sym_global_symbols_mark_and_move(
void)
533 rb_gc_mark_and_move(&symbols->sym_set);
534 rb_gc_mark_and_move(&symbols->ids);
538rb_free_global_symbol_table_i(
VALUE *sym_ptr,
void *data)
540 sym_set_free(*sym_ptr);
546rb_free_global_symbol_table(
void)
548 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_free_global_symbol_table_i, NULL);
551WARN_UNUSED_RESULT(
static ID lookup_str_id(
VALUE str));
552WARN_UNUSED_RESULT(
static VALUE get_id_str(
ID id));
559 if (!is_notop_id(
id)) {
561 case tAREF:
case tASET:
564 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
570 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
571 case ID_CONST:
case ID_CLASS:
case ID_INTERNAL:
577 VALUE str = get_id_str(
id);
579 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
592 VALUE str = get_id_str(
id);
596 if (sym_check_asciionly(str,
false)) {
597 rb_enc_associate(str, rb_usascii_encoding());
600 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
608 RBIMPL_ATTR_NONSTRING_ARRAY()
static const char id_types[][8] = {
618 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
619 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
626is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
630 if (m >= e)
return 0;
631 if (is_global_name_punct(*m)) {
634 else if (*m ==
'-') {
635 if (++m >= e)
return 0;
636 if (is_identchar(m, e, enc)) {
638 m += rb_enc_mbclen(m, e, enc);
646 }
while (m < e &&
ISDIGIT(*m));
648 return m == e ? mb + 1 : 0;
664rb_sym_constant_char_p(
const char *name,
long nlen,
rb_encoding *enc)
667 const char *end = name + nlen;
669 if (nlen < 1)
return FALSE;
671 c = rb_enc_precise_mbclen(name, end, enc);
674 c = rb_enc_mbc_to_codepoint(name, end, enc);
677 if (ONIGENC_IS_UNICODE(enc)) {
678 static int ctype_titlecase = 0;
679 if (!ctype_titlecase) {
680 static const UChar cname[] =
"titlecaseletter";
681 static const UChar *
const end = cname +
sizeof(cname) - 1;
682 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
688 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
689 const OnigUChar *beg = (
const OnigUChar *)name;
690 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
691 &beg, (
const OnigUChar *)end,
693 if (r > 0 && (r !=
len || memcmp(fold, name, r)))
700 const enum { invalid, stophere, needmore, } kind;
701 const enum ruby_id_types
type;
705#define t struct enc_synmane_type_leading_chars_tag
708enc_synmane_type_leading_chars(const char *name,
long len,
rb_encoding *enc,
int allowed_attrset)
710 const char *m = name;
711 const char *e = m +
len;
713 if (! rb_enc_asciicompat(enc)) {
714 return (t) { invalid, 0, 0, };
717 return (t) { invalid, 0, 0, };
719 else if (
len <= 0 ) {
720 return (t) { invalid, 0, 0, };
724 return (t) { invalid, 0, 0, };
727 if (is_special_global_name(++m, e, enc)) {
728 return (t) { stophere, ID_GLOBAL,
len, };
731 return (t) { needmore, ID_GLOBAL, 1, };
736 default:
return (t) { needmore, ID_INSTANCE, 1, };
737 case '@':
return (t) { needmore, ID_CLASS, 2, };
742 default:
return (t) { stophere, ID_INTERNAL, 1, };
743 case '<':
return (t) { stophere, ID_INTERNAL, 2, };
746 default:
return (t) { stophere, ID_INTERNAL, 2, };
747 case '>':
return (t) { stophere, ID_INTERNAL, 3, };
753 default:
return (t) { stophere, ID_INTERNAL, 1, };
754 case '>':
case '=':
return (t) { stophere, ID_INTERNAL, 2, };
759 default:
return (t) { invalid, 0, 1, };
760 case '~':
return (t) { stophere, ID_INTERNAL, 2, };
763 default:
return (t) { stophere, ID_INTERNAL, 2, };
764 case '=':
return (t) { stophere, ID_INTERNAL, 3, };
770 default:
return (t) { stophere, ID_INTERNAL, 1, };
771 case '*':
return (t) { stophere, ID_INTERNAL, 2, };
776 default:
return (t) { stophere, ID_INTERNAL, 1, };
777 case '@':
return (t) { stophere, ID_INTERNAL, 2, };
780 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
781 return (t) { stophere, ID_INTERNAL, 1, };
785 default:
return (t) { needmore, ID_INTERNAL, 0, };
788 default:
return (t) { stophere, ID_INTERNAL, 2, };
789 case '=':
return (t) { stophere, ID_INTERNAL, 3, };
795 case '=':
case '~':
return (t) { stophere, ID_INTERNAL, 2, };
797 if (allowed_attrset & (1U << ID_INTERNAL)) {
798 return (t) { needmore, ID_INTERNAL, 1, };
801 return (t) { stophere, ID_INTERNAL, 1, };
806 if (rb_sym_constant_char_p(name,
len, enc)) {
807 return (t) { needmore, ID_CONST, 0, };
810 return (t) { needmore, ID_LOCAL, 0, };
817rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
820 enc_synmane_type_leading_chars(name,
len, enc, allowed_attrset);
821 const char *m = name + f.nread;
822 const char *e = name +
len;
823 int type = (int)f.type;
826 case invalid:
return -1;
827 case stophere:
break;
831 if (
len > 1 && *(e-1) ==
'=') {
832 type = rb_enc_symname_type(name,
len-1, enc, allowed_attrset);
833 if (allowed_attrset & (1U <<
type))
return ID_ATTRSET;
837 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
841 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
844 if (m + 1 < e || *m !=
'=')
break;
847 if (!(allowed_attrset & (1U <<
type)))
return -1;
854 return m == e ?
type : -1;
860 return rb_enc_symname_type(name,
len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
864get_id_serial_entry(rb_id_serial_t num)
869 size_t idx = num / ID_ENTRY_UNIT;
871 VALUE dir_obj = rbimpl_atomic_value_load(&ruby_global_symbols.ids, RBIMPL_ATOMIC_ACQUIRE);
872 struct id_entry_dir *dir = RTYPEDDATA_GET_DATA(dir_obj);
874 if (idx < (
size_t)dir->capa) {
875 VALUE bucket = rbimpl_atomic_value_load(&dir->entries[idx], RBIMPL_ATOMIC_ACQUIRE);
877 rb_darray(
struct sym_id_entry) entries = RTYPEDDATA_GET_DATA(bucket);
879 size_t pos = (size_t)(num % ID_ENTRY_UNIT);
881 entry = rb_darray_ref(entries, pos);
894 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(
id));
895 return entry ? entry->sym : 0;
901 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(
id));
902 return entry ? entry->str : 0;
906rb_static_id_valid_p(
ID id)
908 return STATIC_ID2SYM(
id) == get_id_sym(
id);
912rb_id_serial_to_id(rb_id_serial_t num)
914 if (is_notop_id((
ID)num)) {
916 if (entry && entry->sym != 0) {
917 return SYM2ID(entry->sym);
920 return ((
ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
931 VALUE str = rb_enc_str_new(name,
len, enc);
933 str = rb_fstring(str);
935 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
937 sym_find_or_insert_static_symbol_id(&ruby_global_symbols, str,
id);
950 sym = rb_concurrent_set_find(&ruby_global_symbols.sym_set, sym_set_static_sym_tag(&static_sym));
953 return sym_set_entry_to_sym(sym);
962STATIC_ASSERT(value_id_same_width,
sizeof(
VALUE) ==
sizeof(
ID));
964sym_id_load_acquire(
VALUE sym)
966 return (
ID)rbimpl_atomic_value_load((
VALUE *)&RSYMBOL(sym)->
id, RBIMPL_ATOMIC_ACQUIRE);
970lookup_str_id(
VALUE str)
972 VALUE sym = sym_find(str);
979 return STATIC_SYM2ID(sym);
982 ID id = sym_id_load_acquire(sym);
983 if (
id & ~ID_SCOPE_MASK)
return id;
986 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
987 rb_builtin_class_name(sym), sym, str);
996 struct RString fake_str = {RBASIC_INIT};
997 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
1000 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
1005rb_intern2(
const char *name,
long len)
1007 return rb_intern3(name,
len, rb_usascii_encoding());
1012rb_intern(
const char *name)
1014 return rb_intern2(name, strlen(name));
1020 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
1025rb_obj_is_symbol_table(
VALUE obj)
1027 return obj == ruby_global_symbols.sym_set;
1031 int (*callback)(
VALUE *key,
void *data);
1036rb_sym_global_symbol_table_foreach_weak_reference_i(
VALUE *key,
void *d)
1041 if (sym_set_sym_static_p(sym)) {
1044 return data->callback(&static_sym->str, data->data);
1047 return data->callback(key, data->data);
1052rb_sym_global_symbol_table_foreach_weak_reference(
int (*callback)(
VALUE *key,
void *data),
void *data)
1054 if (!ruby_global_symbols.sym_set)
return;
1057 .callback = callback,
1061 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_sym_global_symbol_table_foreach_weak_reference_i, &foreach_data);
1065rb_gc_free_dsymbol(
VALUE sym)
1067 VALUE str = RSYMBOL(sym)->fstr;
1070 rb_concurrent_set_delete_by_identity(ruby_global_symbols.sym_set, sym);
1072 RSYMBOL(sym)->fstr = 0;
1087 return sym_find_or_insert_dynamic_symbol(&ruby_global_symbols, str);
1095 id = STATIC_SYM2ID(sym);
1098 id = sym_id_load_acquire(sym);
1099 if (LIKELY(
id & ~ID_SCOPE_MASK)) {
1103 GLOBAL_SYMBOLS_LOCKING(symbols) {
1105 id = RSYMBOL(sym)->id;
1107 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
1108 VALUE fstr = RSYMBOL(sym)->fstr;
1109 ID num = next_id_base();
1115 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
1116 rbimpl_atomic_value_store((
VALUE *)&RSYMBOL(sym)->
id, (
VALUE)
id, RBIMPL_ATOMIC_RELEASE);
1121 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Symbol)",
1122 rb_builtin_class_name(sym));
1131 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
1132 return get_id_sym(x);
1152 str = RSYMBOL(sym)->fstr;
1156 str = rb_id2str(STATIC_SYM2ID(sym));
1166 return get_id_str(
id);
1172 VALUE str = rb_id2str(
id);
1175 return RSTRING_PTR(str);
1179rb_make_internal_id(
void)
1181 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1185rb_make_temporary_id(
size_t n)
1187 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1188 const ID id = max_id - (
ID)n;
1192 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1196symbols_i(
VALUE *key,
void *data)
1201 if (sym_set_sym_static_p(sym)) {
1202 rb_ary_push(ary, sym_set_static_sym_untag(sym)->sym);
1204 else if (rb_objspace_garbage_object_p(sym)) {
1219 GLOBAL_SYMBOLS_LOCKING(symbols) {
1221 ary =
rb_ary_new2(rb_concurrent_set_size(symbols->sym_set));
1222 rb_concurrent_set_foreach_with_replace(symbols->sym_set, symbols_i, (
void *)ary);
1229rb_sym_immortal_count(
void)
1237 return is_const_id(
id);
1243 return is_class_id(
id);
1249 return is_global_id(
id);
1255 return is_instance_id(
id);
1261 return is_attrset_id(
id);
1267 return is_local_id(
id);
1273 return is_internal_id(
id);
1277rb_is_const_sym(
VALUE sym)
1279 return is_const_sym(sym);
1283rb_is_attrset_sym(
VALUE sym)
1285 return is_attrset_sym(sym);
1292 VALUE name = *namep;
1295 return STATIC_SYM2ID(name);
1298 ID id = sym_id_load_acquire(name);
1299 if (
id & ~ID_SCOPE_MASK) {
1303 *namep = RSYMBOL(name)->fstr;
1310 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1317 sym_check_asciionly(name,
false);
1319 return lookup_str_id(name);
1324rb_get_symbol_id(
VALUE name)
1327 return STATIC_SYM2ID(name);
1330 ID id = sym_id_load_acquire(name);
1331 if (
id & ~ID_SCOPE_MASK) {
1339 return lookup_str_id(name);
1352 VALUE name = *namep;
1364 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1371 sym_check_asciionly(name,
false);
1373 if ((sym = sym_find(name)) != 0) {
1383 struct RString fake_str = {RBASIC_INIT};
1384 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1386 sym_check_asciionly(name,
true);
1388 return lookup_str_id(name);
1395 struct RString fake_str = {RBASIC_INIT};
1396 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1398 sym_check_asciionly(name,
true);
1400 if ((sym = sym_find(name)) != 0) {
1407#undef rb_sym_intern_ascii_cstr
1412FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii(
const char *
ptr,
long len));
1413FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii_cstr(
const char *
ptr));
1419 struct RString fake_str = {RBASIC_INIT};
1420 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1425rb_sym_intern_ascii(
const char *
ptr,
long len)
1427 return rb_sym_intern(
ptr,
len, rb_usascii_encoding());
1431rb_sym_intern_ascii_cstr(
const char *
ptr)
1433 return rb_sym_intern_ascii(
ptr, strlen(
ptr));
1437rb_to_symbol_type(
VALUE obj)
1439 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1443rb_is_const_name(
VALUE name)
1445 return rb_str_symname_type(name, 0) == ID_CONST;
1449rb_is_class_name(
VALUE name)
1451 return rb_str_symname_type(name, 0) == ID_CLASS;
1455rb_is_instance_name(
VALUE name)
1457 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1461rb_is_local_name(
VALUE name)
1463 return rb_str_symname_type(name, 0) == ID_LOCAL;
1466#include "id_table.c"
1467#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 Qundef
Old name of RUBY_Qundef.
#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 ZALLOC_N
Old name of RB_ZALLOC_N.
#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 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_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
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_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
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 capa
Designed capacity of the buffer.
int len
Length of the buffer.
#define RB_OBJ_SET_SHAREABLE(obj)
Wrapper of rb_obj_set_shareable().
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
static VALUE RB_OBJ_SET_FROZEN_SHAREABLE(VALUE obj)
Freezes and marks the object as shareable.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
Defines RBIMPL_ATTR_NONSTRING.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
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.