12 #include "ruby/internal/config.h"
17 #include <sys/types.h>
20 #include "internal/array.h"
21 #include "internal/bits.h"
22 #include "internal/string.h"
23 #include "internal/symbol.h"
24 #include "internal/variable.h"
37 #ifdef HAVE_TRUE_LONG_LONG
38 static const char natstr[] =
"sSiIlLqQjJ";
39 # define endstr natstr
41 static const char natstr[] =
"sSiIlLjJ";
42 static const char endstr[] =
"sSiIlLqQjJ";
45 #ifdef HAVE_TRUE_LONG_LONG
47 # define NATINT_LEN_Q NATINT_LEN(long long, 8)
49 # define NATINT_LEN_Q 8
52 #if SIZEOF_SHORT != 2 || SIZEOF_LONG != 4 || (defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG != 8)
63 static int endian_value;
66 if (init)
return endian_value;
69 return endian_value = p[0]?0:1;
71 # define BIGENDIAN_P() (is_bigendian())
72 #elif defined(WORDS_BIGENDIAN)
73 # define BIGENDIAN_P() 1
75 # define BIGENDIAN_P() 0
79 # define NATINT_LEN(type,len) (natint?(int)sizeof(type):(int)(len))
81 # define NATINT_LEN(type,len) ((int)sizeof(type))
94 #define swapf(x) swap32(x)
95 #define swapd(x) swap64(x)
97 #define rb_ntohf(x) (BIGENDIAN_P()?(x):swapf(x))
98 #define rb_ntohd(x) (BIGENDIAN_P()?(x):swapd(x))
99 #define rb_htonf(x) (BIGENDIAN_P()?(x):swapf(x))
100 #define rb_htond(x) (BIGENDIAN_P()?(x):swapd(x))
101 #define rb_htovf(x) (BIGENDIAN_P()?swapf(x):(x))
102 #define rb_htovd(x) (BIGENDIAN_P()?swapd(x):(x))
103 #define rb_vtohf(x) (BIGENDIAN_P()?swapf(x):(x))
104 #define rb_vtohd(x) (BIGENDIAN_P()?swapd(x):(x))
106 #define FLOAT_CONVWITH(x) FLOAT_SWAPPER x;
107 #define HTONF(x) ((x).u = rb_htonf((x).u))
108 #define HTOVF(x) ((x).u = rb_htovf((x).u))
109 #define NTOHF(x) ((x).u = rb_ntohf((x).u))
110 #define VTOHF(x) ((x).u = rb_vtohf((x).u))
112 #define DOUBLE_CONVWITH(x) DOUBLE_SWAPPER x;
113 #define HTOND(x) ((x).u = rb_htond((x).u))
114 #define HTOVD(x) ((x).u = rb_htovd((x).u))
115 #define NTOHD(x) ((x).u = rb_ntohd((x).u))
116 #define VTOHD(x) ((x).u = rb_vtohd((x).u))
118 #define MAX_INTEGER_PACK_SIZE 8
120 static const char toofew[] =
"too few arguments";
122 static void encodes(
VALUE,
const char*,
long,
int,
int);
125 static unsigned long utf8_to_uv(
const char*,
long*);
127 static ID id_associated;
137 str_associated(
VALUE str)
139 VALUE associates = rb_ivar_lookup(str, id_associated,
Qfalse);
146 associated_pointer(
VALUE associates,
const char *t)
150 for (; p < pend; p++) {
160 unknown_directive(const
char *mode,
char type,
VALUE fmt)
169 snprintf(unknown,
sizeof(unknown),
"\\x%.2x",
type & 0xff);
171 fmt = rb_str_quote_unprintable(fmt);
177 VALUE_to_float(
VALUE obj)
185 else if (d < -FLT_MAX) {
188 else if (d <= FLT_MAX) {
197 str_expand_fill(
VALUE res,
int c,
long len)
205 skip_to_eol(
const char *p,
const char *pend)
207 p = memchr(p,
'\n', pend - p);
208 return (
char *)(p ? p + 1 : pend);
211 #define skip_blank(p, type) \
212 (ISSPACE(type) || (type == '#' && (p = skip_to_eol(p, pend), 1)))
215 # define pack_modifiers(p, t, n, e) pack_modifiers(p, t, e)
218 pack_modifiers(
const char *p,
char type,
int *natint,
int *explicit_endian)
224 if (strchr(natstr,
type)) {
237 if (!strchr(endstr,
type)) {
240 if (*explicit_endian) {
243 *explicit_endian = *p++;
254 const char *p, *pend;
255 VALUE res, from, associates = 0;
259 int integer_size, bigendian_p;
278 #define TOO_FEW (rb_raise(rb_eArgError, toofew), 0)
279 #define MORE_ITEM (idx < RARRAY_LEN(ary))
280 #define THISFROM (MORE_ITEM ? RARRAY_AREF(ary, idx) : TOO_FEW)
281 #define NEXTFROM (MORE_ITEM ? RARRAY_AREF(ary, idx++) : TOO_FEW)
284 int explicit_endian = 0;
288 const char type = *p++;
293 if (skip_blank(p,
type))
continue;
294 p = pack_modifiers(p,
type, &natint, &explicit_endian);
298 : strchr(
"PMm",
type) ? 1
316 if (enc_info == 1) enc_info = 2;
318 case 'm':
case 'M':
case 'u':
327 case 'A':
case 'a':
case 'Z':
350 if (p[-1] ==
'*' &&
type ==
'Z')
356 str_expand_fill(res, (
type ==
'A' ?
' ' :
'\0'),
len - plen);
360 #define castchar(from) (char)((from) & 0xff)
368 j = (
len - plen + 1)/2;
371 for (i=0; i++ <
len;
ptr++) {
377 char c = castchar(
byte);
384 byte >>= 7 - (
len & 7);
399 j = (
len - plen + 1)/2;
402 for (i=0; i++ <
len;
ptr++) {
407 char c = castchar(
byte);
414 byte <<= 7 - (
len & 7);
429 j = (
len + 1) / 2 - (plen + 1) / 2;
432 for (i=0; i++ <
len;
ptr++) {
434 byte |= (((*
ptr & 15) + 9) & 15) << 4;
436 byte |= (*
ptr & 15) << 4;
440 char c = castchar(
byte);
446 char c = castchar(
byte);
460 j = (
len + 1) / 2 - (plen + 1) / 2;
463 for (i=0; i++ <
len;
ptr++) {
465 byte |= ((*
ptr & 15) + 9) & 15;
471 char c = castchar(
byte);
477 char c = castchar(
byte);
490 bigendian_p = BIGENDIAN_P();
495 integer_size = NATINT_LEN(
short, 2);
496 bigendian_p = BIGENDIAN_P();
501 integer_size = (int)
sizeof(
int);
502 bigendian_p = BIGENDIAN_P();
507 integer_size = NATINT_LEN(
long, 4);
508 bigendian_p = BIGENDIAN_P();
513 integer_size = NATINT_LEN_Q;
514 bigendian_p = BIGENDIAN_P();
518 integer_size =
sizeof(intptr_t);
519 bigendian_p = BIGENDIAN_P();
523 integer_size =
sizeof(uintptr_t);
524 bigendian_p = BIGENDIAN_P();
548 if (explicit_endian) {
549 bigendian_p = explicit_endian ==
'>';
551 if (integer_size > MAX_INTEGER_PACK_SIZE)
552 rb_bug(
"unexpected integer size for pack: %d", integer_size);
554 char intbuf[MAX_INTEGER_PACK_SIZE];
570 f = VALUE_to_float(from);
580 tmp.f = VALUE_to_float(from);
588 DOUBLE_CONVWITH(tmp);
611 tmp.f = VALUE_to_float(from);
619 DOUBLE_CONVWITH(tmp);
631 str_expand_fill(res,
'\0',
len);
644 if (
len > 0)
goto grow;
646 if (
len > 0)
goto shrink;
678 encodes(res,
ptr, plen,
type, 0);
684 else if (
len > 63 &&
type ==
'u')
695 encodes(res,
ptr, todo,
type, 1);
705 qpencode(res, from,
len);
756 rb_bug(
"buffer size problem?");
759 while (1 < numbytes) {
770 unknown_directive(
"pack",
type, fmt);
777 str_associate(res, associates);
796 return pack_pack(ec, ary, fmt, buffer);
799 static const char uu_table[] =
800 "`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
801 static const char b64_table[] =
802 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
805 encodes(
VALUE str,
const char *s0,
long len,
int type,
int tail_lf)
807 enum {buff_size = 4096, encoded_unit = 4, input_unit = 3};
808 char buff[buff_size + 1];
810 const char *
const trans =
type ==
'u' ? uu_table : b64_table;
812 const unsigned char *s = (
const unsigned char *)s0;
815 buff[i++] = (char)
len +
' ';
821 while (
len >= input_unit) {
822 while (
len >= input_unit && buff_size-i >= encoded_unit) {
823 buff[i++] = trans[077 & (*s >> 2)];
824 buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
825 buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
826 buff[i++] = trans[077 & s[2]];
830 if (buff_size-i < encoded_unit) {
837 buff[i++] = trans[077 & (*s >> 2)];
838 buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
839 buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((
'\0' >> 6) & 03))];
843 buff[i++] = trans[077 & (*s >> 2)];
844 buff[i++] = trans[077 & (((*s << 4) & 060) | ((
'\0' >> 4) & 017))];
848 if (tail_lf) buff[i++] =
'\n';
850 if ((
size_t)i >
sizeof(buff))
rb_bug(
"encodes() buffer overrun");
853 static const char hex_table[] =
"0123456789ABCDEF";
859 long i = 0, n = 0, prev = EOF;
860 unsigned char *s = (
unsigned char*)
RSTRING_PTR(from);
865 (*s < 32 && *s !=
'\n' && *s !=
'\t') ||
868 buff[i++] = hex_table[*s >> 4];
869 buff[i++] = hex_table[*s & 0x0f];
873 else if (*s ==
'\n') {
874 if (prev ==
' ' || prev ==
'\t') {
918 #define PACK_LENGTH_ADJUST_SIZE(sz) do { \
920 if (len > (long)((send-s)/(sz))) { \
922 tmp_len = len-(send-s)/(sz); \
924 len = (send-s)/(sz); \
928 #define PACK_ITEM_ADJUST() do { \
929 if (tmp_len > 0 && mode == UNPACK_ARRAY) \
930 rb_ary_store(ary, RARRAY_LEN(ary)+tmp_len-1, Qnil); \
937 #if defined(__SUNPRO_C) && 0x5130 <= __SUNPRO_C && __SUNPRO_C <= 0x5150
938 # define AVOID_CC_BUG volatile
940 # define AVOID_CC_BUG
950 pack_unpack_internal(
VALUE str,
VALUE fmt,
enum unpack_mode mode,
long offset)
952 #define hexdigits ruby_hexdigits
957 AVOID_CC_BUG
long tmp_len;
958 int signed_p, integer_size, bigendian_p;
959 #define UNPACK_PUSH(item) do {\
960 VALUE item_val = (item);\
961 if ((mode) == UNPACK_BLOCK) {\
964 else if ((mode) == UNPACK_ARRAY) {\
965 rb_ary_push(ary, item_val);\
987 #define UNPACK_FETCH(var, type) (memcpy((var), s, sizeof(type)), s += sizeof(type))
991 int explicit_endian = 0;
992 const char type = *p++;
998 if (skip_blank(p,
type))
continue;
999 p = pack_modifiers(p,
type, &natint, &explicit_endian);
1003 else if (*p ==
'*') {
1025 if (
len > send - s)
len = send - s;
1028 char *t = s +
len - 1;
1031 if (*t !=
' ' && *t !=
'\0')
break;
1043 if (
len > send-s)
len = send-s;
1044 while (t < s+
len && *t) t++;
1047 s = star ? t : s+
len;
1052 if (
len > send - s)
len = send - s;
1064 if (p[-1] ==
'*' ||
len > (send - s) * 8)
1065 len = (send - s) * 8;
1069 for (i=0; i<
len; i++) {
1070 if (i & 7) bits >>= 1;
1071 else bits = (
unsigned char)*s++;
1072 *t++ = (bits & 1) ?
'1' :
'0';
1074 UNPACK_PUSH(bitstr);
1085 if (p[-1] ==
'*' ||
len > (send - s) * 8)
1086 len = (send - s) * 8;
1090 for (i=0; i<
len; i++) {
1091 if (i & 7) bits <<= 1;
1092 else bits = (
unsigned char)*s++;
1093 *t++ = (bits & 128) ?
'1' :
'0';
1095 UNPACK_PUSH(bitstr);
1106 if (p[-1] ==
'*' ||
len > (send - s) * 2)
1107 len = (send - s) * 2;
1111 for (i=0; i<
len; i++) {
1115 bits = (
unsigned char)*s++;
1116 *t++ = hexdigits[bits & 15];
1118 UNPACK_PUSH(bitstr);
1129 if (p[-1] ==
'*' ||
len > (send - s) * 2)
1130 len = (send - s) * 2;
1134 for (i=0; i<
len; i++) {
1138 bits = (
unsigned char)*s++;
1139 *t++ = hexdigits[(bits >> 4) & 15];
1141 UNPACK_PUSH(bitstr);
1148 bigendian_p = BIGENDIAN_P();
1149 goto unpack_integer;
1154 bigendian_p = BIGENDIAN_P();
1155 goto unpack_integer;
1159 integer_size = NATINT_LEN(
short, 2);
1160 bigendian_p = BIGENDIAN_P();
1161 goto unpack_integer;
1165 integer_size = NATINT_LEN(
short, 2);
1166 bigendian_p = BIGENDIAN_P();
1167 goto unpack_integer;
1171 integer_size = (int)
sizeof(
int);
1172 bigendian_p = BIGENDIAN_P();
1173 goto unpack_integer;
1177 integer_size = (int)
sizeof(
int);
1178 bigendian_p = BIGENDIAN_P();
1179 goto unpack_integer;
1183 integer_size = NATINT_LEN(
long, 4);
1184 bigendian_p = BIGENDIAN_P();
1185 goto unpack_integer;
1189 integer_size = NATINT_LEN(
long, 4);
1190 bigendian_p = BIGENDIAN_P();
1191 goto unpack_integer;
1195 integer_size = NATINT_LEN_Q;
1196 bigendian_p = BIGENDIAN_P();
1197 goto unpack_integer;
1201 integer_size = NATINT_LEN_Q;
1202 bigendian_p = BIGENDIAN_P();
1203 goto unpack_integer;
1207 integer_size =
sizeof(intptr_t);
1208 bigendian_p = BIGENDIAN_P();
1209 goto unpack_integer;
1213 integer_size =
sizeof(uintptr_t);
1214 bigendian_p = BIGENDIAN_P();
1215 goto unpack_integer;
1221 goto unpack_integer;
1227 goto unpack_integer;
1233 goto unpack_integer;
1239 goto unpack_integer;
1242 if (explicit_endian) {
1243 bigendian_p = explicit_endian ==
'>';
1245 PACK_LENGTH_ADJUST_SIZE(integer_size);
1260 PACK_LENGTH_ADJUST_SIZE(
sizeof(
float));
1263 UNPACK_FETCH(&tmp,
float);
1264 UNPACK_PUSH(
DBL2NUM((
double)tmp));
1270 PACK_LENGTH_ADJUST_SIZE(
sizeof(
float));
1272 FLOAT_CONVWITH(tmp);
1273 UNPACK_FETCH(tmp.buf,
float);
1281 PACK_LENGTH_ADJUST_SIZE(
sizeof(
double));
1283 DOUBLE_CONVWITH(tmp);
1284 UNPACK_FETCH(tmp.buf,
double);
1293 PACK_LENGTH_ADJUST_SIZE(
sizeof(
double));
1296 UNPACK_FETCH(&tmp,
double);
1303 PACK_LENGTH_ADJUST_SIZE(
sizeof(
float));
1305 FLOAT_CONVWITH(tmp);
1306 UNPACK_FETCH(tmp.buf,
float);
1314 PACK_LENGTH_ADJUST_SIZE(
sizeof(
double));
1316 DOUBLE_CONVWITH(tmp);
1317 UNPACK_FETCH(tmp.buf,
double);
1325 if (
len > send - s)
len = send - s;
1326 while (
len > 0 && s < send) {
1327 long alen = send - s;
1330 l = utf8_to_uv(s, &alen);
1342 while (s < send && (
unsigned char)*s >
' ' && (
unsigned char)*s <
'a') {
1346 len = ((
unsigned char)*s++ -
' ') & 077;
1355 long mlen =
len > 3 ? 3 :
len;
1357 if (s < send && (
unsigned char)*s >=
' ' && (
unsigned char)*s <
'a')
1358 a = ((
unsigned char)*s++ -
' ') & 077;
1361 if (s < send && (
unsigned char)*s >=
' ' && (
unsigned char)*s <
'a')
1362 b = ((
unsigned char)*s++ -
' ') & 077;
1365 if (s < send && (
unsigned char)*s >=
' ' && (
unsigned char)*s <
'a')
1366 c = ((
unsigned char)*s++ -
' ') & 077;
1369 if (s < send && (
unsigned char)*s >=
' ' && (
unsigned char)*s <
'a')
1370 d = ((
unsigned char)*s++ -
' ') & 077;
1373 hunk[0] = (char)(a << 2 | b >> 4);
1374 hunk[1] = (char)(b << 4 | c >> 2);
1375 hunk[2] = (char)(c << 6 | d);
1376 memcpy(
ptr, hunk, mlen);
1380 if (s < send && (
unsigned char)*s !=
'\r' && *s !=
'\n')
1382 if (s < send && *s ==
'\r') s++;
1383 if (s < send && *s ==
'\n') s++;
1395 int a = -1,b = -1,c = 0,d = 0;
1396 static signed char b64_xtable[256];
1398 if (b64_xtable[
'/'] <= 0) {
1401 for (i = 0; i < 256; i++) {
1404 for (i = 0; i < 64; i++) {
1405 b64_xtable[(
unsigned char)b64_table[i]] = (
char)i;
1411 a = b64_xtable[(
unsigned char)*s++];
1413 b = b64_xtable[(
unsigned char)*s++];
1416 if (s + 2 == send && *(s + 1) ==
'=')
break;
1419 c = b64_xtable[(
unsigned char)*s++];
1421 if (s + 1 == send && *s ==
'=')
break;
1422 d = b64_xtable[(
unsigned char)*s++];
1424 *
ptr++ = castchar(a << 2 | b >> 4);
1425 *
ptr++ = castchar(b << 4 | c >> 2);
1426 *
ptr++ = castchar(c << 6 | d);
1429 *
ptr++ = castchar(a << 2 | b >> 4);
1433 *
ptr++ = castchar(a << 2 | b >> 4);
1434 *
ptr++ = castchar(b << 4 | c >> 2);
1441 while ((a = b64_xtable[(
unsigned char)*s]) == -1 && s < send) {s++;}
1442 if (s >= send)
break;
1444 while ((b = b64_xtable[(
unsigned char)*s]) == -1 && s < send) {s++;}
1445 if (s >= send)
break;
1447 while ((c = b64_xtable[(
unsigned char)*s]) == -1 && s < send) {
if (*s ==
'=')
break; s++;}
1448 if (*s ==
'=' || s >= send)
break;
1450 while ((d = b64_xtable[(
unsigned char)*s]) == -1 && s < send) {
if (*s ==
'=')
break; s++;}
1451 if (*s ==
'=' || s >= send)
break;
1453 *
ptr++ = castchar(a << 2 | b >> 4);
1454 *
ptr++ = castchar(b << 4 | c >> 2);
1455 *
ptr++ = castchar(c << 6 | d);
1458 if (a != -1 && b != -1) {
1460 *
ptr++ = castchar(a << 2 | b >> 4);
1462 *
ptr++ = castchar(a << 2 | b >> 4);
1463 *
ptr++ = castchar(b << 4 | c >> 2);
1481 if (++s == send)
break;
1482 if (s+1 < send && *s ==
'\r' && *(s+1) ==
'\n')
1485 if ((c1 = hex2num(*s)) == -1)
break;
1486 if (++s == send)
break;
1487 if ((c2 = hex2num(*s)) == -1)
break;
1488 csum |= *
ptr++ = castchar(c1 << 4 | c2);
1492 csum |= *
ptr++ = *s;
1524 if (
sizeof(
char *) <= (
size_t)(send - s)) {
1528 UNPACK_FETCH(&t,
char *);
1530 if (!associates) associates = str_associated(str);
1531 tmp = associated_pointer(associates, t);
1534 str_associate(tmp, associates);
1542 if (
len > (
long)((send - s) /
sizeof(
char *)))
1543 len = (send - s) /
sizeof(
char *);
1545 if ((
size_t)(send - s) <
sizeof(
char *))
1551 UNPACK_FETCH(&t,
char *);
1553 if (!associates) associates = str_associated(str);
1554 tmp = associated_pointer(associates, t);
1564 while (
len > 0 && s < send) {
1579 unknown_directive(
"unpack",
type, fmt);
1591 return pack_unpack_internal(str, fmt, mode,
RB_NUM2LONG(offset));
1597 return pack_unpack_internal(str, fmt, UNPACK_1,
RB_NUM2LONG(offset));
1608 buf[0] = castchar(((uv>>6)&0xff)|0xc0);
1609 buf[1] = castchar((uv&0x3f)|0x80);
1613 buf[0] = castchar(((uv>>12)&0xff)|0xe0);
1614 buf[1] = castchar(((uv>>6)&0x3f)|0x80);
1615 buf[2] = castchar((uv&0x3f)|0x80);
1618 if (uv <= 0x1fffff) {
1619 buf[0] = castchar(((uv>>18)&0xff)|0xf0);
1620 buf[1] = castchar(((uv>>12)&0x3f)|0x80);
1621 buf[2] = castchar(((uv>>6)&0x3f)|0x80);
1622 buf[3] = castchar((uv&0x3f)|0x80);
1625 if (uv <= 0x3ffffff) {
1626 buf[0] = castchar(((uv>>24)&0xff)|0xf8);
1627 buf[1] = castchar(((uv>>18)&0x3f)|0x80);
1628 buf[2] = castchar(((uv>>12)&0x3f)|0x80);
1629 buf[3] = castchar(((uv>>6)&0x3f)|0x80);
1630 buf[4] = castchar((uv&0x3f)|0x80);
1633 if (uv <= 0x7fffffff) {
1634 buf[0] = castchar(((uv>>30)&0xff)|0xfc);
1635 buf[1] = castchar(((uv>>24)&0x3f)|0x80);
1636 buf[2] = castchar(((uv>>18)&0x3f)|0x80);
1637 buf[3] = castchar(((uv>>12)&0x3f)|0x80);
1638 buf[4] = castchar(((uv>>6)&0x3f)|0x80);
1639 buf[5] = castchar((uv&0x3f)|0x80);
1647 static const unsigned long utf8_limits[] = {
1657 static unsigned long
1658 utf8_to_uv(
const char *p,
long *lenp)
1660 int c = *p++ & 0xff;
1661 unsigned long uv = c;
1673 if (!(uv & 0x20)) { n = 2; uv &= 0x1f; }
1674 else if (!(uv & 0x10)) { n = 3; uv &= 0x0f; }
1675 else if (!(uv & 0x08)) { n = 4; uv &= 0x07; }
1676 else if (!(uv & 0x04)) { n = 5; uv &= 0x03; }
1677 else if (!(uv & 0x02)) { n = 6; uv &= 0x01; }
1690 if ((c & 0xc0) != 0x80) {
1701 if (uv < utf8_limits[n]) {
1707 #include "pack.rbinc"
1712 id_associated = rb_make_internal_id();
int rb_block_given_p(void)
Determines if the current method is given a block.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define ENC_CODERANGE_VALID
Old name of RUBY_ENC_CODERANGE_VALID.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define STRTOUL
Old name of ruby_strtoul.
#define ISDIGIT
Old name of rb_isdigit.
#define ISALPHA
Old name of rb_isalpha.
#define ISASCII
Old name of rb_isascii.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define DBL2NUM
Old name of rb_float_new.
#define ISPRINT
Old name of rb_isprint.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define ENCODING_CODERANGE_SET(obj, encindex, cr)
Old name of RB_ENCODING_CODERANGE_SET.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_to_float(VALUE val)
Identical to rb_check_to_float(), except it raises on error.
VALUE rb_to_int(VALUE val)
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
int rb_utf8_encindex(void)
Identical to rb_utf8_encoding(), except it returns the encoding's index instead of the encoding itsel...
int rb_ascii8bit_encindex(void)
Identical to rb_ascii8bit_encoding(), except it returns the encoding's index instead of the encoding ...
void rb_enc_set_index(VALUE obj, int encindex)
Destructively assigns an encoding (via its index) to an object.
int rb_usascii_encindex(void)
Identical to rb_usascii_encoding(), except it returns the encoding's index instead of the encoding it...
Defines RBIMPL_HAS_BUILTIN.
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.
int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Exports an integer into a buffer.
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
Calculates the number of words needed represent the absolute value of the passed integer.
VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Import an integer from a buffer.
#define INTEGER_PACK_LITTLE_ENDIAN
Little endian combination.
#define INTEGER_PACK_BIG_ENDIAN
Big endian combination.
int rb_uv_to_utf8(char buf[6], unsigned long uv)
Encodes a Unicode codepoint into its UTF-8 representation.
#define INTEGER_PACK_2COMP
Uses 2's complement representation.
VALUE rb_str_buf_cat(VALUE, const char *, long)
Just another name of rb_str_cat.
void rb_str_modify(VALUE str)
Declares that the string is about to be modified.
VALUE rb_usascii_str_new(const char *ptr, long len)
Identical to rb_str_new(), except it generates a string of "US ASCII" encoding.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
void rb_str_modify_expand(VALUE str, long capa)
Identical to rb_str_modify(), except it additionally expands the capacity of the receiver.
VALUE rb_str_buf_new(long capa)
Allocates a "string buffer".
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
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.
RBIMPL_ATTR_NORETURN() void rb_eof_error(void)
Utility function to raise rb_eEOFError.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
const signed char ruby_digit36_to_number_table[]
Character to number mapping like ‘'a’->10,'b'->11` etc.
#define RB_NUM2LONG
Just another name of rb_num2long_inline.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define StringValue(v)
Ensures that the parameter object is a String.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
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.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define errno
Ractor-aware version of errno.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
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.