Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

marshal.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 marshal.c -
4
5 $Author: nagachika $
6 created at: Thu Apr 27 16:30:01 JST 1995
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10 **********************************************************************/
11
12 #include "ruby/ruby.h"
13 #include "ruby/io.h"
14 #include "ruby/st.h"
15 #include "ruby/util.h"
16 #include "ruby/encoding.h"
17 #include "internal.h"
18
19 #include <math.h>
20 #ifdef HAVE_FLOAT_H
21 #include <float.h>
22 #endif
23 #ifdef HAVE_IEEEFP_H
24 #include <ieeefp.h>
25 #endif
26
27 #define BITSPERSHORT (2*CHAR_BIT)
28 #define SHORTMASK ((1<<BITSPERSHORT)-1)
29 #define SHORTDN(x) RSHIFT((x),BITSPERSHORT)
30
31 #if SIZEOF_SHORT == SIZEOF_BDIGITS
32 #define SHORTLEN(x) (x)
33 #else
34 static long
35 shortlen(long len, BDIGIT *ds)
36 {
37 BDIGIT num;
38 int offset = 0;
39
40 num = ds[len-1];
41 while (num) {
42 num = SHORTDN(num);
43 offset++;
44 }
45 return (len - 1)*SIZEOF_BDIGITS/2 + offset;
46 }
47 #define SHORTLEN(x) shortlen((x),d)
48 #endif
49
50 #define MARSHAL_MAJOR 4
51 #define MARSHAL_MINOR 8
52
53 #define TYPE_NIL '0'
54 #define TYPE_TRUE 'T'
55 #define TYPE_FALSE 'F'
56 #define TYPE_FIXNUM 'i'
57
58 #define TYPE_EXTENDED 'e'
59 #define TYPE_UCLASS 'C'
60 #define TYPE_OBJECT 'o'
61 #define TYPE_DATA 'd'
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 '['
69 #define TYPE_HASH '{'
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'
75
76 #define TYPE_SYMBOL ':'
77 #define TYPE_SYMLINK ';'
78
79 #define TYPE_IVAR 'I'
80 #define TYPE_LINK '@'
81
82 static ID s_dump, s_load, s_mdump, s_mload;
83 static ID s_dump_data, s_load_data, s_alloc, s_call;
84 static ID s_getbyte, s_read, s_write, s_binmode;
85
86 typedef struct {
87 VALUE newclass;
88 VALUE oldclass;
89 VALUE (*dumper)(VALUE);
90 VALUE (*loader)(VALUE, VALUE);
91 } marshal_compat_t;
92
93 static st_table *compat_allocator_tbl;
94 static VALUE compat_allocator_tbl_wrapper;
95
96 static int
97 mark_marshal_compat_i(st_data_t key, st_data_t value)
98 {
99 marshal_compat_t *p = (marshal_compat_t *)value;
100 rb_gc_mark(p->newclass);
101 rb_gc_mark(p->oldclass);
102 return ST_CONTINUE;
103 }
104
105 static void
106 mark_marshal_compat_t(void *tbl)
107 {
108 if (!tbl) return;
109 st_foreach(tbl, mark_marshal_compat_i, 0);
110 }
111
112 void
113 rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE))
114 {
115 marshal_compat_t *compat;
116 rb_alloc_func_t allocator = rb_get_alloc_func(newclass);
117
118 if (!allocator) {
119 rb_raise(rb_eTypeError, "no allocator");
120 }
121
122 compat = ALLOC(marshal_compat_t);
123 compat->newclass = Qnil;
124 compat->oldclass = Qnil;
125 compat->newclass = newclass;
126 compat->oldclass = oldclass;
127 compat->dumper = dumper;
128 compat->loader = loader;
129
130 st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat);
131 }
132
133 #define MARSHAL_INFECTION FL_TAINT
134 typedef char ruby_check_marshal_viral_flags[MARSHAL_INFECTION == (int)MARSHAL_INFECTION ? 1 : -1];
135
136 struct dump_arg {
137 VALUE str, dest;
138 st_table *symbols;
139 st_table *data;
140 st_table *compat_tbl;
141 st_table *encodings;
142 int infection;
143 };
144
145 struct dump_call_arg {
146 VALUE obj;
147 struct dump_arg *arg;
148 int limit;
149 };
150
151 static void
152 check_dump_arg(struct dump_arg *arg, ID sym)
153 {
154 if (!arg->symbols) {
155 rb_raise(rb_eRuntimeError, "Marshal.dump reentered at %s",
156 rb_id2name(sym));
157 }
158 }
159
160 static void clear_dump_arg(struct dump_arg *arg);
161
162 static void
163 mark_dump_arg(void *ptr)
164 {
165 struct dump_arg *p = ptr;
166 if (!p->symbols)
167 return;
168 rb_mark_set(p->data);
169 rb_mark_hash(p->compat_tbl);
170 rb_gc_mark(p->str);
171 }
172
173 static void
174 free_dump_arg(void *ptr)
175 {
176 clear_dump_arg(ptr);
177 xfree(ptr);
178 }
179
180 static size_t
181 memsize_dump_arg(const void *ptr)
182 {
183 return ptr ? sizeof(struct dump_arg) : 0;
184 }
185
186 static const rb_data_type_t dump_arg_data = {
187 "dump_arg",
188 {mark_dump_arg, free_dump_arg, memsize_dump_arg,},
189 NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
190 };
191
192 static const char *
193 must_not_be_anonymous(const char *type, VALUE path)
194 {
195 char *n = RSTRING_PTR(path);
196
197 if (!rb_enc_asciicompat(rb_enc_get(path))) {
198 /* cannot occur? */
199 rb_raise(rb_eTypeError, "can't dump non-ascii %s name", type);
200 }
201 if (n[0] == '#') {
202 rb_raise(rb_eTypeError, "can't dump anonymous %s %.*s", type,
203 (int)RSTRING_LEN(path), n);
204 }
205 return n;
206 }
207
208 static VALUE
209 class2path(VALUE klass)
210 {
211 VALUE path = rb_class_path(klass);
212 const char *n;
213
214 n = must_not_be_anonymous((RB_TYPE_P(klass, T_CLASS) ? "class" : "module"), path);
215 if (rb_path_to_class(path) != rb_class_real(klass)) {
216 rb_raise(rb_eTypeError, "%s can't be referred to", n);
217 }
218 return path;
219 }
220
221 static void w_long(long, struct dump_arg*);
222 static void w_encoding(VALUE obj, long num, struct dump_call_arg *arg);
223
224 static void
225 w_nbyte(const char *s, long n, struct dump_arg *arg)
226 {
227 VALUE buf = arg->str;
228 rb_str_buf_cat(buf, s, n);
229 RBASIC(buf)->flags |= arg->infection;
230 if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
231 rb_io_write(arg->dest, buf);
232 rb_str_resize(buf, 0);
233 }
234 }
235
236 static void
237 w_byte(char c, struct dump_arg *arg)
238 {
239 w_nbyte(&c, 1, arg);
240 }
241
242 static void
243 w_bytes(const char *s, long n, struct dump_arg *arg)
244 {
245 w_long(n, arg);
246 w_nbyte(s, n, arg);
247 }
248
249 #define w_cstr(s, arg) w_bytes((s), strlen(s), (arg))
250
251 static void
252 w_short(int x, struct dump_arg *arg)
253 {
254 w_byte((char)((x >> 0) & 0xff), arg);
255 w_byte((char)((x >> 8) & 0xff), arg);
256 }
257
258 static void
259 w_long(long x, struct dump_arg *arg)
260 {
261 char buf[sizeof(long)+1];
262 int i, len = 0;
263
264 #if SIZEOF_LONG > 4
265 if (!(RSHIFT(x, 31) == 0 || RSHIFT(x, 31) == -1)) {
266 /* big long does not fit in 4 bytes */
267 rb_raise(rb_eTypeError, "long too big to dump");
268 }
269 #endif
270
271 if (x == 0) {
272 w_byte(0, arg);
273 return;
274 }
275 if (0 < x && x < 123) {
276 w_byte((char)(x + 5), arg);
277 return;
278 }
279 if (-124 < x && x < 0) {
280 w_byte((char)((x - 5)&0xff), arg);
281 return;
282 }
283 for (i=1;i<(int)sizeof(long)+1;i++) {
284 buf[i] = (char)(x & 0xff);
285 x = RSHIFT(x,8);
286 if (x == 0) {
287 buf[0] = i;
288 break;
289 }
290 if (x == -1) {
291 buf[0] = -i;
292 break;
293 }
294 }
295 len = i;
296 for (i=0;i<=len;i++) {
297 w_byte(buf[i], arg);
298 }
299 }
300
301 #ifdef DBL_MANT_DIG
302 #define DECIMAL_MANT (53-16) /* from IEEE754 double precision */
303
304 #if DBL_MANT_DIG > 32
305 #define MANT_BITS 32
306 #elif DBL_MANT_DIG > 24
307 #define MANT_BITS 24
308 #elif DBL_MANT_DIG > 16
309 #define MANT_BITS 16
310 #else
311 #define MANT_BITS 8
312 #endif
313
314 static double
315 load_mantissa(double d, const char *buf, long len)
316 {
317 if (!len) return d;
318 if (--len > 0 && !*buf++) { /* binary mantissa mark */
319 int e, s = d < 0, dig = 0;
320 unsigned long m;
321
322 modf(ldexp(frexp(fabs(d), &e), DECIMAL_MANT), &d);
323 do {
324 m = 0;
325 switch (len) {
326 default: m = *buf++ & 0xff;
327 #if MANT_BITS > 24
328 case 3: m = (m << 8) | (*buf++ & 0xff);
329 #endif
330 #if MANT_BITS > 16
331 case 2: m = (m << 8) | (*buf++ & 0xff);
332 #endif
333 #if MANT_BITS > 8
334 case 1: m = (m << 8) | (*buf++ & 0xff);
335 #endif
336 }
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);
341 if (s) d = -d;
342 }
343 return d;
344 }
345 #else
346 #define load_mantissa(d, buf, len) (d)
347 #endif
348
349 #ifdef DBL_DIG
350 #define FLOAT_DIG (DBL_DIG+2)
351 #else
352 #define FLOAT_DIG 17
353 #endif
354
355 static void
356 w_float(double d, struct dump_arg *arg)
357 {
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];
360
361 if (isinf(d)) {
362 if (d < 0) w_cstr("-inf", arg);
363 else w_cstr("inf", arg);
364 }
365 else if (isnan(d)) {
366 w_cstr("nan", arg);
367 }
368 else if (d == 0.0) {
369 if (1.0/d < 0) w_cstr("-0", arg);
370 else w_cstr("0", arg);
371 }
372 else {
373 int decpt, sign, digs, len = 0;
374 char *e, *p = ruby_dtoa(d, 0, 0, &decpt, &sign, &e);
375 if (sign) buf[len++] = '-';
376 digs = (int)(e - p);
377 if (decpt < -3 || decpt > digs) {
378 buf[len++] = p[0];
379 if (--digs > 0) buf[len++] = '.';
380 memcpy(buf + len, p + 1, digs);
381 len += digs;
382 len += snprintf(buf + len, sizeof(buf) - len, "e%d", decpt - 1);
383 }
384 else if (decpt > 0) {
385 memcpy(buf + len, p, decpt);
386 len += decpt;
387 if ((digs -= decpt) > 0) {
388 buf[len++] = '.';
389 memcpy(buf + len, p + decpt, digs);
390 len += digs;
391 }
392 }
393 else {
394 buf[len++] = '0';
395 buf[len++] = '.';
396 if (decpt) {
397 memset(buf + len, '0', -decpt);
398 len -= decpt;
399 }
400 memcpy(buf + len, p, digs);
401 len += digs;
402 }
403 xfree(p);
404 w_bytes(buf, len, arg);
405 }
406 }
407
408 static void
409 w_symbol(ID id, struct dump_arg *arg)
410 {
411 VALUE sym;
412 st_data_t num;
413 int encidx = -1;
414
415 if (st_lookup(arg->symbols, id, &num)) {
416 w_byte(TYPE_SYMLINK, arg);
417 w_long((long)num, arg);
418 }
419 else {
420 sym = rb_id2str(id);
421 if (!sym) {
422 rb_raise(rb_eTypeError, "can't dump anonymous ID %"PRIdVALUE, id);
423 }
424 encidx = rb_enc_get_index(sym);
425 if (encidx == rb_usascii_encindex() ||
426 rb_enc_str_coderange(sym) == ENC_CODERANGE_7BIT) {
427 encidx = -1;
428 }
429 else {
430 w_byte(TYPE_IVAR, arg);
431 }
432 w_byte(TYPE_SYMBOL, arg);
433 w_bytes(RSTRING_PTR(sym), RSTRING_LEN(sym), arg);
434 st_add_direct(arg->symbols, id, arg->symbols->num_entries);
435 if (encidx != -1) {
436 struct dump_call_arg c_arg;
437 c_arg.limit = 1;
438 c_arg.arg = arg;
439 w_encoding(sym, 0, &c_arg);
440 }
441 }
442 }
443
444 static void
445 w_unique(VALUE s, struct dump_arg *arg)
446 {
447 must_not_be_anonymous("class", s);
448 w_symbol(rb_intern_str(s), arg);
449 }
450
451 static void w_object(VALUE,struct dump_arg*,int);
452
453 static int
454 hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
455 {
456 w_object(key, arg->arg, arg->limit);
457 w_object(value, arg->arg, arg->limit);
458 return ST_CONTINUE;
459 }
460
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))
464
465 static void
466 w_extended(VALUE klass, struct dump_arg *arg, int check)
467 {
468 if (check && FL_TEST(klass, FL_SINGLETON)) {
469 VALUE origin = RCLASS_ORIGIN(klass);
470 if (SINGLETON_DUMP_UNABLE_P(klass) ||
471 (origin != klass && SINGLETON_DUMP_UNABLE_P(origin))) {
472 rb_raise(rb_eTypeError, "singleton can't be dumped");
473 }
474 klass = RCLASS_SUPER(klass);
475 }
476 while (BUILTIN_TYPE(klass) == T_ICLASS) {
477 VALUE path = rb_class_name(RBASIC(klass)->klass);
478 w_byte(TYPE_EXTENDED, arg);
479 w_unique(path, arg);
480 klass = RCLASS_SUPER(klass);
481 }
482 }
483
484 static void
485 w_class(char type, VALUE obj, struct dump_arg *arg, int check)
486 {
487 VALUE path;
488 st_data_t real_obj;
489 VALUE klass;
490
491 if (st_lookup(arg->compat_tbl, (st_data_t)obj, &real_obj)) {
492 obj = (VALUE)real_obj;
493 }
494 klass = CLASS_OF(obj);
495 w_extended(klass, arg, check);
496 w_byte(type, arg);
497 path = class2path(rb_class_real(klass));
498 w_unique(path, arg);
499 }
500
501 static void
502 w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
503 {
504 VALUE klass = CLASS_OF(obj);
505
506 w_extended(klass, arg, TRUE);
507 klass = rb_class_real(klass);
508 if (klass != super) {
509 w_byte(TYPE_UCLASS, arg);
510 w_unique(class2path(klass), arg);
511 }
512 }
513
514 static int
515 w_obj_each(st_data_t key, st_data_t val, st_data_t a)
516 {
517 ID id = (ID)key;
518 VALUE value = (VALUE)val;
519 struct dump_call_arg *arg = (struct dump_call_arg *)a;
520
521 if (id == rb_id_encoding()) return ST_CONTINUE;
522 if (id == rb_intern("E")) return ST_CONTINUE;
523 w_symbol(id, arg->arg);
524 w_object(value, arg->arg, arg->limit);
525 return ST_CONTINUE;
526 }
527
528 static void
529 w_encoding(VALUE obj, long num, struct dump_call_arg *arg)
530 {
531 int encidx = rb_enc_get_index(obj);
532 rb_encoding *enc = 0;
533 st_data_t name;
534
535 if (encidx <= 0 || !(enc = rb_enc_from_index(encidx))) {
536 w_long(num, arg->arg);
537 return;
538 }
539 w_long(num + 1, arg->arg);
540
541 /* special treatment for US-ASCII and UTF-8 */
542 if (encidx == rb_usascii_encindex()) {
543 w_symbol(rb_intern("E"), arg->arg);
544 w_object(Qfalse, arg->arg, arg->limit + 1);
545 return;
546 }
547 else if (encidx == rb_utf8_encindex()) {
548 w_symbol(rb_intern("E"), arg->arg);
549 w_object(Qtrue, arg->arg, arg->limit + 1);
550 return;
551 }
552
553 w_symbol(rb_id_encoding(), arg->arg);
554 do {
555 if (!arg->arg->encodings)
556 arg->arg->encodings = st_init_strcasetable();
557 else if (st_lookup(arg->arg->encodings, (st_data_t)rb_enc_name(enc), &name))
558 break;
559 name = (st_data_t)rb_str_new2(rb_enc_name(enc));
560 st_insert(arg->arg->encodings, (st_data_t)rb_enc_name(enc), name);
561 } while (0);
562 w_object(name, arg->arg, arg->limit + 1);
563 }
564
565 static void
566 w_ivar(VALUE obj, st_table *tbl, struct dump_call_arg *arg)
567 {
568 long num = tbl ? tbl->num_entries : 0;
569
570 w_encoding(obj, num, arg);
571 if (tbl) {
572 st_foreach_safe(tbl, w_obj_each, (st_data_t)arg);
573 }
574 }
575
576 static void
577 w_objivar(VALUE obj, struct dump_call_arg *arg)
578 {
579 VALUE *ptr;
580 long i, len, num;
581
582 len = ROBJECT_NUMIV(obj);
583 ptr = ROBJECT_IVPTR(obj);
584 num = 0;
585 for (i = 0; i < len; i++)
586 if (ptr[i] != Qundef)
587 num += 1;
588
589 w_encoding(obj, num, arg);
590 if (num != 0) {
591 rb_ivar_foreach(obj, w_obj_each, (st_data_t)arg);
592 }
593 }
594
595 static void
596 w_object(VALUE obj, struct dump_arg *arg, int limit)
597 {
598 struct dump_call_arg c_arg;
599 st_table *ivtbl = 0;
600 st_data_t num;
601 int hasiv = 0;
602 #define has_ivars(obj, ivtbl) ((((ivtbl) = rb_generic_ivar_table(obj)) != 0) || \
603 (!SPECIAL_CONST_P(obj) && !ENCODING_IS_ASCII8BIT(obj)))
604
605 if (limit == 0) {
606 rb_raise(rb_eArgError, "exceed depth limit");
607 }
608
609 limit--;
610 c_arg.limit = limit;
611 c_arg.arg = arg;
612
613 if (st_lookup(arg->data, obj, &num)) {
614 w_byte(TYPE_LINK, arg);
615 w_long((long)num, arg);
616 return;
617 }
618
619 if (obj == Qnil) {
620 w_byte(TYPE_NIL, arg);
621 }
622 else if (obj == Qtrue) {
623 w_byte(TYPE_TRUE, arg);
624 }
625 else if (obj == Qfalse) {
626 w_byte(TYPE_FALSE, arg);
627 }
628 else if (FIXNUM_P(obj)) {
629 #if SIZEOF_LONG <= 4
630 w_byte(TYPE_FIXNUM, arg);
631 w_long(FIX2INT(obj), arg);
632 #else
633 if (RSHIFT((long)obj, 31) == 0 || RSHIFT((long)obj, 31) == -1) {
634 w_byte(TYPE_FIXNUM, arg);
635 w_long(FIX2LONG(obj), arg);
636 }
637 else {
638 w_object(rb_int2big(FIX2LONG(obj)), arg, limit);
639 }
640 #endif
641 }
642 else if (SYMBOL_P(obj)) {
643 w_symbol(SYM2ID(obj), arg);
644 }
645 else if (FLONUM_P(obj)) {
646 st_add_direct(arg->data, obj, arg->data->num_entries);
647 w_byte(TYPE_FLOAT, arg);
648 w_float(RFLOAT_VALUE(obj), arg);
649 }
650 else {
651 VALUE v;
652
653 if (!RBASIC_CLASS(obj)) {
654 rb_raise(rb_eTypeError, "can't dump internal %s",
655 rb_builtin_type_name(BUILTIN_TYPE(obj)));
656 }
657
658 arg->infection |= (int)FL_TEST(obj, MARSHAL_INFECTION);
659
660 if (rb_obj_respond_to(obj, s_mdump, TRUE)) {
661 st_add_direct(arg->data, obj, arg->data->num_entries);
662
663 v = rb_funcall2(obj, s_mdump, 0, 0);
664 check_dump_arg(arg, s_mdump);
665 w_class(TYPE_USRMARSHAL, obj, arg, FALSE);
666 w_object(v, arg, limit);
667 return;
668 }
669 if (rb_obj_respond_to(obj, s_dump, TRUE)) {
670 st_table *ivtbl2 = 0;
671 int hasiv2;
672
673 v = INT2NUM(limit);
674 v = rb_funcall2(obj, s_dump, 1, &v);
675 check_dump_arg(arg, s_dump);
676 if (!RB_TYPE_P(v, T_STRING)) {
677 rb_raise(rb_eTypeError, "_dump() must return string");
678 }
679 hasiv = has_ivars(obj, ivtbl);
680 if (hasiv) w_byte(TYPE_IVAR, arg);
681 if ((hasiv2 = has_ivars(v, ivtbl2)) != 0 && !hasiv) {
682 w_byte(TYPE_IVAR, arg);
683 }
684 w_class(TYPE_USERDEF, obj, arg, FALSE);
685 w_bytes(RSTRING_PTR(v), RSTRING_LEN(v), arg);
686 if (hasiv2) {
687 w_ivar(v, ivtbl2, &c_arg);
688 }
689 else if (hasiv) {
690 w_ivar(obj, ivtbl, &c_arg);
691 }
692 st_add_direct(arg->data, obj, arg->data->num_entries);
693 return;
694 }
695
696 st_add_direct(arg->data, obj, arg->data->num_entries);
697
698 hasiv = has_ivars(obj, ivtbl);
699 {
700 st_data_t compat_data;
701 rb_alloc_func_t allocator = rb_get_alloc_func(RBASIC(obj)->klass);
702 if (st_lookup(compat_allocator_tbl,
703 (st_data_t)allocator,
704 &compat_data)) {
705 marshal_compat_t *compat = (marshal_compat_t*)compat_data;
706 VALUE real_obj = obj;
707 obj = compat->dumper(real_obj);
708 st_insert(arg->compat_tbl, (st_data_t)obj, (st_data_t)real_obj);
709 if (obj != real_obj && !ivtbl) hasiv = 0;
710 }
711 }
712 if (hasiv) w_byte(TYPE_IVAR, arg);
713
714 switch (BUILTIN_TYPE(obj)) {
715 case T_CLASS:
716 if (FL_TEST(obj, FL_SINGLETON)) {
717 rb_raise(rb_eTypeError, "singleton class can't be dumped");
718 }
719 w_byte(TYPE_CLASS, arg);
720 {
721 VALUE path = class2path(obj);
722 w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
723 RB_GC_GUARD(path);
724 }
725 break;
726
727 case T_MODULE:
728 w_byte(TYPE_MODULE, arg);
729 {
730 VALUE path = class2path(obj);
731 w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
732 RB_GC_GUARD(path);
733 }
734 break;
735
736 case T_FLOAT:
737 w_byte(TYPE_FLOAT, arg);
738 w_float(RFLOAT_VALUE(obj), arg);
739 break;
740
741 case T_BIGNUM:
742 w_byte(TYPE_BIGNUM, arg);
743 {
744 char sign = RBIGNUM_SIGN(obj) ? '+' : '-';
745 long len = RBIGNUM_LEN(obj);
746 BDIGIT *d = RBIGNUM_DIGITS(obj);
747
748 w_byte(sign, arg);
749 w_long(SHORTLEN(len), arg); /* w_short? */
750 while (len--) {
751 #if SIZEOF_BDIGITS > SIZEOF_SHORT
752 BDIGIT num = *d;
753 int i;
754
755 for (i=0; i<SIZEOF_BDIGITS; i+=SIZEOF_SHORT) {
756 w_short(num & SHORTMASK, arg);
757 num = SHORTDN(num);
758 if (len == 0 && num == 0) break;
759 }
760 #else
761 w_short(*d, arg);
762 #endif
763 d++;
764 }
765 }
766 break;
767
768 case T_STRING:
769 w_uclass(obj, rb_cString, arg);
770 w_byte(TYPE_STRING, arg);
771 w_bytes(RSTRING_PTR(obj), RSTRING_LEN(obj), arg);
772 break;
773
774 case T_REGEXP:
775 w_uclass(obj, rb_cRegexp, arg);
776 w_byte(TYPE_REGEXP, arg);
777 {
778 int opts = rb_reg_options(obj);
779 w_bytes(RREGEXP_SRC_PTR(obj), RREGEXP_SRC_LEN(obj), arg);
780 w_byte((char)opts, arg);
781 }
782 break;
783
784 case T_ARRAY:
785 w_uclass(obj, rb_cArray, arg);
786 w_byte(TYPE_ARRAY, arg);
787 {
788 long i, len = RARRAY_LEN(obj);
789
790 w_long(len, arg);
791 for (i=0; i<RARRAY_LEN(obj); i++) {
792 w_object(RARRAY_AREF(obj, i), arg, limit);
793 if (len != RARRAY_LEN(obj)) {
794 rb_raise(rb_eRuntimeError, "array modified during dump");
795 }
796 }
797 }
798 break;
799
800 case T_HASH:
801 w_uclass(obj, rb_cHash, arg);
802 if (NIL_P(RHASH_IFNONE(obj))) {
803 w_byte(TYPE_HASH, arg);
804 }
805 else if (FL_TEST(obj, HASH_PROC_DEFAULT)) {
806 rb_raise(rb_eTypeError, "can't dump hash with default proc");
807 }
808 else {
809 w_byte(TYPE_HASH_DEF, arg);
810 }
811 w_long(RHASH_SIZE(obj), arg);
812 rb_hash_foreach(obj, hash_each, (st_data_t)&c_arg);
813 if (!NIL_P(RHASH_IFNONE(obj))) {
814 w_object(RHASH_IFNONE(obj), arg, limit);
815 }
816 break;
817
818 case T_STRUCT:
819 w_class(TYPE_STRUCT, obj, arg, TRUE);
820 {
821 long len = RSTRUCT_LEN(obj);
822 VALUE mem;
823 long i;
824
825 w_long(len, arg);
826 mem = rb_struct_members(obj);
827 for (i=0; i<len; i++) {
828 w_symbol(SYM2ID(RARRAY_AREF(mem, i)), arg);
829 w_object(RSTRUCT_GET(obj, i), arg, limit);
830 }
831 }
832 break;
833
834 case T_OBJECT:
835 w_class(TYPE_OBJECT, obj, arg, TRUE);
836 w_objivar(obj, &c_arg);
837 break;
838
839 case T_DATA:
840 {
841 VALUE v;
842
843 if (!rb_obj_respond_to(obj, s_dump_data, TRUE)) {
844 rb_raise(rb_eTypeError,
845 "no _dump_data is defined for class %s",
846 rb_obj_classname(obj));
847 }
848 v = rb_funcall2(obj, s_dump_data, 0, 0);
849 check_dump_arg(arg, s_dump_data);
850 w_class(TYPE_DATA, obj, arg, TRUE);
851 w_object(v, arg, limit);
852 }
853 break;
854
855 default:
856 rb_raise(rb_eTypeError, "can't dump %s",
857 rb_obj_classname(obj));
858 break;
859 }
860 RB_GC_GUARD(obj);
861 }
862 if (hasiv) {
863 w_ivar(obj, ivtbl, &c_arg);
864 }
865 }
866
867 static void
868 clear_dump_arg(struct dump_arg *arg)
869 {
870 if (!arg->symbols) return;
871 st_free_table(arg->symbols);
872 arg->symbols = 0;
873 st_free_table(arg->data);
874 arg->data = 0;
875 st_free_table(arg->compat_tbl);
876 arg->compat_tbl = 0;
877 if (arg->encodings) {
878 st_free_table(arg->encodings);
879 arg->encodings = 0;
880 }
881 }
882
883 NORETURN(static inline void io_needed(void));
884 static inline void
885 io_needed(void)
886 {
887 rb_raise(rb_eTypeError, "instance of IO needed");
888 }
889
890 /*
891 * call-seq:
892 * dump( obj [, anIO] , limit=-1 ) -> anIO
893 *
894 * Serializes obj and all descendant objects. If anIO is
895 * specified, the serialized data will be written to it, otherwise the
896 * data will be returned as a String. If limit is specified, the
897 * traversal of subobjects will be limited to that depth. If limit is
898 * negative, no checking of depth will be performed.
899 *
900 * class Klass
901 * def initialize(str)
902 * @str = str
903 * end
904 * def say_hello
905 * @str
906 * end
907 * end
908 *
909 * (produces no output)
910 *
911 * o = Klass.new("hello\n")
912 * data = Marshal.dump(o)
913 * obj = Marshal.load(data)
914 * obj.say_hello #=> "hello\n"
915 *
916 * Marshal can't dump following objects:
917 * * anonymous Class/Module.
918 * * objects which are related to system (ex: Dir, File::Stat, IO, File, Socket
919 * and so on)
920 * * an instance of MatchData, Data, Method, UnboundMethod, Proc, Thread,
921 * ThreadGroup, Continuation
922 * * objects which define singleton methods
923 */
924 static VALUE
925 marshal_dump(int argc, VALUE *argv)
926 {
927 VALUE obj, port, a1, a2;
928 int limit = -1;
929 struct dump_arg *arg;
930 volatile VALUE wrapper;
931
932 port = Qnil;
933 rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
934 if (argc == 3) {
935 if (!NIL_P(a2)) limit = NUM2INT(a2);
936 if (NIL_P(a1)) io_needed();
937 port = a1;
938 }
939 else if (argc == 2) {
940 if (FIXNUM_P(a1)) limit = FIX2INT(a1);
941 else if (NIL_P(a1)) io_needed();
942 else port = a1;
943 }
944 RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
945 arg->dest = 0;
946 arg->symbols = st_init_numtable();
947 arg->data = st_init_numtable();
948 arg->infection = 0;
949 arg->compat_tbl = st_init_numtable();
950 arg->encodings = 0;
951 arg->str = rb_str_buf_new(0);
952 if (!NIL_P(port)) {
953 if (!rb_respond_to(port, s_write)) {
954 io_needed();
955 }
956 arg->dest = port;
957 if (rb_check_funcall(port, s_binmode, 0, 0) != Qundef) {
958 check_dump_arg(arg, s_binmode);
959 }
960 }
961 else {
962 port = arg->str;
963 }
964
965 w_byte(MARSHAL_MAJOR, arg);
966 w_byte(MARSHAL_MINOR, arg);
967
968 w_object(obj, arg, limit);
969 if (arg->dest) {
970 rb_io_write(arg->dest, arg->str);
971 rb_str_resize(arg->str, 0);
972 }
973 clear_dump_arg(arg);
974 RB_GC_GUARD(wrapper);
975
976 return port;
977 }
978
979 struct load_arg {
980 VALUE src;
981 char *buf;
982 long buflen;
983 long readable;
984 long offset;
985 st_table *symbols;
986 st_table *data;
987 VALUE proc;
988 st_table *compat_tbl;
989 int infection;
990 };
991
992 static void
993 check_load_arg(struct load_arg *arg, ID sym)
994 {
995 if (!arg->symbols) {
996 rb_raise(rb_eRuntimeError, "Marshal.load reentered at %s",
997 rb_id2name(sym));
998 }
999 }
1000
1001 static void clear_load_arg(struct load_arg *arg);
1002
1003 static void
1004 mark_load_arg(void *ptr)
1005 {
1006 struct load_arg *p = ptr;
1007 if (!p->symbols)
1008 return;
1009 rb_mark_tbl(p->data);
1010 rb_mark_hash(p->compat_tbl);
1011 }
1012
1013 static void
1014 free_load_arg(void *ptr)
1015 {
1016 clear_load_arg(ptr);
1017 xfree(ptr);
1018 }
1019
1020 static size_t
1021 memsize_load_arg(const void *ptr)
1022 {
1023 return ptr ? sizeof(struct load_arg) : 0;
1024 }
1025
1026 static const rb_data_type_t load_arg_data = {
1027 "load_arg",
1028 {mark_load_arg, free_load_arg, memsize_load_arg,},
1029 NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
1030 };
1031
1032 #define r_entry(v, arg) r_entry0((v), (arg)->data->num_entries, (arg))
1033 static VALUE r_entry0(VALUE v, st_index_t num, struct load_arg *arg);
1034 static VALUE r_object(struct load_arg *arg);
1035 static ID r_symbol(struct load_arg *arg);
1036 static VALUE path2class(VALUE path);
1037
1038 NORETURN(static void too_short(void));
1039 static void
1040 too_short(void)
1041 {
1042 rb_raise(rb_eArgError, "marshal data too short");
1043 }
1044
1045 static st_index_t
1046 r_prepare(struct load_arg *arg)
1047 {
1048 st_index_t idx = arg->data->num_entries;
1049
1050 st_insert(arg->data, (st_data_t)idx, (st_data_t)Qundef);
1051 return idx;
1052 }
1053
1054 static unsigned char
1055 r_byte1_buffered(struct load_arg *arg)
1056 {
1057 if (arg->buflen == 0) {
1058 long readable = arg->readable < BUFSIZ ? arg->readable : BUFSIZ;
1059 VALUE str, n = LONG2NUM(readable);
1060
1061 str = rb_funcall2(arg->src, s_read, 1, &n);
1062
1063 check_load_arg(arg, s_read);
1064 if (NIL_P(str)) too_short();
1065 StringValue(str);
1066 arg->infection |= (int)FL_TEST(str, MARSHAL_INFECTION);
1067 memcpy(arg->buf, RSTRING_PTR(str), RSTRING_LEN(str));
1068 arg->offset = 0;
1069 arg->buflen = RSTRING_LEN(str);
1070 }
1071 arg->buflen--;
1072 return arg->buf[arg->offset++];
1073 }
1074
1075 static int
1076 r_byte(struct load_arg *arg)
1077 {
1078 int c;
1079
1080 if (RB_TYPE_P(arg->src, T_STRING)) {
1081 if (RSTRING_LEN(arg->src) > arg->offset) {
1082 c = (unsigned char)RSTRING_PTR(arg->src)[arg->offset++];
1083 }
1084 else {
1085 too_short();
1086 }
1087 }
1088 else {
1089 if (arg->readable >0 || arg->buflen > 0) {
1090 c = r_byte1_buffered(arg);
1091 }
1092 else {
1093 VALUE v = rb_funcall2(arg->src, s_getbyte, 0, 0);
1094 check_load_arg(arg, s_getbyte);
1095 if (NIL_P(v)) rb_eof_error();
1096 c = (unsigned char)NUM2CHR(v);
1097 }
1098 }
1099 return c;
1100 }
1101
1102 static void
1103 long_toobig(int size)
1104 {
1105 rb_raise(rb_eTypeError, "long too big for this architecture (size "
1106 STRINGIZE(SIZEOF_LONG)", given %d)", size);
1107 }
1108
1109 #undef SIGN_EXTEND_CHAR
1110 #if __STDC__
1111 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
1112 #else /* not __STDC__ */
1113 /* As in Harbison and Steele. */
1114 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
1115 #endif
1116
1117 static long
1118 r_long(struct load_arg *arg)
1119 {
1120 register long x;
1121 int c = SIGN_EXTEND_CHAR(r_byte(arg));
1122 long i;
1123
1124 if (c == 0) return 0;
1125 if (c > 0) {
1126 if (4 < c && c < 128) {
1127 return c - 5;
1128 }
1129 if (c > (int)sizeof(long)) long_toobig(c);
1130 x = 0;
1131 for (i=0;i<c;i++) {
1132 x |= (long)r_byte(arg) << (8*i);
1133 }
1134 }
1135 else {
1136 if (-129 < c && c < -4) {
1137 return c + 5;
1138 }
1139 c = -c;
1140 if (c > (int)sizeof(long)) long_toobig(c);
1141 x = -1;
1142 for (i=0;i<c;i++) {
1143 x &= ~((long)0xff << (8*i));
1144 x |= (long)r_byte(arg) << (8*i);
1145 }
1146 }
1147 return x;
1148 }
1149
1150 static VALUE
1151 r_bytes1(long len, struct load_arg *arg)
1152 {
1153 VALUE str, n = LONG2NUM(len);
1154
1155 str = rb_funcall2(arg->src, s_read, 1, &n);
1156 check_load_arg(arg, s_read);
1157 if (NIL_P(str)) too_short();
1158 StringValue(str);
1159 if (RSTRING_LEN(str) != len) too_short();
1160 arg->infection |= (int)FL_TEST(str, MARSHAL_INFECTION);
1161
1162 return str;
1163 }
1164
1165 static VALUE
1166 r_bytes1_buffered(long len, struct load_arg *arg)
1167 {
1168 VALUE str;
1169
1170 if (len <= arg->buflen) {
1171 str = rb_str_new(arg->buf+arg->offset, len);
1172 arg->offset += len;
1173 arg->buflen -= len;
1174 }
1175 else {
1176 long buflen = arg->buflen;
1177 long readable = arg->readable + 1;
1178 long tmp_len, read_len, need_len = len - buflen;
1179 VALUE tmp, n;
1180
1181 readable = readable < BUFSIZ ? readable : BUFSIZ;
1182 read_len = need_len > readable ? need_len : readable;
1183 n = LONG2NUM(read_len);
1184 tmp = rb_funcall2(arg->src, s_read, 1, &n);
1185
1186 check_load_arg(arg, s_read);
1187 if (NIL_P(tmp)) too_short();
1188 StringValue(tmp);
1189
1190 tmp_len = RSTRING_LEN(tmp);
1191
1192 if (tmp_len < need_len) too_short();
1193 arg->infection |= (int)FL_TEST(tmp, MARSHAL_INFECTION);
1194
1195 str = rb_str_new(arg->buf+arg->offset, buflen);
1196 rb_str_cat(str, RSTRING_PTR(tmp), need_len);
1197
1198 if (tmp_len > need_len) {
1199 buflen = tmp_len - need_len;
1200 memcpy(arg->buf, RSTRING_PTR(tmp)+need_len, buflen);
1201 arg->buflen = buflen;
1202 }
1203 else {
1204 arg->buflen = 0;
1205 }
1206 arg->offset = 0;
1207 }
1208
1209 return str;
1210 }
1211
1212 #define r_bytes(arg) r_bytes0(r_long(arg), (arg))
1213
1214 static VALUE
1215 r_bytes0(long len, struct load_arg *arg)
1216 {
1217 VALUE str;
1218
1219 if (len == 0) return rb_str_new(0, 0);
1220 if (RB_TYPE_P(arg->src, T_STRING)) {
1221 if (RSTRING_LEN(arg->src) - arg->offset >= len) {
1222 str = rb_str_new(RSTRING_PTR(arg->src)+arg->offset, len);
1223 arg->offset += len;
1224 }
1225 else {
1226 too_short();
1227 }
1228 }
1229 else {
1230 if (arg->readable > 0 || arg->buflen > 0) {
1231 str = r_bytes1_buffered(len, arg);
1232 }
1233 else {
1234 str = r_bytes1(len, arg);
1235 }
1236 }
1237 return str;
1238 }
1239
1240 static int
1241 id2encidx(ID id, VALUE val)
1242 {
1243 if (id == rb_id_encoding()) {
1244 int idx = rb_enc_find_index(StringValueCStr(val));
1245 return idx;
1246 }
1247 else if (id == rb_intern("E")) {
1248 if (val == Qfalse) return rb_usascii_encindex();
1249 else if (val == Qtrue) return rb_utf8_encindex();
1250 /* bogus ignore */
1251 }
1252 return -1;
1253 }
1254
1255 static ID
1256 r_symlink(struct load_arg *arg)
1257 {
1258 st_data_t id;
1259 long num = r_long(arg);
1260
1261 if (!st_lookup(arg->symbols, num, &id)) {
1262 rb_raise(rb_eArgError, "bad symbol");
1263 }
1264 return (ID)id;
1265 }
1266
1267 static ID
1268 r_symreal(struct load_arg *arg, int ivar)
1269 {
1270 VALUE s = r_bytes(arg);
1271 ID id;
1272 int idx = -1;
1273 st_index_t n = arg->symbols->num_entries;
1274
1275 st_insert(arg->symbols, (st_data_t)n, (st_data_t)0);
1276 if (ivar) {
1277 long num = r_long(arg);
1278 while (num-- > 0) {
1279 id = r_symbol(arg);
1280 idx = id2encidx(id, r_object(arg));
1281 }
1282 }
1283 if (idx > 0) rb_enc_associate_index(s, idx);
1284 id = rb_intern_str(s);
1285 st_insert(arg->symbols, (st_data_t)n, (st_data_t)id);
1286
1287 return id;
1288 }
1289
1290 static ID
1291 r_symbol(struct load_arg *arg)
1292 {
1293 int type, ivar = 0;
1294
1295 again:
1296 switch ((type = r_byte(arg))) {
1297 default:
1298 rb_raise(rb_eArgError, "dump format error for symbol(0x%x)", type);
1299 case TYPE_IVAR:
1300 ivar = 1;
1301 goto again;
1302 case TYPE_SYMBOL:
1303 return r_symreal(arg, ivar);
1304 case TYPE_SYMLINK:
1305 if (ivar) {
1306 rb_raise(rb_eArgError, "dump format error (symlink with encoding)");
1307 }
1308 return r_symlink(arg);
1309 }
1310 }
1311
1312 static VALUE
1313 r_unique(struct load_arg *arg)
1314 {
1315 return rb_id2str(r_symbol(arg));
1316 }
1317
1318 static VALUE
1319 r_string(struct load_arg *arg)
1320 {
1321 return r_bytes(arg);
1322 }
1323
1324 static VALUE
1325 r_entry0(VALUE v, st_index_t num, struct load_arg *arg)
1326 {
1327 st_data_t real_obj = (VALUE)Qundef;
1328 if (st_lookup(arg->compat_tbl, v, &real_obj)) {
1329 st_insert(arg->data, num, (st_data_t)real_obj);
1330 }
1331 else {
1332 st_insert(arg->data, num, (st_data_t)v);
1333 }
1334 if (arg->infection &&
1335 !RB_TYPE_P(v, T_CLASS) && !RB_TYPE_P(v, T_MODULE)) {
1336 FL_SET(v, arg->infection);
1337 if ((VALUE)real_obj != Qundef)
1338 FL_SET((VALUE)real_obj, arg->infection);
1339 }
1340 return v;
1341 }
1342
1343 static VALUE
1344 r_fixup_compat(VALUE v, struct load_arg *arg)
1345 {
1346 st_data_t data;
1347 if (st_lookup(arg->compat_tbl, v, &data)) {
1348 VALUE real_obj = (VALUE)data;
1349 rb_alloc_func_t allocator = rb_get_alloc_func(CLASS_OF(real_obj));
1350 st_data_t key = v;
1351 if (st_lookup(compat_allocator_tbl, (st_data_t)allocator, &data)) {
1352 marshal_compat_t *compat = (marshal_compat_t*)data;
1353 compat->loader(real_obj, v);
1354 }
1355 st_delete(arg->compat_tbl, &key, 0);
1356 v = real_obj;
1357 }
1358 return v;
1359 }
1360
1361 static VALUE
1362 r_post_proc(VALUE v, struct load_arg *arg)
1363 {
1364 if (arg->proc) {
1365 v = rb_funcall(arg->proc, s_call, 1, v);
1366 check_load_arg(arg, s_call);
1367 }
1368 return v;
1369 }
1370
1371 static VALUE
1372 r_leave(VALUE v, struct load_arg *arg)
1373 {
1374 v = r_fixup_compat(v, arg);
1375 v = r_post_proc(v, arg);
1376 return v;
1377 }
1378
1379 static int
1380 copy_ivar_i(st_data_t key, st_data_t val, st_data_t arg)
1381 {
1382 VALUE obj = (VALUE)arg, value = (VALUE)val;
1383 ID vid = (ID)key;
1384
1385 if (!rb_ivar_defined(obj, vid))
1386 rb_ivar_set(obj, vid, value);
1387 return ST_CONTINUE;
1388 }
1389
1390 static VALUE
1391 r_copy_ivar(VALUE v, VALUE data)
1392 {
1393 rb_ivar_foreach(data, copy_ivar_i, (st_data_t)v);
1394 return v;
1395 }
1396
1397 static void
1398 r_ivar(VALUE obj, int *has_encoding, struct load_arg *arg)
1399 {
1400 long len;
1401
1402 len = r_long(arg);
1403 if (len > 0) {
1404 do {
1405 ID id = r_symbol(arg);
1406 VALUE val = r_object(arg);
1407 int idx = id2encidx(id, val);
1408 if (idx >= 0) {
1409 rb_enc_associate_index(obj, idx);
1410 if (has_encoding) *has_encoding = TRUE;
1411 }
1412 else {
1413 rb_ivar_set(obj, id, val);
1414 }
1415 } while (--len > 0);
1416 }
1417 }
1418
1419 static VALUE
1420 path2class(VALUE path)
1421 {
1422 VALUE v = rb_path_to_class(path);
1423
1424 if (!RB_TYPE_P(v, T_CLASS)) {
1425 rb_raise(rb_eArgError, "%"PRIsVALUE" does not refer to class", path);
1426 }
1427 return v;
1428 }
1429
1430 #define path2module(path) must_be_module(rb_path_to_class(path), path)
1431
1432 static VALUE
1433 must_be_module(VALUE v, VALUE path)
1434 {
1435 if (!RB_TYPE_P(v, T_MODULE)) {
1436 rb_raise(rb_eArgError, "%"PRIsVALUE" does not refer to module", path);
1437 }
1438 return v;
1439 }
1440
1441 static VALUE
1442 obj_alloc_by_klass(VALUE klass, struct load_arg *arg, VALUE *oldclass)
1443 {
1444 st_data_t data;
1445 rb_alloc_func_t allocator;
1446
1447 allocator = rb_get_alloc_func(klass);
1448 if (st_lookup(compat_allocator_tbl, (st_data_t)allocator, &data)) {
1449 marshal_compat_t *compat = (marshal_compat_t*)data;
1450 VALUE real_obj = rb_obj_alloc(klass);
1451 VALUE obj = rb_obj_alloc(compat->oldclass);
1452 if (oldclass) *oldclass = compat->oldclass;
1453 st_insert(arg->compat_tbl, (st_data_t)obj, (st_data_t)real_obj);
1454 return obj;
1455 }
1456
1457 return rb_obj_alloc(klass);
1458 }
1459
1460 static VALUE
1461 obj_alloc_by_path(VALUE path, struct load_arg *arg)
1462 {
1463 return obj_alloc_by_klass(path2class(path), arg, 0);
1464 }
1465
1466 static VALUE
1467 append_extmod(VALUE obj, VALUE extmod)
1468 {
1469 long i = RARRAY_LEN(extmod);
1470 while (i > 0) {
1471 VALUE m = RARRAY_AREF(extmod, --i);
1472 rb_extend_object(obj, m);
1473 }
1474 return obj;
1475 }
1476
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"'", \
1481 (str)); \
1482 } while (0)
1483
1484 static VALUE
1485 r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
1486 {
1487 VALUE v = Qnil;
1488 int type = r_byte(arg);
1489 long id;
1490 st_data_t link;
1491
1492 switch (type) {
1493 case TYPE_LINK:
1494 id = r_long(arg);
1495 if (!st_lookup(arg->data, (st_data_t)id, &link)) {
1496 rb_raise(rb_eArgError, "dump format error (unlinked)");
1497 }
1498 v = (VALUE)link;
1499 r_post_proc(v, arg);
1500 break;
1501
1502 case TYPE_IVAR:
1503 {
1504 int ivar = TRUE;
1505
1506 v = r_object0(arg, &ivar, extmod);
1507 if (ivar) r_ivar(v, NULL, arg);
1508 }
1509 break;
1510
1511 case TYPE_EXTENDED:
1512 {
1513 VALUE path = r_unique(arg);
1514 VALUE m = rb_path_to_class(path);
1515
1516 if (RB_TYPE_P(m, T_CLASS)) { /* prepended */
1517 VALUE c;
1518
1519 v = r_object0(arg, 0, Qnil);
1520 c = CLASS_OF(v);
1521 if (c != m || FL_TEST(c, FL_SINGLETON)) {
1522 rb_raise(rb_eArgError,
1523 "prepended class %"PRIsVALUE" differs from class %"PRIsVALUE,
1524 path, rb_class_name(c));
1525 }
1526 c = rb_singleton_class(v);
1527 while (RARRAY_LEN(extmod) > 0) {
1528 m = rb_ary_pop(extmod);
1529 rb_prepend_module(c, m);
1530 }
1531 }
1532 else {
1533 must_be_module(m, path);
1534 if (NIL_P(extmod)) extmod = rb_ary_tmp_new(0);
1535 rb_ary_push(extmod, m);
1536
1537 v = r_object0(arg, 0, extmod);
1538 while (RARRAY_LEN(extmod) > 0) {
1539 m = rb_ary_pop(extmod);
1540 rb_extend_object(v, m);
1541 }
1542 }
1543 }
1544 break;
1545
1546 case TYPE_UCLASS:
1547 {
1548 VALUE c = path2class(r_unique(arg));
1549
1550 if (FL_TEST(c, FL_SINGLETON)) {
1551 rb_raise(rb_eTypeError, "singleton can't be loaded");
1552 }
1553 v = r_object0(arg, 0, extmod);
1554 if (rb_special_const_p(v) || RB_TYPE_P(v, T_OBJECT) || RB_TYPE_P(v, T_CLASS)) {
1555 format_error:
1556 rb_raise(rb_eArgError, "dump format error (user class)");
1557 }
1558 if (RB_TYPE_P(v, T_MODULE) || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) {
1559 VALUE tmp = rb_obj_alloc(c);
1560
1561 if (TYPE(v) != TYPE(tmp)) goto format_error;
1562 }
1563 RBASIC_SET_CLASS(v, c);
1564 }
1565 break;
1566
1567 case TYPE_NIL:
1568 v = Qnil;
1569 v = r_leave(v, arg);
1570 break;
1571
1572 case TYPE_TRUE:
1573 v = Qtrue;
1574 v = r_leave(v, arg);
1575 break;
1576
1577 case TYPE_FALSE:
1578 v = Qfalse;
1579 v = r_leave(v, arg);
1580 break;
1581
1582 case TYPE_FIXNUM:
1583 {
1584 long i = r_long(arg);
1585 v = LONG2FIX(i);
1586 }
1587 v = r_leave(v, arg);
1588 break;
1589
1590 case TYPE_FLOAT:
1591 {
1592 double d;
1593 VALUE str = r_bytes(arg);
1594 const char *ptr = RSTRING_PTR(str);
1595
1596 if (strcmp(ptr, "nan") == 0) {
1597 d = NAN;
1598 }
1599 else if (strcmp(ptr, "inf") == 0) {
1600 d = INFINITY;
1601 }
1602 else if (strcmp(ptr, "-inf") == 0) {
1603 d = -INFINITY;
1604 }
1605 else {
1606 char *e;
1607 d = strtod(ptr, &e);
1608 d = load_mantissa(d, e, RSTRING_LEN(str) - (e - ptr));
1609 }
1610 v = DBL2NUM(d);
1611 v = r_entry(v, arg);
1612 v = r_leave(v, arg);
1613 }
1614 break;
1615
1616 case TYPE_BIGNUM:
1617 {
1618 long len;
1619 VALUE data;
1620 int sign;
1621
1622 sign = r_byte(arg);
1623 len = r_long(arg);
1624 data = r_bytes0(len * 2, arg);
1625 v = rb_integer_unpack(RSTRING_PTR(data), len, 2, 0,
1626 INTEGER_PACK_LITTLE_ENDIAN | (sign == '-' ? INTEGER_PACK_NEGATIVE : 0));
1627 rb_str_resize(data, 0L);
1628 v = r_entry(v, arg);
1629 v = r_leave(v, arg);
1630 }
1631 break;
1632
1633 case TYPE_STRING:
1634 v = r_entry(r_string(arg), arg);
1635 v = r_leave(v, arg);
1636 break;
1637
1638 case TYPE_REGEXP:
1639 {
1640 VALUE str = r_bytes(arg);
1641 int options = r_byte(arg);
1642 int has_encoding = FALSE;
1643 st_index_t idx = r_prepare(arg);
1644
1645 if (ivp) {
1646 r_ivar(str, &has_encoding, arg);
1647 *ivp = FALSE;
1648 }
1649 if (!has_encoding) {
1650 /* 1.8 compatibility; remove escapes undefined in 1.8 */
1651 char *ptr = RSTRING_PTR(str), *dst = ptr, *src = ptr;
1652 long len = RSTRING_LEN(str);
1653 long bs = 0;
1654 for (; len-- > 0; *dst++ = *src++) {
1655 switch (*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':
1662 if (bs & 1) --dst;
1663 default: bs = 0; break;
1664 }
1665 }
1666 rb_str_set_len(str, dst - ptr);
1667 }
1668 v = r_entry0(rb_reg_new_str(str, options), idx, arg);
1669 v = r_leave(v, arg);
1670 }
1671 break;
1672
1673 case TYPE_ARRAY:
1674 {
1675 volatile long len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */
1676
1677 v = rb_ary_new2(len);
1678 v = r_entry(v, arg);
1679 arg->readable += len - 1;
1680 while (len--) {
1681 rb_ary_push(v, r_object(arg));
1682 arg->readable--;
1683 }
1684 v = r_leave(v, arg);
1685 arg->readable++;
1686 }
1687 break;
1688
1689 case TYPE_HASH:
1690 case TYPE_HASH_DEF:
1691 {
1692 long len = r_long(arg);
1693
1694 v = rb_hash_new();
1695 v = r_entry(v, arg);
1696 arg->readable += (len - 1) * 2;
1697 while (len--) {
1698 VALUE key = r_object(arg);
1699 VALUE value = r_object(arg);
1700 rb_hash_aset(v, key, value);
1701 arg->readable -= 2;
1702 }
1703 arg->readable += 2;
1704 if (type == TYPE_HASH_DEF) {
1705 RHASH_SET_IFNONE(v, r_object(arg));
1706 }
1707 v = r_leave(v, arg);
1708 }
1709 break;
1710
1711 case TYPE_STRUCT:
1712 {
1713 VALUE mem, values;
1714 volatile long i; /* gcc 2.7.2.3 -O2 bug?? */
1715 ID slot;
1716 st_index_t idx = r_prepare(arg);
1717 VALUE klass = path2class(r_unique(arg));
1718 long len = r_long(arg);
1719
1720 v = rb_obj_alloc(klass);
1721 if (!RB_TYPE_P(v, T_STRUCT)) {
1722 rb_raise(rb_eTypeError, "class %s not a struct", rb_class2name(klass));
1723 }
1724 mem = rb_struct_s_members(klass);
1725 if (RARRAY_LEN(mem) != len) {
1726 rb_raise(rb_eTypeError, "struct %s not compatible (struct size differs)",
1727 rb_class2name(klass));
1728 }
1729
1730 arg->readable += (len - 1) * 2;
1731 v = r_entry0(v, idx, arg);
1732 values = rb_ary_new2(len);
1733 for (i=0; i<len; i++) {
1734 slot = r_symbol(arg);
1735
1736 if (RARRAY_AREF(mem, i) != ID2SYM(slot)) {
1737 rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)",
1738 rb_class2name(klass),
1739 rb_id2name(slot),
1740 rb_id2name(SYM2ID(RARRAY_AREF(mem, i))));
1741 }
1742 rb_ary_push(values, r_object(arg));
1743 arg->readable -= 2;
1744 }
1745 rb_struct_initialize(v, values);
1746 v = r_leave(v, arg);
1747 arg->readable += 2;
1748 }
1749 break;
1750
1751 case TYPE_USERDEF:
1752 {
1753 VALUE klass = path2class(r_unique(arg));
1754 VALUE data;
1755
1756 if (!rb_obj_respond_to(klass, s_load, TRUE)) {
1757 rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
1758 rb_class2name(klass));
1759 }
1760 data = r_string(arg);
1761 if (ivp) {
1762 r_ivar(data, NULL, arg);
1763 *ivp = FALSE;
1764 }
1765 v = rb_funcall2(klass, s_load, 1, &data);
1766 check_load_arg(arg, s_load);
1767 v = r_entry(v, arg);
1768 v = r_leave(v, arg);
1769 }
1770 break;
1771
1772 case TYPE_USRMARSHAL:
1773 {
1774 VALUE klass = path2class(r_unique(arg));
1775 VALUE oldclass = 0;
1776 VALUE data;
1777
1778 v = obj_alloc_by_klass(klass, arg, &oldclass);
1779 if (!NIL_P(extmod)) {
1780 /* for the case marshal_load is overridden */
1781 append_extmod(v, extmod);
1782 }
1783 if (!rb_obj_respond_to(v, s_mload, TRUE)) {
1784 rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
1785 rb_class2name(klass));
1786 }
1787 v = r_entry(v, arg);
1788 data = r_object(arg);
1789 rb_funcall2(v, s_mload, 1, &data);
1790 check_load_arg(arg, s_mload);
1791 v = r_fixup_compat(v, arg);
1792 v = r_copy_ivar(v, data);
1793 v = r_post_proc(v, arg);
1794 if (!NIL_P(extmod)) {
1795 if (oldclass) append_extmod(v, extmod);
1796 rb_ary_clear(extmod);
1797 }
1798 }
1799 break;
1800
1801 case TYPE_OBJECT:
1802 {
1803 st_index_t idx = r_prepare(arg);
1804 v = obj_alloc_by_path(r_unique(arg), arg);
1805 if (!RB_TYPE_P(v, T_OBJECT)) {
1806 rb_raise(rb_eArgError, "dump format error");
1807 }
1808 v = r_entry0(v, idx, arg);
1809 r_ivar(v, NULL, arg);
1810 v = r_leave(v, arg);
1811 }
1812 break;
1813
1814 case TYPE_DATA:
1815 {
1816 VALUE klass = path2class(r_unique(arg));
1817 VALUE oldclass = 0;
1818 VALUE r;
1819
1820 v = obj_alloc_by_klass(klass, arg, &oldclass);
1821 if (!RB_TYPE_P(v, T_DATA)) {
1822 rb_raise(rb_eArgError, "dump format error");
1823 }
1824 v = r_entry(v, arg);
1825 if (!rb_obj_respond_to(v, s_load_data, TRUE)) {
1826 rb_raise(rb_eTypeError,
1827 "class %s needs to have instance method `_load_data'",
1828 rb_class2name(klass));
1829 }
1830 r = r_object0(arg, 0, extmod);
1831 rb_funcall2(v, s_load_data, 1, &r);
1832 check_load_arg(arg, s_load_data);
1833 v = r_leave(v, arg);
1834 }
1835 break;
1836
1837 case TYPE_MODULE_OLD:
1838 {
1839 VALUE str = r_bytes(arg);
1840
1841 v = rb_path_to_class(str);
1842 prohibit_ivar("class/module", str);
1843 v = r_entry(v, arg);
1844 v = r_leave(v, arg);
1845 }
1846 break;
1847
1848 case TYPE_CLASS:
1849 {
1850 VALUE str = r_bytes(arg);
1851
1852 v = path2class(str);
1853 prohibit_ivar("class", str);
1854 v = r_entry(v, arg);
1855 v = r_leave(v, arg);
1856 }
1857 break;
1858
1859 case TYPE_MODULE:
1860 {
1861 VALUE str = r_bytes(arg);
1862
1863 v = path2module(str);
1864 prohibit_ivar("module", str);
1865 v = r_entry(v, arg);
1866 v = r_leave(v, arg);
1867 }
1868 break;
1869
1870 case TYPE_SYMBOL:
1871 if (ivp) {
1872 v = ID2SYM(r_symreal(arg, *ivp));
1873 *ivp = FALSE;
1874 }
1875 else {
1876 v = ID2SYM(r_symreal(arg, 0));
1877 }
1878 v = r_leave(v, arg);
1879 break;
1880
1881 case TYPE_SYMLINK:
1882 v = ID2SYM(r_symlink(arg));
1883 break;
1884
1885 default:
1886 rb_raise(rb_eArgError, "dump format error(0x%x)", type);
1887 break;
1888 }
1889 return v;
1890 }
1891
1892 static VALUE
1893 r_object(struct load_arg *arg)
1894 {
1895 return r_object0(arg, 0, Qnil);
1896 }
1897
1898 static void
1899 clear_load_arg(struct load_arg *arg)
1900 {
1901 if (arg->buf) {
1902 xfree(arg->buf);
1903 arg->buf = 0;
1904 }
1905 arg->buflen = 0;
1906 arg->offset = 0;
1907 arg->readable = 0;
1908 if (!arg->symbols) return;
1909 st_free_table(arg->symbols);
1910 arg->symbols = 0;
1911 st_free_table(arg->data);
1912 arg->data = 0;
1913 st_free_table(arg->compat_tbl);
1914 arg->compat_tbl = 0;
1915 }
1916
1917 /*
1918 * call-seq:
1919 * load( source [, proc] ) -> obj
1920 * restore( source [, proc] ) -> obj
1921 *
1922 * Returns the result of converting the serialized data in source into a
1923 * Ruby object (possibly with associated subordinate objects). source
1924 * may be either an instance of IO or an object that responds to
1925 * to_str. If proc is specified, each object will be passed to the proc, as the object
1926 * is being deserialized.
1927 *
1928 * Never pass untrusted data (including user supplied input) to this method.
1929 * Please see the overview for further details.
1930 */
1931 static VALUE
1932 marshal_load(int argc, VALUE *argv)
1933 {
1934 VALUE port, proc;
1935 int major, minor, infection = 0;
1936 VALUE v;
1937 volatile VALUE wrapper;
1938 struct load_arg *arg;
1939
1940 rb_scan_args(argc, argv, "11", &port, &proc);
1941 v = rb_check_string_type(port);
1942 if (!NIL_P(v)) {
1943 infection = (int)FL_TEST(port, MARSHAL_INFECTION); /* original taintedness */
1944 port = v;
1945 }
1946 else if (rb_respond_to(port, s_getbyte) && rb_respond_to(port, s_read)) {
1947 rb_check_funcall(port, s_binmode, 0, 0);
1948 infection = (int)FL_TAINT;
1949 }
1950 else {
1951 io_needed();
1952 }
1953 RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
1954 arg->infection = infection;
1955 arg->src = port;
1956 arg->offset = 0;
1957 arg->symbols = st_init_numtable();
1958 arg->data = st_init_numtable();
1959 arg->compat_tbl = st_init_numtable();
1960 arg->proc = 0;
1961 arg->readable = 0;
1962
1963 if (NIL_P(v))
1964 arg->buf = xmalloc(BUFSIZ);
1965 else
1966 arg->buf = 0;
1967
1968 major = r_byte(arg);
1969 minor = r_byte(arg);
1970 if (major != MARSHAL_MAJOR || minor > MARSHAL_MINOR) {
1971 clear_load_arg(arg);
1972 rb_raise(rb_eTypeError, "incompatible marshal file format (can't be read)\n\
1973 \tformat version %d.%d required; %d.%d given",
1974 MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
1975 }
1976 if (RTEST(ruby_verbose) && minor != MARSHAL_MINOR) {
1977 rb_warn("incompatible marshal file format (can be read)\n\
1978 \tformat version %d.%d required; %d.%d given",
1979 MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
1980 }
1981
1982 if (!NIL_P(proc)) arg->proc = proc;
1983 v = r_object(arg);
1984 clear_load_arg(arg);
1985 RB_GC_GUARD(wrapper);
1986
1987 return v;
1988 }
1989
1990 /*
1991 * The marshaling library converts collections of Ruby objects into a
1992 * byte stream, allowing them to be stored outside the currently
1993 * active script. This data may subsequently be read and the original
1994 * objects reconstituted.
1995 *
1996 * Marshaled data has major and minor version numbers stored along
1997 * with the object information. In normal use, marshaling can only
1998 * load data written with the same major version number and an equal
1999 * or lower minor version number. If Ruby's ``verbose'' flag is set
2000 * (normally using -d, -v, -w, or --verbose) the major and minor
2001 * numbers must match exactly. Marshal versioning is independent of
2002 * Ruby's version numbers. You can extract the version by reading the
2003 * first two bytes of marshaled data.
2004 *
2005 * str = Marshal.dump("thing")
2006 * RUBY_VERSION #=> "1.9.0"
2007 * str[0].ord #=> 4
2008 * str[1].ord #=> 8
2009 *
2010 * Some objects cannot be dumped: if the objects to be dumped include
2011 * bindings, procedure or method objects, instances of class IO, or
2012 * singleton objects, a TypeError will be raised.
2013 *
2014 * If your class has special serialization needs (for example, if you
2015 * want to serialize in some specific format), or if it contains
2016 * objects that would otherwise not be serializable, you can implement
2017 * your own serialization strategy.
2018 *
2019 * There are two methods of doing this, your object can define either
2020 * marshal_dump and marshal_load or _dump and _load. marshal_dump will take
2021 * precedence over _dump if both are defined. marshal_dump may result in
2022 * smaller Marshal strings.
2023 *
2024 * == Security considerations
2025 *
2026 * By design, Marshal.load can deserialize almost any class loaded into the
2027 * Ruby process. In many cases this can lead to remote code execution if the
2028 * Marshal data is loaded from an untrusted source.
2029 *
2030 * As a result, Marshal.load is not suitable as a general purpose serialization
2031 * format and you should never unmarshal user supplied input or other untrusted
2032 * data.
2033 *
2034 * If you need to deserialize untrusted data, use JSON or another serialization
2035 * format that is only able to load simple, 'primitive' types such as String,
2036 * Array, Hash, etc. Never allow user input to specify arbitrary types to
2037 * deserialize into.
2038 *
2039 * == marshal_dump and marshal_load
2040 *
2041 * When dumping an object the method marshal_dump will be called.
2042 * marshal_dump must return a result containing the information necessary for
2043 * marshal_load to reconstitute the object. The result can be any object.
2044 *
2045 * When loading an object dumped using marshal_dump the object is first
2046 * allocated then marshal_load is called with the result from marshal_dump.
2047 * marshal_load must recreate the object from the information in the result.
2048 *
2049 * Example:
2050 *
2051 * class MyObj
2052 * def initialize name, version, data
2053 * @name = name
2054 * @version = version
2055 * @data = data
2056 * end
2057 *
2058 * def marshal_dump
2059 * [@name, @version]
2060 * end
2061 *
2062 * def marshal_load array
2063 * @name, @version = array
2064 * end
2065 * end
2066 *
2067 * == _dump and _load
2068 *
2069 * Use _dump and _load when you need to allocate the object you're restoring
2070 * yourself.
2071 *
2072 * When dumping an object the instance method _dump is called with an Integer
2073 * which indicates the maximum depth of objects to dump (a value of -1 implies
2074 * that you should disable depth checking). _dump must return a String
2075 * containing the information necessary to reconstitute the object.
2076 *
2077 * The class method _load should take a String and use it to return an object
2078 * of the same class.
2079 *
2080 * Example:
2081 *
2082 * class MyObj
2083 * def initialize name, version, data
2084 * @name = name
2085 * @version = version
2086 * @data = data
2087 * end
2088 *
2089 * def _dump level
2090 * [@name, @version].join ':'
2091 * end
2092 *
2093 * def self._load args
2094 * new(*args.split(':'))
2095 * end
2096 * end
2097 *
2098 * Since Marhsal.dump outputs a string you can have _dump return a Marshal
2099 * string which is Marshal.loaded in _load for complex objects.
2100 */
2101 void
2102 Init_marshal(void)
2103 {
2104 #undef rb_intern
2105 #define rb_intern(str) rb_intern_const(str)
2106
2107 VALUE rb_mMarshal = rb_define_module("Marshal");
2108
2109 s_dump = rb_intern("_dump");
2110 s_load = rb_intern("_load");
2111 s_mdump = rb_intern("marshal_dump");
2112 s_mload = rb_intern("marshal_load");
2113 s_dump_data = rb_intern("_dump_data");
2114 s_load_data = rb_intern("_load_data");
2115 s_alloc = rb_intern("_alloc");
2116 s_call = rb_intern("call");
2117 s_getbyte = rb_intern("getbyte");
2118 s_read = rb_intern("read");
2119 s_write = rb_intern("write");
2120 s_binmode = rb_intern("binmode");
2121
2122 rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1);
2123 rb_define_module_function(rb_mMarshal, "load", marshal_load, -1);
2124 rb_define_module_function(rb_mMarshal, "restore", marshal_load, -1);
2125
2126 /* major version */
2127 rb_define_const(rb_mMarshal, "MAJOR_VERSION", INT2FIX(MARSHAL_MAJOR));
2128 /* minor version */
2129 rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR));
2130
2131 compat_allocator_tbl = st_init_numtable();
2132 compat_allocator_tbl_wrapper =
2133 Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
2134 rb_gc_register_mark_object(compat_allocator_tbl_wrapper);
2135 }
2136
2137 VALUE
2138 rb_marshal_dump(VALUE obj, VALUE port)
2139 {
2140 int argc = 1;
2141 VALUE argv[2];
2142
2143 argv[0] = obj;
2144 argv[1] = port;
2145 if (!NIL_P(port)) argc = 2;
2146 return marshal_dump(argc, argv);
2147 }
2148
2149 VALUE
2150 rb_marshal_load(VALUE port)
2151 {
2152 return marshal_load(1, &port);
2153 }
rb_cString
RUBY_EXTERN VALUE rb_cString
Definition: ruby.h:1583
rb_alloc_func_t
VALUE(* rb_alloc_func_t)(VALUE)
Definition: intern.h:374
marshal_load
static VALUE marshal_load(int argc, VALUE *argv)
Definition: marshal.c:1932
T_OBJECT
#define T_OBJECT
Definition: ruby.h:477
dump_arg_data
static const rb_data_type_t dump_arg_data
Definition: marshal.c:186
long_toobig
static void long_toobig(int size)
Definition: marshal.c:1103
rb_enc_get_index
int rb_enc_get_index(VALUE obj)
Definition: encoding.c:739
TYPE_OBJECT
#define TYPE_OBJECT
Definition: marshal.c:60
rb_cData
RUBY_EXTERN VALUE rb_cData
Definition: ruby.h:1560
r_long
static long r_long(struct load_arg *arg)
Definition: marshal.c:1118
load_arg::proc
VALUE proc
Definition: marshal.c:987
path2module
#define path2module(path)
Definition: marshal.c:1430
load_arg::buf
char * buf
Definition: marshal.c:981
rb_ary_pop
VALUE rb_ary_pop(VALUE ary)
Definition: array.c:940
dump_arg::infection
int infection
Definition: marshal.c:142
RARRAY_LEN
#define RARRAY_LEN(a)
Definition: ruby.h:878
class2path
static VALUE class2path(VALUE klass)
Definition: marshal.c:209
FALSE
#define FALSE
Definition: nkf.h:174
RUBY_TYPED_FREE_IMMEDIATELY
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
load_mantissa
#define load_mantissa(d, buf, len)
Definition: marshal.c:346
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1288
st_table
Definition: st.h:69
r_byte1_buffered
static unsigned char r_byte1_buffered(struct load_arg *arg)
Definition: marshal.c:1055
rb_id2str
VALUE rb_id2str(ID id)
Definition: ripper.c:17160
minor
int minor
Definition: tcltklib.c:111
memsize_dump_arg
static size_t memsize_dump_arg(const void *ptr)
Definition: marshal.c:181
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:630
dump_arg
Definition: marshal.c:136
dump_call_arg::arg
struct dump_arg * arg
Definition: marshal.c:147
w_obj_each
static int w_obj_each(st_data_t key, st_data_t val, st_data_t a)
Definition: marshal.c:515
w_objivar
static void w_objivar(VALUE obj, struct dump_call_arg *arg)
Definition: marshal.c:577
ruby.h
FL_TAINT
#define FL_TAINT
Definition: ruby.h:1137
CLASS_OF
#define CLASS_OF(v)
Definition: ruby.h:440
T_MODULE
#define T_MODULE
Definition: ruby.h:480
rb_str_cat
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:2140
rb_marshal_dump
VALUE rb_marshal_dump(VALUE obj, VALUE port)
Definition: marshal.c:2138
must_not_be_anonymous
static const char * must_not_be_anonymous(const char *type, VALUE path)
Definition: marshal.c:193
r_copy_ivar
static VALUE r_copy_ivar(VALUE v, VALUE data)
Definition: marshal.c:1391
dump_call_arg
Definition: marshal.c:145
Qtrue
#define Qtrue
Definition: ruby.h:426
st_insert
int st_insert(st_table *, st_data_t, st_data_t)
SHORTMASK
#define SHORTMASK
Definition: marshal.c:28
w_long
static void w_long(long, struct dump_arg *)
Definition: marshal.c:259
rb_cHash
VALUE rb_cHash
Definition: hash.c:67
ST_CONTINUE
Definition: st.h:100
w_object
static void w_object(VALUE, struct dump_arg *, int)
Definition: marshal.c:596
id
const int id
Definition: nkf.c:209
rb_builtin_type_name
const char * rb_builtin_type_name(int t)
Definition: error.c:440
marshal_dump
static VALUE marshal_dump(int argc, VALUE *argv)
Definition: marshal.c:925
r_bytes
#define r_bytes(arg)
Definition: marshal.c:1212
TYPE_LINK
#define TYPE_LINK
Definition: marshal.c:80
NAN
#define NAN
Definition: missing.h:149
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:548
FLOAT_DIG
#define FLOAT_DIG
Definition: marshal.c:352
SHORTLEN
#define SHORTLEN(x)
Definition: marshal.c:32
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:896
TYPE_SYMLINK
#define TYPE_SYMLINK
Definition: marshal.c:77
st_free_table
void st_free_table(st_table *)
Definition: st.c:334
SYM2ID
#define SYM2ID(x)
Definition: ruby.h:356
s_load_data
static ID s_load_data
Definition: marshal.c:83
rb_ary_tmp_new
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:534
r_byte
static int r_byte(struct load_arg *arg)
Definition: marshal.c:1076
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:775
rb_path_to_class
VALUE rb_path_to_class(VALUE)
Definition: variable.c:339
rb_str_set_len
void rb_str_set_len(VALUE, long)
Definition: string.c:2008
dump_arg::dest
VALUE dest
Definition: marshal.c:137
RBASIC_SET_CLASS
#define RBASIC_SET_CLASS(obj, cls)
Definition: internal.h:609
rb_reg_options
int rb_reg_options(VALUE)
Definition: re.c:3102
rb_enc_str_coderange
int rb_enc_str_coderange(VALUE)
Definition: string.c:435
w_short
static void w_short(int x, struct dump_arg *arg)
Definition: marshal.c:252
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
rb_ary_clear
VALUE rb_ary_clear(VALUE ary)
Definition: array.c:3381
s_getbyte
static ID s_getbyte
Definition: marshal.c:84
rb_utf8_encindex
#define rb_utf8_encindex()
Definition: internal.h:403
RB_GC_GUARD
#define RB_GC_GUARD(v)
Definition: ruby.h:523
T_HASH
#define T_HASH
Definition: ruby.h:485
ruby_check_marshal_viral_flags
char ruby_check_marshal_viral_flags[MARSHAL_INFECTION==(int) MARSHAL_INFECTION?1:-1]
Definition: marshal.c:134
rb_gc_mark
void rb_gc_mark(VALUE ptr)
Definition: gc.c:3604
w_uclass
static void w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
Definition: marshal.c:502
T_ARRAY
#define T_ARRAY
Definition: ruby.h:484
st_index_t
st_data_t st_index_t
Definition: st.h:48
TYPE_UCLASS
#define TYPE_UCLASS
Definition: marshal.c:59
SHORTDN
#define SHORTDN(x)
Definition: marshal.c:29
rb_io_write
VALUE rb_io_write(VALUE, VALUE)
Definition: io.c:1427
ROBJECT_NUMIV
#define ROBJECT_NUMIV(o)
Definition: ruby.h:774
w_ivar
static void w_ivar(VALUE obj, st_table *tbl, struct dump_call_arg *arg)
Definition: marshal.c:566
copy_ivar_i
static int copy_ivar_i(st_data_t key, st_data_t val, st_data_t arg)
Definition: marshal.c:1380
rb_id_encoding
ID rb_id_encoding(void)
Definition: encoding.c:732
TYPE_USERDEF
#define TYPE_USERDEF
Definition: marshal.c:62
dump_call_arg::limit
int limit
Definition: marshal.c:148
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:347
path2class
static VALUE path2class(VALUE path)
Definition: marshal.c:1420
r_bytes1_buffered
static VALUE r_bytes1_buffered(long len, struct load_arg *arg)
Definition: marshal.c:1166
w_class
static void w_class(char type, VALUE obj, struct dump_arg *arg, int check)
Definition: marshal.c:485
rb_ivar_defined
VALUE rb_ivar_defined(VALUE, ID)
Definition: variable.c:1207
hash_each
static int hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
Definition: marshal.c:454
io.h
obj_alloc_by_path
static VALUE obj_alloc_by_path(VALUE path, struct load_arg *arg)
Definition: marshal.c:1461
RHASH_IFNONE
#define RHASH_IFNONE(h)
Definition: ruby.h:929
rb_ivar_foreach
void rb_ivar_foreach(VALUE, int(*)(ANYARGS), st_data_t)
Definition: variable.c:1274
ENC_CODERANGE_7BIT
#define ENC_CODERANGE_7BIT
Definition: encoding.h:49
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
rb_ary_new2
#define rb_ary_new2
Definition: intern.h:90
w_nbyte
static void w_nbyte(const char *s, long n, struct dump_arg *arg)
Definition: marshal.c:225
marshal_compat_t
Definition: marshal.c:86
TYPE_IVAR
#define TYPE_IVAR
Definition: marshal.c:79
load_arg::symbols
st_table * symbols
Definition: marshal.c:985
RHASH_SET_IFNONE
#define RHASH_SET_IFNONE(h, ifnone)
Definition: ruby.h:932
sym
#define sym(x)
Definition: date_core.c:3695
TYPE_FALSE
#define TYPE_FALSE
Definition: marshal.c:55
rb_str_buf_cat
VALUE rb_str_buf_cat(VALUE, const char *, long)
Definition: string.c:2124
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
TYPE_HASH_DEF
#define TYPE_HASH_DEF
Definition: marshal.c:70
Data_Wrap_Struct
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:1018
load_arg::compat_tbl
st_table * compat_tbl
Definition: marshal.c:988
rb_hash_foreach
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
Definition: hash.c:264
r_string
static VALUE r_string(struct load_arg *arg)
Definition: marshal.c:1319
rb_struct_members
VALUE rb_struct_members(VALUE)
Definition: struct.c:53
FL_SINGLETON
#define FL_SINGLETON
Definition: ruby.h:1133
rb_prepend_module
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:940
st_init_strcasetable
st_table * st_init_strcasetable(void)
Definition: st.c:296
strtod
#define strtod(s, e)
Definition: util.h:74
rb_singleton_class
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1628
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1664
rb_struct_s_members
VALUE rb_struct_s_members(VALUE)
Definition: struct.c:39
prohibit_ivar
#define prohibit_ivar(type, str)
Definition: marshal.c:1477
st_lookup
int st_lookup(st_table *, st_data_t, st_data_t *)
TYPE_FLOAT
#define TYPE_FLOAT
Definition: marshal.c:64
s_read
static ID s_read
Definition: marshal.c:84
FL_TEST
#define FL_TEST(x, f)
Definition: ruby.h:1169
check_dump_arg
static void check_dump_arg(struct dump_arg *arg, ID sym)
Definition: marshal.c:152
TYPE_CLASS
#define TYPE_CLASS
Definition: marshal.c:73
load_arg::data
st_table * data
Definition: marshal.c:986
check_load_arg
static void check_load_arg(struct load_arg *arg, ID sym)
Definition: marshal.c:993
ROBJECT_IVPTR
#define ROBJECT_IVPTR(o)
Definition: ruby.h:778
rb_intern_str
#define rb_intern_str(string)
Definition: generator.h:17
rb_class_name
VALUE rb_class_name(VALUE)
Definition: variable.c:391
TYPE_STRING
#define TYPE_STRING
Definition: marshal.c:66
rb_hash_aset
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1393
load_arg::buflen
long buflen
Definition: marshal.c:982
val
#define val
RREGEXP_SRC_PTR
#define RREGEXP_SRC_PTR(r)
Definition: ruby.h:916
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:547
TYPE_REGEXP
#define TYPE_REGEXP
Definition: marshal.c:67
PRIdVALUE
#define PRIdVALUE
Definition: ruby.h:132
SINGLETON_DUMP_UNABLE_P
#define SINGLETON_DUMP_UNABLE_P(klass)
Definition: marshal.c:461
rb_class_real
VALUE rb_class_real(VALUE)
Definition: object.c:204
TYPE_BIGNUM
#define TYPE_BIGNUM
Definition: marshal.c:65
TYPE_MODULE_OLD
#define TYPE_MODULE_OLD
Definition: marshal.c:72
s_call
static ID s_call
Definition: marshal.c:83
marshal_compat_t::oldclass
VALUE oldclass
Definition: marshal.c:88
RSTRUCT_LEN
#define RSTRUCT_LEN(st)
Definition: ruby.h:1058
snprintf
#define snprintf
Definition: subst.h:6
RCLASS_ORIGIN
#define RCLASS_ORIGIN(c)
Definition: internal.h:297
NIL_P
#define NIL_P(v)
Definition: ruby.h:438
st_add_direct
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
r_fixup_compat
static VALUE r_fixup_compat(VALUE v, struct load_arg *arg)
Definition: marshal.c:1344
st_delete
int st_delete(st_table *, st_data_t *, st_data_t *)
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2225
r_symlink
static ID r_symlink(struct load_arg *arg)
Definition: marshal.c:1256
FLONUM_P
#define FLONUM_P(x)
Definition: ruby.h:367
T_FLOAT
#define T_FLOAT
Definition: ruby.h:481
rb_class_inherited_p
VALUE rb_class_inherited_p(VALUE, VALUE)
Definition: object.c:1564
r_entry0
static VALUE r_entry0(VALUE v, st_index_t num, struct load_arg *arg)
Definition: marshal.c:1325
TYPE
#define TYPE(x)
Definition: ruby.h:505
r_object0
static VALUE r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
Definition: marshal.c:1485
argc
int argc
Definition: ruby.c:131
TYPE_SYMBOL
#define TYPE_SYMBOL
Definition: marshal.c:76
r_prepare
static st_index_t r_prepare(struct load_arg *arg)
Definition: marshal.c:1046
RBIGNUM_LEN
#define RBIGNUM_LEN(b)
Definition: ruby.h:1103
Qfalse
#define Qfalse
Definition: ruby.h:425
T_BIGNUM
#define T_BIGNUM
Definition: ruby.h:487
r_post_proc
static VALUE r_post_proc(VALUE v, struct load_arg *arg)
Definition: marshal.c:1362
rb_gc_register_mark_object
void rb_gc_register_mark_object(VALUE obj)
Definition: gc.c:4920
rb_get_alloc_func
rb_alloc_func_t rb_get_alloc_func(VALUE)
Definition: vm_method.c:525
isinf
RUBY_EXTERN int isinf(double)
Definition: isinf.c:56
rb_enc_associate_index
VALUE rb_enc_associate_index(VALUE obj, int idx)
Definition: encoding.c:798
dump_arg::str
VALUE str
Definition: marshal.c:137
rb_str_new2
#define rb_str_new2
Definition: intern.h:840
rb_obj_alloc
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1801
TYPE_NIL
#define TYPE_NIL
Definition: marshal.c:53
link
int link(const char *, const char *)
Definition: win32.c:4595
HASH_PROC_DEFAULT
#define HASH_PROC_DEFAULT
Definition: internal.h:482
memsize_load_arg
static size_t memsize_load_arg(const void *ptr)
Definition: marshal.c:1021
RBIGNUM_DIGITS
#define RBIGNUM_DIGITS(b)
Definition: ruby.h:1109
encoding.h
mark_dump_arg
static void mark_dump_arg(void *ptr)
Definition: marshal.c:163
ALLOC
#define ALLOC(type)
Definition: ruby.h:1334
rb_integer_unpack
VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Definition: bignum.c:3617
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2025
st_foreach_safe
void st_foreach_safe(st_table *table, int(*func)(ANYARGS), st_data_t a)
Definition: hash.c:189
too_short
static void too_short(void)
Definition: marshal.c:1040
w_unique
static void w_unique(VALUE s, struct dump_arg *arg)
Definition: marshal.c:445
must_be_module
static VALUE must_be_module(VALUE v, VALUE path)
Definition: marshal.c:1433
TYPE_USRMARSHAL
#define TYPE_USRMARSHAL
Definition: marshal.c:63
rb_cRegexp
RUBY_EXTERN VALUE rb_cRegexp
Definition: ruby.h:1581
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:841
rb_define_module_function
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1670
TYPE_FIXNUM
#define TYPE_FIXNUM
Definition: marshal.c:56
util.h
TRUE
#define TRUE
Definition: nkf.h:175
T_DATA
#define T_DATA
Definition: ruby.h:492
TYPE_STRUCT
#define TYPE_STRUCT
Definition: marshal.c:71
rb_obj_respond_to
int rb_obj_respond_to(VALUE, ID, int)
Definition: vm_method.c:1600
MARSHAL_MAJOR
#define MARSHAL_MAJOR
Definition: marshal.c:50
const
#define const
Definition: strftime.c:102
rb_enc_name
#define rb_enc_name(enc)
Definition: encoding.h:125
r_bytes1
static VALUE r_bytes1(long len, struct load_arg *arg)
Definition: marshal.c:1151
rb_class_path
VALUE rb_class_path(VALUE)
Definition: variable.c:257
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:298
TYPE_TRUE
#define TYPE_TRUE
Definition: marshal.c:54
NUM2CHR
#define NUM2CHR(x)
Definition: ruby.h:1329
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1728
dump_arg::compat_tbl
st_table * compat_tbl
Definition: marshal.c:140
TYPE_DATA
#define TYPE_DATA
Definition: marshal.c:61
compat_allocator_tbl
static st_table * compat_allocator_tbl
Definition: marshal.c:93
marshal_compat_t::loader
VALUE(* loader)(VALUE, VALUE)
Definition: marshal.c:90
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1133
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:137
internal.h
ID
unsigned long ID
Definition: ruby.h:89
RHASH_SIZE
#define RHASH_SIZE(h)
Definition: ruby.h:930
r_symbol
static ID r_symbol(struct load_arg *arg)
Definition: marshal.c:1291
r_ivar
static void r_ivar(VALUE obj, int *has_encoding, struct load_arg *arg)
Definition: marshal.c:1398
T_STRUCT
#define T_STRUCT
Definition: ruby.h:486
Qnil
#define Qnil
Definition: ruby.h:427
rb_intern
#define rb_intern(str)
type
int type
Definition: tcltklib.c:112
options
static int options(unsigned char *cp)
Definition: nkf.c:6357
BUILTIN_TYPE
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
TYPE_ARRAY
#define TYPE_ARRAY
Definition: marshal.c:68
VALUE
unsigned long VALUE
Definition: ruby.h:88
rb_funcall2
#define rb_funcall2
Definition: ruby.h:1456
s_dump
static ID s_dump
Definition: marshal.c:82
clear_dump_arg
static void clear_dump_arg(struct dump_arg *arg)
Definition: marshal.c:868
RBASIC
#define RBASIC(obj)
Definition: ruby.h:1116
rb_class2name
const char * rb_class2name(VALUE)
Definition: variable.c:397
rb_extend_object
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1305
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:632
rb_usascii_encindex
#define rb_usascii_encindex()
Definition: internal.h:404
rb_mark_tbl
void rb_mark_tbl(st_table *tbl)
Definition: gc.c:3519
has_ivars
#define has_ivars(obj, ivtbl)
free_load_arg
static void free_load_arg(void *ptr)
Definition: marshal.c:1014
rb_check_funcall
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:409
SIGN_EXTEND_CHAR
#define SIGN_EXTEND_CHAR(c)
Definition: marshal.c:1114
TYPE_MODULE
#define TYPE_MODULE
Definition: marshal.c:74
INFINITY
#define INFINITY
Definition: missing.h:141
rb_enc_asciicompat
#define rb_enc_asciicompat(enc)
Definition: encoding.h:188
INTEGER_PACK_LITTLE_ENDIAN
#define INTEGER_PACK_LITTLE_ENDIAN
Definition: intern.h:153
s_alloc
static ID s_alloc
Definition: marshal.c:83
mark_marshal_compat_i
static int mark_marshal_compat_i(st_data_t key, st_data_t value)
Definition: marshal.c:97
isnan
#define isnan(x)
Definition: win32.h:376
mark_load_arg
static void mark_load_arg(void *ptr)
Definition: marshal.c:1004
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:272
dump_arg::symbols
st_table * symbols
Definition: marshal.c:138
id2encidx
static int id2encidx(ID id, VALUE val)
Definition: marshal.c:1241
w_cstr
#define w_cstr(s, arg)
Definition: marshal.c:249
LONG2NUM
#define LONG2NUM(x)
Definition: ruby.h:1309
r_bytes0
static VALUE r_bytes0(long len, struct load_arg *arg)
Definition: marshal.c:1215
rb_respond_to
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1639
MARSHAL_INFECTION
#define MARSHAL_INFECTION
Definition: marshal.c:133
StringValueCStr
#define StringValueCStr(v)
Definition: ruby.h:541
dump_arg::encodings
st_table * encodings
Definition: marshal.c:141
s_mload
static ID s_mload
Definition: marshal.c:82
s_load
static ID s_load
Definition: marshal.c:82
s_binmode
static ID s_binmode
Definition: marshal.c:84
NORETURN
NORETURN(static inline void io_needed(void))
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:845
w_bytes
static void w_bytes(const char *s, long n, struct dump_arg *arg)
Definition: marshal.c:243
marshal_compat_t::dumper
VALUE(* dumper)(VALUE)
Definition: marshal.c:89
INTEGER_PACK_NEGATIVE
#define INTEGER_PACK_NEGATIVE
Definition: intern.h:151
rb_enc_get
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:832
MARSHAL_MINOR
#define MARSHAL_MINOR
Definition: marshal.c:51
s_write
static ID s_write
Definition: marshal.c:84
RFLOAT_VALUE
#define RFLOAT_VALUE(v)
Definition: ruby.h:814
size
int size
Definition: encoding.c:49
clear_load_arg
static void clear_load_arg(struct load_arg *arg)
Definition: marshal.c:1899
RSTRUCT_GET
#define RSTRUCT_GET(st, idx)
Definition: ruby.h:1071
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:231
RCLASS_SUPER
#define RCLASS_SUPER(c)
Definition: classext.h:16
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition: ruby.h:901
xmalloc
#define xmalloc
Definition: defines.h:108
RBASIC_CLASS
#define RBASIC_CLASS(obj)
Definition: ruby.h:759
TYPE_HASH
#define TYPE_HASH
Definition: marshal.c:69
rb_data_type_struct
Definition: ruby.h:966
Init_marshal
void Init_marshal(void)
Definition: marshal.c:2102
rb_mark_set
void rb_mark_set(st_table *tbl)
Definition: gc.c:3357
rb_check_string_type
VALUE rb_check_string_type(VALUE)
Definition: string.c:1679
load_arg::infection
int infection
Definition: marshal.c:989
w_symbol
static void w_symbol(ID id, struct dump_arg *arg)
Definition: marshal.c:409
key
uint8_t key[16]
Definition: random.c:1250
rb_special_const_p
static int rb_special_const_p(VALUE obj)
Definition: ruby.h:1687
LONG2FIX
#define LONG2FIX(i)
Definition: ruby.h:232
RTEST
#define RTEST(v)
Definition: ruby.h:437
T_STRING
#define T_STRING
Definition: ruby.h:482
compat_allocator_tbl_wrapper
static VALUE compat_allocator_tbl_wrapper
Definition: marshal.c:94
load_arg::src
VALUE src
Definition: marshal.c:980
load_arg::offset
long offset
Definition: marshal.c:984
append_extmod
static VALUE append_extmod(VALUE obj, VALUE extmod)
Definition: marshal.c:1467
r_unique
static VALUE r_unique(struct load_arg *arg)
Definition: marshal.c:1313
TypedData_Make_Struct
#define TypedData_Make_Struct(klass, type, data_type, sval)
Definition: ruby.h:1030
r_symreal
static ID r_symreal(struct load_arg *arg, int ivar)
Definition: marshal.c:1268
free_dump_arg
static void free_dump_arg(void *ptr)
Definition: marshal.c:174
st.h
rb_cArray
VALUE rb_cArray
Definition: array.c:27
rb_int2big
VALUE rb_int2big(SIGNED_VALUE n)
Definition: bignum.c:3164
r_object
static VALUE r_object(struct load_arg *arg)
Definition: marshal.c:1893
T_CLASS
#define T_CLASS
Definition: ruby.h:478
mark_marshal_compat_t
static void mark_marshal_compat_t(void *tbl)
Definition: marshal.c:106
load_arg::readable
long readable
Definition: marshal.c:983
rb_marshal_define_compat
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Definition: marshal.c:113
dump_arg::data
st_table * data
Definition: marshal.c:139
RREGEXP_SRC_LEN
#define RREGEXP_SRC_LEN(r)
Definition: ruby.h:917
readable
static struct StringIO * readable(VALUE strio)
Definition: stringio.c:126
name
const char * name
Definition: nkf.c:208
FL_SET
#define FL_SET(x, f)
Definition: ruby.h:1172
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:355
obj_alloc_by_klass
static VALUE obj_alloc_by_klass(VALUE klass, struct load_arg *arg, VALUE *oldclass)
Definition: marshal.c:1442
io_needed
static void io_needed(void)
Definition: marshal.c:885
rb_id2name
const char * rb_id2name(ID id)
Definition: ripper.c:17230
rb_reg_new_str
VALUE rb_reg_new_str(VALUE, int)
Definition: re.c:2505
SIZEOF_BDIGITS
#define SIZEOF_BDIGITS
Definition: bigdecimal.h:50
load_arg_data
static const rb_data_type_t load_arg_data
Definition: marshal.c:1026
rb_enc_find_index
int rb_enc_find_index(const char *name)
Definition: encoding.c:684
RBIGNUM_SIGN
#define RBIGNUM_SIGN(b)
Definition: ruby.h:1093
STRINGIZE
#define STRINGIZE(expr)
Definition: defines.h:128
major
int major
Definition: tcltklib.c:110
xfree
void void xfree(void *)
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:746
rb_mark_hash
void rb_mark_hash(st_table *tbl)
Definition: gc.c:3381
rb_str_buf_new
VALUE rb_str_buf_new(long)
Definition: string.c:891
SYMBOL_P
#define SYMBOL_P(x)
Definition: ruby.h:354
dump_call_arg::obj
VALUE obj
Definition: marshal.c:146
w_extended
static void w_extended(VALUE klass, struct dump_arg *arg, int check)
Definition: marshal.c:466
NULL
#define NULL
Definition: _sdbm.c:103
FIX2LONG
#define FIX2LONG(x)
Definition: ruby.h:345
w_byte
static void w_byte(char c, struct dump_arg *arg)
Definition: marshal.c:237
Qundef
#define Qundef
Definition: ruby.h:428
T_ICLASS
#define T_ICLASS
Definition: ruby.h:479
w_float
static void w_float(double d, struct dump_arg *arg)
Definition: marshal.c:356
rb_marshal_load
VALUE rb_marshal_load(VALUE port)
Definition: marshal.c:2150
rb_struct_initialize
VALUE rb_struct_initialize(VALUE, VALUE)
Definition: struct.c:466
r_entry
#define r_entry(v, arg)
Definition: marshal.c:1032
s_dump_data
static ID s_dump_data
Definition: marshal.c:83
s_mdump
static ID s_mdump
Definition: marshal.c:82
st_table::num_entries
st_index_t num_entries
Definition: st.h:85
ruby_verbose
#define ruby_verbose
Definition: ruby.h:1475
st_foreach
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1034
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:223
rb_eArgError
VALUE rb_eArgError
Definition: error.c:549
marshal_compat_t::newclass
VALUE newclass
Definition: marshal.c:87
T_REGEXP
#define T_REGEXP
Definition: ruby.h:483
BDIGIT
#define BDIGIT
Definition: bigdecimal.h:47
argv
char ** argv
Definition: ruby.c:132
DBL2NUM
#define DBL2NUM(dbl)
Definition: ruby.h:815
r_leave
static VALUE r_leave(VALUE v, struct load_arg *arg)
Definition: marshal.c:1372
StringValue
#define StringValue(v)
Definition: ruby.h:539
TYPE_EXTENDED
#define TYPE_EXTENDED
Definition: marshal.c:58
ruby_dtoa
char * ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
Definition: util.c:3094
load_arg
Definition: marshal.c:979
rb_enc_from_index
rb_encoding * rb_enc_from_index(int index)
Definition: encoding.c:590
OnigEncodingTypeST
Definition: oniguruma.h:158
rb_str_new
VALUE rb_str_new(const char *, long)
Definition: string.c:534
w_encoding
static void w_encoding(VALUE obj, long num, struct dump_call_arg *arg)
Definition: marshal.c:529
rb_eof_error
void rb_eof_error(void)
Definition: io.c:596