12#include "ruby/internal/config.h"
18#include "internal/enc.h"
19#include "internal/encoding.h"
20#include "internal/inits.h"
21#include "internal/load.h"
22#include "internal/object.h"
23#include "internal/string.h"
24#include "internal/vm.h"
28#include "ruby_assert.h"
34#define ENC_ASSERT(expr) RUBY_ASSERT_WHEN(ENC_DEBUG, expr)
35#define MUST_STRING(str) (ENC_ASSERT(RB_TYPE_P(str, T_STRING)), str)
37#undef rb_ascii8bit_encindex
38#undef rb_utf8_encindex
39#undef rb_usascii_encindex
43#if defined __GNUC__ && __GNUC__ >= 4
44#pragma GCC visibility push(default)
45int rb_enc_register(
const char *name,
rb_encoding *encoding);
46void rb_enc_set_base(
const char *name,
const char *orig);
47int rb_enc_set_dummy(
int index);
48void rb_encdb_declare(
const char *name);
49int rb_encdb_replicate(
const char *name,
const char *orig);
50int rb_encdb_dummy(
const char *name);
51int rb_encdb_alias(
const char *alias,
const char *orig);
52void rb_encdb_set_unicode(
int index);
53#pragma GCC visibility pop
59#define DEFAULT_ENCODING_LIST_CAPA 128
60static VALUE rb_default_encoding_list;
61static VALUE rb_additional_encoding_list;
80#define GLOBAL_ENC_TABLE_ENTER(enc_table) struct enc_table *enc_table = &global_enc_table; RB_VM_LOCK_ENTER()
81#define GLOBAL_ENC_TABLE_LEAVE() RB_VM_LOCK_LEAVE()
82#define GLOBAL_ENC_TABLE_EVAL(enc_table, expr) do { \
83 GLOBAL_ENC_TABLE_ENTER(enc_table); \
87 GLOBAL_ENC_TABLE_LEAVE(); \
91#define ENC_DUMMY_FLAG (1<<24)
92#define ENC_INDEX_MASK (~(~0U<<24))
94#define ENC_TO_ENCINDEX(enc) (int)((enc)->ruby_encoding_index & ENC_INDEX_MASK)
95#define ENC_DUMMY_P(enc) ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)
96#define ENC_SET_DUMMY(enc) ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)
98#define ENCODING_COUNT ENCINDEX_BUILTIN_MAX
99#define UNSPECIFIED_ENCODING INT_MAX
101#define ENCODING_NAMELEN_MAX 63
102#define valid_encoding_name_p(name) ((name) && strlen(name) <= ENCODING_NAMELEN_MAX)
107 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
110#define is_data_encoding(obj) (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)
111#define is_obj_encoding(obj) (RB_TYPE_P((obj), T_DATA) && is_data_encoding(obj))
114rb_data_is_encoding(VALUE obj)
116 return is_data_encoding(obj);
131 if (index < DEFAULT_ENCODING_LIST_CAPA) {
132 VALUE list = rb_default_encoding_list;
141 VALUE list = rb_additional_encoding_list;
144 rb_ary_store(list, index - DEFAULT_ENCODING_LIST_CAPA, enc_new(encoding));
152enc_list_lookup(
int idx)
156 if (idx < DEFAULT_ENCODING_LIST_CAPA) {
157 if (!(list = rb_default_encoding_list)) {
158 rb_bug(
"rb_enc_from_encoding_index(%d): no rb_default_encoding_list", idx);
165 if (!(list = rb_additional_encoding_list)) {
166 rb_bug(
"rb_enc_from_encoding_index(%d): no rb_additional_encoding_list", idx);
168 enc =
rb_ary_entry(list, idx - DEFAULT_ENCODING_LIST_CAPA);
174 rb_bug(
"rb_enc_from_encoding_index(%d): not created yet", idx);
182rb_enc_from_encoding_index(
int idx)
184 return enc_list_lookup(idx);
191 if (!encoding)
return Qnil;
192 idx = ENC_TO_ENCINDEX(encoding);
193 return rb_enc_from_encoding_index(idx);
199 return enc ? ENC_TO_ENCINDEX(enc) : 0;
205 return ENC_DUMMY_P(enc) != 0;
214 if (rb_enc_autoload_p(enc)) {
215 index = rb_enc_autoload(enc);
221enc_check_encoding(VALUE obj)
223 if (!is_obj_encoding(obj)) {
226 return check_encoding(
RDATA(obj)->data);
229NORETURN(
static void not_encoding(VALUE enc));
231not_encoding(VALUE enc)
233 rb_raise(rb_eTypeError,
"wrong argument type %"PRIsVALUE
" (expected Encoding)",
238must_encoding(VALUE enc)
240 int index = enc_check_encoding(enc);
248must_encindex(
int index)
252 rb_raise(rb_eEncodingError,
"encoding index out of bound: %d",
255 if (ENC_TO_ENCINDEX(enc) != (
int)(index & ENC_INDEX_MASK)) {
256 rb_raise(rb_eEncodingError,
"wrong encoding index %d for %s (expected %d)",
259 if (rb_enc_autoload_p(enc) && rb_enc_autoload(enc) == -1) {
260 rb_loaderror(
"failed to load encoding (%s)",
272 idx = enc_check_encoding(enc);
282 if (!(name = rb_str_to_cstr(enc))) {
289name_for_encoding(
volatile VALUE *enc)
295 rb_raise(rb_eArgError,
"invalid encoding name (non ASCII)");
297 if (!(n = rb_str_to_cstr(name))) {
298 rb_raise(rb_eArgError,
"invalid encoding name (NUL byte)");
305str_find_encindex(VALUE enc)
313str_to_encindex(VALUE enc)
315 int idx = str_find_encindex(enc);
317 rb_raise(rb_eArgError,
"unknown encoding name - %"PRIsVALUE, enc);
323str_to_encoding(VALUE enc)
331 if (enc_check_encoding(enc) >= 0)
return RDATA(enc)->data;
332 return str_to_encoding(enc);
339 if (enc_check_encoding(enc) >= 0)
return RDATA(enc)->data;
340 idx = str_find_encindex(enc);
341 if (idx < 0)
return NULL;
351 if (
enc_table->size >= newsize)
return newsize;
352 newsize = (newsize + 7) / 8 * 8;
366 if (!valid_encoding_name_p(name))
return -1;
368 ent->name = name =
strdup(name);
378 *encoding = *base_encoding;
381 memset(encoding, 0,
sizeof(*ent->enc));
383 encoding->name = name;
384 encoding->ruby_encoding_index = index;
386 st_insert(
enc_table->names, (st_data_t)name, (st_data_t)index);
388 enc_list_update(index, encoding);
398 return enc_register_at(
enc_table, index, name, encoding);
401static void set_encoding_const(
const char *,
rb_encoding *);
407 if (UNLIKELY(index < 0 || enc_table->count <= (index &= ENC_INDEX_MASK))) {
419 case ENCINDEX_ASCII:
return global_enc_ascii;
420 case ENCINDEX_UTF_8:
return global_enc_utf_8;
421 case ENCINDEX_US_ASCII:
return global_enc_us_ascii;
430rb_enc_register(
const char *name,
rb_encoding *encoding)
441 index = enc_register(
enc_table, name, encoding);
443 else if (rb_enc_autoload_p(oldenc) || !ENC_DUMMY_P(oldenc)) {
444 enc_register_at(
enc_table, index, name, encoding);
447 rb_raise(rb_eArgError,
"encoding %s is already registered", name);
451 index = enc_register(
enc_table, name, encoding);
455 GLOBAL_ENC_TABLE_LEAVE();
464 if (!name)
return -1;
466 if (st_lookup(
enc_table->names, (st_data_t)name, &idx)) {
473rb_encdb_declare(
const char *name)
477 int idx = enc_registered(
enc_table, name);
483 GLOBAL_ENC_TABLE_LEAVE();
489 if (enc_registered(
enc_table, name) >= 0) {
490 rb_raise(rb_eArgError,
"encoding %s is already registered", name);
510rb_enc_set_base(
const char *name,
const char *orig)
514 int idx = enc_registered(
enc_table, name);
515 int origidx = enc_registered(
enc_table, orig);
518 GLOBAL_ENC_TABLE_LEAVE();
525rb_enc_set_dummy(
int index)
542 idx = enc_register(
enc_table, name, encoding);
543 if (idx < 0)
rb_raise(rb_eArgError,
"invalid encoding name: %s", name);
544 set_base_encoding(
enc_table, idx, encoding);
555 r = enc_replicate(
enc_table, name, encoding));
570enc_replicate_m(VALUE encoding, VALUE name)
574 return rb_enc_from_encoding_index(idx);
581 idx = enc_register(
enc_table, name, origenc);
584 idx = enc_register_at(
enc_table, idx, name, origenc);
587 set_base_encoding(
enc_table, idx, origenc);
591 rb_raise(rb_eArgError,
"failed to replicate encoding");
597rb_encdb_replicate(
const char *name,
const char *orig)
603 int origidx = enc_registered(
enc_table, orig);
604 int idx = enc_registered(
enc_table, name);
607 origidx = enc_register(
enc_table, orig, 0);
611 GLOBAL_ENC_TABLE_LEAVE();
627 GLOBAL_ENC_TABLE_LEAVE();
633rb_encdb_dummy(
const char *name)
639 index = enc_replicate_with_index(
enc_table, name,
645 GLOBAL_ENC_TABLE_LEAVE();
664enc_dummy_p(VALUE enc)
666 return RBOOL(ENC_DUMMY_P(must_encoding(enc)));
680enc_ascii_compatible_p(VALUE enc)
691 return ONIGENC_IS_UNICODE(enc);
695enc_dup_name(st_data_t name)
697 return (st_data_t)
strdup((
const char *)name);
707 return st_insert2(
enc_table->names, (st_data_t)alias, (st_data_t)idx,
714 if (!valid_encoding_name_p(alias))
return -1;
715 if (!enc_alias_internal(
enc_table, alias, idx))
716 set_encoding_const(alias, enc_from_index(
enc_table, idx));
735 GLOBAL_ENC_TABLE_LEAVE();
741rb_encdb_alias(
const char *alias,
const char *orig)
747 int idx = enc_registered(
enc_table, orig);
754 GLOBAL_ENC_TABLE_LEAVE();
760rb_encdb_set_unicode(
int index)
764 enc->flags |= ONIGENC_FLAG_UNICODE;
770 enc_table_expand(
enc_table, ENCODING_COUNT + 1);
772 enc_table->names = st_init_strcasetable();
774#define ENC_REGISTER(enc) enc_register_at(enc_table, ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)
777 ENC_REGISTER(US_ASCII);
778 global_enc_ascii =
enc_table->list[ENCINDEX_ASCII].enc;
779 global_enc_utf_8 =
enc_table->list[ENCINDEX_UTF_8].enc;
780 global_enc_us_ascii =
enc_table->list[ENCINDEX_US_ASCII].enc;
782#define ENCDB_REGISTER(name, enc) enc_register_at(enc_table, ENCINDEX_##enc, name, NULL)
783 ENCDB_REGISTER(
"UTF-16BE", UTF_16BE);
784 ENCDB_REGISTER(
"UTF-16LE", UTF_16LE);
785 ENCDB_REGISTER(
"UTF-32BE", UTF_32BE);
786 ENCDB_REGISTER(
"UTF-32LE", UTF_32LE);
787 ENCDB_REGISTER(
"UTF-16", UTF_16);
788 ENCDB_REGISTER(
"UTF-32", UTF_32);
789 ENCDB_REGISTER(
"UTF8-MAC", UTF8_MAC);
791 ENCDB_REGISTER(
"EUC-JP", EUC_JP);
792 ENCDB_REGISTER(
"Windows-31J", Windows_31J);
798rb_enc_get_from_index(
int index)
800 return must_encindex(index);
803int rb_require_internal_silent(VALUE fname);
806load_encoding(
const char *name)
820 enclib = rb_fstring(enclib);
823 loaded = rb_require_internal_silent(enclib);
829 if (loaded < 0 || 1 < loaded) {
832 else if ((idx = enc_registered(
enc_table, name)) < 0) {
835 else if (rb_enc_autoload_p(
enc_table->list[idx].enc)) {
839 GLOBAL_ENC_TABLE_LEAVE();
853 }
while (
enc_table->list[i].enc != base && (++i, 1));
854 if (rb_enc_autoload_p(base)) {
855 if (rb_enc_autoload(base) < 0)
return -1;
857 i = enc->ruby_encoding_index;
889 i = load_encoding(name);
892 if (i != UNSPECIFIED_ENCODING) {
893 rb_raise(rb_eArgError,
"encoding %s is not registered", name);
896 else if (rb_enc_autoload_p(enc)) {
897 if (rb_enc_autoload(enc) < 0) {
898 rb_warn(
"failed to load encoding (%s); use ASCII-8BIT instead",
907rb_enc_find_index2(
const char *name,
long len)
909 char buf[ENCODING_NAMELEN_MAX+1];
911 if (len > ENCODING_NAMELEN_MAX)
return -1;
912 memcpy(buf, name, len);
921 if (idx < 0) idx = 0;
926enc_capable(VALUE obj)
936 if (is_data_encoding(obj))
return TRUE;
945 return enc_capable(obj);
956enc_get_index_str(VALUE str)
992 i = enc_get_index_str(obj);
999 if (is_obj_encoding(tmp)) {
1000 i = enc_check_encoding(tmp);
1004 if (is_data_encoding(obj)) {
1005 i = enc_check_encoding(obj);
1015enc_set_index(VALUE obj,
int idx)
1017 if (!enc_capable(obj)) {
1018 rb_raise(rb_eArgError,
"cannot set encoding on non-encoding capable object");
1034 enc_set_index(obj, idx);
1041 int oldidx, oldtermlen, termlen;
1049 rb_raise(rb_eArgError,
"cannot set encoding");
1051 enc = must_encindex(idx);
1059 rb_str_change_terminator_length(obj, oldtermlen, termlen);
1061 enc_set_index(obj, idx);
1078rb_encoding_check(
rb_encoding* enc, VALUE str1, VALUE str2)
1081 rb_raise(rb_eEncCompatError,
"incompatible character encodings: %s and %s",
1087static rb_encoding* enc_compatible_str(VALUE str1, VALUE str2);
1090rb_enc_check_str(VALUE str1, VALUE str2)
1092 rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2));
1093 return rb_encoding_check(enc, str1, str2);
1100 return rb_encoding_check(enc, str1, str2);
1104enc_compatible_latter(VALUE str1, VALUE str2,
int idx1,
int idx2)
1121 if (!isstr2 && idx2 == ENCINDEX_US_ASCII)
1123 if (!isstr1 && idx1 == ENCINDEX_US_ASCII)
1159enc_compatible_str(VALUE str1, VALUE str2)
1161 int idx1 = enc_get_index_str(str1);
1162 int idx2 = enc_get_index_str(str2);
1164 if (idx1 < 0 || idx2 < 0)
1171 return enc_compatible_latter(str1, str2, idx1, idx2);
1181 if (idx1 < 0 || idx2 < 0)
1188 return enc_compatible_latter(str1, str2, idx1, idx2);
1210 rb_raise(rb_eTypeError,
"unknown encoding");
1212 return rb_enc_from_encoding_index(idx & ENC_INDEX_MASK);
1218 return ONIGENC_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1224 int n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1229 return min <= e-p ? min : (int)(e-p);
1238 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
1239 n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
1241 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n-(
int)(e-p));
1253 c = (
unsigned char)*p;
1274 rb_raise(rb_eArgError,
"empty string");
1286 int n = ONIGENC_CODE_TO_MBCLEN(enc,c);
1296 return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_UPPER_CASE(c):(c));
1302 return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_LOWER_CASE(c):(c));
1315enc_inspect(VALUE
self)
1319 if (!is_data_encoding(
self)) {
1323 rb_raise(rb_eTypeError,
"broken Encoding");
1326 "#<%"PRIsVALUE
":%s%s%s>", rb_obj_class(
self),
1328 (ENC_DUMMY_P(enc) ?
" (dummy)" :
""),
1329 rb_enc_autoload_p(enc) ?
" (autoload)" :
"");
1348enc_names_i(st_data_t name, st_data_t idx, st_data_t args)
1350 VALUE *arg = (VALUE *)args;
1352 if ((
int)idx == (int)arg[0]) {
1353 VALUE str = rb_fstring_cstr((
char *)name);
1368enc_names(VALUE
self)
1400enc_list(VALUE klass)
1437enc_find(VALUE klass, VALUE enc)
1440 if (is_obj_encoding(enc))
1442 idx = str_to_encindex(enc);
1443 if (idx == UNSPECIFIED_ENCODING)
return Qnil;
1444 return rb_enc_from_encoding_index(idx);
1472enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
1476 if (!enc_capable(str1))
return Qnil;
1477 if (!enc_capable(str2))
return Qnil;
1479 if (!enc)
return Qnil;
1483NORETURN(
static VALUE enc_s_alloc(VALUE klass));
1486enc_s_alloc(VALUE klass)
1488 rb_undefined_alloc(klass);
1494enc_dump(
int argc, VALUE *argv, VALUE
self)
1497 return enc_name(
self);
1502enc_load(VALUE klass, VALUE str)
1509enc_m_loader(VALUE klass, VALUE str)
1511 return enc_find(klass, str);
1517 return global_enc_ascii;
1523 return ENCINDEX_ASCII;
1529 return global_enc_utf_8;
1535 return ENCINDEX_UTF_8;
1541 return global_enc_us_ascii;
1547 return ENCINDEX_US_ASCII;
1550int rb_locale_charmap_index(
void);
1555 int idx = rb_locale_charmap_index();
1557 if (idx < 0) idx = ENCINDEX_UTF_8;
1560 if (enc_registered(
enc_table,
"locale") < 0) {
1562 void Init_w32_codepage(
void);
1563 Init_w32_codepage();
1565 enc_alias_internal(
enc_table,
"locale", idx);
1567 GLOBAL_ENC_TABLE_LEAVE();
1584 idx = enc_registered(
enc_table,
"filesystem"));
1587 idx = ENCINDEX_ASCII;
1605enc_set_default_encoding(
struct default_encoding *def, VALUE encoding,
const char *name)
1607 int overridden = FALSE;
1609 if (def->index != -2)
1615 if (
NIL_P(encoding)) {
1619 (st_data_t)UNSPECIFIED_ENCODING);
1624 enc_alias_internal(
enc_table, name, def->index);
1627 if (def == &default_external) {
1628 enc_alias_internal(
enc_table,
"filesystem", Init_enc_set_filesystem_encoding());
1631 GLOBAL_ENC_TABLE_LEAVE();
1639 if (default_external.enc)
return default_external.enc;
1641 if (default_external.index >= 0) {
1643 return default_external.enc;
1685get_default_external(VALUE klass)
1693 if (
NIL_P(encoding)) {
1694 rb_raise(rb_eArgError,
"default external can not be nil");
1696 enc_set_default_encoding(&default_external, encoding,
1714set_default_external(VALUE klass, VALUE encoding)
1716 rb_warning(
"setting Encoding.default_external");
1726 if (!default_internal.enc && default_internal.index >= 0) {
1729 return default_internal.enc;
1768get_default_internal(VALUE klass)
1776 enc_set_default_encoding(&default_internal, encoding,
1794set_default_internal(VALUE klass, VALUE encoding)
1796 rb_warning(
"setting Encoding.default_internal");
1802set_encoding_const(
const char *name,
rb_encoding *enc)
1805 char *s = (
char *)name;
1806 int haslower = 0, hasupper = 0, valid = 0;
1811 while (*++s && (
ISALNUM(*s) || *s ==
'_')) {
1812 if (
ISLOWER(*s)) haslower = 1;
1816 if (s - name > ENCODING_NAMELEN_MAX)
return;
1820 if (!valid || haslower) {
1821 size_t len = s - name;
1822 if (len > ENCODING_NAMELEN_MAX)
return;
1823 if (!haslower || !hasupper) {
1825 if (
ISLOWER(*s)) haslower = 1;
1826 if (
ISUPPER(*s)) hasupper = 1;
1827 }
while (*++s && (!haslower || !hasupper));
1831 if (len++ > ENCODING_NAMELEN_MAX)
return;
1835 if (
ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((
int)*s);
1844 for (s = (
char *)name; *s; ++s) {
1845 if (
ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((
int)*s);
1853rb_enc_name_list_i(st_data_t name, st_data_t idx, st_data_t arg)
1855 VALUE ary = (
VALUE)arg;
1856 VALUE str = rb_fstring_cstr((
char *)name);
1876rb_enc_name_list(VALUE klass)
1885 GLOBAL_ENC_TABLE_LEAVE();
1891rb_enc_aliases_enc_i(st_data_t name, st_data_t orig, st_data_t arg)
1893 VALUE *p = (VALUE *)arg;
1894 VALUE aliases = p[0], ary = p[1];
1895 int idx = (int)orig;
1901 if (!enc)
return ST_CONTINUE;
1908 key = rb_fstring_cstr((
char *)name);
1926rb_enc_aliases(VALUE klass)
2172 if (DEFAULT_ENCODING_LIST_CAPA < enc_table->count)
rb_bug(
"DEFAULT_ENCODING_LIST_CAPA is too small");
2174 list = rb_additional_encoding_list =
rb_ary_new();
2175 RBASIC_CLEAR_CLASS(list);
2178 list = rb_default_encoding_list =
rb_ary_new2(DEFAULT_ENCODING_LIST_CAPA);
2179 RBASIC_CLEAR_CLASS(list);
2182 for (i = 0; i <
enc_table->count; ++i) {
2192 rb_enc_init(&global_enc_table);
2198rb_enc_foreach_name(
int (*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg)
#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 REALLOC_N
Old name of RB_REALLOC_N.
#define T_STRING
Old name of RUBY_T_STRING.
#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.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
VALUE rb_errinfo(void)
This is the same as $! in Ruby.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_cEncoding
Encoding class.
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(), except it takes an encoding itself instead of its index.
rb_encoding * rb_utf8_encoding(void)
Queries the encoding that represents UTF-8.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
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.
rb_encoding * rb_to_encoding(VALUE obj)
Identical to rb_find_encoding(), except it raises an exception instead of returning NULL.
rb_encoding * rb_filesystem_encoding(void)
Queries the "filesystem" encoding.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
rb_encoding * rb_default_internal_encoding(void)
Queries the "default internal" 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.
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
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_ascii8bit_encindex(void)
Identical to rb_ascii8bit_encoding(), except it returns the encoding's index instead of the encoding ...
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.
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.
VALUE rb_locale_charmap(VALUE klass)
Returns a platform-depended "charmap" of the current locale.
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_find(const char *name)
Identical to rb_find_encoding(), except it takes a C's string instead of Ruby's.
VALUE rb_enc_from_encoding(rb_encoding *enc)
Queries the Ruby-level counterpart instance of rb_cEncoding that corresponds to the passed encoding.
rb_encoding * rb_find_encoding(VALUE obj)
Identical to rb_to_encoding_index(), except the return type.
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_default_external_encoding(void)
Queries the "default external" encoding.
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_check(VALUE str1, VALUE str2)
Identical to rb_enc_compatible(), except it raises an exception instead of returning NULL.
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_compatible(VALUE str1, VALUE str2)
Look for the "common" encoding between the two.
int rb_enc_replicate(const char *name, rb_encoding *src)
Creates a new encoding, using the passed one as a template.
rb_encoding * rb_locale_encoding(void)
Queries the encoding that represents the current locale.
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.
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...
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.
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_concat(VALUE lhs, VALUE rhs)
Destructively appends the contents of latter into the end of former.
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.
#define rb_check_frozen
Just another name of rb_check_frozen.
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_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.
#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 long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer 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 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.