Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

marshal.c File Reference

#include "ruby.h"
#include "rubyio.h"
#include "st.h"
#include "util.h"
#include <math.h>
#include <float.h>

Go to the source code of this file.

Data Structures

struct  dump_arg
struct  dump_call_arg
struct  load_arg

Defines

#define BITSPERSHORT   (2*CHAR_BIT)
#define SHORTMASK   ((1<<BITSPERSHORT)-1)
#define SHORTDN(x)   RSHIFT(x,BITSPERSHORT)
#define SHORTLEN(x)   shortlen((x),d)
#define MARSHAL_MAJOR   4
#define MARSHAL_MINOR   8
#define TYPE_NIL   '0'
#define TYPE_TRUE   'T'
#define TYPE_FALSE   'F'
#define TYPE_FIXNUM   'i'
#define TYPE_EXTENDED   'e'
#define TYPE_UCLASS   'C'
#define TYPE_OBJECT   'o'
#define TYPE_DATA   'd'
#define TYPE_USERDEF   'u'
#define TYPE_USRMARSHAL   'U'
#define TYPE_FLOAT   'f'
#define TYPE_BIGNUM   'l'
#define TYPE_STRING   '"'
#define TYPE_REGEXP   '/'
#define TYPE_ARRAY   '['
#define TYPE_HASH   '{'
#define TYPE_HASH_DEF   '}'
#define TYPE_STRUCT   'S'
#define TYPE_MODULE_OLD   'M'
#define TYPE_CLASS   'c'
#define TYPE_MODULE   'm'
#define TYPE_SYMBOL   ':'
#define TYPE_SYMLINK   ';'
#define TYPE_IVAR   'I'
#define TYPE_LINK   '@'
#define load_mantissa(d, buf, len)   (d)
#define save_mantissa(d, buf)   0
#define FLOAT_DIG   17
#define SIGN_EXTEND_CHAR(c)   ((((unsigned char)(c)) ^ 128) - 128)
#define r_bytes(arg)   r_bytes0(r_long(arg), (arg))

Functions

int shortlen (long len, BDIGIT *ds)
VALUE class2path (VALUE klass)
void w_long (long, struct dump_arg *)
void w_nbyte (char *s, int n, struct dump_arg *arg)
void w_byte (char c, struct dump_arg *arg)
void w_bytes (char *s, int n, struct dump_arg *arg)
void w_short (int x, struct dump_arg *arg)
void w_float (double d, struct dump_arg *arg)
void w_symbol (ID id, struct dump_arg *arg)
void w_unique (char *s, struct dump_arg *arg)
void w_object (VALUE, struct dump_arg *, int)
int hash_each (VALUE key, VALUE value, struct dump_call_arg *arg)
void w_extended (VALUE klass, struct dump_arg *arg, int check)
void w_class (int type, VALUE obj, struct dump_arg *arg, int check)
void w_uclass (VALUE obj, VALUE base_klass, struct dump_arg *arg)
int w_obj_each (ID id, VALUE value, struct dump_call_arg *arg)
void w_ivar (st_table *tbl, struct dump_call_arg *arg)
VALUE dump (struct dump_call_arg *arg)
VALUE dump_ensure (struct dump_arg *arg)
VALUE marshal_dump (int argc, VALUE *argv)
VALUE r_object (struct load_arg *arg)
int r_byte (struct load_arg *arg)
void long_toobig (int size)
long r_long (struct load_arg *arg)
VALUE r_bytes0 (long len, struct load_arg *arg)
ID r_symlink (struct load_arg *arg)
ID r_symreal (struct load_arg *arg)
ID r_symbol (struct load_arg *arg)
char * r_unique (struct load_arg *arg)
VALUE r_string (struct load_arg *arg)
VALUE r_entry (VALUE v, struct load_arg *arg)
void r_ivar (VALUE obj, struct load_arg *arg)
VALUE path2class (char *path)
VALUE path2module (char *path)
VALUE r_object0 (struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod)
VALUE load (struct load_arg *arg)
VALUE load_ensure (struct load_arg *arg)
VALUE marshal_load (int argc, VALUE *argv)
void Init_marshal ()
VALUE rb_marshal_dump (VALUE obj, VALUE port)
VALUE rb_marshal_load (VALUE port)

Variables

ID s_dump
ID s_load
ID s_mdump
ID s_mload
ID s_dump_data
ID s_load_data
ID s_alloc
ID s_getc
ID s_read
ID s_write
ID s_binmode


Define Documentation

#define BITSPERSHORT   (2*CHAR_BIT)
 

Definition at line 26 of file marshal.c.

#define FLOAT_DIG   17
 

Definition at line 293 of file marshal.c.

Referenced by w_float().

#define load_mantissa d,
buf,
len   )     (d)
 

Definition at line 286 of file marshal.c.

Referenced by r_object0().

#define MARSHAL_MAJOR   4
 

Definition at line 51 of file marshal.c.

Referenced by Init_marshal(), marshal_dump(), and marshal_load().

#define MARSHAL_MINOR   8
 

Definition at line 52 of file marshal.c.

Referenced by Init_marshal(), marshal_dump(), and marshal_load().

#define r_bytes arg   )     r_bytes0(r_long(arg), (arg))
 

Definition at line 865 of file marshal.c.

Referenced by r_object0(), r_string(), and r_symreal().

#define save_mantissa d,
buf   )     0
 

Definition at line 287 of file marshal.c.

Referenced by w_float().

#define SHORTDN  )     RSHIFT(x,BITSPERSHORT)
 

Definition at line 28 of file marshal.c.

Referenced by shortlen(), and w_object().

#define SHORTLEN  )     shortlen((x),d)
 

Definition at line 48 of file marshal.c.

Referenced by w_object().

#define SHORTMASK   ((1<<BITSPERSHORT)-1)
 

Definition at line 27 of file marshal.c.

Referenced by w_object().

#define SIGN_EXTEND_CHAR  )     ((((unsigned char)(c)) ^ 128) - 128)
 

Definition at line 828 of file marshal.c.

Referenced by r_long().

#define TYPE_ARRAY   '['
 

Definition at line 69 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_BIGNUM   'l'
 

Definition at line 66 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_CLASS   'c'
 

Definition at line 74 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_DATA   'd'
 

Definition at line 62 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_EXTENDED   'e'
 

Definition at line 59 of file marshal.c.

Referenced by r_object0(), and w_extended().

#define TYPE_FALSE   'F'
 

Definition at line 56 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_FIXNUM   'i'
 

Definition at line 57 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_FLOAT   'f'
 

Definition at line 65 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_HASH   '{'
 

Definition at line 70 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_HASH_DEF   '}'
 

Definition at line 71 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_IVAR   'I'
 

Definition at line 80 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_LINK   '@'
 

Definition at line 81 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_MODULE   'm'
 

Definition at line 75 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_MODULE_OLD   'M'
 

Definition at line 73 of file marshal.c.

Referenced by r_object0().

#define TYPE_NIL   '0'
 

Definition at line 54 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_OBJECT   'o'
 

Definition at line 61 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_REGEXP   '/'
 

Definition at line 68 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_STRING   '"'
 

Definition at line 67 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_STRUCT   'S'
 

Definition at line 72 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_SYMBOL   ':'
 

Definition at line 77 of file marshal.c.

Referenced by r_object0(), and w_symbol().

#define TYPE_SYMLINK   ';'
 

Definition at line 78 of file marshal.c.

Referenced by r_object0(), r_symbol(), and w_symbol().

#define TYPE_TRUE   'T'
 

Definition at line 55 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_UCLASS   'C'
 

Definition at line 60 of file marshal.c.

Referenced by r_object0(), and w_uclass().

#define TYPE_USERDEF   'u'
 

Definition at line 63 of file marshal.c.

Referenced by r_object0(), and w_object().

#define TYPE_USRMARSHAL   'U'
 

Definition at line 64 of file marshal.c.

Referenced by r_object0(), and w_object().


Function Documentation

VALUE class2path VALUE  klass  )  [static]
 

Definition at line 102 of file marshal.c.

References rb_class_path(), rb_class_real(), rb_eTypeError, rb_path2class(), rb_raise(), RSTRING, T_CLASS, TYPE, and VALUE.

Referenced by w_class(), w_object(), and w_uclass().

VALUE dump struct dump_call_arg arg  )  [static]
 

Definition at line 678 of file marshal.c.

References rb_io_write(), rb_str_resize(), and w_object().

Referenced by marshal_dump().

VALUE dump_ensure struct dump_arg arg  )  [static]
 

Definition at line 690 of file marshal.c.

References OBJ_TAINT, and st_free_table().

Referenced by marshal_dump().

int hash_each VALUE  key,
VALUE  value,
struct dump_call_arg arg
[static]
 

Definition at line 359 of file marshal.c.

References ST_CONTINUE, VALUE, and w_object().

Referenced by w_object().

void Init_marshal void   ) 
 

Definition at line 1468 of file marshal.c.

References INT2FIX, marshal_dump(), marshal_load(), MARSHAL_MAJOR, MARSHAL_MINOR, rb_define_const(), rb_define_module(), rb_define_module_function(), rb_intern(), s_alloc, s_binmode, s_dump, s_dump_data, s_getc, s_load, s_load_data, s_mdump, s_mload, s_read, s_write, and VALUE.

Referenced by rb_call_inits().

VALUE load struct load_arg arg  )  [static]
 

Definition at line 1360 of file marshal.c.

References r_object().

Referenced by dln_load(), and marshal_load().

VALUE load_ensure struct load_arg arg  )  [static]
 

Definition at line 1367 of file marshal.c.

References st_free_table().

Referenced by marshal_load().

void long_toobig int  size  )  [static]
 

Definition at line 816 of file marshal.c.

References rb_eTypeError, and rb_raise().

Referenced by r_long().

VALUE marshal_dump int  argc,
VALUE argv
[static]
 

Definition at line 728 of file marshal.c.

References dump_call_arg::arg, dump_arg::data, dump_arg::dest, dump(), dump_ensure(), FIX2INT, FIXNUM_P, dump_call_arg::limit, MARSHAL_MAJOR, MARSHAL_MINOR, NIL_P, NUM2INT, dump_call_arg::obj, Qfalse, Qnil, rb_ensure(), rb_eTypeError, rb_funcall2(), rb_raise(), rb_respond_to(), rb_scan_args(), rb_str_buf_new(), s_binmode, s_write, st_init_numtable(), dump_arg::str, dump_arg::symbols, dump_arg::taint, VALUE, and w_byte().

Referenced by Init_marshal(), and rb_marshal_dump().

VALUE marshal_load int  argc,
VALUE argv
[static]
 

Definition at line 1386 of file marshal.c.

References load_arg::data, load(), load_ensure(), MARSHAL_MAJOR, MARSHAL_MINOR, NIL_P, OBJ_TAINTED, load_arg::offset, load_arg::proc, Qtrue, r_byte(), rb_ensure(), rb_eTypeError, rb_funcall2(), rb_hash_new(), rb_intern(), rb_raise(), rb_respond_to(), rb_scan_args(), rb_warn(), RTEST, ruby_verbose, s_binmode, s_getc, s_read, load_arg::src, st_init_numtable(), StringValue, load_arg::symbols, load_arg::taint, and VALUE.

Referenced by Init_marshal(), and rb_marshal_load().

VALUE path2class char *  path  )  [static]
 

Definition at line 974 of file marshal.c.

References rb_eArgError, rb_path2class(), rb_raise(), T_CLASS, TYPE, and VALUE.

Referenced by r_object0().

VALUE path2module char *  path  )  [static]
 

Definition at line 986 of file marshal.c.

References rb_eArgError, rb_path2class(), rb_raise(), T_MODULE, TYPE, and VALUE.

Referenced by r_object0().

int r_byte struct load_arg arg  )  [static]
 

Definition at line 793 of file marshal.c.

References FIX2INT, NIL_P, rb_eArgError, rb_eof_error(), rb_funcall2(), rb_raise(), RSTRING, s_getc, T_STRING, TYPE, and VALUE.

Referenced by marshal_load(), r_long(), r_object0(), and r_symbol().

VALUE r_bytes0 long  len,
struct load_arg arg
[static]
 

Definition at line 868 of file marshal.c.

References LONG2NUM, NIL_P, OBJ_TAINTED, Qtrue, rb_eArgError, rb_funcall2(), rb_raise(), rb_str_new(), RSTRING, s_read, StringValue, T_STRING, TYPE, and VALUE.

Referenced by r_object0().

VALUE r_entry VALUE  v,
struct load_arg arg
[static]
 

Definition at line 947 of file marshal.c.

References INT2FIX, OBJ_TAINT, rb_hash_aset(), RHASH, and VALUE.

Referenced by r_object0().

void r_ivar VALUE  obj,
struct load_arg arg
[static]
 

Definition at line 957 of file marshal.c.

References ID, r_long(), r_object(), r_symbol(), rb_ivar_set(), and VALUE.

Referenced by r_object0().

long r_long struct load_arg arg  )  [static]
 

Definition at line 832 of file marshal.c.

References long_toobig(), r_byte(), and SIGN_EXTEND_CHAR.

Referenced by r_ivar(), r_object0(), and r_symlink().

VALUE r_object struct load_arg arg  )  [static]
 

Definition at line 1353 of file marshal.c.

References Qnil, and r_object0().

Referenced by load(), r_ivar(), and r_object0().

VALUE r_object0 struct load_arg arg,
VALUE  proc,
int *  ivp,
VALUE  extmod
[static]
 

Definition at line 998 of file marshal.c.

References ALLOC_N, BDIGIT, FL_SINGLETON, FL_TEST, ID, ID2SYM, load_mantissa, LONG2FIX, MEMCPY, MEMZERO, NEWOBJ, NIL_P, OBJSETUP, path2class(), path2module(), Qfalse, Qnil, Qtrue, r_byte(), r_bytes, r_bytes0(), r_entry(), r_ivar(), r_long(), r_object(), r_string(), r_symbol(), r_symlink(), r_symreal(), r_unique(), RARRAY, rb_ary_new2(), rb_ary_pop(), rb_ary_push(), rb_big_norm(), rb_cBignum, rb_class2name(), rb_class_inherited_p(), rb_eArgError, rb_eTypeError, rb_extend_object(), rb_float_new(), rb_funcall(), rb_hash_aref(), rb_hash_aset(), rb_hash_new(), rb_id2name(), rb_intern(), rb_obj_alloc(), rb_path2class(), rb_raise(), rb_reg_new(), rb_respond_to(), rb_special_const_p(), rb_struct_alloc(), rb_struct_aset(), rb_struct_s_members(), rb_warn(), RBASIC, RHASH, RSTRING, RTEST, s_alloc, s_load, s_load_data, s_mload, SIZEOF_BDIGITS, strtod, SYM2ID, T_BIGNUM, T_CLASS, T_DATA, T_MODULE, T_OBJECT, TYPE, TYPE_ARRAY, TYPE_BIGNUM, TYPE_CLASS, TYPE_DATA, TYPE_EXTENDED, TYPE_FALSE, TYPE_FIXNUM, TYPE_FLOAT, TYPE_HASH, TYPE_HASH_DEF, TYPE_IVAR, TYPE_LINK, TYPE_MODULE, TYPE_MODULE_OLD, TYPE_NIL, TYPE_OBJECT, TYPE_REGEXP, TYPE_STRING, TYPE_STRUCT, TYPE_SYMBOL, TYPE_SYMLINK, TYPE_TRUE, TYPE_UCLASS, TYPE_USERDEF, TYPE_USRMARSHAL, and VALUE.

Referenced by r_object().

VALUE r_string struct load_arg arg  )  [static]
 

Definition at line 940 of file marshal.c.

References r_bytes.

Referenced by r_object0().

ID r_symbol struct load_arg arg  )  [static]
 

Definition at line 923 of file marshal.c.

References r_byte(), r_symlink(), r_symreal(), and TYPE_SYMLINK.

Referenced by r_ivar(), r_object0(), and r_unique().

ID r_symlink struct load_arg arg  )  [static]
 

Definition at line 898 of file marshal.c.

References ID, r_long(), rb_eArgError, rb_raise(), and st_lookup().

Referenced by r_object0(), and r_symbol().

ID r_symreal struct load_arg arg  )  [static]
 

Definition at line 911 of file marshal.c.

References ID, r_bytes, rb_intern(), RSTRING, and st_insert().

Referenced by r_object0(), and r_symbol().

char* r_unique struct load_arg arg  )  [static]
 

Definition at line 933 of file marshal.c.

References r_symbol(), and rb_id2name().

Referenced by r_object0().

int shortlen long  len,
BDIGIT *  ds
[static]
 

Definition at line 34 of file marshal.c.

References BDIGIT, and SHORTDN.

void w_byte char  c,
struct dump_arg arg
[static]
 

Definition at line 137 of file marshal.c.

References w_nbyte().

Referenced by marshal_dump(), w_class(), w_extended(), w_long(), w_object(), w_short(), w_symbol(), and w_uclass().

void w_bytes char *  s,
int  n,
struct dump_arg arg
[static]
 

Definition at line 145 of file marshal.c.

References w_long(), and w_nbyte().

Referenced by w_float(), w_object(), and w_symbol().

void w_class int  type,
VALUE  obj,
struct dump_arg arg,
int  check
[static]
 

Definition at line 392 of file marshal.c.

References class2path(), CLASS_OF, rb_class_real(), RSTRING, VALUE, w_byte(), w_extended(), and w_unique().

Referenced by w_object().

void w_extended VALUE  klass,
struct dump_arg arg,
int  check
[static]
 

Definition at line 369 of file marshal.c.

References BUILTIN_TYPE, FL_SINGLETON, FL_TEST, rb_class2name(), rb_eTypeError, rb_raise(), RBASIC, RCLASS, T_ICLASS, TYPE_EXTENDED, VALUE, w_byte(), and w_unique().

Referenced by w_class(), and w_uclass().

void w_float double  d,
struct dump_arg arg
[static]
 

Definition at line 297 of file marshal.c.

References FLOAT_DIG, isinf(), isnan(), save_mantissa, and w_bytes().

Referenced by w_object().

void w_ivar st_table tbl,
struct dump_call_arg arg
[static]
 

Definition at line 434 of file marshal.c.

References st_data_t, st_foreach_safe(), w_long(), and w_obj_each().

Referenced by w_object().

void w_long long  ,
struct dump_arg
[static]
 

Definition at line 164 of file marshal.c.

References rb_eTypeError, rb_raise(), RSHIFT, and w_byte().

Referenced by w_bytes(), w_ivar(), w_object(), and w_symbol().

void w_nbyte char *  s,
int  n,
struct dump_arg arg
[static]
 

Definition at line 122 of file marshal.c.

References OBJ_TAINT, rb_io_write(), rb_str_buf_cat(), rb_str_resize(), RSTRING, and VALUE.

Referenced by w_byte(), and w_bytes().

int w_obj_each ID  id,
VALUE  value,
struct dump_call_arg arg
[static]
 

Definition at line 423 of file marshal.c.

References ID, ST_CONTINUE, VALUE, w_object(), and w_symbol().

Referenced by w_ivar().

void w_object VALUE  ,
struct dump_arg ,
int 
[static]
 

Definition at line 448 of file marshal.c.

References dump_call_arg::arg, BDIGIT, BUILTIN_TYPE, class2path(), FIX2INT, FIX2LONG, FIXNUM_P, FL_SINGLETON, FL_TEST, FL_USER2, hash_each(), INT2NUM, dump_call_arg::limit, NIL_P, OBJ_TAINTED, Qfalse, Qnil, Qtrue, RARRAY, rb_cArray, rb_cHash, rb_cRegexp, rb_cString, rb_eArgError, rb_eTypeError, rb_funcall(), rb_generic_ivar_table(), rb_hash_foreach(), rb_int2big(), rb_obj_classname(), rb_raise(), rb_reg_options(), rb_respond_to(), rb_struct_members(), RBIGNUM, RFLOAT, RHASH, ROBJECT, RREGEXP, RSHIFT, RSTRING, RSTRUCT, s_dump, s_dump_data, s_mdump, SHORTDN, SHORTLEN, SHORTMASK, SIZEOF_BDIGITS, SIZEOF_SHORT, st_add_direct(), st_data_t, st_lookup(), SYM2ID, SYMBOL_P, T_ARRAY, T_BIGNUM, T_CLASS, T_DATA, T_FLOAT, T_HASH, T_MODULE, T_OBJECT, T_REGEXP, T_STRING, T_STRUCT, TYPE, TYPE_ARRAY, TYPE_BIGNUM, TYPE_CLASS, TYPE_DATA, TYPE_FALSE, TYPE_FIXNUM, TYPE_FLOAT, TYPE_HASH, TYPE_HASH_DEF, TYPE_IVAR, TYPE_LINK, TYPE_MODULE, TYPE_NIL, TYPE_OBJECT, TYPE_REGEXP, TYPE_STRING, TYPE_STRUCT, TYPE_TRUE, TYPE_USERDEF, TYPE_USRMARSHAL, VALUE, w_byte(), w_bytes(), w_class(), w_float(), w_ivar(), w_long(), w_short(), w_symbol(), and w_uclass().

Referenced by dump(), hash_each(), and w_obj_each().

void w_short int  x,
struct dump_arg arg
[static]
 

Definition at line 155 of file marshal.c.

References w_byte().

Referenced by w_object().

void w_symbol ID  id,
struct dump_arg arg
[static]