Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)
symbol.c
1/**********************************************************************
2
3 symbol.h -
4
5 $Author$
6 created at: Tue Jul 8 15:49:54 JST 2014
7
8 Copyright (C) 2014 Yukihiro Matsumoto
9
10**********************************************************************/
11
12#include "internal.h"
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"
19#include "probes.h"
20#include "ruby/encoding.h"
21#include "ruby/st.h"
22#include "symbol.h"
23#include "vm_sync.h"
24#include "builtin.h"
26
27#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
28# undef USE_SYMBOL_GC
29# define USE_SYMBOL_GC 0
30#else
31# undef USE_SYMBOL_GC
32# define USE_SYMBOL_GC 1
33#endif
34#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
35# undef SYMBOL_DEBUG
36# define SYMBOL_DEBUG 1
37#else
38# undef SYMBOL_DEBUG
39# define SYMBOL_DEBUG 0
40#endif
41#ifndef CHECK_ID_SERIAL
42# define CHECK_ID_SERIAL SYMBOL_DEBUG
43#endif
44
45#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
46
47#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
48
49static ID register_static_symid(ID, const char *, long, rb_encoding *);
50static ID register_static_symid_str(ID, VALUE);
51#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
52#include "id.c"
53
54#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
55
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)
59
60static void
61Init_op_tbl(void)
62{
63 int i;
64 rb_encoding *const enc = rb_usascii_encoding();
65
66 for (i = '!'; i <= '~'; ++i) {
67 if (!ISALNUM(i) && i != '_') {
68 char c = (char)i;
69 register_static_symid(i, &c, 1, enc);
70 }
71 }
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);
74 }
75}
76
77static const int ID_ENTRY_UNIT = 512;
78
79enum id_entry_type {
80 ID_ENTRY_STR,
81 ID_ENTRY_SYM,
82 ID_ENTRY_SIZE
83};
84
85rb_symbols_t ruby_global_symbols = {tNEXT_ID-1};
86
87static const struct st_hash_type symhash = {
90};
91
92void
93Init_sym(void)
94{
95 rb_symbols_t *symbols = &ruby_global_symbols;
96
97 VALUE dsym_fstrs = rb_ident_hash_new();
98 symbols->dsymbol_fstr_hash = dsym_fstrs;
99 rb_vm_register_global_object(dsym_fstrs);
100 rb_obj_hide(dsym_fstrs);
101
102 symbols->str_sym = st_init_table_with_size(&symhash, 1000);
103 symbols->ids = rb_ary_hidden_new(0);
104 rb_vm_register_global_object(symbols->ids);
105
106 Init_op_tbl();
107 Init_id();
108}
109
110WARN_UNUSED_RESULT(static VALUE dsymbol_alloc(rb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding *const enc, const ID type));
111WARN_UNUSED_RESULT(static VALUE dsymbol_check(rb_symbols_t *symbols, const VALUE sym));
112WARN_UNUSED_RESULT(static ID lookup_str_id(VALUE str));
113WARN_UNUSED_RESULT(static VALUE lookup_str_sym_with_lock(rb_symbols_t *symbols, const VALUE str));
114WARN_UNUSED_RESULT(static VALUE lookup_str_sym(const VALUE str));
115WARN_UNUSED_RESULT(static VALUE lookup_id_str(ID id));
116WARN_UNUSED_RESULT(static ID intern_str(VALUE str, int mutable));
117
118#define GLOBAL_SYMBOLS_ENTER(symbols) rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()
119#define GLOBAL_SYMBOLS_LEAVE() RB_VM_LOCK_LEAVE()
120
121ID
122rb_id_attrset(ID id)
123{
124 VALUE str, sym;
125 int scope;
126
127 if (!is_notop_id(id)) {
128 switch (id) {
129 case tAREF: case tASET:
130 return tASET; /* only exception */
131 }
132 rb_name_error(id, "cannot make operator ID :%"PRIsVALUE" attrset",
133 rb_id2str(id));
134 }
135 else {
136 scope = id_type(id);
137 switch (scope) {
138 case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
139 case ID_CONST: case ID_CLASS: case ID_JUNK:
140 break;
141 case ID_ATTRSET:
142 return id;
143 default:
144 {
145 if ((str = lookup_id_str(id)) != 0) {
146 rb_name_error(id, "cannot make unknown type ID %d:%"PRIsVALUE" attrset",
147 scope, str);
148 }
149 else {
150 rb_name_error_str(Qnil, "cannot make unknown type anonymous ID %d:%"PRIxVALUE" attrset",
151 scope, (VALUE)id);
152 }
153 }
154 }
155 }
156
157 /* make new symbol and ID */
158 if (!(str = lookup_id_str(id))) {
159 RBIMPL_ATTR_NONSTRING() static const char id_types[][8] = {
160 "local",
161 "instance",
162 "invalid",
163 "global",
164 "attrset",
165 "const",
166 "class",
167 "junk",
168 };
169 rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
170 (int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
171 }
172 str = rb_str_dup(str);
173 rb_str_cat(str, "=", 1);
174 sym = lookup_str_sym(str);
175 id = sym ? rb_sym2id(sym) : intern_str(str, 1);
176 return id;
177}
178
179static int
180is_special_global_name(const char *m, const char *e, rb_encoding *enc)
181{
182 int mb = 0;
183
184 if (m >= e) return 0;
185 if (is_global_name_punct(*m)) {
186 ++m;
187 }
188 else if (*m == '-') {
189 if (++m >= e) return 0;
190 if (is_identchar(m, e, enc)) {
191 if (!ISASCII(*m)) mb = 1;
192 m += rb_enc_mbclen(m, e, enc);
193 }
194 }
195 else {
196 if (!ISDIGIT(*m)) return 0;
197 do {
198 if (!ISASCII(*m)) mb = 1;
199 ++m;
200 } while (m < e && ISDIGIT(*m));
201 }
202 return m == e ? mb + 1 : 0;
203}
204
205int
206rb_symname_p(const char *name)
207{
209}
210
211int
212rb_enc_symname_p(const char *name, rb_encoding *enc)
213{
214 return rb_enc_symname2_p(name, strlen(name), enc);
215}
216
217static int
218rb_sym_constant_char_p(const char *name, long nlen, rb_encoding *enc)
219{
220 int c, len;
221 const char *end = name + nlen;
222
223 if (nlen < 1) return FALSE;
224 if (ISASCII(*name)) return ISUPPER(*name);
225 c = rb_enc_precise_mbclen(name, end, enc);
226 if (!MBCLEN_CHARFOUND_P(c)) return FALSE;
228 c = rb_enc_mbc_to_codepoint(name, end, enc);
229 if (rb_enc_isupper(c, enc)) return TRUE;
230 if (rb_enc_islower(c, enc)) return FALSE;
231 if (ONIGENC_IS_UNICODE(enc)) {
232 static int ctype_titlecase = 0;
233 if (!ctype_titlecase) {
234 static const UChar cname[] = "titlecaseletter";
235 static const UChar *const end = cname + sizeof(cname) - 1;
236 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
237 }
238 if (rb_enc_isctype(c, ctype_titlecase, enc)) return TRUE;
239 }
240 else {
241 /* fallback to case-folding */
242 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
243 const OnigUChar *beg = (const OnigUChar *)name;
244 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
245 &beg, (const OnigUChar *)end,
246 fold, enc);
247 if (r > 0 && (r != len || memcmp(fold, name, r)))
248 return TRUE;
249 }
250 return FALSE;
251}
252
253#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
254#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
255
257 const enum { invalid, stophere, needmore, } kind;
258 const enum ruby_id_types type;
259 const long nread;
260};
261
262#define t struct enc_synmane_type_leading_chars_tag
263
265enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int allowed_attrset)
266{
267 const char *m = name;
268 const char *e = m + len;
269
270 if (! rb_enc_asciicompat(enc)) {
271 return (t) { invalid, 0, 0, };
272 }
273 else if (! m) {
274 return (t) { invalid, 0, 0, };
275 }
276 else if ( len <= 0 ) {
277 return (t) { invalid, 0, 0, };
278 }
279 switch (*m) {
280 case '\0':
281 return (t) { invalid, 0, 0, };
282
283 case '$':
284 if (is_special_global_name(++m, e, enc)) {
285 return (t) { stophere, ID_GLOBAL, len, };
286 }
287 else {
288 return (t) { needmore, ID_GLOBAL, 1, };
289 }
290
291 case '@':
292 switch (*++m) {
293 default: return (t) { needmore, ID_INSTANCE, 1, };
294 case '@': return (t) { needmore, ID_CLASS, 2, };
295 }
296
297 case '<':
298 switch (*++m) {
299 default: return (t) { stophere, ID_JUNK, 1, };
300 case '<': return (t) { stophere, ID_JUNK, 2, };
301 case '=':
302 switch (*++m) {
303 default: return (t) { stophere, ID_JUNK, 2, };
304 case '>': return (t) { stophere, ID_JUNK, 3, };
305 }
306 }
307
308 case '>':
309 switch (*++m) {
310 default: return (t) { stophere, ID_JUNK, 1, };
311 case '>': case '=': return (t) { stophere, ID_JUNK, 2, };
312 }
313
314 case '=':
315 switch (*++m) {
316 default: return (t) { invalid, 0, 1, };
317 case '~': return (t) { stophere, ID_JUNK, 2, };
318 case '=':
319 switch (*++m) {
320 default: return (t) { stophere, ID_JUNK, 2, };
321 case '=': return (t) { stophere, ID_JUNK, 3, };
322 }
323 }
324
325 case '*':
326 switch (*++m) {
327 default: return (t) { stophere, ID_JUNK, 1, };
328 case '*': return (t) { stophere, ID_JUNK, 2, };
329 }
330
331 case '+': case '-':
332 switch (*++m) {
333 default: return (t) { stophere, ID_JUNK, 1, };
334 case '@': return (t) { stophere, ID_JUNK, 2, };
335 }
336
337 case '|': case '^': case '&': case '/': case '%': case '~': case '`':
338 return (t) { stophere, ID_JUNK, 1, };
339
340 case '[':
341 switch (*++m) {
342 default: return (t) { needmore, ID_JUNK, 0, };
343 case ']':
344 switch (*++m) {
345 default: return (t) { stophere, ID_JUNK, 2, };
346 case '=': return (t) { stophere, ID_JUNK, 3, };
347 }
348 }
349
350 case '!':
351 switch (*++m) {
352 case '=': case '~': return (t) { stophere, ID_JUNK, 2, };
353 default:
354 if (allowed_attrset & (1U << ID_JUNK)) {
355 return (t) { needmore, ID_JUNK, 1, };
356 }
357 else {
358 return (t) { stophere, ID_JUNK, 1, };
359 }
360 }
361
362 default:
363 if (rb_sym_constant_char_p(name, len, enc)) {
364 return (t) { needmore, ID_CONST, 0, };
365 }
366 else {
367 return (t) { needmore, ID_LOCAL, 0, };
368 }
369 }
370}
371#undef t
372
373int
374rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
375{
377 enc_synmane_type_leading_chars(name, len, enc, allowed_attrset);
378 const char *m = name + f.nread;
379 const char *e = name + len;
380 int type = (int)f.type;
381
382 switch (f.kind) {
383 case invalid: return -1;
384 case stophere: break;
385 case needmore:
386
387 if (m >= e || (*m != '_' && !ISALPHA(*m) && ISASCII(*m))) {
388 if (len > 1 && *(e-1) == '=') {
389 type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
390 if (allowed_attrset & (1U << type)) return ID_ATTRSET;
391 }
392 return -1;
393 }
394 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
395 if (m >= e) break;
396 switch (*m) {
397 case '!': case '?':
398 if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
399 type = ID_JUNK;
400 ++m;
401 if (m + 1 < e || *m != '=') break;
402 /* fall through */
403 case '=':
404 if (!(allowed_attrset & (1U << type))) return -1;
405 type = ID_ATTRSET;
406 ++m;
407 break;
408 }
409 }
410
411 return m == e ? type : -1;
412}
413
414int
415rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
416{
417 return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
418}
419
420static int
421rb_str_symname_type(VALUE name, unsigned int allowed_attrset)
422{
423 const char *ptr = StringValuePtr(name);
424 long len = RSTRING_LEN(name);
425 int type = rb_enc_symname_type(ptr, len, rb_enc_get(name), allowed_attrset);
426 RB_GC_GUARD(name);
427 return type;
428}
429
430static void
431set_id_entry(rb_symbols_t *symbols, rb_id_serial_t num, VALUE str, VALUE sym)
432{
433 ASSERT_vm_locking();
436
437 size_t idx = num / ID_ENTRY_UNIT;
438
439 VALUE ary, ids = symbols->ids;
440 if (idx >= (size_t)RARRAY_LEN(ids) || NIL_P(ary = rb_ary_entry(ids, (long)idx))) {
441 ary = rb_ary_hidden_new(ID_ENTRY_UNIT * ID_ENTRY_SIZE);
442 rb_ary_store(ids, (long)idx, ary);
443 }
444 idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
445 rb_ary_store(ary, (long)idx + ID_ENTRY_STR, str);
446 rb_ary_store(ary, (long)idx + ID_ENTRY_SYM, sym);
447}
448
449static VALUE
450get_id_serial_entry(rb_id_serial_t num, ID id, const enum id_entry_type t)
451{
452 VALUE result = 0;
453
454 GLOBAL_SYMBOLS_ENTER(symbols);
455 {
456 if (num && num <= symbols->last_id) {
457 size_t idx = num / ID_ENTRY_UNIT;
458 VALUE ids = symbols->ids;
459 VALUE ary;
460 if (idx < (size_t)RARRAY_LEN(ids) && !NIL_P(ary = rb_ary_entry(ids, (long)idx))) {
461 long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
462 result = rb_ary_entry(ary, pos + t);
463
464 if (NIL_P(result)) {
465 result = 0;
466 }
467 else if (CHECK_ID_SERIAL) {
468 if (id) {
469 VALUE sym = result;
470 if (t != ID_ENTRY_SYM)
471 sym = rb_ary_entry(ary, pos + ID_ENTRY_SYM);
472 if (STATIC_SYM_P(sym)) {
473 if (STATIC_SYM2ID(sym) != id) result = 0;
474 }
475 else {
476 if (RSYMBOL(sym)->id != id) result = 0;
477 }
478 }
479 }
480 }
481 }
482 }
483 GLOBAL_SYMBOLS_LEAVE();
484
485 if (result) {
486 switch (t) {
487 case ID_ENTRY_STR:
489 break;
490 case ID_ENTRY_SYM:
492 break;
493 default:
494 break;
495 }
496 }
497
498 return result;
499}
500
501static VALUE
502get_id_entry(ID id, const enum id_entry_type t)
503{
504 return get_id_serial_entry(rb_id_to_serial(id), id, t);
505}
506
507int
508rb_static_id_valid_p(ID id)
509{
510 return STATIC_ID2SYM(id) == get_id_entry(id, ID_ENTRY_SYM);
511}
512
513static inline ID
514rb_id_serial_to_id(rb_id_serial_t num)
515{
516 if (is_notop_id((ID)num)) {
517 VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
518 if (sym) return SYM2ID(sym);
519 return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
520 }
521 else {
522 return (ID)num;
523 }
524}
525
526static int
527register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
528{
529 if (existing) {
530 rb_fatal("symbol :% "PRIsVALUE" is already registered with %"PRIxVALUE,
531 (VALUE)*key, (VALUE)*value);
532 }
533 *value = arg;
534 return ST_CONTINUE;
535}
536
537static void
538register_sym(rb_symbols_t *symbols, VALUE str, VALUE sym)
539{
540 ASSERT_vm_locking();
541
542 if (SYMBOL_DEBUG) {
543 st_update(symbols->str_sym, (st_data_t)str,
544 register_sym_update_callback, (st_data_t)sym);
545 }
546 else {
547 st_add_direct(symbols->str_sym, (st_data_t)str, (st_data_t)sym);
548 }
549}
550
551void
552rb_free_static_symid_str(void)
553{
554 GLOBAL_SYMBOLS_ENTER(symbols)
555 {
556 st_free_table(symbols->str_sym);
557 }
558 GLOBAL_SYMBOLS_LEAVE();
559}
560
561static void
562unregister_sym(rb_symbols_t *symbols, VALUE str, VALUE sym)
563{
564 ASSERT_vm_locking();
565
566 st_data_t str_data = (st_data_t)str;
567 if (!st_delete(symbols->str_sym, &str_data, NULL)) {
568 rb_bug("%p can't remove str from str_id (%s)", (void *)sym, RSTRING_PTR(str));
569 }
570}
571
572static ID
573register_static_symid(ID id, const char *name, long len, rb_encoding *enc)
574{
575 VALUE str = rb_enc_str_new(name, len, enc);
576 return register_static_symid_str(id, str);
577}
578
579static ID
580register_static_symid_str(ID id, VALUE str)
581{
582 rb_id_serial_t num = rb_id_to_serial(id);
583 VALUE sym = STATIC_ID2SYM(id);
584
585 OBJ_FREEZE(str);
586 str = rb_fstring(str);
587
588 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
589
590 GLOBAL_SYMBOLS_ENTER(symbols)
591 {
592 register_sym(symbols, str, sym);
593 set_id_entry(symbols, num, str, sym);
594 }
595 GLOBAL_SYMBOLS_LEAVE();
596
597 return id;
598}
599
600static int
601sym_check_asciionly(VALUE str, bool fake_str)
602{
603 if (!rb_enc_asciicompat(rb_enc_get(str))) return FALSE;
604 switch (rb_enc_str_coderange(str)) {
606 if (fake_str) {
607 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
608 }
609 rb_raise(rb_eEncodingError, "invalid symbol in encoding %s :%+"PRIsVALUE,
610 rb_enc_name(rb_enc_get(str)), str);
612 return TRUE;
613 }
614 return FALSE;
615}
616
617#if 0
618/*
619 * _str_ itself will be registered at the global symbol table. _str_
620 * can be modified before the registration, since the encoding will be
621 * set to ASCII-8BIT if it is a special global name.
622 */
623
624static inline void
625must_be_dynamic_symbol(VALUE x)
626{
627 if (UNLIKELY(!DYNAMIC_SYM_P(x))) {
628 if (STATIC_SYM_P(x)) {
629 VALUE str = lookup_id_str(RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT));
630
631 if (str) {
632 rb_bug("wrong argument: %s (inappropriate Symbol)", RSTRING_PTR(str));
633 }
634 else {
635 rb_bug("wrong argument: inappropriate Symbol (%p)", (void *)x);
636 }
637 }
638 else {
639 rb_bug("wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
640 }
641 }
642}
643#endif
644
645static VALUE
646dsymbol_alloc(rb_symbols_t *symbols, const VALUE klass, const VALUE str, rb_encoding * const enc, const ID type)
647{
648 ASSERT_vm_locking();
649
650 NEWOBJ_OF(obj, struct RSymbol, klass, T_SYMBOL | FL_WB_PROTECTED, sizeof(struct RSymbol), 0);
651
652 long hashval;
653
654 rb_enc_set_index((VALUE)obj, rb_enc_to_index(enc));
655 OBJ_FREEZE((VALUE)obj);
656 RB_OBJ_WRITE((VALUE)obj, &obj->fstr, str);
657 obj->id = type;
658
659 /* we want hashval to be in Fixnum range [ruby-core:15713] r15672 */
660 hashval = (long)rb_str_hash(str);
661 obj->hashval = RSHIFT((long)hashval, 1);
662 register_sym(symbols, str, (VALUE)obj);
663 rb_hash_aset(symbols->dsymbol_fstr_hash, str, Qtrue);
664 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
665
666 return (VALUE)obj;
667}
668
669static inline VALUE
670dsymbol_check(rb_symbols_t *symbols, const VALUE sym)
671{
672 ASSERT_vm_locking();
673
674 if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
675 const VALUE fstr = RSYMBOL(sym)->fstr;
676 const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
677 RSYMBOL(sym)->fstr = 0;
678 unregister_sym(symbols, fstr, sym);
679 return dsymbol_alloc(symbols, rb_cSymbol, fstr, rb_enc_get(fstr), type);
680 }
681 else {
682 return sym;
683 }
684}
685
686static ID
687lookup_str_id(VALUE str)
688{
689 st_data_t sym_data;
690 int found;
691
692 GLOBAL_SYMBOLS_ENTER(symbols);
693 {
694 found = st_lookup(symbols->str_sym, (st_data_t)str, &sym_data);
695 }
696 GLOBAL_SYMBOLS_LEAVE();
697
698 if (found) {
699 const VALUE sym = (VALUE)sym_data;
700
701 if (STATIC_SYM_P(sym)) {
702 return STATIC_SYM2ID(sym);
703 }
704 else if (DYNAMIC_SYM_P(sym)) {
705 ID id = RSYMBOL(sym)->id;
706 if (id & ~ID_SCOPE_MASK) return id;
707 }
708 else {
709 rb_bug("non-symbol object %s:%"PRIxVALUE" for %"PRIsVALUE" in symbol table",
710 rb_builtin_class_name(sym), sym, str);
711 }
712 }
713 return (ID)0;
714}
715
716static VALUE
717lookup_str_sym_with_lock(rb_symbols_t *symbols, const VALUE str)
718{
719 st_data_t sym_data;
720 if (st_lookup(symbols->str_sym, (st_data_t)str, &sym_data)) {
721 VALUE sym = (VALUE)sym_data;
722 if (DYNAMIC_SYM_P(sym)) {
723 sym = dsymbol_check(symbols, sym);
724 }
725 return sym;
726 }
727 else {
728 return Qfalse;
729 }
730}
731
732static VALUE
733lookup_str_sym(const VALUE str)
734{
735 VALUE sym;
736
737 GLOBAL_SYMBOLS_ENTER(symbols);
738 {
739 sym = lookup_str_sym_with_lock(symbols, str);
740 }
741 GLOBAL_SYMBOLS_LEAVE();
742
743 return sym;
744}
745
746static VALUE
747lookup_id_str(ID id)
748{
749 return get_id_entry(id, ID_ENTRY_STR);
750}
751
752ID
753rb_intern3(const char *name, long len, rb_encoding *enc)
754{
755 VALUE sym;
756 struct RString fake_str;
757 VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
758 OBJ_FREEZE(str);
759 sym = lookup_str_sym(str);
760 if (sym) return rb_sym2id(sym);
761 str = rb_enc_str_new(name, len, enc); /* make true string */
762 return intern_str(str, 1);
763}
764
765static ID
766next_id_base_with_lock(rb_symbols_t *symbols)
767{
768 ID id;
769 rb_id_serial_t next_serial = symbols->last_id + 1;
770
771 if (next_serial == 0) {
772 id = (ID)-1;
773 }
774 else {
775 const size_t num = ++symbols->last_id;
776 id = num << ID_SCOPE_SHIFT;
777 }
778
779 return id;
780}
781
782static ID
783next_id_base(void)
784{
785 ID id;
786 GLOBAL_SYMBOLS_ENTER(symbols);
787 {
788 id = next_id_base_with_lock(symbols);
789 }
790 GLOBAL_SYMBOLS_LEAVE();
791 return id;
792}
793
794static ID
795intern_str(VALUE str, int mutable)
796{
797 ID id;
798 ID nid;
799
800 id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
801 if (id == (ID)-1) id = ID_JUNK;
802 if (sym_check_asciionly(str, false)) {
803 if (!mutable) str = rb_str_dup(str);
804 rb_enc_associate(str, rb_usascii_encoding());
805 }
806 if ((nid = next_id_base()) == (ID)-1) {
807 str = rb_str_ellipsize(str, 20);
808 rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %"PRIsVALUE")",
809 str);
810 }
811 id |= nid;
812 id |= ID_STATIC_SYM;
813 return register_static_symid_str(id, str);
814}
815
816ID
817rb_intern2(const char *name, long len)
818{
819 return rb_intern3(name, len, rb_usascii_encoding());
820}
821
822#undef rb_intern
823ID
824rb_intern(const char *name)
825{
826 return rb_intern2(name, strlen(name));
827}
828
829ID
830rb_intern_str(VALUE str)
831{
832 VALUE sym = lookup_str_sym(str);
833
834 if (sym) {
835 return SYM2ID(sym);
836 }
837
838 return intern_str(str, 0);
839}
840
841void
842rb_gc_free_dsymbol(VALUE sym)
843{
844 VALUE str = RSYMBOL(sym)->fstr;
845
846 if (str) {
847 RSYMBOL(sym)->fstr = 0;
848
849 GLOBAL_SYMBOLS_ENTER(symbols);
850 {
851 unregister_sym(symbols, str, sym);
852 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, str);
853 }
854 GLOBAL_SYMBOLS_LEAVE();
855 }
856}
857
858/*
859 * call-seq:
860 * str.intern -> symbol
861 * str.to_sym -> symbol
862 *
863 * Returns the +Symbol+ corresponding to <i>str</i>, creating the
864 * symbol if it did not previously exist. See Symbol#id2name.
865 *
866 * "Koala".intern #=> :Koala
867 * s = 'cat'.to_sym #=> :cat
868 * s == :cat #=> true
869 * s = '@cat'.to_sym #=> :@cat
870 * s == :@cat #=> true
871 *
872 * This can also be used to create symbols that cannot be represented using the
873 * <code>:xxx</code> notation.
874 *
875 * 'cat and dog'.to_sym #=> :"cat and dog"
876 */
877
878VALUE
880{
881 VALUE sym;
882
883 GLOBAL_SYMBOLS_ENTER(symbols);
884 {
885 sym = lookup_str_sym_with_lock(symbols, str);
886
887 if (sym) {
888 // ok
889 }
890 else if (USE_SYMBOL_GC) {
891 rb_encoding *enc = rb_enc_get(str);
892 rb_encoding *ascii = rb_usascii_encoding();
893 if (enc != ascii && sym_check_asciionly(str, false)) {
894 str = rb_str_dup(str);
895 rb_enc_associate(str, ascii);
896 OBJ_FREEZE(str);
897 enc = ascii;
898 }
899 else {
900 str = rb_str_dup(str);
901 OBJ_FREEZE(str);
902 }
903 str = rb_fstring(str);
904 int type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
905 if (type < 0) type = ID_JUNK;
906 sym = dsymbol_alloc(symbols, rb_cSymbol, str, enc, type);
907 }
908 else {
909 ID id = intern_str(str, 0);
910 sym = ID2SYM(id);
911 }
912 }
913 GLOBAL_SYMBOLS_LEAVE();
914 return sym;
915}
916
917ID
919{
920 ID id;
921 if (STATIC_SYM_P(sym)) {
922 id = STATIC_SYM2ID(sym);
923 }
924 else if (DYNAMIC_SYM_P(sym)) {
925 GLOBAL_SYMBOLS_ENTER(symbols);
926 {
927 sym = dsymbol_check(symbols, sym);
928 id = RSYMBOL(sym)->id;
929
930 if (UNLIKELY(!(id & ~ID_SCOPE_MASK))) {
931 VALUE fstr = RSYMBOL(sym)->fstr;
932 ID num = next_id_base_with_lock(symbols);
933
934 RSYMBOL(sym)->id = id |= num;
935 /* make it permanent object */
936
937 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
938 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
939 }
940 }
941 GLOBAL_SYMBOLS_LEAVE();
942 }
943 else {
944 rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
945 rb_builtin_class_name(sym));
946 }
947 return id;
948}
949
950#undef rb_id2sym
951VALUE
953{
954 if (!DYNAMIC_ID_P(x)) return STATIC_ID2SYM(x);
955 return get_id_entry(x, ID_ENTRY_SYM);
956}
957
958/*
959 * call-seq:
960 * name -> string
961 *
962 * Returns a frozen string representation of +self+ (not including the leading colon):
963 *
964 * :foo.name # => "foo"
965 * :foo.name.frozen? # => true
966 *
967 * Related: Symbol#to_s, Symbol#inspect.
968 */
969
970VALUE
972{
973 VALUE str;
974 if (DYNAMIC_SYM_P(sym)) {
975 str = RSYMBOL(sym)->fstr;
977 }
978 else {
979 str = rb_id2str(STATIC_SYM2ID(sym));
980 if (str) RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
981 }
982
983 return str;
984}
985
986VALUE
987rb_id2str(ID id)
988{
989 return lookup_id_str(id);
990}
991
992const char *
993rb_id2name(ID id)
994{
995 VALUE str = rb_id2str(id);
996
997 if (!str) return 0;
998 return RSTRING_PTR(str);
999}
1000
1001ID
1002rb_make_internal_id(void)
1003{
1004 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1005}
1006
1007ID
1008rb_make_temporary_id(size_t n)
1009{
1010 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1011 const ID id = max_id - (ID)n;
1012 if (id <= ruby_global_symbols.last_id) {
1013 rb_raise(rb_eRuntimeError, "too big to make temporary ID: %" PRIdSIZE, n);
1014 }
1015 return (id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1016}
1017
1018static int
1019symbols_i(st_data_t key, st_data_t value, st_data_t arg)
1020{
1021 VALUE ary = (VALUE)arg;
1022 VALUE sym = (VALUE)value;
1023
1024 if (STATIC_SYM_P(sym)) {
1025 rb_ary_push(ary, sym);
1026 return ST_CONTINUE;
1027 }
1028 else if (!DYNAMIC_SYM_P(sym)) {
1029 rb_bug("invalid symbol: %s", RSTRING_PTR((VALUE)key));
1030 }
1031 else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
1032 RSYMBOL(sym)->fstr = 0;
1033 return ST_DELETE;
1034 }
1035 else {
1036 rb_ary_push(ary, sym);
1037 return ST_CONTINUE;
1038 }
1039
1040}
1041
1042VALUE
1044{
1045 VALUE ary;
1046
1047 GLOBAL_SYMBOLS_ENTER(symbols);
1048 {
1049 ary = rb_ary_new2(symbols->str_sym->num_entries);
1050 st_foreach(symbols->str_sym, symbols_i, ary);
1051 }
1052 GLOBAL_SYMBOLS_LEAVE();
1053
1054 return ary;
1055}
1056
1057size_t
1058rb_sym_immortal_count(void)
1059{
1060 return (size_t)ruby_global_symbols.last_id;
1061}
1062
1063int
1065{
1066 return is_const_id(id);
1067}
1068
1069int
1071{
1072 return is_class_id(id);
1073}
1074
1075int
1077{
1078 return is_global_id(id);
1079}
1080
1081int
1083{
1084 return is_instance_id(id);
1085}
1086
1087int
1089{
1090 return is_attrset_id(id);
1091}
1092
1093int
1095{
1096 return is_local_id(id);
1097}
1098
1099int
1101{
1102 return is_junk_id(id);
1103}
1104
1105int
1106rb_is_const_sym(VALUE sym)
1107{
1108 return is_const_sym(sym);
1109}
1110
1111int
1112rb_is_attrset_sym(VALUE sym)
1113{
1114 return is_attrset_sym(sym);
1115}
1116
1117ID
1118rb_check_id(volatile VALUE *namep)
1119{
1120 VALUE tmp;
1121 VALUE name = *namep;
1122
1123 if (STATIC_SYM_P(name)) {
1124 return STATIC_SYM2ID(name);
1125 }
1126 else if (DYNAMIC_SYM_P(name)) {
1127 if (SYMBOL_PINNED_P(name)) {
1128 return RSYMBOL(name)->id;
1129 }
1130 else {
1131 *namep = RSYMBOL(name)->fstr;
1132 return 0;
1133 }
1134 }
1135 else if (!RB_TYPE_P(name, T_STRING)) {
1136 tmp = rb_check_string_type(name);
1137 if (NIL_P(tmp)) {
1138 rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
1139 name);
1140 }
1141 name = tmp;
1142 *namep = name;
1143 }
1144
1145 sym_check_asciionly(name, false);
1146
1147 return lookup_str_id(name);
1148}
1149
1150// Used by yjit for handling .send without throwing exceptions
1151ID
1152rb_get_symbol_id(VALUE name)
1153{
1154 if (STATIC_SYM_P(name)) {
1155 return STATIC_SYM2ID(name);
1156 }
1157 else if (DYNAMIC_SYM_P(name)) {
1158 if (SYMBOL_PINNED_P(name)) {
1159 return RSYMBOL(name)->id;
1160 }
1161 else {
1162 return 0;
1163 }
1164 }
1165 else if (RB_TYPE_P(name, T_STRING)) {
1166 return lookup_str_id(name);
1167 }
1168 else {
1169 return 0;
1170 }
1171}
1172
1173
1174VALUE
1175rb_check_symbol(volatile VALUE *namep)
1176{
1177 VALUE sym;
1178 VALUE tmp;
1179 VALUE name = *namep;
1180
1181 if (STATIC_SYM_P(name)) {
1182 return name;
1183 }
1184 else if (DYNAMIC_SYM_P(name)) {
1185 if (!SYMBOL_PINNED_P(name)) {
1186 GLOBAL_SYMBOLS_ENTER(symbols);
1187 {
1188 name = dsymbol_check(symbols, name);
1189 }
1190 GLOBAL_SYMBOLS_LEAVE();
1191
1192 *namep = name;
1193 }
1194 return name;
1195 }
1196 else if (!RB_TYPE_P(name, T_STRING)) {
1197 tmp = rb_check_string_type(name);
1198 if (NIL_P(tmp)) {
1199 rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
1200 name);
1201 }
1202 name = tmp;
1203 *namep = name;
1204 }
1205
1206 sym_check_asciionly(name, false);
1207
1208 if ((sym = lookup_str_sym(name)) != 0) {
1209 return sym;
1210 }
1211
1212 return Qnil;
1213}
1214
1215ID
1216rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
1217{
1218 struct RString fake_str;
1219 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1220
1221 sym_check_asciionly(name, true);
1222
1223 return lookup_str_id(name);
1224}
1225
1226VALUE
1227rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
1228{
1229 VALUE sym;
1230 struct RString fake_str;
1231 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1232
1233 sym_check_asciionly(name, true);
1234
1235 if ((sym = lookup_str_sym(name)) != 0) {
1236 return sym;
1237 }
1238
1239 return Qnil;
1240}
1241
1242#undef rb_sym_intern_ascii_cstr
1243#ifdef __clang__
1244NOINLINE(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
1245#else
1246FUNC_MINIMIZED(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
1247FUNC_MINIMIZED(VALUE rb_sym_intern_ascii(const char *ptr, long len));
1248FUNC_MINIMIZED(VALUE rb_sym_intern_ascii_cstr(const char *ptr));
1249#endif
1250
1251VALUE
1252rb_sym_intern(const char *ptr, long len, rb_encoding *enc)
1253{
1254 struct RString fake_str;
1255 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1256 return rb_str_intern(name);
1257}
1258
1259VALUE
1260rb_sym_intern_ascii(const char *ptr, long len)
1261{
1262 return rb_sym_intern(ptr, len, rb_usascii_encoding());
1263}
1264
1265VALUE
1266rb_sym_intern_ascii_cstr(const char *ptr)
1267{
1268 return rb_sym_intern_ascii(ptr, strlen(ptr));
1269}
1270
1271VALUE
1272rb_to_symbol_type(VALUE obj)
1273{
1274 return rb_convert_type_with_id(obj, T_SYMBOL, "Symbol", idTo_sym);
1275}
1276
1277int
1278rb_is_const_name(VALUE name)
1279{
1280 return rb_str_symname_type(name, 0) == ID_CONST;
1281}
1282
1283int
1284rb_is_class_name(VALUE name)
1285{
1286 return rb_str_symname_type(name, 0) == ID_CLASS;
1287}
1288
1289int
1290rb_is_instance_name(VALUE name)
1291{
1292 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1293}
1294
1295int
1296rb_is_local_name(VALUE name)
1297{
1298 return rb_str_symname_type(name, 0) == ID_LOCAL;
1299}
1300
1301#include "id_table.c"
1302#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.
Definition assert.h:291
static bool rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isupper(), except it additionally takes an encoding.
Definition ctype.h:124
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.
Definition ctype.h:63
static bool rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
Identical to rb_islower(), except it additionally takes an encoding.
Definition ctype.h:110
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
Definition coderange.h:180
#define T_STRING
Old name of RUBY_T_STRING.
Definition value_type.h:78
#define ISUPPER
Old name of rb_isupper.
Definition ctype.h:89
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:135
#define SYM2ID
Old name of RB_SYM2ID.
Definition symbol.h:45
#define ISDIGIT
Old name of rb_isdigit.
Definition ctype.h:93
#define STATIC_SYM_P
Old name of RB_STATIC_SYM_P.
#define MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
Definition encoding.h:517
#define ISALPHA
Old name of rb_isalpha.
Definition ctype.h:92
#define ISASCII
Old name of rb_isascii.
Definition ctype.h:85
#define Qtrue
Old name of RUBY_Qtrue.
#define DYNAMIC_SYM_P
Old name of RB_DYNAMIC_SYM_P.
Definition value_type.h:86
#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.
Definition coderange.h:182
#define NIL_P
Old name of RB_NIL_P.
#define MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
Definition encoding.h:516
#define FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
Definition fl_type.h:59
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
Definition value_type.h:80
#define rb_ary_new2
Old name of rb_ary_new_capa.
Definition array.h:657
#define ISALNUM
Old name of rb_isalnum.
Definition ctype.h:91
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
Definition error.c:2344
VALUE rb_eTypeError
TypeError exception.
Definition error.c:1430
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
Definition error.c:2359
VALUE rb_eRuntimeError
RuntimeError exception.
Definition error.c:1428
VALUE rb_eEncodingError
EncodingError exception.
Definition error.c:1436
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
Definition object.c:104
VALUE rb_cSymbol
Symbol class.
Definition string.c:80
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
Definition gc.h:603
Encoding relates APIs.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
Definition encoding.c:1463
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
Definition encoding.c:1487
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
Definition string.c:905
int rb_enc_symname_p(const char *str, rb_encoding *enc)
Identical to rb_symname_p(), except it additionally takes an encoding.
Definition symbol.c:212
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id_cstr(), except for the return type.
Definition symbol.c:1227
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.
Definition symbol.c:415
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.
Definition symbol.c:1216
VALUE rb_sym_all_symbols(void)
Collects every single bits of symbols that have ever interned in the entire history of the current pr...
Definition symbol.c:1043
int rb_is_global_id(ID id)
Classifies the given ID, then sees if it is a global variable.
Definition symbol.c:1076
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
Definition symbol.c:1082
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
Definition symbol.c:1064
int rb_is_junk_id(ID)
Classifies the given ID, then sees if it is a junk ID.
Definition symbol.c:1100
int rb_symname_p(const char *str)
Sees if the passed C string constructs a valid syntactic symbol.
Definition symbol.c:206
int rb_is_class_id(ID id)
Classifies the given ID, then sees if it is a class variable.
Definition symbol.c:1070
int rb_is_attrset_id(ID id)
Classifies the given ID, then sees if it is an attribute writer.
Definition symbol.c:1088
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
Definition symbol.c:1094
int rb_str_hash_cmp(VALUE str1, VALUE str2)
Compares two strings.
Definition string.c:4050
VALUE rb_str_ellipsize(VALUE str, long len)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
Definition string.c:11457
VALUE rb_str_dup(VALUE str)
Duplicates a string.
Definition string.c:1921
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
Definition string.c:4036
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
Definition string.c:3449
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
Definition string.c:2855
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
Definition symbol.c:879
VALUE rb_check_symbol(volatile VALUE *namep)
Identical to rb_check_id(), except it returns an instance of rb_cSymbol instead.
Definition symbol.c:1175
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
Definition symbol.c:952
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
Definition symbol.c:1118
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
Definition symbol.c:971
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
Definition symbol.c:918
int len
Length of the buffer.
Definition io.h:8
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
Definition memory.h:167
VALUE type(ANYARGS)
ANYARGS-ed function type.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
Defines RBIMPL_ATTR_NONSTRING.
#define RBIMPL_ATTR_NONSTRING()
Wraps (or simulates) __attribute__((nonstring))
Definition nonstring.h:29
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:51
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
Definition rstring.h:76
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
Definition rstring.h:416
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
Ruby's String.
Definition rstring.h:196
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:376