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