Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Functions
marshal.c File Reference
`#include "ruby/ruby.h"`
`#include "ruby/io.h"`
`#include "internal.h"`
`#include "ruby/st.h"`
`#include "ruby/util.h"`
`#include "encindex.h"`
`#include "id_table.h"`
`#include <math.h>`

Go to the source code of this file.

## Data Structures
struct | marshal_compat_t
struct | dump_arg
struct | dump_call_arg
struct | w_ivar_arg
struct | load_arg

## Macros
#define | BITSPERSHORT (2*CHAR_BIT)
#define | SHORTMASK ((1<<BITSPERSHORT)-1)
#define | SHORTDN(x) RSHIFT((x),BITSPERSHORT)
#define | SHORTLEN(x) (x)
#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 | name_s_dump "_dump"
#define | name_s_load "_load"
#define | name_s_mdump "marshal_dump"
#define | name_s_mload "marshal_load"
#define | name_s_dump_data "_dump_data"
#define | name_s_load_data "_load_data"
#define | name_s_alloc "_alloc"
#define | name_s_call "call"
#define | name_s_getbyte "getbyte"
#define | name_s_read "read"
#define | name_s_write "write"
#define | name_s_binmode "binmode"
#define | name_s_encoding_short "E"
#define | dump_funcall(arg, obj, sym, argc, argv) check_userdump_arg(obj, sym, argc, argv, arg, name_##sym)
#define | dump_check_funcall(arg, obj, sym, argc, argv) check_dump_arg(rb_check_funcall(obj, sym, argc, argv), arg, name_##sym)
#define | w_cstr(s, arg) w_bytes((s), strlen(s), (arg))
#define | load_mantissa(d, buf, len) (d)
#define | FLOAT_DIG 17
#define | SINGLETON_DUMP_UNABLE_P(klass)
#define | to_be_skipped_id(id) (id == rb_id_encoding() || id == s_encoding_short || !rb_id2str(id))
#define | load_funcall(arg, obj, sym, argc, argv) check_load_arg(rb_funcallv(obj, sym, argc, argv), arg, name_##sym)
#define | r_entry(v, arg) r_entry0((v), (arg)->data->num_entries, (arg))
#define | r_bytes(arg) r_bytes0(r_long(arg), (arg))
#define | path2module(path) must_be_module(rb_path_to_class(path), path)
#define | prohibit_ivar(type, str)
#define | rb_intern(str) rb_intern_const(str)
#define | set_id(sym) sym = rb_intern_const(name_##sym)
#define | RUBY_UNTYPED_DATA_WARNING 0

## Functions
void | rb_marshal_define_compat (VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
int | ruby_marshal_write_long (long x, char *buf)
| NORETURN (static inline void io_needed(void))
| NORETURN (static void too_short(void))
| NORETURN (static void long_toobig(int size))
long | ruby_marshal_read_long (const char **buf, long len)
void | Init_marshal (void)
VALUE | rb_marshal_dump (VALUE obj, VALUE port)
VALUE | rb_marshal_load (VALUE port)

## Macro Definition Documentation

## ◆ BITSPERSHORT

#define BITSPERSHORT (2*CHAR_BIT)

Definition at line 28 of file marshal.c.

## ◆ dump_check_funcall

#define dump_check_funcall | ( |  | arg,
|  |  | obj,
|  |  | sym,
|  |  | argc,
|  |  | argv
| ) |  | check_dump_arg(rb_check_funcall(obj, sym, argc, argv), arg, name_##sym)

Definition at line 192 of file marshal.c.

## ◆ dump_funcall

#define dump_funcall | ( |  | arg,
|  |  | obj,
|  |  | sym,
|  |  | argc,
|  |  | argv
| ) |  | check_userdump_arg(obj, sym, argc, argv, arg, name_##sym)

Definition at line 190 of file marshal.c.

## ◆ FLOAT_DIG

#define FLOAT_DIG 17

Definition at line 396 of file marshal.c.

## ◆ load_funcall

#define load_funcall | ( |  | arg,
|  |  | obj,
|  |  | sym,
|  |  | argc,
|  |  | argv
| ) |  | check_load_arg(rb_funcallv(obj, sym, argc, argv), arg, name_##sym)

Definition at line 1122 of file marshal.c.

## ◆ load_mantissa

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

Definition at line 390 of file marshal.c.

## ◆ MARSHAL_MAJOR

#define MARSHAL_MAJOR 4

Definition at line 51 of file marshal.c.

## ◆ MARSHAL_MINOR

#define MARSHAL_MINOR 8

Definition at line 52 of file marshal.c.

## ◆ name_s_alloc

#define name_s_alloc "_alloc"

Definition at line 94 of file marshal.c.

## ◆ name_s_binmode

#define name_s_binmode "binmode"

Definition at line 99 of file marshal.c.

## ◆ name_s_call

#define name_s_call "call"

Definition at line 95 of file marshal.c.

## ◆ name_s_dump

#define name_s_dump "_dump"

Definition at line 88 of file marshal.c.

## ◆ name_s_dump_data

#define name_s_dump_data "_dump_data"

Definition at line 92 of file marshal.c.

## ◆ name_s_encoding_short

#define name_s_encoding_short "E"

Definition at line 100 of file marshal.c.

## ◆ name_s_getbyte

#define name_s_getbyte "getbyte"

Definition at line 96 of file marshal.c.

## ◆ name_s_load

#define name_s_load "_load"

Definition at line 89 of file marshal.c.

## ◆ name_s_load_data

#define name_s_load_data "_load_data"

Definition at line 93 of file marshal.c.

## ◆ name_s_mdump

#define name_s_mdump "marshal_dump"

Definition at line 90 of file marshal.c.

## ◆ name_s_mload

#define name_s_mload "marshal_load"

Definition at line 91 of file marshal.c.

## ◆ name_s_read

#define name_s_read "read"

Definition at line 97 of file marshal.c.

## ◆ name_s_write

#define name_s_write "write"

Definition at line 98 of file marshal.c.

## ◆ path2module

#define path2module | ( |  | path | ) | must_be_module(rb_path_to_class(path), path)

Definition at line 1556 of file marshal.c.

## ◆ prohibit_ivar

#define prohibit_ivar | ( |  | type,
|  |  | str
| ) |  |

Value:
do { \
if (!ivp || !*ivp) break; \
rb_raise(rb_eTypeError, \
"can't override instance variable of "type" `%"PRIsVALUE"'", \
(str)); \
} while (0)

Definition at line 1607 of file marshal.c.

## ◆ r_bytes

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

Definition at line 1335 of file marshal.c.

## ◆ r_entry

#define r_entry | ( |  | v,
|  |  | arg
| ) |  | r_entry0((v), (arg)->data->num_entries, (arg))

Definition at line 1157 of file marshal.c.

## ◆ rb_intern

#define rb_intern | ( |  | str | ) | rb_intern_const(str)

## ◆ RUBY_UNTYPED_DATA_WARNING

#define RUBY_UNTYPED_DATA_WARNING 0

## ◆ set_id

#define set_id | ( |  | sym | ) | sym = rb_intern_const(name_##sym)

## ◆ SHORTDN

#define SHORTDN | ( |  | x | ) | RSHIFT((x),BITSPERSHORT)

Definition at line 30 of file marshal.c.

## ◆ SHORTLEN

#define SHORTLEN | ( |  | x | ) | (x)

Definition at line 33 of file marshal.c.

## ◆ SHORTMASK

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

Definition at line 29 of file marshal.c.

## ◆ SINGLETON_DUMP_UNABLE_P

#define SINGLETON_DUMP_UNABLE_P | ( |  | klass | ) |

Value:
(rb_id_table_size(RCLASS_M_TBL(klass)) > 0 || \
(RCLASS_IV_TBL(klass) && RCLASS_IV_TBL(klass)->num_entries > 1))

Definition at line 506 of file marshal.c.

## ◆ to_be_skipped_id

#define to_be_skipped_id | ( |  | id | ) | (id == rb_id_encoding() || id == s_encoding_short || !rb_id2str(id))

Definition at line 560 of file marshal.c.

## ◆ TYPE_ARRAY

#define TYPE_ARRAY '['

Definition at line 69 of file marshal.c.

## ◆ TYPE_BIGNUM

#define TYPE_BIGNUM 'l'

Definition at line 66 of file marshal.c.

## ◆ TYPE_CLASS

#define TYPE_CLASS 'c'

Definition at line 74 of file marshal.c.

## ◆ TYPE_DATA

#define TYPE_DATA 'd'

Definition at line 62 of file marshal.c.

## ◆ TYPE_EXTENDED

#define TYPE_EXTENDED 'e'

Definition at line 59 of file marshal.c.

## ◆ TYPE_FALSE

#define TYPE_FALSE 'F'

Definition at line 56 of file marshal.c.

## ◆ TYPE_FIXNUM

#define TYPE_FIXNUM 'i'

Definition at line 57 of file marshal.c.

## ◆ TYPE_FLOAT

#define TYPE_FLOAT 'f'

Definition at line 65 of file marshal.c.

## ◆ TYPE_HASH

#define TYPE_HASH '{'

Definition at line 70 of file marshal.c.

## ◆ TYPE_HASH_DEF

#define TYPE_HASH_DEF '}'

Definition at line 71 of file marshal.c.

## ◆ TYPE_IVAR

#define TYPE_IVAR 'I'

Definition at line 80 of file marshal.c.

## ◆ TYPE_LINK

#define TYPE_LINK '@'

Definition at line 81 of file marshal.c.

## ◆ TYPE_MODULE

#define TYPE_MODULE 'm'

Definition at line 75 of file marshal.c.

## ◆ TYPE_MODULE_OLD

#define TYPE_MODULE_OLD 'M'

Definition at line 73 of file marshal.c.

## ◆ TYPE_NIL

#define TYPE_NIL '0'

Definition at line 54 of file marshal.c.

## ◆ TYPE_OBJECT

#define TYPE_OBJECT 'o'

Definition at line 61 of file marshal.c.

## ◆ TYPE_REGEXP

#define TYPE_REGEXP '/'

Definition at line 68 of file marshal.c.

## ◆ TYPE_STRING

#define TYPE_STRING '"'

Definition at line 67 of file marshal.c.

## ◆ TYPE_STRUCT

#define TYPE_STRUCT 'S'

Definition at line 72 of file marshal.c.

## ◆ TYPE_SYMBOL

#define TYPE_SYMBOL ':'

Definition at line 77 of file marshal.c.

## ◆ TYPE_SYMLINK

#define TYPE_SYMLINK ';'

Definition at line 78 of file marshal.c.

## ◆ TYPE_TRUE

#define TYPE_TRUE 'T'

Definition at line 55 of file marshal.c.

## ◆ TYPE_UCLASS

#define TYPE_UCLASS 'C'

Definition at line 60 of file marshal.c.

## ◆ TYPE_USERDEF

#define TYPE_USERDEF 'u'

Definition at line 63 of file marshal.c.

## ◆ TYPE_USRMARSHAL

#define TYPE_USRMARSHAL 'U'

Definition at line 64 of file marshal.c.

## ◆ w_cstr

#define w_cstr | ( |  | s,
|  |  | arg
| ) |  | w_bytes((s), strlen(s), (arg))

Definition at line 286 of file marshal.c.

## Function Documentation

## ◆ Init_marshal()

void Init_marshal | ( | void |  | ) |

Definition at line 2265 of file marshal.c.

References rb_define_module(), and set_id.

## ◆ NORETURN() [1/3]

NORETURN | ( | static inline void | io_neededvoid | ) |

## ◆ NORETURN() [2/3]

NORETURN | ( | static void | long_toobigint size | ) |

## ◆ NORETURN() [3/3]

NORETURN | ( | static void | too_shortvoid | ) |

## ◆ rb_marshal_define_compat()

void rb_marshal_define_compat | ( | VALUE | newclass,
|  | VALUE | oldclass,
|  | VALUE(*)(VALUE) | dumper,
|  | VALUE(*)(VALUE, VALUE) | loader
| ) |  |

Definition at line 133 of file marshal.c.

References ALLOC, marshal_compat_t::dumper, marshal_compat_t::loader, marshal_compat_t::newclass, marshal_compat_t::oldclass, Qnil, rb_eTypeError, rb_get_alloc_func(), rb_raise(), and st_insert().

## ◆ rb_marshal_dump()

VALUE rb_marshal_dump | ( | VALUE | obj,
|  | VALUE | port
| ) |  |

Definition at line 2310 of file marshal.c.

## ◆ rb_marshal_load()

VALUE rb_marshal_load | ( | VALUE | port | ) |

Definition at line 2316 of file marshal.c.

## ◆ ruby_marshal_read_long()

long ruby_marshal_read_long | ( | const char ** | buf,
|  | long | len
| ) |  |

Definition at line 1266 of file marshal.c.

References arg, buf, len, memset(), rb_setup_fake_str(), and src.

## ◆ ruby_marshal_write_long()

int ruby_marshal_write_long | ( | long | x,
|  | char * | buf
| ) |  |

Definition at line 307 of file marshal.c.

References buf, char, i, int, and RSHIFT.

rb_id_table_size
size_t rb_id_table_size(const struct rb_id_table *tbl)
Definition: id_table.c:117
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
RCLASS_M_TBL
#define RCLASS_M_TBL(c)
Definition: internal.h:1069
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
RCLASS_IV_TBL
#define RCLASS_IV_TBL(c)
Definition: internal.h:1066
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39