14#include "internal/error.h"
15#include "internal/gc.h"
16#include "internal/hash.h"
17#include "internal/object.h"
18#include "internal/symbol.h"
19#include "internal/vm.h"
27# define USE_SYMBOL_GC 1
30# define SYMBOL_DEBUG 0
32#ifndef CHECK_ID_SERIAL
33# define CHECK_ID_SERIAL SYMBOL_DEBUG
36#define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
38#define STATIC_SYM2ID(sym) RSHIFT((VALUE)(sym), RUBY_SPECIAL_SHIFT)
40static ID register_static_symid(ID,
const char *,
long,
rb_encoding *);
41static ID register_static_symid_str(ID, VALUE);
42#define REGISTER_SYMID(id, name) register_static_symid((id), (name), strlen(name), enc)
45#define is_identchar(p,e,enc) (ISALNUM((unsigned char)*(p)) || (*(p)) == '_' || !ISASCII(*(p)))
47#define op_tbl_count numberof(op_tbl)
48STATIC_ASSERT(op_tbl_name_size,
sizeof(op_tbl[0].name) == 3);
49#define op_tbl_len(i) (!op_tbl[i].name[1] ? 1 : !op_tbl[i].name[2] ? 2 : 3)
57 for (i =
'!'; i <=
'~'; ++i) {
60 register_static_symid(i, &c, 1, enc);
63 for (i = 0; i < op_tbl_count; ++i) {
64 register_static_symid(op_tbl[i].token, op_tbl[i].name, op_tbl_len(i), enc);
68static const int ID_ENTRY_UNIT = 512;
88 VALUE dsym_fstrs = rb_ident_hash_new();
89 symbols->dsymbol_fstr_hash = dsym_fstrs;
91 rb_obj_hide(dsym_fstrs);
93 symbols->str_sym = st_init_table_with_size(&symhash, 1000);
101WARN_UNUSED_RESULT(
static VALUE dsymbol_alloc(
rb_symbols_t *symbols,
const VALUE klass,
const VALUE str,
rb_encoding *
const enc,
const ID
type));
102WARN_UNUSED_RESULT(
static VALUE dsymbol_check(
rb_symbols_t *symbols,
const VALUE sym));
103WARN_UNUSED_RESULT(
static ID lookup_str_id(VALUE str));
104WARN_UNUSED_RESULT(
static VALUE lookup_str_sym_with_lock(
rb_symbols_t *symbols,
const VALUE str));
105WARN_UNUSED_RESULT(
static VALUE lookup_str_sym(
const VALUE str));
106WARN_UNUSED_RESULT(
static VALUE lookup_id_str(ID
id));
107WARN_UNUSED_RESULT(
static ID intern_str(VALUE str,
int mutable));
109#define GLOBAL_SYMBOLS_ENTER(symbols) rb_symbols_t *symbols = &ruby_global_symbols; RB_VM_LOCK_ENTER()
110#define GLOBAL_SYMBOLS_LEAVE() RB_VM_LOCK_LEAVE()
118 if (!is_notop_id(
id)) {
120 case tAREF:
case tASET:
123 rb_name_error(
id,
"cannot make operator ID :%"PRIsVALUE
" attrset",
129 case ID_LOCAL:
case ID_INSTANCE:
case ID_GLOBAL:
130 case ID_CONST:
case ID_CLASS:
case ID_JUNK:
136 if ((str = lookup_id_str(
id)) != 0) {
137 rb_name_error(
id,
"cannot make unknown type ID %d:%"PRIsVALUE
" attrset",
141 rb_name_error_str(
Qnil,
"cannot make unknown type anonymous ID %d:%"PRIxVALUE
" attrset",
149 if (!(str = lookup_id_str(
id))) {
150 static const char id_types[][8] = {
160 rb_name_error(
id,
"cannot make anonymous %.*s ID %"PRIxVALUE
" attrset",
161 (
int)
sizeof(id_types[0]), id_types[scope], (VALUE)
id);
165 sym = lookup_str_sym(str);
166 id = sym ?
rb_sym2id(sym) : intern_str(str, 1);
171is_special_global_name(
const char *m,
const char *e,
rb_encoding *enc)
175 if (m >= e)
return 0;
176 if (is_global_name_punct(*m)) {
179 else if (*m ==
'-') {
180 if (++m >= e)
return 0;
181 if (is_identchar(m, e, enc)) {
191 }
while (m < e &&
ISDIGIT(*m));
193 return m == e ? mb + 1 : 0;
209rb_sym_constant_char_p(
const char *name,
long nlen,
rb_encoding *enc)
212 const char *end = name + nlen;
214 if (nlen < 1)
return FALSE;
220 if (ONIGENC_IS_UNICODE(enc)) {
221 static int ctype_titlecase = 0;
224 if (!ctype_titlecase) {
225 static const UChar cname[] =
"titlecaseletter";
226 static const UChar *
const end = cname +
sizeof(cname) - 1;
227 ctype_titlecase = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, cname, end);
233 OnigUChar fold[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
234 const OnigUChar *beg = (
const OnigUChar *)name;
235 int r = enc->mbc_case_fold(ONIGENC_CASE_FOLD,
236 &beg, (
const OnigUChar *)end,
238 if (r > 0 && (r != len || memcmp(fold, name, r)))
244#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
245#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
248 const enum { invalid, stophere, needmore, } kind;
249 const enum ruby_id_types type;
253#define t struct enc_synmane_type_leading_chars_tag
256enc_synmane_type_leading_chars(const char *name,
long len,
rb_encoding *enc,
int allowed_attrset)
258 const char *m = name;
259 const char *e = m + len;
262 return (t) { invalid, 0, 0, };
265 return (t) { invalid, 0, 0, };
267 else if ( len <= 0 ) {
268 return (t) { invalid, 0, 0, };
272 return (t) { invalid, 0, 0, };
275 if (is_special_global_name(++m, e, enc)) {
276 return (t) { stophere, ID_GLOBAL, len, };
279 return (t) { needmore, ID_GLOBAL, 1, };
284 default:
return (t) { needmore, ID_INSTANCE, 1, };
285 case '@':
return (t) { needmore, ID_CLASS, 2, };
290 default:
return (t) { stophere, ID_JUNK, 1, };
291 case '<':
return (t) { stophere, ID_JUNK, 2, };
294 default:
return (t) { stophere, ID_JUNK, 2, };
295 case '>':
return (t) { stophere, ID_JUNK, 3, };
301 default:
return (t) { stophere, ID_JUNK, 1, };
302 case '>':
case '=':
return (t) { stophere, ID_JUNK, 2, };
307 default:
return (t) { invalid, 0, 1, };
308 case '~':
return (t) { stophere, ID_JUNK, 2, };
311 default:
return (t) { stophere, ID_JUNK, 2, };
312 case '=':
return (t) { stophere, ID_JUNK, 3, };
318 default:
return (t) { stophere, ID_JUNK, 1, };
319 case '*':
return (t) { stophere, ID_JUNK, 2, };
324 default:
return (t) { stophere, ID_JUNK, 1, };
325 case '@':
return (t) { stophere, ID_JUNK, 2, };
328 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
329 return (t) { stophere, ID_JUNK, 1, };
333 default:
return (t) { needmore, ID_JUNK, 0, };
336 default:
return (t) { stophere, ID_JUNK, 2, };
337 case '=':
return (t) { stophere, ID_JUNK, 3, };
343 case '=':
case '~':
return (t) { stophere, ID_JUNK, 2, };
345 if (allowed_attrset & (1U << ID_JUNK)) {
346 return (t) { needmore, ID_JUNK, 1, };
349 return (t) { stophere, ID_JUNK, 1, };
354 if (rb_sym_constant_char_p(name, len, enc)) {
355 return (t) { needmore, ID_CONST, 0, };
358 return (t) { needmore, ID_LOCAL, 0, };
365rb_enc_symname_type(
const char *name,
long len,
rb_encoding *enc,
unsigned int allowed_attrset)
368 enc_synmane_type_leading_chars(name, len, enc, allowed_attrset);
369 const char *m = name + f.nread;
370 const char *e = name + len;
371 int type = (int)f.type;
374 case invalid:
return -1;
375 case stophere:
break;
379 if (len > 1 && *(e-1) ==
'=') {
380 type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
381 if (
type != ID_ATTRSET)
return ID_ATTRSET;
385 while (m < e && is_identchar(m, e, enc)) m +=
rb_enc_mbclen(m, e, enc);
389 if (
type == ID_GLOBAL ||
type == ID_CLASS ||
type == ID_INSTANCE)
return -1;
392 if (m + 1 < e || *m !=
'=')
break;
395 if (!(allowed_attrset & (1U <<
type)))
return -1;
402 return m == e ?
type : -1;
408 return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
412rb_str_symname_type(VALUE name,
unsigned int allowed_attrset)
416 int type = rb_enc_symname_type(ptr, len,
rb_enc_get(name), allowed_attrset);
422set_id_entry(
rb_symbols_t *symbols, rb_id_serial_t num, VALUE str, VALUE sym)
425 size_t idx = num / ID_ENTRY_UNIT;
427 VALUE ary, ids = symbols->ids;
432 idx = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
438get_id_serial_entry(rb_id_serial_t num, ID
id,
const enum id_entry_type t)
442 GLOBAL_SYMBOLS_ENTER(symbols);
444 if (num && num <= symbols->last_id) {
445 size_t idx = num / ID_ENTRY_UNIT;
446 VALUE ids = symbols->ids;
449 long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE;
459 if (t != ID_ENTRY_SYM)
462 if (STATIC_SYM2ID(sym) !=
id) result = 0;
465 if (RSYMBOL(sym)->
id !=
id) result = 0;
473 GLOBAL_SYMBOLS_LEAVE();
479get_id_entry(ID
id,
const enum id_entry_type t)
481 return get_id_serial_entry(rb_id_to_serial(
id),
id, t);
485rb_id_serial_to_id(rb_id_serial_t num)
487 if (is_notop_id((ID)num)) {
488 VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
489 if (sym)
return SYM2ID(sym);
490 return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
499register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
502 rb_fatal(
"symbol :% "PRIsVALUE
" is already registered with %"PRIxVALUE,
503 (VALUE)*key, (VALUE)*value);
511register_sym(
rb_symbols_t *symbols, VALUE str, VALUE sym)
516 st_update(symbols->str_sym, (st_data_t)str,
517 register_sym_update_callback, (st_data_t)sym);
519 st_add_direct(symbols->str_sym, (st_data_t)str, (st_data_t)sym);
524unregister_sym(
rb_symbols_t *symbols, VALUE str, VALUE sym)
528 st_data_t str_data = (st_data_t)str;
529 if (!st_delete(symbols->str_sym, &str_data, NULL)) {
535register_static_symid(ID
id,
const char *name,
long len,
rb_encoding *enc)
538 return register_static_symid_str(
id, str);
542register_static_symid_str(ID
id, VALUE str)
544 rb_id_serial_t num = rb_id_to_serial(
id);
545 VALUE sym = STATIC_ID2SYM(
id);
548 str = rb_fstring(str);
552 GLOBAL_SYMBOLS_ENTER(symbols)
554 register_sym(symbols, str, sym);
555 set_id_entry(symbols, num, str, sym);
557 GLOBAL_SYMBOLS_LEAVE();
563sym_check_asciionly(VALUE str)
568 rb_raise(rb_eEncodingError,
"invalid symbol in encoding %s :%+"PRIsVALUE,
584must_be_dynamic_symbol(VALUE x)
594 rb_bug(
"wrong argument: inappropriate Symbol (%p)", (
void *)x);
598 rb_bug(
"wrong argument type %s (expected Symbol)", rb_builtin_class_name(x));
615 RSYMBOL(dsym)->id =
type;
619 RSYMBOL(dsym)->hashval = RSHIFT((
long)hashval, 1);
620 register_sym(symbols, str, dsym);
622 RUBY_DTRACE_CREATE_HOOK(SYMBOL,
RSTRING_PTR(RSYMBOL(dsym)->fstr));
632 if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
633 const VALUE fstr = RSYMBOL(sym)->fstr;
634 const ID
type = RSYMBOL(sym)->id & ID_SCOPE_MASK;
635 RSYMBOL(sym)->fstr = 0;
636 unregister_sym(symbols, fstr, sym);
645lookup_str_id(VALUE str)
650 GLOBAL_SYMBOLS_ENTER(symbols);
652 found = st_lookup(symbols->str_sym, (st_data_t)str, &sym_data);
654 GLOBAL_SYMBOLS_LEAVE();
657 const VALUE sym = (
VALUE)sym_data;
660 return STATIC_SYM2ID(sym);
663 ID
id = RSYMBOL(sym)->id;
664 if (
id & ~ID_SCOPE_MASK)
return id;
667 rb_bug(
"non-symbol object %s:%"PRIxVALUE
" for %"PRIsVALUE
" in symbol table",
668 rb_builtin_class_name(sym), sym, str);
675lookup_str_sym_with_lock(
rb_symbols_t *symbols,
const VALUE str)
678 if (st_lookup(symbols->str_sym, (st_data_t)str, &sym_data)) {
679 VALUE sym = (
VALUE)sym_data;
681 sym = dsymbol_check(symbols, sym);
691lookup_str_sym(
const VALUE str)
695 GLOBAL_SYMBOLS_ENTER(symbols);
697 sym = lookup_str_sym_with_lock(symbols, str);
699 GLOBAL_SYMBOLS_LEAVE();
707 return get_id_entry(
id, ID_ENTRY_STR);
715 VALUE str = rb_setup_fake_str(&fake_str, name,
len, enc);
717 sym = lookup_str_sym(str);
720 return intern_str(str, 1);
727 rb_id_serial_t next_serial = symbols->last_id + 1;
729 if (next_serial == 0) {
733 const size_t num = ++symbols->last_id;
734 id = num << ID_SCOPE_SHIFT;
744 GLOBAL_SYMBOLS_ENTER(symbols);
746 id = next_id_base_with_lock(symbols);
748 GLOBAL_SYMBOLS_LEAVE();
753intern_str(VALUE str,
int mutable)
758 id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
759 if (
id == (ID)-1)
id = ID_JUNK;
760 if (sym_check_asciionly(str)) {
764 if ((nid = next_id_base()) == (ID)-1) {
766 rb_raise(rb_eRuntimeError,
"symbol table overflow (symbol %"PRIsVALUE
")",
771 return register_static_symid_str(
id, str);
790 VALUE sym = lookup_str_sym(str);
796 return intern_str(str, 0);
800rb_gc_free_dsymbol(VALUE sym)
802 VALUE str = RSYMBOL(sym)->fstr;
805 RSYMBOL(sym)->fstr = 0;
807 GLOBAL_SYMBOLS_ENTER(symbols);
809 unregister_sym(symbols, str, sym);
810 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, str);
812 GLOBAL_SYMBOLS_LEAVE();
846 GLOBAL_SYMBOLS_ENTER(symbols);
848 sym = lookup_str_sym_with_lock(symbols, str);
857 if (enc != ascii && sym_check_asciionly(str)) {
867 str = rb_fstring(str);
868 type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
872 id = intern_str(str, 0);
877 GLOBAL_SYMBOLS_LEAVE();
886 id = STATIC_SYM2ID(sym);
889 GLOBAL_SYMBOLS_ENTER(symbols);
891 sym = dsymbol_check(symbols, sym);
892 id = RSYMBOL(sym)->id;
894 if (UNLIKELY(!(
id & ~ID_SCOPE_MASK))) {
895 VALUE fstr = RSYMBOL(sym)->fstr;
896 ID num = next_id_base_with_lock(symbols);
898 RSYMBOL(sym)->id =
id |= num;
901 set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
902 rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
905 GLOBAL_SYMBOLS_LEAVE();
908 rb_raise(rb_eTypeError,
"wrong argument type %s (expected Symbol)",
909 rb_builtin_class_name(sym));
918 if (!DYNAMIC_ID_P(x))
return STATIC_ID2SYM(x);
919 return get_id_entry(x, ID_ENTRY_SYM);
927 return RSYMBOL(sym)->fstr;
937 return lookup_id_str(
id);
950rb_make_internal_id(
void)
952 return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
956rb_make_temporary_id(
size_t n)
958 const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
959 const ID
id = max_id - (
ID)n;
960 if (
id <= ruby_global_symbols.last_id) {
961 rb_raise(rb_eRuntimeError,
"too big to make temporary ID: %" PRIdSIZE, n);
963 return (
id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
967symbols_i(st_data_t key, st_data_t value, st_data_t arg)
970 VALUE sym = (
VALUE)value;
979 else if (!SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
980 RSYMBOL(sym)->fstr = 0;
995 GLOBAL_SYMBOLS_ENTER(symbols);
1000 GLOBAL_SYMBOLS_LEAVE();
1006rb_sym_immortal_count(
void)
1008 return (
size_t)ruby_global_symbols.last_id;
1014 return is_const_id(
id);
1020 return is_class_id(
id);
1026 return is_global_id(
id);
1032 return is_instance_id(
id);
1038 return is_attrset_id(
id);
1044 return is_local_id(
id);
1050 return is_junk_id(
id);
1054rb_is_const_sym(VALUE sym)
1056 return is_const_sym(sym);
1060rb_is_attrset_sym(VALUE sym)
1062 return is_attrset_sym(sym);
1069 VALUE name = *namep;
1072 return STATIC_SYM2ID(name);
1075 if (SYMBOL_PINNED_P(name)) {
1076 return RSYMBOL(name)->id;
1079 *namep = RSYMBOL(name)->fstr;
1086 rb_raise(rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1093 sym_check_asciionly(name);
1095 return lookup_str_id(name);
1103 VALUE name = *namep;
1109 if (!SYMBOL_PINNED_P(name)) {
1110 GLOBAL_SYMBOLS_ENTER(symbols);
1112 name = dsymbol_check(symbols, name);
1114 GLOBAL_SYMBOLS_LEAVE();
1123 rb_raise(rb_eTypeError,
"%+"PRIsVALUE
" is not a symbol nor a string",
1130 sym_check_asciionly(name);
1132 if ((sym = lookup_str_sym(name)) != 0) {
1143 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1145 sym_check_asciionly(name);
1147 return lookup_str_id(name);
1155 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1157 sym_check_asciionly(name);
1159 if ((sym = lookup_str_sym(name)) != 0) {
1166#undef rb_sym_intern_ascii_cstr
1170FUNC_MINIMIZED(VALUE rb_sym_intern(
const char *
ptr,
long len,
rb_encoding *enc));
1171FUNC_MINIMIZED(VALUE rb_sym_intern_ascii(
const char *
ptr,
long len));
1172FUNC_MINIMIZED(VALUE rb_sym_intern_ascii_cstr(
const char *
ptr));
1179 const VALUE name = rb_setup_fake_str(&fake_str,
ptr,
len, enc);
1184rb_sym_intern_ascii(
const char *
ptr,
long len)
1190rb_sym_intern_ascii_cstr(
const char *
ptr)
1192 return rb_sym_intern_ascii(
ptr, strlen(
ptr));
1196rb_to_symbol_type(VALUE obj)
1198 return rb_convert_type_with_id(obj,
T_SYMBOL,
"Symbol", idTo_sym);
1202rb_is_const_name(VALUE name)
1204 return rb_str_symname_type(name, 0) == ID_CONST;
1208rb_is_class_name(VALUE name)
1210 return rb_str_symname_type(name, 0) == ID_CLASS;
1214rb_is_instance_name(VALUE name)
1216 return rb_str_symname_type(name, 0) == ID_INSTANCE;
1220rb_is_local_name(VALUE name)
1222 return rb_str_symname_type(name, 0) == ID_LOCAL;
1225#include "id_table.c"
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_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
void rb_fatal(const char *fmt,...)
Raises the unsung "fatal" exception.
VALUE rb_cSymbol
Sumbol class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
Queries the number of bytes of the character at the passed pointer.
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Identical to rb_enc_associate(), except it takes an encoding itself instead of its index.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
int rb_enc_to_index(rb_encoding *enc)
Queries the index of the encoding.
void rb_enc_set_index(VALUE obj, int encindex)
Destructively assigns an encoding (via its index) to an object.
static bool rb_enc_asciicompat(rb_encoding *enc)
Queries if the passed encoding is in some sense compatible with ASCII.
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
Queries the number of bytes of the character at the passed pointer.
static OnigCodePoint rb_enc_mbc_to_codepoint(const char *p, const char *e, rb_encoding *enc)
Identical to rb_enc_codepoint(), except it assumes the passed character is not broken.
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.
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it additionally takes an encoding.
int rb_enc_symname_p(const char *str, rb_encoding *enc)
Identical to rb_symname_p(), except it additionally takes an encoding.
ID rb_intern3(const char *name, long len, rb_encoding *enc)
Identical to rb_intern2(), 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.
void rb_gc_register_mark_object(VALUE object)
Inform the garbage collector that object is a live Ruby object that should not be moved.
VALUE rb_ary_tmp_new(long capa)
Allocates a "temporary" 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_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
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.
ID rb_id_attrset(ID id)
Calculates an ID of attribute writer.
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.
ID rb_intern2(const char *name, long len)
Identical to rb_intern(), except it additionally takes the length of the string.
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.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
const char * rb_id2name(ID id)
Retrieves the name mapped to the given id.
ID rb_intern_str(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
#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.
VALUE rb_newobj_of(VALUE klass, VALUE flags)
This is the implementation detail of RB_NEWOBJ_OF.
#define RARRAY_LEN
Just another name of rb_array_len.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
long len
Length of the string, not including terminating NUL character.
char ary[RSTRING_EMBED_LEN_MAX+1]
When a string is short enough, it uses this area to store the contents themselves.
char * ptr
Pointer to the contents of the string.
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.