Ruby 4.1.0dev (2026-03-05 revision 8a87cebd1874f8f9f68af8928191ee3f0d97bb28)
symbol.c (8a87cebd1874f8f9f68af8928191ee3f0d97bb28)
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 "darray.h"
13#include "internal.h"
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"
21#include "probes.h"
22#include "ruby/encoding.h"
23#include "ruby/ractor.h"
24#include "ruby/st.h"
25#include "symbol.h"
26#include "vm_sync.h"
27#include "builtin.h"
29
30#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
31# undef USE_SYMBOL_GC
32# define USE_SYMBOL_GC 0
33#else
34# undef USE_SYMBOL_GC
35# define USE_SYMBOL_GC 1
36#endif
37#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
38# undef SYMBOL_DEBUG
39# define SYMBOL_DEBUG 1
40#else
41# undef SYMBOL_DEBUG
42# define SYMBOL_DEBUG 0
43#endif
44#ifndef CHECK_ID_SERIAL
45# define CHECK_ID_SERIAL SYMBOL_DEBUG
46#endif
47
48#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
49#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
50
51#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
52
53#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
54
55static ID register_static_symid(ID, const char *, long, rb_encoding *);
56#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
57#include "id.c"
58
59#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
60
61#define op_tbl_count numberof(op_tbl)
62STATIC_ASSERT(op_tbl_name_size, sizeof(op_tbl[0].name) == 3);
63#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
64
65
66#define GLOBAL_SYMBOLS_LOCKING(symbols) \
67 for (rb_symbols_t *symbols = &ruby_global_symbols, **locking = &symbols; \
68 locking; \
69 locking = NULL) \
70 RB_VM_LOCKING()
71
72static void
73Init_op_tbl(void)
74{
75 int i;
76 rb_encoding *const enc = rb_usascii_encoding();
77
78 for (i = '!'; i <= '~'; ++i) {
79 if (!ISALNUM(i) && i != '_') {
80 char c = (char)i;
81 register_static_symid(i, &c, 1, enc);
82 }
83 }
84 for (i = 0; i < op_tbl_count; ++i) {
85 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
86 }
87}
88
89static const int ID_ENTRY_UNIT = 512;
90
91typedef struct {
92 rb_atomic_t next_id;
93 VALUE sym_set;
94
95 VALUE ids;
97
98rb_symbols_t ruby_global_symbols = {
99 .next_id = tNEXT_ID,
100};
101
103 VALUE sym;
104 VALUE str;
105};
106
107#define SYM_SET_SYM_STATIC_TAG 1
108
109static bool
110sym_set_sym_static_p(VALUE sym)
111{
112 return sym & SYM_SET_SYM_STATIC_TAG;
113}
114
115static VALUE
116sym_set_static_sym_tag(struct sym_set_static_sym_entry *sym)
117{
118 VALUE value = (VALUE)sym | SYM_SET_SYM_STATIC_TAG;
119 RUBY_ASSERT(IMMEDIATE_P(value));
120 RUBY_ASSERT(sym_set_sym_static_p(value));
121
122 return value;
123}
124
125static struct sym_set_static_sym_entry *
126sym_set_static_sym_untag(VALUE sym)
127{
128 RUBY_ASSERT(sym_set_sym_static_p(sym));
129
130 return (struct sym_set_static_sym_entry *)(sym & ~((VALUE)SYM_SET_SYM_STATIC_TAG));
131}
132
133static VALUE
134sym_set_sym_get_str(VALUE sym)
135{
136 VALUE str;
137 if (sym_set_sym_static_p(sym)) {
138 str = sym_set_static_sym_untag(sym)->str;
139 }
140 else {
142 str = RSYMBOL(sym)->fstr;
143 }
144
146
147 return str;
148}
149
150static VALUE
151sym_set_hash(VALUE sym)
152{
153 if (sym_set_sym_static_p(sym)) {
154 return (VALUE)rb_str_hash(sym_set_static_sym_untag(sym)->str);
155 }
156 else {
157 return (VALUE)RSYMBOL(sym)->hashval;
158 }
159}
160
161static bool
162sym_set_cmp(VALUE a, VALUE b)
163{
164 return rb_str_hash_cmp(sym_set_sym_get_str(a), sym_set_sym_get_str(b)) == false;
165}
166
168 VALUE sym;
169 VALUE str;
170};
171
172static void
173sym_id_entry_list_mark(void *ptr)
174{
175 rb_darray(struct sym_id_entry) ary = ptr;
176
177 struct sym_id_entry *entry;
178 rb_darray_foreach(ary, i, entry) {
179 // sym must be pinned because it may be used in places that don't
180 // support compaction
181 rb_gc_mark(entry->sym);
182 rb_gc_mark_movable(entry->str);
183 }
184}
185
186static void
187sym_id_entry_list_free(void *ptr)
188{
189 rb_darray_free_sized(ptr, struct sym_id_entry);
190}
191
192static size_t
193sym_id_entry_list_memsize(const void *ptr)
194{
195 const rb_darray(struct sym_id_entry) ary = ptr;
196
197 return rb_darray_memsize(ary);
198}
199
200static void
201sym_id_entry_list_compact(void *ptr)
202{
203 rb_darray(struct sym_id_entry) ary = ptr;
204
205 struct sym_id_entry *entry;
206 rb_darray_foreach(ary, i, entry) {
207 entry->str = rb_gc_location(entry->str);
208 }
209}
210
211static const rb_data_type_t sym_id_entry_list_type = {
212 "symbol_id_entry_list",
213 {
214 sym_id_entry_list_mark,
215 sym_id_entry_list_free,
216 sym_id_entry_list_memsize,
217 sym_id_entry_list_compact,
218 },
219 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
220};
221
222static int
223sym_check_asciionly(VALUE str, bool fake_str)
224{
225 if (!rb_enc_asciicompat(rb_enc_get(str))) return FALSE;
226 switch (rb_enc_str_coderange(str)) {
228 if (fake_str) {
229 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
230 }
231 rb_raise(rb_eEncodingError, "invalid symbol in encoding %s :%+"PRIsVALUE,
232 rb_enc_name(rb_enc_get(str)), str);
234 return TRUE;
235 }
236 return FALSE;
237}
238
239static VALUE
240dup_string_for_create(VALUE str)
241{
242 rb_encoding *enc = rb_enc_get(str);
243
244 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), enc);
245
246 rb_encoding *ascii = rb_usascii_encoding();
247 if (enc != ascii && sym_check_asciionly(str, false)) {
248 rb_enc_associate(str, ascii);
249 }
250 OBJ_FREEZE(str);
251
252 str = rb_fstring(str);
253 return str;
254}
255
256static int
257rb_str_symname_type(VALUE name, unsigned int allowed_attrset)
258{
259 const char *ptr = StringValuePtr(name);
260 long len = RSTRING_LEN(name);
261 int type = rb_enc_symname_type(ptr, len, rb_enc_get(name), allowed_attrset);
262 RB_GC_GUARD(name);
263 return type;
264}
265
266static ID
267next_id_base(void)
268{
269 rb_atomic_t serial = RUBY_ATOMIC_FETCH_ADD(ruby_global_symbols.next_id, 1);
270
271 return (ID)serial << ID_SCOPE_SHIFT;
272}
273
274static void
275set_id_entry(rb_symbols_t *symbols, rb_id_serial_t num, VALUE str, VALUE sym)
276{
277 ASSERT_vm_locking();
280
281 size_t idx = num / ID_ENTRY_UNIT;
282
283 VALUE id_entry_list, ids = symbols->ids;
284 rb_darray(struct sym_id_entry) entries;
285 if (idx >= (size_t)RARRAY_LEN(ids) || NIL_P(id_entry_list = rb_ary_entry(ids, (long)idx))) {
286 rb_darray_make(&entries, ID_ENTRY_UNIT);
287 id_entry_list = TypedData_Wrap_Struct(0, &sym_id_entry_list_type, entries);
288 rb_ary_store(ids, (long)idx, id_entry_list);
289 }
290 else {
291 entries = RTYPEDDATA_GET_DATA(id_entry_list);
292 }
293
294 idx = num % ID_ENTRY_UNIT;
295 struct sym_id_entry *entry = rb_darray_ref(entries, idx);
296 RUBY_ASSERT(entry->str == 0);
297 RUBY_ASSERT(entry->sym == 0);
298
299 RB_OBJ_WRITE(id_entry_list, &entry->str, str);
300 RB_OBJ_WRITE(id_entry_list, &entry->sym, sym);
301}
302
303static VALUE
304sym_set_create(VALUE sym, void *data)
305{
306 bool create_dynamic_symbol = (bool)data;
307
308 struct sym_set_static_sym_entry *static_sym_entry = sym_set_static_sym_untag(sym);
309
310 VALUE str = dup_string_for_create(static_sym_entry->str);
311
312 if (create_dynamic_symbol) {
313 NEWOBJ_OF(obj, struct RSymbol, rb_cSymbol, T_SYMBOL | FL_WB_PROTECTED, sizeof(struct RSymbol), 0);
314
315 rb_encoding *enc = rb_enc_get(str);
316 rb_enc_set_index((VALUE)obj, rb_enc_to_index(enc));
317 RB_OBJ_WRITE((VALUE)obj, &obj->fstr, str);
318 RB_OBJ_SET_FROZEN_SHAREABLE((VALUE)obj);
319
320 int id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
321 if (id < 0) id = ID_INTERNAL;
322 obj->id = id;
323
324 obj->hashval = rb_str_hash(str);
325 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
326
327 return (VALUE)obj;
328 }
329 else {
330 struct sym_set_static_sym_entry *new_static_sym_entry = xmalloc(sizeof(struct sym_set_static_sym_entry));
331 new_static_sym_entry->str = str;
332
333 VALUE static_sym = static_sym_entry->sym;
334 if (static_sym == 0) {
335 ID id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
336 if (id == (ID)-1) id = ID_INTERNAL;
337
338 id |= next_id_base();
339 id |= ID_STATIC_SYM;
340
341 static_sym = STATIC_ID2SYM(id);
342 }
343 new_static_sym_entry->sym = static_sym;
344
345 RB_VM_LOCKING() {
346 set_id_entry(&ruby_global_symbols, rb_id_to_serial(STATIC_SYM2ID(static_sym)), str, static_sym);
347 }
348
349 return sym_set_static_sym_tag(new_static_sym_entry);
350 }
351}
352
353static void
354sym_set_free(VALUE sym)
355{
356 if (sym_set_sym_static_p(sym)) {
357 xfree(sym_set_static_sym_untag(sym));
358 }
359}
360
361static const struct rb_concurrent_set_funcs sym_set_funcs = {
362 .hash = sym_set_hash,
363 .cmp = sym_set_cmp,
364 .create = sym_set_create,
365 .free = sym_set_free,
366};
367
368static VALUE
369sym_set_entry_to_sym(VALUE entry)
370{
371 if (sym_set_sym_static_p(entry)) {
372 RUBY_ASSERT(STATIC_SYM_P(sym_set_static_sym_untag(entry)->sym));
373
374 if (!STATIC_SYM_P(sym_set_static_sym_untag(entry)->sym)) rb_bug("not sym");
375
376 return sym_set_static_sym_untag(entry)->sym;
377 }
378 else {
380 if (!DYNAMIC_SYM_P(entry)) rb_bug("not sym");
381
382 return entry;
383 }
384}
385
386static VALUE
387sym_find_or_insert_dynamic_symbol(rb_symbols_t *symbols, const VALUE str)
388{
389 struct sym_set_static_sym_entry static_sym = {
390 .str = str
391 };
392 return sym_set_entry_to_sym(
393 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (void *)true)
394 );
395}
396
397static VALUE
398sym_find_or_insert_static_symbol(rb_symbols_t *symbols, const VALUE str)
399{
400 struct sym_set_static_sym_entry static_sym = {
401 .str = str
402 };
403 return sym_set_entry_to_sym(
404 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (void *)false)
405 );
406}
407
408static VALUE
409sym_find_or_insert_static_symbol_id(rb_symbols_t *symbols, const VALUE str, ID id)
410{
411 struct sym_set_static_sym_entry static_sym = {
412 .sym = STATIC_ID2SYM(id),
413 .str = str,
414 };
415 return sym_set_entry_to_sym(
416 rb_concurrent_set_find_or_insert(&symbols->sym_set, sym_set_static_sym_tag(&static_sym), (void *)false)
417 );
418}
419
420void
421Init_sym(void)
422{
423 rb_symbols_t *symbols = &ruby_global_symbols;
424
425 symbols->sym_set = rb_concurrent_set_new(&sym_set_funcs, 1024);
426 symbols->ids = rb_ary_hidden_new(0);
427
428 Init_op_tbl();
429 Init_id();
430}
431
432void
433rb_sym_global_symbols_mark_and_move(void)
434{
435 rb_symbols_t *symbols = &ruby_global_symbols;
436
437 rb_gc_mark_and_move(&symbols->sym_set);
438 rb_gc_mark_and_move(&symbols->ids);
439}
440
441static int
442rb_free_global_symbol_table_i(VALUE *sym_ptr, void *data)
443{
444 sym_set_free(*sym_ptr);
445
446 return ST_DELETE;
447}
448
449void
450rb_free_global_symbol_table(void)
451{
452 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_free_global_symbol_table_i, NULL);
453}
454
455WARN_UNUSED_RESULT(static ID lookup_str_id(VALUE str));
456WARN_UNUSED_RESULT(static VALUE get_id_str(ID id));
457
458ID
459rb_id_attrset(ID id)
460{
461 int scope;
462
463 if (!is_notop_id(id)) {
464 switch (id) {
465 case tAREF: case tASET:
466 return tASET; /* only exception */
467 }
468 rb_name_error(id, "cannot make operator ID :%"PRIsVALUE" attrset",
469 rb_id2str(id));
470 }
471 else {
472 scope = id_type(id);
473 switch (scope) {
474 case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
475 case ID_CONST: case ID_CLASS: case ID_INTERNAL:
476 break;
477 case ID_ATTRSET:
478 return id;
479 default:
480 {
481 VALUE str = get_id_str(id);
482 if (str != 0) {
483 rb_name_error(id, "cannot make unknown type ID %d:%"PRIsVALUE" attrset",
484 scope, str);
485 }
486 else {
487 rb_name_error_str(Qnil, "cannot make unknown type anonymous ID %d:%"PRIxVALUE" attrset",
488 scope, (VALUE)id);
489 }
490 }
491 }
492 }
493
494 bool error = false;
495 /* make new symbol and ID */
496 VALUE str = get_id_str(id);
497 if (str) {
498 str = rb_str_dup(str);
499 rb_str_cat(str, "=", 1);
500 if (sym_check_asciionly(str, false)) {
501 rb_enc_associate(str, rb_usascii_encoding());
502 }
503
504 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
505 id = rb_sym2id(sym);
506 }
507 else {
508 error = true;
509 }
510
511 if (error) {
512 RBIMPL_ATTR_NONSTRING_ARRAY() static const char id_types[][8] = {
513 "local",
514 "instance",
515 "invalid",
516 "global",
517 "attrset",
518 "const",
519 "class",
520 "internal",
521 };
522 rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
523 (int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
524 }
525
526 return id;
527}
528
529static int
530is_special_global_name(const char *m, const char *e, rb_encoding *enc)
531{
532 int mb = 0;
533
534 if (m >= e) return 0;
535 if (is_global_name_punct(*m)) {
536 ++m;
537 }
538 else if (*m == '-') {
539 if (++m >= e) return 0;
540 if (is_identchar(m, e, enc)) {
541 if (!ISASCII(*m)) mb = 1;
542 m += rb_enc_mbclen(m, e, enc);
543 }
544 }
545 else {
546 if (!ISDIGIT(*m)) return 0;
547 do {
548 if (!ISASCII(*m)) mb = 1;
549 ++m;
550 } while (m < e && ISDIGIT(*m));
551 }
552 return m == e ? mb + 1 : 0;
553}
554
555int
556rb_symname_p(const char *name)
557{
558 return rb_enc_symname_p(name, rb_ascii8bit_encoding());
559}
560
561int
562rb_enc_symname_p(const char *name, rb_encoding *enc)
563{
564 return rb_enc_symname2_p(name, strlen(name), enc);
565}
566
567static int
568rb_sym_constant_char_p(const char *name, long nlen, rb_encoding *enc)
569{
570 int c, len;
571 const char *end = name + nlen;
572
573 if (nlen < 1) return FALSE;
574 if (ISASCII(*name)) return ISUPPER(*name);
575 c = rb_enc_precise_mbclen(name, end, enc);
576 if (!MBCLEN_CHARFOUND_P(c)) return FALSE;
578 c = rb_enc_mbc_to_codepoint(name, end, enc);
579 if (rb_enc_isupper(c, enc)) return TRUE;
580 if (rb_enc_islower(c, enc)) return FALSE;
581 if (ONIGENC_IS_UNICODE(enc)) {
582 static int ctype_titlecase = 0;
583 if (!ctype_titlecase) {
584 static const UChar cname[] = "titlecaseletter";
585 static const UChar *const end = cname + sizeof(cname) - 1;
586 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
587 }
588 if (rb_enc_isctype(c, ctype_titlecase, enc)) return TRUE;
589 }
590 else {
591 /* fallback to case-folding */
592 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
593 const OnigUChar *beg = (const OnigUChar *)name;
594 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
595 &beg, (const OnigUChar *)end,
596 fold, enc);
597 if (r > 0 && (r != len || memcmp(fold, name, r)))
598 return TRUE;
599 }
600 return FALSE;
601}
602
604 const enum { invalid, stophere, needmore, } kind;
605 const enum ruby_id_types type;
606 const long nread;
607};
608
609#define t struct enc_synmane_type_leading_chars_tag
610
612enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int allowed_attrset)
613{
614 const char *m = name;
615 const char *e = m + len;
616
617 if (! rb_enc_asciicompat(enc)) {
618 return (t) { invalid, 0, 0, };
619 }
620 else if (! m) {
621 return (t) { invalid, 0, 0, };
622 }
623 else if ( len <= 0 ) {
624 return (t) { invalid, 0, 0, };
625 }
626 switch (*m) {
627 case '\0':
628 return (t) { invalid, 0, 0, };
629
630 case '$':
631 if (is_special_global_name(++m, e, enc)) {
632 return (t) { stophere, ID_GLOBAL, len, };
633 }
634 else {
635 return (t) { needmore, ID_GLOBAL, 1, };
636 }
637
638 case '@':
639 switch (*++m) {
640 default: return (t) { needmore, ID_INSTANCE, 1, };
641 case '@': return (t) { needmore, ID_CLASS, 2, };
642 }
643
644 case '<':
645 switch (*++m) {
646 default: return (t) { stophere, ID_INTERNAL, 1, };
647 case '<': return (t) { stophere, ID_INTERNAL, 2, };
648 case '=':
649 switch (*++m) {
650 default: return (t) { stophere, ID_INTERNAL, 2, };
651 case '>': return (t) { stophere, ID_INTERNAL, 3, };
652 }
653 }
654
655 case '>':
656 switch (*++m) {
657 default: return (t) { stophere, ID_INTERNAL, 1, };
658 case '>': case '=': return (t) { stophere, ID_INTERNAL, 2, };
659 }
660
661 case '=':
662 switch (*++m) {
663 default: return (t) { invalid, 0, 1, };
664 case '~': return (t) { stophere, ID_INTERNAL, 2, };
665 case '=':
666 switch (*++m) {
667 default: return (t) { stophere, ID_INTERNAL, 2, };
668 case '=': return (t) { stophere, ID_INTERNAL, 3, };
669 }
670 }
671
672 case '*':
673 switch (*++m) {
674 default: return (t) { stophere, ID_INTERNAL, 1, };
675 case '*': return (t) { stophere, ID_INTERNAL, 2, };
676 }
677
678 case '+': case '-':
679 switch (*++m) {
680 default: return (t) { stophere, ID_INTERNAL, 1, };
681 case '@': return (t) { stophere, ID_INTERNAL, 2, };
682 }
683
684 case '|': case '^': case '&': case '/': case '%': case '~': case '`':
685 return (t) { stophere, ID_INTERNAL, 1, };
686
687 case '[':
688 switch (*++m) {
689 default: return (t) { needmore, ID_INTERNAL, 0, };
690 case ']':
691 switch (*++m) {
692 default: return (t) { stophere, ID_INTERNAL, 2, };
693 case '=': return (t) { stophere, ID_INTERNAL, 3, };
694 }
695 }
696
697 case '!':
698 switch (*++m) {
699 case '=': case '~': return (t) { stophere, ID_INTERNAL, 2, };
700 default:
701 if (allowed_attrset & (1U << ID_INTERNAL)) {
702 return (t) { needmore, ID_INTERNAL, 1, };
703 }
704 else {
705 return (t) { stophere, ID_INTERNAL, 1, };
706 }
707 }
708
709 default:
710 if (rb_sym_constant_char_p(name, len, enc)) {
711 return (t) { needmore, ID_CONST, 0, };
712 }
713 else {
714 return (t) { needmore, ID_LOCAL, 0, };
715 }
716 }
717}
718#undef t
719
720int
721rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
722{
724 enc_synmane_type_leading_chars(name, len, enc, allowed_attrset);
725 const char *m = name + f.nread;
726 const char *e = name + len;
727 int type = (int)f.type;
728
729 switch (f.kind) {
730 case invalid: return -1;
731 case stophere: break;
732 case needmore:
733
734 if (m >= e || (*m != '_' && !ISALPHA(*m) && ISASCII(*m))) {
735 if (len > 1 && *(e-1) == '=') {
736 type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
737 if (allowed_attrset & (1U << type)) return ID_ATTRSET;
738 }
739 return -1;
740 }
741 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
742 if (m >= e) break;
743 switch (*m) {
744 case '!': case '?':
745 if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
746 type = ID_INTERNAL;
747 ++m;
748 if (m + 1 < e || *m != '=') break;
749 /* fall through */
750 case '=':
751 if (!(allowed_attrset & (1U << type))) return -1;
752 type = ID_ATTRSET;
753 ++m;
754 break;
755 }
756 }
757
758 return m == e ? type : -1;
759}
760
761int
762rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
763{
764 return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
765}
766
767static struct sym_id_entry *
768get_id_serial_entry(rb_id_serial_t num)
769{
770 struct sym_id_entry *entry = NULL;
771
772 GLOBAL_SYMBOLS_LOCKING(symbols) {
773 if (num && num < RUBY_ATOMIC_LOAD(symbols->next_id)) {
774 size_t idx = num / ID_ENTRY_UNIT;
775 VALUE ids = symbols->ids;
776 VALUE id_entry_list;
777 if (idx < (size_t)RARRAY_LEN(ids) && !NIL_P(id_entry_list = rb_ary_entry(ids, (long)idx))) {
778 rb_darray(struct sym_id_entry) entries = RTYPEDDATA_GET_DATA(id_entry_list);
779
780 size_t pos = (size_t)(num % ID_ENTRY_UNIT);
781 RUBY_ASSERT(pos < rb_darray_size(entries));
782 entry = rb_darray_ref(entries, pos);
783 }
784 }
785 }
786
787 return entry;
788}
789
790static VALUE
791get_id_sym(ID id)
792{
793 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(id));
794 return entry ? entry->sym : 0;
795}
796
797static VALUE
798get_id_str(ID id)
799{
800 struct sym_id_entry *entry = get_id_serial_entry(rb_id_to_serial(id));
801 return entry ? entry->str : 0;
802}
803
804int
805rb_static_id_valid_p(ID id)
806{
807 return STATIC_ID2SYM(id) == get_id_sym(id);
808}
809
810static inline ID
811rb_id_serial_to_id(rb_id_serial_t num)
812{
813 if (is_notop_id((ID)num)) {
814 struct sym_id_entry *entry = get_id_serial_entry(num);
815 if (entry && entry->sym != 0) {
816 return SYM2ID(entry->sym);
817 }
818 else {
819 return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
820 }
821 }
822 else {
823 return (ID)num;
824 }
825}
826
827static ID
828register_static_symid(ID id, const char *name, long len, rb_encoding *enc)
829{
830 VALUE str = rb_enc_str_new(name, len, enc);
831 OBJ_FREEZE(str);
832 str = rb_fstring(str);
833
834 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
835
836 sym_find_or_insert_static_symbol_id(&ruby_global_symbols, str, id);
837
838 return id;
839}
840
841static VALUE
842sym_find(VALUE str)
843{
844 VALUE sym;
845
846 struct sym_set_static_sym_entry static_sym = {
847 .str = str
848 };
849 sym = rb_concurrent_set_find(&ruby_global_symbols.sym_set, sym_set_static_sym_tag(&static_sym));
850
851 if (sym) {
852 return sym_set_entry_to_sym(sym);
853 }
854 else {
855 return 0;
856 }
857}
858
859static ID
860lookup_str_id(VALUE str)
861{
862 VALUE sym = sym_find(str);
863
864 if (sym == 0) {
865 return (ID)0;
866 }
867
868 if (STATIC_SYM_P(sym)) {
869 return STATIC_SYM2ID(sym);
870 }
871 else if (DYNAMIC_SYM_P(sym)) {
872 ID id = RSYMBOL(sym)->id;
873 if (id & ~ID_SCOPE_MASK) return id;
874 }
875 else {
876 rb_bug("non-symbol object %s:%"PRIxVALUE" for %"PRIsVALUE" in symbol table",
877 rb_builtin_class_name(sym), sym, str);
878 }
879
880 return (ID)0;
881}
882
883ID
884rb_intern3(const char *name, long len, rb_encoding *enc)
885{
886 struct RString fake_str = {RBASIC_INIT};
887 VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
888 OBJ_FREEZE(str);
889
890 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
891 return rb_sym2id(sym);
892}
893
894ID
895rb_intern2(const char *name, long len)
896{
897 return rb_intern3(name, len, rb_usascii_encoding());
898}
899
900#undef rb_intern
901ID
902rb_intern(const char *name)
903{
904 return rb_intern2(name, strlen(name));
905}
906
907ID
908rb_intern_str(VALUE str)
909{
910 VALUE sym = sym_find_or_insert_static_symbol(&ruby_global_symbols, str);
911 return SYM2ID(sym);
912}
913
914bool
915rb_obj_is_symbol_table(VALUE obj)
916{
917 return obj == ruby_global_symbols.sym_set;
918}
919
921 int (*callback)(VALUE *key, void *data);
922 void *data;
923};
924
925static int
926rb_sym_global_symbol_table_foreach_weak_reference_i(VALUE *key, void *d)
927{
929 VALUE sym = *key;
930
931 if (sym_set_sym_static_p(sym)) {
932 struct sym_set_static_sym_entry *static_sym = sym_set_static_sym_untag(sym);
933
934 return data->callback(&static_sym->str, data->data);
935 }
936 else {
937 return data->callback(key, data->data);
938 }
939}
940
941void
942rb_sym_global_symbol_table_foreach_weak_reference(int (*callback)(VALUE *key, void *data), void *data)
943{
944 if (!ruby_global_symbols.sym_set) return;
945
947 .callback = callback,
948 .data = data,
949 };
950
951 rb_concurrent_set_foreach_with_replace(ruby_global_symbols.sym_set, rb_sym_global_symbol_table_foreach_weak_reference_i, &foreach_data);
952}
953
954void
955rb_gc_free_dsymbol(VALUE sym)
956{
957 VALUE str = RSYMBOL(sym)->fstr;
958
959 if (str) {
960 rb_concurrent_set_delete_by_identity(ruby_global_symbols.sym_set, sym);
961
962 RSYMBOL(sym)->fstr = 0;
963 }
964}
965
966/*
967 * call-seq:
968 * intern -> symbol
969 *
970 * :include: doc/string/intern.rdoc
971 *
972 */
973
974VALUE
976{
977 return sym_find_or_insert_dynamic_symbol(&ruby_global_symbols, str);
978}
979
980ID
982{
983 ID id = 0;
984 if (STATIC_SYM_P(sym)) {
985 id = STATIC_SYM2ID(sym);
986 }
987 else if (DYNAMIC_SYM_P(sym)) {
988 GLOBAL_SYMBOLS_LOCKING(symbols) {
989 RUBY_ASSERT(!rb_objspace_garbage_object_p(sym));
990 id = RSYMBOL(sym)->id;
991
992 if (UNLIKELY(!(id & ~ID_SCOPE_MASK))) {
993 VALUE fstr = RSYMBOL(sym)->fstr;
994 ID num = next_id_base();
995
996 RSYMBOL(sym)->id = id |= num;
997 /* make it permanent object */
998
999 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
1000 }
1001 }
1002 }
1003 else {
1004 rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
1005 rb_builtin_class_name(sym));
1006 }
1007 return id;
1008}
1009
1010#undef rb_id2sym
1011VALUE
1013{
1014 if (!DYNAMIC_ID_P(x)) return STATIC_ID2SYM(x);
1015 return get_id_sym(x);
1016}
1017
1018/*
1019 * call-seq:
1020 * name -> string
1021 *
1022 * Returns a frozen string representation of +self+ (not including the leading colon):
1023 *
1024 * :foo.name # => "foo"
1025 * :foo.name.frozen? # => true
1026 *
1027 * Related: Symbol#to_s, Symbol#inspect.
1028 */
1029
1030VALUE
1032{
1033 VALUE str;
1034 if (DYNAMIC_SYM_P(sym)) {
1035 str = RSYMBOL(sym)->fstr;
1037 }
1038 else {
1039 str = rb_id2str(STATIC_SYM2ID(sym));
1040 if (str) RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
1041 }
1042
1043 return str;
1044}
1045
1046VALUE
1047rb_id2str(ID id)
1048{
1049 return get_id_str(id);
1050}
1051
1052const char *
1053rb_id2name(ID id)
1054{
1055 VALUE str = rb_id2str(id);
1056
1057 if (!str) return 0;
1058 return RSTRING_PTR(str);
1059}
1060
1061ID
1062rb_make_internal_id(void)
1063{
1064 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1065}
1066
1067ID
1068rb_make_temporary_id(size_t n)
1069{
1070 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1071 const ID id = max_id - (ID)n;
1072 if (id < RUBY_ATOMIC_LOAD(ruby_global_symbols.next_id)) {
1073 rb_raise(rb_eRuntimeError, "too big to make temporary ID: %" PRIdSIZE, n);
1074 }
1075 return (id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1076}
1077
1078static int
1079symbols_i(VALUE *key, void *data)
1080{
1081 VALUE ary = (VALUE)data;
1082 VALUE sym = (VALUE)*key;
1083
1084 if (sym_set_sym_static_p(sym)) {
1085 rb_ary_push(ary, sym_set_static_sym_untag(sym)->sym);
1086 }
1087 else if (rb_objspace_garbage_object_p(sym)) {
1088 return ST_DELETE;
1089 }
1090 else {
1091 rb_ary_push(ary, sym);
1092 }
1093
1094 return ST_CONTINUE;
1095}
1096
1097VALUE
1099{
1100 VALUE ary;
1101
1102 GLOBAL_SYMBOLS_LOCKING(symbols) {
1103 ary = rb_ary_new2(rb_concurrent_set_size(symbols->sym_set));
1104 rb_concurrent_set_foreach_with_replace(symbols->sym_set, symbols_i, (void *)ary);
1105 }
1106
1107 return ary;
1108}
1109
1110size_t
1111rb_sym_immortal_count(void)
1112{
1113 return (size_t)(RUBY_ATOMIC_LOAD(ruby_global_symbols.next_id) - 1);
1114}
1115
1116int
1118{
1119 return is_const_id(id);
1120}
1121
1122int
1124{
1125 return is_class_id(id);
1126}
1127
1128int
1130{
1131 return is_global_id(id);
1132}
1133
1134int
1136{
1137 return is_instance_id(id);
1138}
1139
1140int
1142{
1143 return is_attrset_id(id);
1144}
1145
1146int
1148{
1149 return is_local_id(id);
1150}
1151
1152int
1154{
1155 return is_internal_id(id);
1156}
1157
1158int
1159rb_is_const_sym(VALUE sym)
1160{
1161 return is_const_sym(sym);
1162}
1163
1164int
1165rb_is_attrset_sym(VALUE sym)
1166{
1167 return is_attrset_sym(sym);
1168}
1169
1170ID
1171rb_check_id(volatile VALUE *namep)
1172{
1173 VALUE tmp;
1174 VALUE name = *namep;
1175
1176 if (STATIC_SYM_P(name)) {
1177 return STATIC_SYM2ID(name);
1178 }
1179 else if (DYNAMIC_SYM_P(name)) {
1180 if (SYMBOL_PINNED_P(name)) {
1181 return RSYMBOL(name)->id;
1182 }
1183 else {
1184 *namep = RSYMBOL(name)->fstr;
1185 return 0;
1186 }
1187 }
1188 else if (!RB_TYPE_P(name, T_STRING)) {
1189 tmp = rb_check_string_type(name);
1190 if (NIL_P(tmp)) {
1191 rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
1192 name);
1193 }
1194 name = tmp;
1195 *namep = name;
1196 }
1197
1198 sym_check_asciionly(name, false);
1199
1200 return lookup_str_id(name);
1201}
1202
1203// Used by yjit for handling .send without throwing exceptions
1204ID
1205rb_get_symbol_id(VALUE name)
1206{
1207 if (STATIC_SYM_P(name)) {
1208 return STATIC_SYM2ID(name);
1209 }
1210 else if (DYNAMIC_SYM_P(name)) {
1211 if (SYMBOL_PINNED_P(name)) {
1212 return RSYMBOL(name)->id;
1213 }
1214 else {
1215 return 0;
1216 }
1217 }
1218 else if (RB_TYPE_P(name, T_STRING)) {
1219 return lookup_str_id(name);
1220 }
1221 else {
1222 return 0;
1223 }
1224}
1225
1226
1227VALUE
1228rb_check_symbol(volatile VALUE *namep)
1229{
1230 VALUE sym;
1231 VALUE tmp;
1232 VALUE name = *namep;
1233
1234 if (STATIC_SYM_P(name)) {
1235 return name;
1236 }
1237 else if (DYNAMIC_SYM_P(name)) {
1238 RUBY_ASSERT(!rb_objspace_garbage_object_p(name));
1239 return name;
1240 }
1241 else if (!RB_TYPE_P(name, T_STRING)) {
1242 tmp = rb_check_string_type(name);
1243 if (NIL_P(tmp)) {
1244 rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string",
1245 name);
1246 }
1247 name = tmp;
1248 *namep = name;
1249 }
1250
1251 sym_check_asciionly(name, false);
1252
1253 if ((sym = sym_find(name)) != 0) {
1254 return sym;
1255 }
1256
1257 return Qnil;
1258}
1259
1260ID
1261rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
1262{
1263 struct RString fake_str = {RBASIC_INIT};
1264 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1265
1266 sym_check_asciionly(name, true);
1267
1268 return lookup_str_id(name);
1269}
1270
1271VALUE
1272rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
1273{
1274 VALUE sym;
1275 struct RString fake_str = {RBASIC_INIT};
1276 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1277
1278 sym_check_asciionly(name, true);
1279
1280 if ((sym = sym_find(name)) != 0) {
1281 return sym;
1282 }
1283
1284 return Qnil;
1285}
1286
1287#undef rb_sym_intern_ascii_cstr
1288#ifdef __clang__
1289NOINLINE(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
1290#else
1291FUNC_MINIMIZED(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
1292FUNC_MINIMIZED(VALUE rb_sym_intern_ascii(const char *ptr, long len));
1293FUNC_MINIMIZED(VALUE rb_sym_intern_ascii_cstr(const char *ptr));
1294#endif
1295
1296VALUE
1297rb_sym_intern(const char *ptr, long len, rb_encoding *enc)
1298{
1299 struct RString fake_str = {RBASIC_INIT};
1300 const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
1301 return rb_str_intern(name);
1302}
1303
1304VALUE
1305rb_sym_intern_ascii(const char *ptr, long len)
1306{
1307 return rb_sym_intern(ptr, len, rb_usascii_encoding());
1308}
1309
1310VALUE
1311rb_sym_intern_ascii_cstr(const char *ptr)
1312{
1313 return rb_sym_intern_ascii(ptr, strlen(ptr));
1314}
1315
1316VALUE
1317rb_to_symbol_type(VALUE obj)
1318{
1319 return rb_convert_type_with_id(obj, T_SYMBOL, "Symbol", idTo_sym);
1320}
1321
1322int
1323rb_is_const_name(VALUE name)
1324{
1325 return rb_str_symname_type(name, 0) == ID_CONST;
1326}
1327
1328int
1329rb_is_class_name(VALUE name)
1330{
1331 return rb_str_symname_type(name, 0) == ID_CLASS;
1332}
1333
1334int
1335rb_is_instance_name(VALUE name)
1336{
1337 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1338}
1339
1340int
1341rb_is_local_name(VALUE name)
1342{
1343 return rb_str_symname_type(name, 0) == ID_LOCAL;
1344}
1345
1346#include "id_table.c"
1347#include "symbol.rbinc"
#define RUBY_ASSERT_BUILTIN_TYPE(obj, type)
A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or built-in type of obj is type.
Definition assert.h:291
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
Definition atomic.h:69
#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...
Definition atomic.h:118
#define RUBY_ATOMIC_LOAD(var)
Atomic load.
Definition atomic.h:175
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 xfree
Old name of ruby_xfree.
Definition xmalloc.h:58
#define ISUPPER
Old name of rb_isupper.
Definition ctype.h:89
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:131
#define SYM2ID
Old name of RB_SYM2ID.
Definition symbol.h:45
#define xmalloc
Old name of ruby_xmalloc.
Definition xmalloc.h:53
#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 DYNAMIC_SYM_P
Old name of RB_DYNAMIC_SYM_P.
Definition value_type.h:86
#define Qnil
Old name of RUBY_Qnil.
#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 IMMEDIATE_P
Old name of RB_IMMEDIATE_P.
#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:2332
VALUE rb_eTypeError
TypeError exception.
Definition error.c:1418
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:2347
VALUE rb_eRuntimeError
RuntimeError exception.
Definition error.c:1416
VALUE rb_eEncodingError
EncodingError exception.
Definition error.c:1424
VALUE rb_cSymbol
Symbol class.
Definition string.c:85
#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:930
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:562
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:1272
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:762
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:1261
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:1098
int rb_is_global_id(ID id)
Classifies the given ID, then sees if it is a global variable.
Definition symbol.c:1129
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
Definition symbol.c:1135
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
Definition symbol.c:1117
int rb_is_junk_id(ID)
Classifies the given ID, then sees if it is a junk ID.
Definition symbol.c:1153
int rb_symname_p(const char *str)
Sees if the passed C string constructs a valid syntactic symbol.
Definition symbol.c:556
int rb_is_class_id(ID id)
Classifies the given ID, then sees if it is a class variable.
Definition symbol.c:1123
int rb_is_attrset_id(ID id)
Classifies the given ID, then sees if it is an attribute writer.
Definition symbol.c:1141
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
Definition symbol.c:1147
int rb_str_hash_cmp(VALUE str1, VALUE str2)
Compares two strings.
Definition string.c:4181
VALUE rb_str_dup(VALUE str)
Duplicates a string.
Definition string.c:1979
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
Definition string.c:4167
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
Definition string.c:3586
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
Definition string.c:2968
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
Definition symbol.c:975
VALUE rb_check_symbol(volatile VALUE *namep)
Identical to rb_check_id(), except it returns an instance of rb_cSymbol instead.
Definition symbol.c:1228
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
Definition symbol.c:1012
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
Definition symbol.c:1171
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
Definition symbol.c:1031
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
Definition symbol.c:981
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
#define RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
Definition rtypeddata.h:119
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
Definition rtypeddata.h:514
Ruby's String.
Definition rstring.h:196
char * ptr
Pointer to the contents of the string.
Definition rstring.h:222
This is the struct that holds necessary info for a struct.
Definition rtypeddata.h:211
Definition symbol.c:167
Definition symbol.c:102
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