Ruby: pack.c File Reference

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

Data Structures | Macros | Functions
pack.c File Reference
`#include "ruby/internal/config.h"`
`#include <ctype.h>`
`#include <errno.h>`
`#include <float.h>`
`#include <sys/types.h>`
`#include "internal.h"`
`#include "internal/array.h"`
`#include "internal/bits.h"`
`#include "internal/string.h"`
`#include "internal/symbol.h"`
`#include "internal/util.h"`
`#include "internal/variable.h"`
`#include "builtin.h"`
`#include "pack.rbinc"`

Go to the source code of this file.

## Data Structures
union | FLOAT_SWAPPER
union | DOUBLE_SWAPPER

## Macros
#define | NATINT_LEN_Q 8
#define | NATINT_PACK
#define | BIGENDIAN_P() 0
#define | NATINT_LEN(type, len) (natint?(int)sizeof(type):(int)(len))
#define | swapf(x) swap32(x)
#define | swapd(x) swap64(x)
#define | rb_ntohf(x) (BIGENDIAN_P()?(x):swapf(x))
#define | rb_ntohd(x) (BIGENDIAN_P()?(x):swapd(x))
#define | rb_htonf(x) (BIGENDIAN_P()?(x):swapf(x))
#define | rb_htond(x) (BIGENDIAN_P()?(x):swapd(x))
#define | rb_htovf(x) (BIGENDIAN_P()?swapf(x):(x))
#define | rb_htovd(x) (BIGENDIAN_P()?swapd(x):(x))
#define | rb_vtohf(x) (BIGENDIAN_P()?swapf(x):(x))
#define | rb_vtohd(x) (BIGENDIAN_P()?swapd(x):(x))
#define | FLOAT_CONVWITH(x) FLOAT_SWAPPER x;
#define | HTONF(x) ((x).u = rb_htonf((x).u))
#define | HTOVF(x) ((x).u = rb_htovf((x).u))
#define | NTOHF(x) ((x).u = rb_ntohf((x).u))
#define | VTOHF(x) ((x).u = rb_vtohf((x).u))
#define | DOUBLE_CONVWITH(x) DOUBLE_SWAPPER x;
#define | HTOND(x) ((x).u = rb_htond((x).u))
#define | HTOVD(x) ((x).u = rb_htovd((x).u))
#define | NTOHD(x) ((x).u = rb_ntohd((x).u))
#define | VTOHD(x) ((x).u = rb_vtohd((x).u))
#define | MAX_INTEGER_PACK_SIZE 8
#define | TOO_FEW (rb_raise(rb_eArgError, toofew), 0)
#define | MORE_ITEM (idx < RARRAY_LEN(ary))
#define | THISFROM (MORE_ITEM ? RARRAY_AREF(ary, idx) : TOO_FEW)
#define | NEXTFROM (MORE_ITEM ? RARRAY_AREF(ary, idx++) : TOO_FEW)
#define | castchar(from) (char)((from) & 0xff)
#define | PACK_LENGTH_ADJUST_SIZE(sz)
#define | PACK_ITEM_ADJUST()
#define | AVOID_CC_BUG
#define | UNPACK_ARRAY 0
#define | UNPACK_BLOCK 1
#define | UNPACK_1 2
#define | hexdigits ruby_hexdigits
#define | UNPACK_PUSH(item)

## Functions
int | rb_uv_to_utf8 (char buf[6], unsigned long uv)
void | Init_pack (void)

## Macro Definition Documentation

## ◆ AVOID_CC_BUG

#define AVOID_CC_BUG

Definition at line 926 of file pack.c.

## ◆ BIGENDIAN_P

#define BIGENDIAN_P | ( |  | ) | 0

Definition at line 74 of file pack.c.

## ◆ castchar

#define castchar | ( |  | from | ) | (char)((from) & 0xff)

## ◆ DOUBLE_CONVWITH

#define DOUBLE_CONVWITH | ( |  | x | ) | DOUBLE_SWAPPER x;

Definition at line 111 of file pack.c.

## ◆ FLOAT_CONVWITH

#define FLOAT_CONVWITH | ( |  | x | ) | FLOAT_SWAPPER x;

Definition at line 105 of file pack.c.

## ◆ hexdigits

#define hexdigits ruby_hexdigits

## ◆ HTOND

#define HTOND | ( |  | x | ) | ((x).u = rb_htond((x).u))

Definition at line 112 of file pack.c.

## ◆ HTONF

#define HTONF | ( |  | x | ) | ((x).u = rb_htonf((x).u))

Definition at line 106 of file pack.c.

## ◆ HTOVD

#define HTOVD | ( |  | x | ) | ((x).u = rb_htovd((x).u))

Definition at line 113 of file pack.c.

## ◆ HTOVF

#define HTOVF | ( |  | x | ) | ((x).u = rb_htovf((x).u))

Definition at line 107 of file pack.c.

## ◆ MAX_INTEGER_PACK_SIZE

#define MAX_INTEGER_PACK_SIZE 8

Definition at line 117 of file pack.c.

## ◆ MORE_ITEM

#define MORE_ITEM (idx < RARRAY_LEN(ary))

## ◆ NATINT_LEN

#define NATINT_LEN | ( |  | type,
|  |  | len
| ) |  | (natint?(int)sizeof(type):(int)(len))

Definition at line 78 of file pack.c.

## ◆ NATINT_LEN_Q

#define NATINT_LEN_Q 8

Definition at line 48 of file pack.c.

## ◆ NATINT_PACK

#define NATINT_PACK

Definition at line 52 of file pack.c.

## ◆ NEXTFROM

#define NEXTFROM (MORE_ITEM ? RARRAY_AREF(ary, idx++) : TOO_FEW)

## ◆ NTOHD

#define NTOHD | ( |  | x | ) | ((x).u = rb_ntohd((x).u))

Definition at line 114 of file pack.c.

## ◆ NTOHF

#define NTOHF | ( |  | x | ) | ((x).u = rb_ntohf((x).u))

Definition at line 108 of file pack.c.

## ◆ PACK_ITEM_ADJUST

#define PACK_ITEM_ADJUST | ( |  | ) |

Value:
do { \
if (tmp_len > 0 && mode == UNPACK_ARRAY) \
rb_ary_store(ary, RARRAY_LEN(ary)+tmp_len-1, Qnil); \
} while (0)
mode
const char int mode
Definition: ioapi.h:137
UNPACK_ARRAY
#define UNPACK_ARRAY
Definition: pack.c:930
RARRAY_LEN
#define RARRAY_LEN
Definition: rarray.h:52
Qnil
#define Qnil
Definition: special_consts.h:51

Definition at line 914 of file pack.c.

## ◆ PACK_LENGTH_ADJUST_SIZE

#define PACK_LENGTH_ADJUST_SIZE | ( |  | sz | ) |

Value:
do { \
tmp_len = 0; \
if (len > (long)((send-s)/(sz))) { \
if (!star) { \
tmp_len = len-(send-s)/(sz); \
} \
len = (send-s)/(sz); \
} \
} while (0)
len
uint8_t len
Definition: escape.c:17

Definition at line 904 of file pack.c.

## ◆ rb_htond

#define rb_htond | ( |  | x | ) | (BIGENDIAN_P()?(x):swapd(x))

Definition at line 99 of file pack.c.

## ◆ rb_htonf

#define rb_htonf | ( |  | x | ) | (BIGENDIAN_P()?(x):swapf(x))

Definition at line 98 of file pack.c.

## ◆ rb_htovd

#define rb_htovd | ( |  | x | ) | (BIGENDIAN_P()?swapd(x):(x))

Definition at line 101 of file pack.c.

## ◆ rb_htovf

#define rb_htovf | ( |  | x | ) | (BIGENDIAN_P()?swapf(x):(x))

Definition at line 100 of file pack.c.

## ◆ rb_ntohd

#define rb_ntohd | ( |  | x | ) | (BIGENDIAN_P()?(x):swapd(x))

Definition at line 97 of file pack.c.

## ◆ rb_ntohf

#define rb_ntohf | ( |  | x | ) | (BIGENDIAN_P()?(x):swapf(x))

Definition at line 96 of file pack.c.

## ◆ rb_vtohd

#define rb_vtohd | ( |  | x | ) | (BIGENDIAN_P()?swapd(x):(x))

Definition at line 103 of file pack.c.

## ◆ rb_vtohf

#define rb_vtohf | ( |  | x | ) | (BIGENDIAN_P()?swapf(x):(x))

Definition at line 102 of file pack.c.

## ◆ swapd

#define swapd | ( |  | x | ) | swap64(x)

Definition at line 94 of file pack.c.

## ◆ swapf

#define swapf | ( |  | x | ) | swap32(x)

Definition at line 93 of file pack.c.

## ◆ THISFROM

#define THISFROM (MORE_ITEM ? RARRAY_AREF(ary, idx) : TOO_FEW)

## ◆ TOO_FEW

#define TOO_FEW (rb_raise(rb_eArgError, toofew), 0)

## ◆ UNPACK_1

#define UNPACK_1 2

Definition at line 932 of file pack.c.

## ◆ UNPACK_ARRAY

#define UNPACK_ARRAY 0

Definition at line 930 of file pack.c.

## ◆ UNPACK_BLOCK

#define UNPACK_BLOCK 1

Definition at line 931 of file pack.c.

## ◆ UNPACK_PUSH

#define UNPACK_PUSH | ( |  | item | ) |

Value:
do {\
VALUE item_val = (item);\
if ((mode) == UNPACK_BLOCK) {\
rb_yield(item_val);\
}\
else if ((mode) == UNPACK_ARRAY) {\
rb_ary_push(ary, item_val);\
}\
else /* if ((mode) == UNPACK_1) { */ {\
return item_val; \
}\
} while (0)
UNPACK_BLOCK
#define UNPACK_BLOCK
Definition: pack.c:931
VALUE
unsigned long VALUE
Definition: value.h:38

## ◆ VTOHD

#define VTOHD | ( |  | x | ) | ((x).u = rb_vtohd((x).u))

Definition at line 115 of file pack.c.

## ◆ VTOHF

#define VTOHF | ( |  | x | ) | ((x).u = rb_vtohf((x).u))

Definition at line 109 of file pack.c.

## Function Documentation

## ◆ Init_pack()

void Init_pack | ( | void |  | ) |

Definition at line 1769 of file pack.c.

References rb_make_internal_id().

## ◆ rb_uv_to_utf8()

int rb_uv_to_utf8 | ( | char | buf[6],
|  | unsigned long | uv
| ) |  |

Definition at line 1660 of file pack.c.

References castchar, Qnil, rb_eRangeError, rb_raise(), and UNREACHABLE_RETURN.