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"
27#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
29# define USE_SYMBOL_GC 0
32# define USE_SYMBOL_GC 1
34#if defined(SYMBOL_DEBUG) && (SYMBOL_DEBUG+0)
36# define SYMBOL_DEBUG 1
39# define SYMBOL_DEBUG 0
41#ifndef CHECK_ID_SERIAL
42# define CHECK_ID_SERIAL SYMBOL_DEBUG
45#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
47#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
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)
54#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
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)
66 for (i =
'!'; i <=
'~'; ++i) {
69 register_static_symid(i, &c, 1, enc);
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);
77static const int ID_ENTRY_UNIT = 512;
87static const struct st_hash_type symhash = {
97 VALUE dsym_fstrs = rb_ident_hash_new();
98 symbols->dsymbol_fstr_hash = dsym_fstrs;
99 rb_vm_register_global_object(dsym_fstrs);
102 symbols->str_sym = st_init_table_with_size(&symhash, 1000);
103 symbols->ids = rb_ary_hidden_new(0);
104 rb_vm_register_global_object(symbols->ids);
112WARN_UNUSED_RESULT(
static ID lookup_str_id(
VALUE str));
114WARN_UNUSED_RESULT(
static VALUE lookup_str_sym(
const VALUE str));
115WARN_UNUSED_RESULT(
static VALUE lookup_id_str(
ID id));
116WARN_UNUSED_RESULT(
static ID intern_str(
VALUE str,
int mutable));
118#define GLOBAL_SYMBOLS_ENTER(symbols) rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()
119#define GLOBAL_SYMBOLS_LEAVE() RB_VM_LOCK_LEAVE()
127 if (!is_notop_id(
id)) {
129 case tAREF:
case tASET:
132 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
138 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
139 case ID_CONST:
case ID_CLASS:
case ID_JUNK:
145 if ((str = lookup_id_str(
id)) != 0) {
146 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
158 if (!(str = lookup_id_str(
id))) {
169 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
170 (
int)
sizeof(id_types[0]), id_types[scope], (
VALUE)
id);
174 sym = lookup_str_sym(str);
175 id = sym ?
rb_sym2id(sym) : intern_str(str, 1);
180is_special_global_name(
const char *m,
const char *e, rb_encoding *enc)
184 if (m >= e)
return 0;
185 if (is_global_name_punct(*m)) {
188 else if (*m ==
'-') {
189 if (++m >= e)
return 0;
190 if (is_identchar(m, e, enc)) {
192 m += rb_enc_mbclen(m, e, enc);
200 }
while (m < e &&
ISDIGIT(*m));
202 return m == e ? mb + 1 : 0;
218rb_sym_constant_char_p(
const char *name,
long nlen, rb_encoding *enc)
221 const char *end = name + nlen;
223 if (nlen < 1)
return FALSE;
225 c = rb_enc_precise_mbclen(name, end, enc);
228 c = rb_enc_mbc_to_codepoint(name, end, enc);
231 if (ONIGENC_IS_UNICODE(enc)) {
232 static int ctype_titlecase = 0;
233 if (!ctype_titlecase) {
234 static const UChar cname[] =
"titlecaseletter";
235 static const UChar *
const end = cname +
sizeof(cname) - 1;
236 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
242 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
243 const OnigUChar *beg = (
const OnigUChar *)name;
244 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
245 &beg, (
const OnigUChar *)end,
247 if (r > 0 && (r !=
len || memcmp(fold, name, r)))
253#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
254#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
257 const enum { invalid, stophere, needmore, } kind;
258 const enum ruby_id_types type;
262#define t struct enc_synmane_type_leading_chars_tag
265enc_synmane_type_leading_chars(const char *name,
long len, rb_encoding *enc,
int allowed_attrset)
267 const char *m = name;
268 const char *e = m +
len;
270 if (! rb_enc_asciicompat(enc)) {
271 return (t) { invalid, 0, 0, };
274 return (t) { invalid, 0, 0, };
276 else if (
len <= 0 ) {
277 return (t) { invalid, 0, 0, };
281 return (t) { invalid, 0, 0, };
284 if (is_special_global_name(++m, e, enc)) {
285 return (t) { stophere, ID_GLOBAL,
len, };
288 return (t) { needmore, ID_GLOBAL, 1, };
293 default:
return (t) { needmore, ID_INSTANCE, 1, };
294 case '@':
return (t) { needmore, ID_CLASS, 2, };
299 default:
return (t) { stophere, ID_JUNK, 1, };
300 case '<':
return (t) { stophere, ID_JUNK, 2, };
303 default:
return (t) { stophere, ID_JUNK, 2, };
304 case '>':
return (t) { stophere, ID_JUNK, 3, };
310 default:
return (t) { stophere, ID_JUNK, 1, };
311 case '>':
case '=':
return (t) { stophere, ID_JUNK, 2, };
316 default:
return (t) { invalid, 0, 1, };
317 case '~':
return (t) { stophere, ID_JUNK, 2, };
320 default:
return (t) { stophere, ID_JUNK, 2, };
321 case '=':
return (t) { stophere, ID_JUNK, 3, };
327 default:
return (t) { stophere, ID_JUNK, 1, };
328 case '*':
return (t) { stophere, ID_JUNK, 2, };
333 default:
return (t) { stophere, ID_JUNK, 1, };
334 case '@':
return (t) { stophere, ID_JUNK, 2, };
337 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
338 return (t) { stophere, ID_JUNK, 1, };
342 default:
return (t) { needmore, ID_JUNK, 0, };
345 default:
return (t) { stophere, ID_JUNK, 2, };
346 case '=':
return (t) { stophere, ID_JUNK, 3, };
352 case '=':
case '~':
return (t) { stophere, ID_JUNK, 2, };
354 if (allowed_attrset & (1U << ID_JUNK)) {
355 return (t) { needmore, ID_JUNK, 1, };
358 return (t) { stophere, ID_JUNK, 1, };
363 if (rb_sym_constant_char_p(name,
len, enc)) {
364 return (t) { needmore, ID_CONST, 0, };
367 return (t) { needmore, ID_LOCAL, 0, };
374rb_enc_symname_type(
const char *name,
long len, rb_encoding *enc,
unsigned int allowed_attrset)
377 enc_synmane_type_leading_chars(name,
len, enc, allowed_attrset);
378 const char *m = name + f.nread;
379 const char *e = name +
len;
380 int type = (int)f.type;
383 case invalid:
return -1;
384 case stophere:
break;
388 if (
len > 1 && *(e-1) ==
'=') {
389 type = rb_enc_symname_type(name,
len-1, enc, allowed_attrset);
390 if (allowed_attrset & (1U <<
type))
return ID_ATTRSET;
394 while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
398 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
401 if (m + 1 < e || *m !=
'=')
break;
404 if (!(allowed_attrset & (1U <<
type)))
return -1;
411 return m == e ?
type : -1;
417 return rb_enc_symname_type(name,
len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
421rb_str_symname_type(
VALUE name,
unsigned int allowed_attrset)
424 long len = RSTRING_LEN(name);
425 int type = rb_enc_symname_type(ptr,
len, rb_enc_get(name), allowed_attrset);
437 size_t idx = num / ID_ENTRY_UNIT;
439 VALUE ary, ids = symbols->ids;
440 if (idx >= (
size_t)
RARRAY_LEN(ids) ||
NIL_P(ary = rb_ary_entry(ids, (
long)idx))) {
441 ary = rb_ary_hidden_new(ID_ENTRY_UNIT * ID_ENTRY_SIZE);
442 rb_ary_store(ids, (
long)idx, ary);
444 idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
445 rb_ary_store(ary, (
long)idx + ID_ENTRY_STR, str);
446 rb_ary_store(ary, (
long)idx + ID_ENTRY_SYM, sym);
450get_id_serial_entry(rb_id_serial_t num,
ID id,
const enum id_entry_type t)
454 GLOBAL_SYMBOLS_ENTER(symbols);
456 if (num && num <= symbols->last_id) {
457 size_t idx = num / ID_ENTRY_UNIT;
458 VALUE ids = symbols->ids;
460 if (idx < (
size_t)
RARRAY_LEN(ids) && !
NIL_P(ary = rb_ary_entry(ids, (
long)idx))) {
461 long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
462 result = rb_ary_entry(ary, pos + t);
467 else if (CHECK_ID_SERIAL) {
470 if (t != ID_ENTRY_SYM)
471 sym = rb_ary_entry(ary, pos + ID_ENTRY_SYM);
473 if (STATIC_SYM2ID(sym) !=
id) result = 0;
476 if (RSYMBOL(sym)->
id !=
id) result = 0;
483 GLOBAL_SYMBOLS_LEAVE();
502get_id_entry(
ID id,
const enum id_entry_type t)
504 return get_id_serial_entry(rb_id_to_serial(
id),
id, t);
508rb_static_id_valid_p(
ID id)
510 return STATIC_ID2SYM(
id) == get_id_entry(
id, ID_ENTRY_SYM);
514rb_id_serial_to_id(rb_id_serial_t num)
516 if (is_notop_id((
ID)num)) {
517 VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
518 if (sym)
return SYM2ID(sym);
519 return ((
ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
527register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
530 rb_fatal(
"symbol :% "PRIsVALUE
" is already registered with %"PRIxVALUE,
543 st_update(symbols->str_sym, (st_data_t)str,
544 register_sym_update_callback, (st_data_t)sym);
547 st_add_direct(symbols->str_sym, (st_data_t)str, (st_data_t)sym);
552rb_free_static_symid_str(
void)
554 GLOBAL_SYMBOLS_ENTER(symbols)
556 st_free_table(symbols->str_sym);
558 GLOBAL_SYMBOLS_LEAVE();
566 st_data_t str_data = (st_data_t)str;
567 if (!st_delete(symbols->str_sym, &str_data, NULL)) {
568 rb_bug(
"%p can't remove str from str_id (%s)", (
void *)sym, RSTRING_PTR(str));
573register_static_symid(
ID id,
const char *name,
long len, rb_encoding *enc)
575 VALUE str = rb_enc_str_new(name,
len, enc);
576 return register_static_symid_str(
id, str);
580register_static_symid_str(
ID id,
VALUE str)
582 rb_id_serial_t num = rb_id_to_serial(
id);
583 VALUE sym = STATIC_ID2SYM(
id);
586 str = rb_fstring(str);
588 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
590 GLOBAL_SYMBOLS_ENTER(symbols)
592 register_sym(symbols, str, sym);
593 set_id_entry(symbols, num, str, sym);
595 GLOBAL_SYMBOLS_LEAVE();
601sym_check_asciionly(
VALUE str,
bool fake_str)
603 if (!rb_enc_asciicompat(rb_enc_get(str)))
return FALSE;
607 str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
610 rb_enc_name(rb_enc_get(str)), str);
625must_be_dynamic_symbol(
VALUE x)
632 rb_bug(
"wrong argument: %s (inappropriate Symbol)", RSTRING_PTR(str));
635 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
639 rb_bug(
"wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
654 rb_enc_set_index((
VALUE)obj, rb_enc_to_index(enc));
661 obj->hashval = RSHIFT((
long)hashval, 1);
662 register_sym(symbols, str, (
VALUE)obj);
663 rb_hash_aset(symbols->dsymbol_fstr_hash, str,
Qtrue);
664 RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(obj->fstr));
674 if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
675 const VALUE fstr = RSYMBOL(sym)->fstr;
676 const ID type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
677 RSYMBOL(sym)->fstr = 0;
678 unregister_sym(symbols, fstr, sym);
679 return dsymbol_alloc(symbols,
rb_cSymbol, fstr, rb_enc_get(fstr),
type);
687lookup_str_id(
VALUE str)
692 GLOBAL_SYMBOLS_ENTER(symbols);
694 found = st_lookup(symbols->str_sym, (st_data_t)str, &sym_data);
696 GLOBAL_SYMBOLS_LEAVE();
702 return STATIC_SYM2ID(sym);
705 ID id = RSYMBOL(sym)->id;
706 if (
id & ~ID_SCOPE_MASK)
return id;
709 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
710 rb_builtin_class_name(sym), sym, str);
720 if (st_lookup(symbols->str_sym, (st_data_t)str, &sym_data)) {
723 sym = dsymbol_check(symbols, sym);
733lookup_str_sym(
const VALUE str)
737 GLOBAL_SYMBOLS_ENTER(symbols);
739 sym = lookup_str_sym_with_lock(symbols, str);
741 GLOBAL_SYMBOLS_LEAVE();
749 return get_id_entry(
id, ID_ENTRY_STR);
753rb_intern3(
const char *name,
long len, rb_encoding *enc)
757 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
759 sym = lookup_str_sym(str);
761 str = rb_enc_str_new(name,
len, enc);
762 return intern_str(str, 1);
769 rb_id_serial_t next_serial = symbols->last_id + 1;
771 if (next_serial == 0) {
775 const size_t num = ++symbols->last_id;
776 id = num << ID_SCOPE_SHIFT;
786 GLOBAL_SYMBOLS_ENTER(symbols);
788 id = next_id_base_with_lock(symbols);
790 GLOBAL_SYMBOLS_LEAVE();
795intern_str(
VALUE str,
int mutable)
800 id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
801 if (
id == (
ID)-1)
id = ID_JUNK;
802 if (sym_check_asciionly(str,
false)) {
806 if ((nid = next_id_base()) == (
ID)-1) {
813 return register_static_symid_str(
id, str);
817rb_intern2(
const char *name,
long len)
824rb_intern(
const char *name)
826 return rb_intern2(name, strlen(name));
832 VALUE sym = lookup_str_sym(str);
838 return intern_str(str, 0);
842rb_gc_free_dsymbol(
VALUE sym)
844 VALUE str = RSYMBOL(sym)->fstr;
847 RSYMBOL(sym)->fstr = 0;
849 GLOBAL_SYMBOLS_ENTER(symbols);
851 unregister_sym(symbols, str, sym);
852 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, str);
854 GLOBAL_SYMBOLS_LEAVE();
883 GLOBAL_SYMBOLS_ENTER(symbols);
885 sym = lookup_str_sym_with_lock(symbols, str);
890 else if (USE_SYMBOL_GC) {
891 rb_encoding *enc = rb_enc_get(str);
893 if (enc != ascii && sym_check_asciionly(str,
false)) {
895 rb_enc_associate(str, ascii);
903 str = rb_fstring(str);
904 int type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
909 ID id = intern_str(str, 0);
913 GLOBAL_SYMBOLS_LEAVE();
922 id = STATIC_SYM2ID(sym);
925 GLOBAL_SYMBOLS_ENTER(symbols);
927 sym = dsymbol_check(symbols, sym);
928 id = RSYMBOL(sym)->id;
930 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
931 VALUE fstr = RSYMBOL(sym)->fstr;
932 ID num = next_id_base_with_lock(symbols);
934 RSYMBOL(sym)->id =
id |= num;
937 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
938 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
941 GLOBAL_SYMBOLS_LEAVE();
944 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Symbol)",
945 rb_builtin_class_name(sym));
954 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
955 return get_id_entry(x, ID_ENTRY_SYM);
975 str = RSYMBOL(sym)->fstr;
979 str = rb_id2str(STATIC_SYM2ID(sym));
989 return lookup_id_str(
id);
995 VALUE str = rb_id2str(
id);
1002rb_make_internal_id(
void)
1004 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
1008rb_make_temporary_id(
size_t n)
1010 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
1011 const ID id = max_id - (
ID)n;
1012 if (
id <= ruby_global_symbols.last_id) {
1015 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
1019symbols_i(st_data_t key, st_data_t value, st_data_t arg)
1025 rb_ary_push(ary, sym);
1031 else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
1032 RSYMBOL(sym)->fstr = 0;
1036 rb_ary_push(ary, sym);
1047 GLOBAL_SYMBOLS_ENTER(symbols);
1050 st_foreach(symbols->str_sym, symbols_i, ary);
1052 GLOBAL_SYMBOLS_LEAVE();
1058rb_sym_immortal_count(
void)
1060 return (
size_t)ruby_global_symbols.last_id;
1066 return is_const_id(
id);
1072 return is_class_id(
id);
1078 return is_global_id(
id);
1084 return is_instance_id(
id);
1090 return is_attrset_id(
id);
1096 return is_local_id(
id);
1102 return is_junk_id(
id);
1106rb_is_const_sym(
VALUE sym)
1108 return is_const_sym(sym);
1112rb_is_attrset_sym(
VALUE sym)
1114 return is_attrset_sym(sym);
1121 VALUE name = *namep;
1124 return STATIC_SYM2ID(name);
1127 if (SYMBOL_PINNED_P(name)) {
1128 return RSYMBOL(name)->id;
1131 *namep = RSYMBOL(name)->fstr;
1138 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1145 sym_check_asciionly(name,
false);
1147 return lookup_str_id(name);
1152rb_get_symbol_id(
VALUE name)
1155 return STATIC_SYM2ID(name);
1158 if (SYMBOL_PINNED_P(name)) {
1159 return RSYMBOL(name)->id;
1166 return lookup_str_id(name);
1179 VALUE name = *namep;
1185 if (!SYMBOL_PINNED_P(name)) {
1186 GLOBAL_SYMBOLS_ENTER(symbols);
1188 name = dsymbol_check(symbols, name);
1190 GLOBAL_SYMBOLS_LEAVE();
1199 rb_raise(
rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1206 sym_check_asciionly(name,
false);
1208 if ((sym = lookup_str_sym(name)) != 0) {
1219 const VALUE name = rb_setup_fake_str(&fake_str, ptr,
len, enc);
1221 sym_check_asciionly(name,
true);
1223 return lookup_str_id(name);
1231 const VALUE name = rb_setup_fake_str(&fake_str, ptr,
len, enc);
1233 sym_check_asciionly(name,
true);
1235 if ((sym = lookup_str_sym(name)) != 0) {
1242#undef rb_sym_intern_ascii_cstr
1244NOINLINE(
VALUE rb_sym_intern(
const char *ptr,
long len, rb_encoding *enc));
1246FUNC_MINIMIZED(
VALUE rb_sym_intern(
const char *ptr,
long len, rb_encoding *enc));
1247FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii(
const char *ptr,
long len));
1248FUNC_MINIMIZED(
VALUE rb_sym_intern_ascii_cstr(
const char *ptr));
1252rb_sym_intern(
const char *ptr,
long len, rb_encoding *enc)
1255 const VALUE name = rb_setup_fake_str(&fake_str, ptr,
len, enc);
1260rb_sym_intern_ascii(
const char *ptr,
long len)
1266rb_sym_intern_ascii_cstr(
const char *ptr)
1268 return rb_sym_intern_ascii(ptr, strlen(ptr));
1272rb_to_symbol_type(
VALUE obj)
1274 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1278rb_is_const_name(
VALUE name)
1280 return rb_str_symname_type(name, 0) == ID_CONST;
1284rb_is_class_name(
VALUE name)
1286 return rb_str_symname_type(name, 0) == ID_CLASS;
1290rb_is_instance_name(
VALUE name)
1292 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1296rb_is_local_name(
VALUE name)
1298 return rb_str_symname_type(name, 0) == ID_LOCAL;
1301#include "id_table.c"
1302#include "symbol.rbinc"
#define RUBY_ASSERT_BUILTIN_TYPE(obj, type)
A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or built-in type of obj is type.
static bool rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isupper(), except it additionally takes an encoding.
static bool rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc)
Queries if the passed code point is of passed character type in the passed encoding.
static bool rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
Identical to rb_islower(), except it additionally takes an encoding.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define T_STRING
Old name of RUBY_T_STRING.
#define ISUPPER
Old name of rb_isupper.
#define ID2SYM
Old name of RB_ID2SYM.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define SYM2ID
Old name of RB_SYM2ID.
#define ISDIGIT
Old name of rb_isdigit.
#define STATIC_SYM_P
Old name of RB_STATIC_SYM_P.
#define MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
#define ISALPHA
Old name of rb_isalpha.
#define ISASCII
Old name of rb_isascii.
#define Qtrue
Old name of RUBY_Qtrue.
#define DYNAMIC_SYM_P
Old name of RB_DYNAMIC_SYM_P.
#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.
#define NIL_P
Old name of RB_NIL_P.
#define MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
#define FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ISALNUM
Old name of rb_isalnum.
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
VALUE rb_eTypeError
TypeError exception.
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eEncodingError
EncodingError exception.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_cSymbol
Symbol class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
int rb_enc_symname_p(const char *str, rb_encoding *enc)
Identical to rb_symname_p(), except it additionally takes an encoding.
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id_cstr(), except for the return type.
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
Identical to rb_enc_symname_p(), except it additionally takes the passed string's length.
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id(), except it takes a pointer to a memory region instead of Ruby's string.
VALUE rb_sym_all_symbols(void)
Collects every single bits of symbols that have ever interned in the entire history of the current pr...
int rb_is_global_id(ID id)
Classifies the given ID, then sees if it is a global variable.
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
int rb_is_junk_id(ID)
Classifies the given ID, then sees if it is a junk ID.
int rb_symname_p(const char *str)
Sees if the passed C string constructs a valid syntactic symbol.
int rb_is_class_id(ID id)
Classifies the given ID, then sees if it is a class variable.
int rb_is_attrset_id(ID id)
Classifies the given ID, then sees if it is an attribute writer.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
int rb_str_hash_cmp(VALUE str1, VALUE str2)
Compares two strings.
VALUE rb_str_ellipsize(VALUE str, long len)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_check_symbol(volatile VALUE *namep)
Identical to rb_check_id(), except it returns an instance of rb_cSymbol instead.
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
int len
Length of the buffer.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
Defines RBIMPL_ATTR_NONSTRING.
#define RBIMPL_ATTR_NONSTRING()
Wraps (or simulates) __attribute__((nonstring))
#define RARRAY_LEN
Just another name of rb_array_len.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.