12 #include "ruby/internal/config.h"
18 #include "internal/enc.h"
19 #include "internal/encoding.h"
20 #include "internal/error.h"
21 #include "internal/inits.h"
22 #include "internal/load.h"
23 #include "internal/object.h"
24 #include "internal/string.h"
25 #include "internal/vm.h"
29 #include "ruby_assert.h"
35 #define ENC_ASSERT(expr) RUBY_ASSERT_WHEN(ENC_DEBUG, expr)
36 #define MUST_STRING(str) (ENC_ASSERT(RB_TYPE_P(str, T_STRING)), str)
38 #undef rb_ascii8bit_encindex
39 #undef rb_utf8_encindex
40 #undef rb_usascii_encindex
44 #if defined __GNUC__ && __GNUC__ >= 4
45 #pragma GCC visibility push(default)
46 int rb_enc_register(
const char *name,
rb_encoding *encoding);
47 void rb_enc_set_base(
const char *name,
const char *orig);
48 int rb_enc_set_dummy(
int index);
49 void rb_encdb_declare(
const char *name);
50 int rb_encdb_replicate(
const char *name,
const char *orig);
51 int rb_encdb_dummy(
const char *name);
52 int rb_encdb_alias(
const char *alias,
const char *orig);
53 #pragma GCC visibility pop
56 static ID id_encoding;
59 #define ENCODING_LIST_CAPA 256
60 static VALUE rb_encoding_list;
75 enc_names_free_i(st_data_t name, st_data_t idx, st_data_t args)
82 rb_free_global_enc_table(
void)
84 for (
size_t i = 0; i < ENCODING_LIST_CAPA; i++) {
85 xfree((
void *)global_enc_table.list[i].enc);
88 st_foreach(global_enc_table.names, enc_names_free_i, (st_data_t)0);
89 st_free_table(global_enc_table.names);
96 #define GLOBAL_ENC_TABLE_ENTER(enc_table) struct enc_table *enc_table = &global_enc_table; RB_VM_LOCK_ENTER()
97 #define GLOBAL_ENC_TABLE_LEAVE() RB_VM_LOCK_LEAVE()
98 #define GLOBAL_ENC_TABLE_EVAL(enc_table, expr) do { \
99 GLOBAL_ENC_TABLE_ENTER(enc_table); \
103 GLOBAL_ENC_TABLE_LEAVE(); \
107 #define ENC_DUMMY_FLAG (1<<24)
108 #define ENC_INDEX_MASK (~(~0U<<24))
110 #define ENC_TO_ENCINDEX(enc) (int)((enc)->ruby_encoding_index & ENC_INDEX_MASK)
111 #define ENC_DUMMY_P(enc) ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)
112 #define ENC_SET_DUMMY(enc) ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)
114 #define ENCODING_COUNT ENCINDEX_BUILTIN_MAX
115 #define UNSPECIFIED_ENCODING INT_MAX
117 #define ENCODING_NAMELEN_MAX 63
118 #define valid_encoding_name_p(name) ((name) && strlen(name) <= ENCODING_NAMELEN_MAX)
123 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
126 #define is_data_encoding(obj) (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)
127 #define is_obj_encoding(obj) (RB_TYPE_P((obj), T_DATA) && is_data_encoding(obj))
130 rb_data_is_encoding(
VALUE obj)
132 return is_data_encoding(obj);
149 VALUE list = rb_encoding_list;
157 enc_list_lookup(
int idx)
161 if (idx < ENCODING_LIST_CAPA) {
162 list = rb_encoding_list;
168 rb_bug(
"rb_enc_from_encoding_index(%d): not created yet", idx);
176 rb_enc_from_encoding_index(
int idx)
178 return enc_list_lookup(idx);
185 if (!encoding)
return Qnil;
186 idx = ENC_TO_ENCINDEX(encoding);
187 return rb_enc_from_encoding_index(idx);
193 return enc ? ENC_TO_ENCINDEX(enc) : 0;
199 return ENC_DUMMY_P(enc) != 0;
208 if (rb_enc_autoload_p(enc)) {
209 index = rb_enc_autoload(enc);
215 enc_check_encoding(
VALUE obj)
217 if (!is_obj_encoding(obj)) {
220 return check_encoding(
RDATA(obj)->data);
223 NORETURN(
static void not_encoding(
VALUE enc));
225 not_encoding(
VALUE enc)
232 must_encoding(
VALUE enc)
234 int index = enc_check_encoding(enc);
242 must_encindex(
int index)
249 if (ENC_TO_ENCINDEX(enc) != (
int)(index & ENC_INDEX_MASK)) {
253 if (rb_enc_autoload_p(enc) && rb_enc_autoload(enc) == -1) {
266 idx = enc_check_encoding(enc);
276 if (!(name = rb_str_to_cstr(enc))) {
283 name_for_encoding(
volatile VALUE *enc)
291 if (!(n = rb_str_to_cstr(name))) {
299 str_find_encindex(
VALUE enc)
307 str_to_encindex(
VALUE enc)
309 int idx = str_find_encindex(enc);
317 str_to_encoding(
VALUE enc)
325 if (enc_check_encoding(enc) >= 0)
return RDATA(enc)->data;
326 return str_to_encoding(enc);
333 if (enc_check_encoding(enc) >= 0)
return RDATA(enc)->data;
334 idx = str_find_encindex(enc);
335 if (idx < 0)
return NULL;
342 if (newsize > ENCODING_LIST_CAPA) {
354 if (!valid_encoding_name_p(name))
return -1;
356 ent->name = name =
strdup(name);
366 *encoding = *base_encoding;
369 memset(encoding, 0,
sizeof(*ent->enc));
371 encoding->name = name;
372 encoding->ruby_encoding_index = index;
374 st_insert(
enc_table->names, (st_data_t)name, (st_data_t)index);
376 enc_list_update(index, encoding);
386 return enc_register_at(
enc_table, index, name, encoding);
389 static void set_encoding_const(
const char *,
rb_encoding *);
395 if (UNLIKELY(index < 0 || enc_table->count <= (index &= ENC_INDEX_MASK))) {
404 return enc_from_index(&global_enc_table, index);
408 rb_enc_register(
const char *name,
rb_encoding *encoding)
419 index = enc_register(
enc_table, name, encoding);
421 else if (rb_enc_autoload_p(oldenc) || !ENC_DUMMY_P(oldenc)) {
422 enc_register_at(
enc_table, index, name, encoding);
429 index = enc_register(
enc_table, name, encoding);
433 GLOBAL_ENC_TABLE_LEAVE();
442 if (!name)
return -1;
444 if (st_lookup(
enc_table->names, (st_data_t)name, &idx)) {
451 rb_encdb_declare(
const char *name)
455 int idx = enc_registered(
enc_table, name);
461 GLOBAL_ENC_TABLE_LEAVE();
467 if (enc_registered(
enc_table, name) >= 0) {
470 else if (!valid_encoding_name_p(name)) {
491 rb_enc_set_base(
const char *name,
const char *orig)
495 int idx = enc_registered(
enc_table, name);
496 int origidx = enc_registered(
enc_table, orig);
499 GLOBAL_ENC_TABLE_LEAVE();
506 rb_enc_set_dummy(
int index)
508 rb_encoding *enc = global_enc_table.list[index].enc;
519 idx = enc_register(
enc_table, name, encoding);
521 set_base_encoding(
enc_table, idx, encoding);
530 idx = enc_register(
enc_table, name, origenc);
533 idx = enc_register_at(
enc_table, idx, name, origenc);
536 set_base_encoding(
enc_table, idx, origenc);
546 rb_encdb_replicate(
const char *name,
const char *orig)
552 int origidx = enc_registered(
enc_table, orig);
553 int idx = enc_registered(
enc_table, name);
556 origidx = enc_register(
enc_table, orig, 0);
560 GLOBAL_ENC_TABLE_LEAVE();
576 GLOBAL_ENC_TABLE_LEAVE();
582 rb_encdb_dummy(
const char *name)
588 index = enc_replicate_with_index(
enc_table, name,
594 GLOBAL_ENC_TABLE_LEAVE();
613 enc_dummy_p(
VALUE enc)
615 return RBOOL(ENC_DUMMY_P(must_encoding(enc)));
629 enc_ascii_compatible_p(
VALUE enc)
640 return ONIGENC_IS_UNICODE(enc);
644 enc_dup_name(st_data_t name)
646 return (st_data_t)
strdup((
const char *)name);
656 return st_insert2(
enc_table->names, (st_data_t)alias, (st_data_t)idx,
663 if (!valid_encoding_name_p(alias))
return -1;
664 if (!enc_alias_internal(
enc_table, alias, idx))
665 set_encoding_const(alias, enc_from_index(
enc_table, idx));
684 GLOBAL_ENC_TABLE_LEAVE();
690 rb_encdb_alias(
const char *alias,
const char *orig)
696 int idx = enc_registered(
enc_table, orig);
703 GLOBAL_ENC_TABLE_LEAVE();
711 enc_table_expand(
enc_table, ENCODING_COUNT + 1);
713 enc_table->names = st_init_strcasetable_with_size(ENCODING_LIST_CAPA);
715 #define OnigEncodingASCII_8BIT OnigEncodingASCII
716 #define ENC_REGISTER(enc) enc_register_at(enc_table, ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)
717 ENC_REGISTER(ASCII_8BIT);
719 ENC_REGISTER(US_ASCII);
720 global_enc_ascii =
enc_table->list[ENCINDEX_ASCII_8BIT].enc;
721 global_enc_utf_8 =
enc_table->list[ENCINDEX_UTF_8].enc;
722 global_enc_us_ascii =
enc_table->list[ENCINDEX_US_ASCII].enc;
724 #undef OnigEncodingASCII_8BIT
725 #define ENCDB_REGISTER(name, enc) enc_register_at(enc_table, ENCINDEX_##enc, name, NULL)
726 ENCDB_REGISTER(
"UTF-16BE", UTF_16BE);
727 ENCDB_REGISTER(
"UTF-16LE", UTF_16LE);
728 ENCDB_REGISTER(
"UTF-32BE", UTF_32BE);
729 ENCDB_REGISTER(
"UTF-32LE", UTF_32LE);
730 ENCDB_REGISTER(
"UTF-16", UTF_16);
731 ENCDB_REGISTER(
"UTF-32", UTF_32);
732 ENCDB_REGISTER(
"UTF8-MAC", UTF8_MAC);
734 ENCDB_REGISTER(
"EUC-JP", EUC_JP);
735 ENCDB_REGISTER(
"Windows-31J", Windows_31J);
736 #undef ENCDB_REGISTER
741 rb_enc_get_from_index(
int index)
743 return must_encindex(index);
746 int rb_require_internal_silent(
VALUE fname);
749 load_encoding(
const char *name)
763 enclib = rb_fstring(enclib);
766 loaded = rb_require_internal_silent(enclib);
772 if (loaded < 0 || 1 < loaded) {
775 else if ((idx = enc_registered(
enc_table, name)) < 0) {
778 else if (rb_enc_autoload_p(
enc_table->list[idx].enc)) {
782 GLOBAL_ENC_TABLE_LEAVE();
796 }
while (
enc_table->list[i].enc != base && (++i, 1));
797 if (rb_enc_autoload_p(base)) {
798 if (rb_enc_autoload(base) < 0)
return -1;
800 i = enc->ruby_encoding_index;
826 int i = enc_registered(&global_enc_table, name);
830 i = load_encoding(name);
833 if (i != UNSPECIFIED_ENCODING) {
837 else if (rb_enc_autoload_p(enc)) {
838 if (rb_enc_autoload(enc) < 0) {
839 rb_warn(
"failed to load encoding (%s); use ASCII-8BIT instead",
848 rb_enc_find_index2(
const char *name,
long len)
850 char buf[ENCODING_NAMELEN_MAX+1];
852 if (
len > ENCODING_NAMELEN_MAX)
return -1;
853 memcpy(buf, name,
len);
862 if (idx < 0) idx = 0;
867 enc_capable(
VALUE obj)
877 if (is_data_encoding(obj))
return TRUE;
886 return enc_capable(obj);
897 enc_get_index_str(
VALUE str)
933 i = enc_get_index_str(obj);
940 if (is_obj_encoding(tmp)) {
941 i = enc_check_encoding(tmp);
945 if (is_data_encoding(obj)) {
946 i = enc_check_encoding(obj);
956 enc_set_index(
VALUE obj,
int idx)
958 if (!enc_capable(obj)) {
975 int idx = enc ? ENC_TO_ENCINDEX(enc) : 0;
988 rb_check_frozen(obj);
990 enc_set_index(obj, idx);
997 int oldidx, oldtermlen, termlen;
1000 rb_check_frozen(obj);
1007 enc = must_encindex(idx);
1015 rb_str_change_terminator_length(obj, oldtermlen, termlen);
1017 enc_set_index(obj, idx);
1036 if (enc == global_enc_ascii) {
1037 return "BINARY (ASCII-8BIT)";
1057 rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2));
1058 return rb_encoding_check(enc, str1, str2);
1065 return rb_encoding_check(enc, str1, str2);
1069 enc_compatible_latter(
VALUE str1,
VALUE str2,
int idx1,
int idx2)
1071 if (idx1 < 0 || idx2 < 0)
1093 if (!isstr2 && idx2 == ENCINDEX_US_ASCII)
1095 if (!isstr1 && idx1 == ENCINDEX_US_ASCII)
1133 int idx1 = enc_get_index_str(str1);
1134 int idx2 = enc_get_index_str(str2);
1136 return enc_compatible_latter(str1, str2, idx1, idx2);
1145 return enc_compatible_latter(str1, str2, idx1, idx2);
1169 return rb_enc_from_encoding_index(idx & ENC_INDEX_MASK);
1175 return ONIGENC_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1181 int n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1186 return min <= e-p ? min : (int)(e-p);
1195 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
1196 n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1198 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n-(
int)(e-p));
1210 c = (
unsigned char)*p;
1243 int n = ONIGENC_CODE_TO_MBCLEN(enc,c);
1253 return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_UPPER_CASE(c):(c));
1259 return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_LOWER_CASE(c):(c));
1272 enc_inspect(
VALUE self)
1276 if (!is_data_encoding(
self)) {
1285 rb_enc_inspect_name(enc),
1286 (ENC_DUMMY_P(enc) ?
" (dummy)" :
""),
1287 rb_enc_autoload_p(enc) ?
" (autoload)" :
"");
1300 enc_name(
VALUE self)
1306 enc_names_i(st_data_t name, st_data_t idx, st_data_t args)
1310 if ((
int)idx == (int)arg[0]) {
1326 enc_names(
VALUE self)
1332 st_foreach(global_enc_table.names, enc_names_i, (st_data_t)args);
1355 enc_list(
VALUE klass)
1388 if (is_obj_encoding(enc))
1390 idx = str_to_encindex(enc);
1391 if (idx == UNSPECIFIED_ENCODING)
return Qnil;
1392 return rb_enc_from_encoding_index(idx);
1424 if (!enc_capable(str1))
return Qnil;
1425 if (!enc_capable(str2))
return Qnil;
1427 if (!enc)
return Qnil;
1431 NORETURN(
static VALUE enc_s_alloc(
VALUE klass));
1434 enc_s_alloc(
VALUE klass)
1436 rb_undefined_alloc(klass);
1445 return enc_name(
self);
1459 return enc_find(klass, str);
1465 return global_enc_ascii;
1471 return ENCINDEX_ASCII_8BIT;
1477 return global_enc_utf_8;
1483 return ENCINDEX_UTF_8;
1489 return global_enc_us_ascii;
1495 return ENCINDEX_US_ASCII;
1498 int rb_locale_charmap_index(
void);
1503 int idx = rb_locale_charmap_index();
1505 if (idx < 0) idx = ENCINDEX_UTF_8;
1507 if (enc_registered(&global_enc_table,
"locale") < 0) {
1509 void Init_w32_codepage(
void);
1510 Init_w32_codepage();
1514 enc_alias_internal(
enc_table,
"locale", idx);
1516 GLOBAL_ENC_TABLE_LEAVE();
1531 int idx = enc_registered(&global_enc_table,
"filesystem");
1532 if (idx < 0) idx = ENCINDEX_ASCII_8BIT;
1552 int overridden = FALSE;
1554 if (def->index != -2)
1560 if (
NIL_P(encoding)) {
1563 char *name_dup =
strdup(name);
1565 st_data_t existing_name = (st_data_t)name_dup;
1566 if (st_delete(
enc_table->names, &existing_name, NULL)) {
1567 xfree((
void *)existing_name);
1570 st_insert(
enc_table->names, (st_data_t)name_dup,
1571 (st_data_t)UNSPECIFIED_ENCODING);
1576 enc_alias_internal(
enc_table, name, def->index);
1579 if (def == &default_external) {
1580 enc_alias_internal(
enc_table,
"filesystem", Init_enc_set_filesystem_encoding());
1583 GLOBAL_ENC_TABLE_LEAVE();
1591 if (default_external.enc)
return default_external.enc;
1593 if (default_external.index >= 0) {
1595 return default_external.enc;
1637 get_default_external(
VALUE klass)
1645 if (
NIL_P(encoding)) {
1648 enc_set_default_encoding(&default_external, encoding,
1666 set_default_external(
VALUE klass,
VALUE encoding)
1668 rb_warning(
"setting Encoding.default_external");
1678 if (!default_internal.enc && default_internal.index >= 0) {
1681 return default_internal.enc;
1720 get_default_internal(
VALUE klass)
1728 enc_set_default_encoding(&default_internal, encoding,
1746 set_default_internal(
VALUE klass,
VALUE encoding)
1748 rb_warning(
"setting Encoding.default_internal");
1754 set_encoding_const(
const char *name,
rb_encoding *enc)
1757 char *s = (
char *)name;
1758 int haslower = 0, hasupper = 0, valid = 0;
1763 while (*++s && (
ISALNUM(*s) || *s ==
'_')) {
1764 if (
ISLOWER(*s)) haslower = 1;
1768 if (s - name > ENCODING_NAMELEN_MAX)
return;
1772 if (!valid || haslower) {
1773 size_t len = s - name;
1774 if (
len > ENCODING_NAMELEN_MAX)
return;
1775 if (!haslower || !hasupper) {
1777 if (
ISLOWER(*s)) haslower = 1;
1778 if (
ISUPPER(*s)) hasupper = 1;
1779 }
while (*++s && (!haslower || !hasupper));
1783 if (
len++ > ENCODING_NAMELEN_MAX)
return;
1787 if (
ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((
int)*s);
1796 for (s = (
char *)name; *s; ++s) {
1797 if (
ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((
int)*s);
1805 rb_enc_name_list_i(st_data_t name, st_data_t idx, st_data_t arg)
1828 rb_enc_name_list(
VALUE klass)
1831 st_foreach(global_enc_table.names, rb_enc_name_list_i, (st_data_t)ary);
1836 rb_enc_aliases_enc_i(st_data_t name, st_data_t orig, st_data_t arg)
1839 VALUE aliases = p[0], ary = p[1];
1840 int idx = (int)orig;
1846 if (!enc)
return ST_CONTINUE;
1871 rb_enc_aliases(
VALUE klass)
1877 st_foreach(global_enc_table.names, rb_enc_aliases_enc_i, (st_data_t)aliases);
1945 list = rb_encoding_list =
rb_ary_new2(ENCODING_LIST_CAPA);
1946 RBASIC_CLEAR_CLASS(list);
1947 rb_vm_register_global_object(list);
1949 for (i = 0; i <
enc_table->count; ++i) {
1957 Init_encodings(
void)
1959 rb_enc_init(&global_enc_table);
1965 rb_enc_foreach_name(
int (*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg)
1967 st_foreach(global_enc_table.names, func, arg);
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
static bool rb_enc_isascii(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isascii(), except it additionally takes an encoding.
int rb_enc_tolower(int c, rb_encoding *enc)
Identical to rb_tolower(), except it additionally takes an encoding.
int rb_enc_toupper(int c, rb_encoding *enc)
Identical to rb_toupper(), except it additionally takes an encoding.
VALUE rb_enc_sprintf(rb_encoding *enc, const char *fmt,...)
Identical to rb_sprintf(), except it additionally takes an encoding.
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
#define ENCODING_SET_INLINED(obj, i)
Old name of RB_ENCODING_SET_INLINED.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define T_FILE
Old name of RUBY_T_FILE.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define ISUPPER
Old name of rb_isupper.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define T_DATA
Old name of RUBY_T_DATA.
#define CLASS_OF
Old name of rb_class_of.
#define xmalloc
Old name of ruby_xmalloc.
#define ISDIGIT
Old name of rb_isdigit.
#define ISLOWER
Old name of rb_islower.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
#define ENCODING_INLINE_MAX
Old name of RUBY_ENCODING_INLINE_MAX.
#define STRCASECMP
Old name of st_locale_insensitive_strcasecmp.
#define ISASCII
Old name of rb_isascii.
#define TOLOWER
Old name of rb_tolower.
#define NUM2INT
Old name of RB_NUM2INT.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define ENC_CODERANGE_ASCIIONLY(obj)
Old name of RB_ENC_CODERANGE_ASCIIONLY.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define ENCODING_GET_INLINED(obj)
Old name of RB_ENCODING_GET_INLINED.
#define ENC_CODERANGE_CLEAR(obj)
Old name of RB_ENC_CODERANGE_CLEAR.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ISALNUM
Old name of rb_isalnum.
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
#define T_REGEXP
Old name of RUBY_T_REGEXP.
#define ruby_debug
This variable controls whether the interpreter is in debug mode.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eEncCompatError
Encoding::CompatibilityError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eArgError
ArgumentError exception.
void rb_loaderror(const char *fmt,...)
Raises an instance of rb_eLoadError.
VALUE rb_errinfo(void)
This is the same as $! in Ruby.
VALUE rb_eEncodingError
EncodingError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_cEncoding
Encoding class.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
rb_encoding * rb_locale_encoding(void)
Queries the encoding that represents the current locale.
rb_encoding * rb_default_external_encoding(void)
Queries the "default external" encoding.
int rb_enc_dummy_p(rb_encoding *enc)
Queries if the passed encoding is dummy.
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.
int rb_enc_get_index(VALUE obj)
Queries the index of the encoding of the passed object, if any.
int rb_to_encoding_index(VALUE obj)
Obtains a encoding index from a wider range of objects (than rb_enc_find_index()).
int rb_filesystem_encindex(void)
Identical to rb_filesystem_encoding(), except it returns the encoding's index instead of the encoding...
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Identical to rb_enc_associate_index(), except it takes an encoding itself instead of its index.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
int rb_enc_codelen(int code, rb_encoding *enc)
Queries the number of bytes requested to represent the passed code point using the passed encoding.
void rb_enc_copy(VALUE dst, VALUE src)
Destructively copies the encoding of the latter object to that of former one.
int rb_utf8_encindex(void)
Identical to rb_utf8_encoding(), except it returns the encoding's index instead of the encoding itsel...
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
Identical to rb_enc_mbclen() unless the character at p overruns e.
int rb_ascii8bit_encindex(void)
Identical to rb_ascii8bit_encoding(), except it returns the encoding's index instead of the encoding ...
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
Look for the "common" encoding between the two.
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc)
Queries the code point of character pointed by the passed pointer.
int rb_enc_unicode_p(rb_encoding *enc)
Queries if the passed encoding is either one of UTF-8/16/32.
rb_encoding * rb_default_internal_encoding(void)
Queries the "default internal" encoding.
int rb_enc_to_index(rb_encoding *enc)
Queries the index of the encoding.
rb_encoding * rb_find_encoding(VALUE obj)
Identical to rb_to_encoding_index(), except the return type.
rb_encoding * rb_enc_find(const char *name)
Identical to rb_find_encoding(), except it takes a C's string instead of Ruby's.
rb_encoding * rb_to_encoding(VALUE obj)
Identical to rb_find_encoding(), except it raises an exception instead of returning NULL.
void rb_enc_set_index(VALUE obj, int encindex)
Destructively assigns an encoding (via its index) to an object.
VALUE rb_locale_charmap(VALUE klass)
Returns a platform-depended "charmap" of the current locale.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
void rb_enc_set_default_internal(VALUE encoding)
Destructively assigns the passed encoding as the default internal encoding.
VALUE rb_enc_default_external(void)
Identical to rb_default_external_encoding(), except it returns the Ruby-level counterpart instance of...
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
Identical to rb_enc_compatible(), except it raises an exception instead of returning NULL.
VALUE rb_enc_from_encoding(rb_encoding *enc)
Queries the Ruby-level counterpart instance of rb_cEncoding that corresponds to the passed encoding.
static bool rb_enc_asciicompat(rb_encoding *enc)
Queries if the passed encoding is in some sense compatible with ASCII.
int rb_define_dummy_encoding(const char *name)
Creates a new "dummy" encoding.
rb_encoding * rb_utf8_encoding(void)
Queries the encoding that represents UTF-8.
int rb_locale_encindex(void)
Identical to rb_locale_encoding(), except it returns the encoding's index instead of the encoding its...
rb_encoding * rb_enc_from_index(int idx)
Identical to rb_find_encoding(), except it takes an encoding index instead of a Ruby object.
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.
int rb_enc_capable(VALUE obj)
Queries if the passed object can have its encoding.
VALUE rb_enc_default_internal(void)
Identical to rb_default_internal_encoding(), except it returns the Ruby-level counterpart instance of...
VALUE rb_enc_associate_index(VALUE obj, int encindex)
Identical to rb_enc_set_index(), except it additionally does contents fix-up depending on the passed ...
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
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.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
void rb_enc_set_default_external(VALUE encoding)
Destructively assigns the passed encoding as the default external encoding.
int rb_enc_find_index(const char *name)
Queries the index of the encoding.
static int rb_enc_mbminlen(rb_encoding *enc)
Queries the minimum number of bytes that the passed encoding needs to represent a character.
int rb_enc_alias(const char *alias, const char *orig)
Registers an "alias" name.
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
Queries the code point of character pointed by the passed pointer.
int rb_usascii_encindex(void)
Identical to rb_usascii_encoding(), except it returns the encoding's index instead of the encoding it...
rb_encoding * rb_filesystem_encoding(void)
Queries the "filesystem" encoding.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
int rb_enc_str_asciionly_p(VALUE str)
Queries if the passed string is "ASCII only".
VALUE rb_obj_encoding(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_ary_replace(VALUE copy, VALUE orig)
Replaces the contents of the former object with the contents of the latter.
VALUE rb_ary_new(void)
Allocates a new, 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.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_interned_str_cstr(const char *ptr)
Identical to rb_interned_str(), except it assumes the passed pointer is a pointer to a C's string.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
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.
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
int len
Length of the buffer.
#define strdup(s)
Just another name of ruby_strdup.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define ALLOCA_N(type, n)
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
#define DATA_PTR(obj)
Convenient getter macro.
#define RDATA(obj)
Convenient casting macro.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
This is the struct that holds necessary info for a struct.
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.
void ruby_xfree(void *ptr)
Deallocates a storage instance.