27 #define BITSPERSHORT (2*CHAR_BIT)
28 #define SHORTMASK ((1<<BITSPERSHORT)-1)
29 #define SHORTDN(x) RSHIFT((x),BITSPERSHORT)
31 #if SIZEOF_SHORT == SIZEOF_BDIGITS
32 #define SHORTLEN(x) (x)
35 shortlen(
long len,
BDIGIT *ds)
47 #define SHORTLEN(x) shortlen((x),d)
50 #define MARSHAL_MAJOR 4
51 #define MARSHAL_MINOR 8
55 #define TYPE_FALSE 'F'
56 #define TYPE_FIXNUM 'i'
58 #define TYPE_EXTENDED 'e'
59 #define TYPE_UCLASS 'C'
60 #define TYPE_OBJECT 'o'
62 #define TYPE_USERDEF 'u'
63 #define TYPE_USRMARSHAL 'U'
64 #define TYPE_FLOAT 'f'
65 #define TYPE_BIGNUM 'l'
66 #define TYPE_STRING '"'
67 #define TYPE_REGEXP '/'
68 #define TYPE_ARRAY '['
70 #define TYPE_HASH_DEF '}'
71 #define TYPE_STRUCT 'S'
72 #define TYPE_MODULE_OLD 'M'
73 #define TYPE_CLASS 'c'
74 #define TYPE_MODULE 'm'
76 #define TYPE_SYMBOL ':'
77 #define TYPE_SYMLINK ';'
133 #define MARSHAL_INFECTION FL_TAINT
183 return ptr ?
sizeof(
struct dump_arg) : 0;
249 #define w_cstr(s, arg) w_bytes((s), strlen(s), (arg))
254 w_byte((
char)((x >> 0) & 0xff), arg);
255 w_byte((
char)((x >> 8) & 0xff), arg);
261 char buf[
sizeof(long)+1];
265 if (!(RSHIFT(x, 31) == 0 || RSHIFT(x, 31) == -1)) {
275 if (0 < x && x < 123) {
276 w_byte((
char)(x + 5), arg);
279 if (-124 < x && x < 0) {
280 w_byte((
char)((x - 5)&0xff), arg);
283 for (i=1;i<(int)
sizeof(
long)+1;i++) {
284 buf[i] = (char)(x & 0xff);
296 for (i=0;i<=len;i++) {
302 #define DECIMAL_MANT (53-16)
304 #if DBL_MANT_DIG > 32
306 #elif DBL_MANT_DIG > 24
308 #elif DBL_MANT_DIG > 16
318 if (--len > 0 && !*buf++) {
319 int e, s = d < 0, dig = 0;
322 modf(ldexp(frexp(fabs(d), &e), DECIMAL_MANT), &d);
326 default: m = *buf++ & 0xff;
328 case 3: m = (m << 8) | (*buf++ & 0xff);
331 case 2: m = (m << 8) | (*buf++ & 0xff);
334 case 1: m = (m << 8) | (*buf++ & 0xff);
337 dig -= len < MANT_BITS / 8 ? 8 * (unsigned)len : MANT_BITS;
338 d += ldexp((
double)m, dig);
339 }
while ((len -= MANT_BITS / 8) > 0);
340 d = ldexp(d, e - DECIMAL_MANT);
346 #define load_mantissa(d, buf, len) (d)
350 #define FLOAT_DIG (DBL_DIG+2)
358 char *
ruby_dtoa(
double d_,
int mode,
int ndigits,
int *decpt,
int *sign,
char **rve);
359 char buf[
FLOAT_DIG + (DECIMAL_MANT + 7) / 8 + 10];
362 if (d < 0)
w_cstr(
"-inf", arg);
369 if (1.0/d < 0)
w_cstr(
"-0", arg);
373 int decpt, sign, digs, len = 0;
374 char *e, *p =
ruby_dtoa(d, 0, 0, &decpt, &sign, &e);
375 if (sign) buf[len++] =
'-';
377 if (decpt < -3 || decpt > digs) {
379 if (--digs > 0) buf[len++] =
'.';
380 memcpy(buf + len, p + 1, digs);
382 len +=
snprintf(buf + len,
sizeof(buf) - len,
"e%d", decpt - 1);
384 else if (decpt > 0) {
385 memcpy(buf + len, p, decpt);
387 if ((digs -= decpt) > 0) {
389 memcpy(buf + len, p + decpt, digs);
397 memset(buf + len,
'0', -decpt);
400 memcpy(buf + len, p, digs);
461 #define SINGLETON_DUMP_UNABLE_P(klass) \
462 (RCLASS_M_TBL(klass)->num_entries || \
463 (RCLASS_IV_TBL(klass) && RCLASS_IV_TBL(klass)->num_entries > 1))
492 obj = (
VALUE)real_obj;
508 if (klass != super) {
585 for (i = 0; i < len; i++)
602 #define has_ivars(obj, ivtbl) ((((ivtbl) = rb_generic_ivar_table(obj)) != 0) || \
603 (!SPECIAL_CONST_P(obj) && !ENCODING_IS_ASCII8BIT(obj)))
622 else if (obj ==
Qtrue) {
633 if (RSHIFT((
long)obj, 31) == 0 || RSHIFT((
long)obj, 31) == -1) {
681 if ((hasiv2 =
has_ivars(v, ivtbl2)) != 0 && !hasiv) {
687 w_ivar(v, ivtbl2, &c_arg);
690 w_ivar(obj, ivtbl, &c_arg);
707 obj = compat->
dumper(real_obj);
709 if (obj != real_obj && !ivtbl) hasiv = 0;
751 #if SIZEOF_BDIGITS > SIZEOF_SHORT
758 if (len == 0 && num == 0)
break;
793 if (len != RARRAY_LEN(obj)) {
827 for (i=0; i<len; i++) {
845 "no _dump_data is defined for class %s",
863 w_ivar(obj, ivtbl, &c_arg);
930 volatile VALUE wrapper;
939 else if (argc == 2) {
1023 return ptr ?
sizeof(
struct load_arg) : 0;
1032 #define r_entry(v, arg) r_entry0((v), (arg)->data->num_entries, (arg))
1054 static unsigned char
1096 c = (
unsigned char)
NUM2CHR(v);
1106 STRINGIZE(SIZEOF_LONG)
", given %d)", size);
1109 #undef SIGN_EXTEND_CHAR
1111 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
1114 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
1124 if (c == 0)
return 0;
1126 if (4 < c && c < 128) {
1132 x |= (long)
r_byte(arg) << (8*i);
1136 if (-129 < c && c < -4) {
1143 x &= ~((long)0xff << (8*i));
1144 x |= (long)
r_byte(arg) << (8*i);
1170 if (len <= arg->buflen) {
1176 long buflen = arg->
buflen;
1178 long tmp_len, read_len, need_len = len - buflen;
1181 readable = readable < BUFSIZ ? readable : BUFSIZ;
1182 read_len = need_len > readable ? need_len :
readable;
1198 if (tmp_len > need_len) {
1199 buflen = tmp_len - need_len;
1212 #define r_bytes(arg) r_bytes0(r_long(arg), (arg))
1296 switch ((type =
r_byte(arg))) {
1353 compat->
loader(real_obj, v);
1410 if (has_encoding) *has_encoding =
TRUE;
1415 }
while (--len > 0);
1430 #define path2module(path) must_be_module(rb_path_to_class(path), path)
1452 if (oldclass) *oldclass = compat->
oldclass;
1477 #define prohibit_ivar(type, str) do { \
1478 if (!ivp || !*ivp) break; \
1479 rb_raise(rb_eTypeError, \
1480 "can't override instance variable of "type" `%"PRIsVALUE"'", \
1561 if (
TYPE(v) !=
TYPE(tmp))
goto format_error;
1596 if (strcmp(ptr,
"nan") == 0) {
1599 else if (strcmp(ptr,
"inf") == 0) {
1602 else if (strcmp(ptr,
"-inf") == 0) {
1642 int has_encoding =
FALSE;
1646 r_ivar(str, &has_encoding, arg);
1649 if (!has_encoding) {
1651 char *ptr =
RSTRING_PTR(str), *dst = ptr, *src = ptr;
1654 for (; len-- > 0; *dst++ = *src++) {
1656 case '\\': bs++;
break;
1657 case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
1658 case 'm':
case 'o':
case 'p':
case 'q':
case 'u':
case 'y':
1659 case 'E':
case 'F':
case 'H':
case 'I':
case 'J':
case 'K':
1660 case 'L':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
1661 case 'S':
case 'T':
case 'U':
case 'V':
case 'X':
case 'Y':
1663 default: bs = 0;
break;
1675 volatile long len =
r_long(arg);
1733 for (i=0; i<len; i++) {
1779 if (!
NIL_P(extmod)) {
1794 if (!
NIL_P(extmod)) {
1827 "class %s needs to have instance method `_load_data'",
1937 volatile VALUE wrapper;
1943 infection = (int)
FL_TEST(port, MARSHAL_INFECTION);
1973 \tformat version %d.%d required; %d.%d given",
1977 rb_warn(
"incompatible marshal file format (can be read)\n\
1978 \tformat version %d.%d required; %d.%d given",
2105 #define rb_intern(str) rb_intern_const(str)
2145 if (!
NIL_P(port)) argc = 2;