Ruby: marshal.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Functions
marshal.c File Reference
`#include "ruby/internal/config.h"`
`#include <math.h>`
`#include "encindex.h"`
`#include "id_table.h"`
`#include "internal.h"`
`#include "internal/array.h"`
`#include "internal/bignum.h"`
`#include "internal/class.h"`
`#include "internal/encoding.h"`
`#include "internal/error.h"`
`#include "internal/hash.h"`
`#include "internal/object.h"`
`#include "internal/struct.h"`
`#include "internal/util.h"`
`#include "internal/vm.h"`
`#include "ruby/io.h"`
`#include "ruby/ruby.h"`
`#include "ruby/st.h"`
`#include "ruby/util.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 | name_s_ruby2_keywords_flag "K"
#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 || id == s_ruby2_keywords_flag || !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 | 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)
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 40 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 205 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 203 of file marshal.c.

## ◆ FLOAT_DIG

#define FLOAT_DIG 17

Definition at line 409 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 1154 of file marshal.c.

## ◆ load_mantissa

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

Definition at line 403 of file marshal.c.

## ◆ MARSHAL_MAJOR

#define MARSHAL_MAJOR 4

Definition at line 63 of file marshal.c.

## ◆ MARSHAL_MINOR

#define MARSHAL_MINOR 8

Definition at line 64 of file marshal.c.

## ◆ name_s_alloc

#define name_s_alloc "_alloc"

Definition at line 106 of file marshal.c.

## ◆ name_s_binmode

#define name_s_binmode "binmode"

Definition at line 111 of file marshal.c.

## ◆ name_s_call

#define name_s_call "call"

Definition at line 107 of file marshal.c.

## ◆ name_s_dump

#define name_s_dump "_dump"

Definition at line 100 of file marshal.c.

## ◆ name_s_dump_data

#define name_s_dump_data "_dump_data"

Definition at line 104 of file marshal.c.

## ◆ name_s_encoding_short

#define name_s_encoding_short "E"

Definition at line 112 of file marshal.c.

## ◆ name_s_getbyte

#define name_s_getbyte "getbyte"

Definition at line 108 of file marshal.c.

## ◆ name_s_load

#define name_s_load "_load"

Definition at line 101 of file marshal.c.

## ◆ name_s_load_data

#define name_s_load_data "_load_data"

Definition at line 105 of file marshal.c.

## ◆ name_s_mdump

#define name_s_mdump "marshal_dump"

Definition at line 102 of file marshal.c.

## ◆ name_s_mload

#define name_s_mload "marshal_load"

Definition at line 103 of file marshal.c.

## ◆ name_s_read

#define name_s_read "read"

Definition at line 109 of file marshal.c.

## ◆ name_s_ruby2_keywords_flag

#define name_s_ruby2_keywords_flag "K"

Definition at line 113 of file marshal.c.

## ◆ name_s_write

#define name_s_write "write"

Definition at line 110 of file marshal.c.

## ◆ path2module

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

Definition at line 1628 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)
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
PRIsVALUE
#define PRIsVALUE
Definition: function.c:10
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:1057
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56

Definition at line 1679 of file marshal.c.

## ◆ r_bytes

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

Definition at line 1368 of file marshal.c.

## ◆ r_entry

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

Definition at line 1190 of file marshal.c.

## ◆ 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 42 of file marshal.c.

## ◆ SHORTLEN

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

Definition at line 45 of file marshal.c.

## ◆ SHORTMASK

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

Definition at line 41 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))
rb_id_table_size
size_t rb_id_table_size(const struct rb_id_table *tbl)
Definition: id_table.c:118
RCLASS_IV_TBL
#define RCLASS_IV_TBL(c)
Definition: class.h:77
RCLASS_M_TBL
#define RCLASS_M_TBL(c)
Definition: class.h:80

Definition at line 519 of file marshal.c.

## ◆ to_be_skipped_id

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

Definition at line 576 of file marshal.c.

## ◆ TYPE_ARRAY

#define TYPE_ARRAY '['

Definition at line 81 of file marshal.c.

## ◆ TYPE_BIGNUM

#define TYPE_BIGNUM 'l'

Definition at line 78 of file marshal.c.

## ◆ TYPE_CLASS

#define TYPE_CLASS 'c'

Definition at line 86 of file marshal.c.

## ◆ TYPE_DATA

#define TYPE_DATA 'd'

Definition at line 74 of file marshal.c.

## ◆ TYPE_EXTENDED

#define TYPE_EXTENDED 'e'

Definition at line 71 of file marshal.c.

## ◆ TYPE_FALSE

#define TYPE_FALSE 'F'

Definition at line 68 of file marshal.c.

## ◆ TYPE_FIXNUM

#define TYPE_FIXNUM 'i'

Definition at line 69 of file marshal.c.

## ◆ TYPE_FLOAT

#define TYPE_FLOAT 'f'

Definition at line 77 of file marshal.c.

## ◆ TYPE_HASH

#define TYPE_HASH '{'

Definition at line 82 of file marshal.c.

## ◆ TYPE_HASH_DEF

#define TYPE_HASH_DEF '}'

Definition at line 83 of file marshal.c.

## ◆ TYPE_IVAR

#define TYPE_IVAR 'I'

Definition at line 92 of file marshal.c.

## ◆ TYPE_LINK

#define TYPE_LINK '@'

Definition at line 93 of file marshal.c.

## ◆ TYPE_MODULE

#define TYPE_MODULE 'm'

Definition at line 87 of file marshal.c.

## ◆ TYPE_MODULE_OLD

#define TYPE_MODULE_OLD 'M'

Definition at line 85 of file marshal.c.

## ◆ TYPE_NIL

#define TYPE_NIL '0'

Definition at line 66 of file marshal.c.

## ◆ TYPE_OBJECT

#define TYPE_OBJECT 'o'

Definition at line 73 of file marshal.c.

## ◆ TYPE_REGEXP

#define TYPE_REGEXP '/'

Definition at line 80 of file marshal.c.

## ◆ TYPE_STRING

#define TYPE_STRING '"'

Definition at line 79 of file marshal.c.

## ◆ TYPE_STRUCT

#define TYPE_STRUCT 'S'

Definition at line 84 of file marshal.c.

## ◆ TYPE_SYMBOL

#define TYPE_SYMBOL ':'

Definition at line 89 of file marshal.c.

## ◆ TYPE_SYMLINK

#define TYPE_SYMLINK ';'

Definition at line 90 of file marshal.c.

## ◆ TYPE_TRUE

#define TYPE_TRUE 'T'

Definition at line 67 of file marshal.c.

## ◆ TYPE_UCLASS

#define TYPE_UCLASS 'C'

Definition at line 72 of file marshal.c.

## ◆ TYPE_USERDEF

#define TYPE_USERDEF 'u'

Definition at line 75 of file marshal.c.

## ◆ TYPE_USRMARSHAL

#define TYPE_USRMARSHAL 'U'

Definition at line 76 of file marshal.c.

## ◆ w_cstr

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

Definition at line 299 of file marshal.c.

## Function Documentation

## ◆ Init_marshal()

void Init_marshal | ( | void |  | ) |

Definition at line 2345 of file marshal.c.

## ◆ rb_marshal_define_compat()

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

Definition at line 146 of file marshal.c.

Referenced by Init_Complex(), Init_Encoding(), Init_Exception(), Init_Range(), Init_Rational(), Init_vm_backtrace(), and InitVM_process().

## ◆ rb_marshal_dump()

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

Definition at line 2388 of file marshal.c.

## ◆ rb_marshal_load()

VALUE rb_marshal_load | ( | VALUE | port | ) |

Definition at line 2394 of file marshal.c.

## ◆ ruby_marshal_read_long()

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

Definition at line 1299 of file marshal.c.

## ◆ ruby_marshal_write_long()

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

Definition at line 320 of file marshal.c.