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