Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions | Variables
pack.c File Reference
#include "internal.h"
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
Include dependency graph for pack.c:

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

static void encodes (VALUE, const char *, long, int, int)
 
static void qpencode (VALUE, VALUE, long)
 
static unsigned long utf8_to_uv (const char *, long *)
 
static void str_associate (VALUE str, VALUE add)
 
static VALUE str_associated (VALUE str)
 
void rb_str_associate (VALUE str, VALUE add)
 
VALUE rb_str_associated (VALUE str)
 
static VALUE pack_pack (int argc, VALUE *argv, VALUE ary)
 
static int hex2num (char c)
 
static VALUE infected_str_new (const char *ptr, long len, VALUE str)
 
static VALUE pack_unpack_internal (VALUE str, VALUE fmt, int mode)
 
static VALUE pack_unpack (VALUE str, VALUE fmt)
 
static VALUE pack_unpack1 (VALUE str, VALUE fmt)
 
int rb_uv_to_utf8 (char buf[6], unsigned long uv)
 
void Init_pack (void)
 

Variables

static const char natstr [] = "sSiIlLjJ"
 
static const char endstr [] = "sSiIlLqQjJ"
 
static const char toofew [] = "too few arguments"
 
static ID id_associated
 
static const char uu_table []
 
static const char b64_table []
 
static const char hex_table [] = "0123456789ABCDEF"
 
static const unsigned long utf8_limits []
 

Macro Definition Documentation

◆ AVOID_CC_BUG

#define AVOID_CC_BUG

Definition at line 1032 of file pack.c.

Referenced by pack_unpack_internal().

◆ BIGENDIAN_P

#define BIGENDIAN_P ( )    0

Definition at line 62 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ castchar

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

◆ DOUBLE_CONVWITH

#define DOUBLE_CONVWITH (   x)    DOUBLE_SWAPPER x;

Definition at line 99 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ FLOAT_CONVWITH

#define FLOAT_CONVWITH (   x)    FLOAT_SWAPPER x;

Definition at line 93 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ hexdigits

#define hexdigits   ruby_hexdigits

Referenced by pack_unpack_internal().

◆ HTOND

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

Definition at line 100 of file pack.c.

Referenced by pack_pack().

◆ HTONF

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

Definition at line 94 of file pack.c.

Referenced by pack_pack().

◆ HTOVD

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

Definition at line 101 of file pack.c.

Referenced by pack_pack().

◆ HTOVF

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

Definition at line 95 of file pack.c.

Referenced by pack_pack().

◆ MAX_INTEGER_PACK_SIZE

#define MAX_INTEGER_PACK_SIZE   8

Definition at line 105 of file pack.c.

Referenced by pack_pack().

◆ 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 66 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ NATINT_LEN_Q

#define NATINT_LEN_Q   8

Definition at line 36 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ NATINT_PACK

#define NATINT_PACK

Definition at line 40 of file pack.c.

◆ NEXTFROM

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

Referenced by pack_pack().

◆ NTOHD

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

Definition at line 102 of file pack.c.

Referenced by pack_unpack_internal().

◆ NTOHF

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

Definition at line 96 of file pack.c.

Referenced by pack_unpack_internal().

◆ 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)
#define RARRAY_LEN(a)
Definition: ruby.h:1026
#define Qnil
Definition: ruby.h:438
#define UNPACK_ARRAY
Definition: pack.c:1045

Definition at line 1021 of file pack.c.

Referenced by pack_unpack_internal().

◆ 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)
register unsigned int len
Definition: zonetab.h:51

Definition at line 1011 of file pack.c.

Referenced by pack_unpack_internal().

◆ rb_htond

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

Definition at line 87 of file pack.c.

◆ rb_htonf

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

Definition at line 86 of file pack.c.

◆ rb_htovd

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

Definition at line 89 of file pack.c.

◆ rb_htovf

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

Definition at line 88 of file pack.c.

◆ rb_ntohd

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

Definition at line 85 of file pack.c.

◆ rb_ntohf

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

Definition at line 84 of file pack.c.

◆ rb_vtohd

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

Definition at line 91 of file pack.c.

◆ rb_vtohf

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

Definition at line 90 of file pack.c.

◆ swapd

#define swapd (   x)    swap64(x)

Definition at line 82 of file pack.c.

◆ swapf

#define swapf (   x)    swap32(x)

Definition at line 81 of file pack.c.

◆ THISFROM

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

Referenced by pack_pack().

◆ TOO_FEW

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

◆ UNPACK_1

#define UNPACK_1   2

Definition at line 1047 of file pack.c.

Referenced by pack_unpack1().

◆ UNPACK_ARRAY

#define UNPACK_ARRAY   0

Definition at line 1045 of file pack.c.

Referenced by pack_unpack(), and pack_unpack_internal().

◆ UNPACK_BLOCK

#define UNPACK_BLOCK   1

Definition at line 1046 of file pack.c.

Referenced by pack_unpack().

◆ 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)
#define UNPACK_ARRAY
Definition: pack.c:1045
#define UNPACK_BLOCK
Definition: pack.c:1046

Referenced by pack_unpack_internal().

◆ VTOHD

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

Definition at line 103 of file pack.c.

Referenced by pack_unpack_internal().

◆ VTOHF

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

Definition at line 97 of file pack.c.

Referenced by pack_unpack_internal().

Function Documentation

◆ encodes()

static void encodes ( VALUE  str,
const char *  s0,
long  len,
int  type,
int  tail_lf 
)
static

Definition at line 898 of file pack.c.

References b64_table, rb_bug(), rb_str_buf_cat(), and uu_table.

Referenced by pack_pack().

◆ hex2num()

static int hex2num ( char  c)
inlinestatic

Definition at line 1002 of file pack.c.

References ruby_digit36_to_number_table.

Referenced by pack_unpack_internal().

◆ infected_str_new()

static VALUE infected_str_new ( const char *  ptr,
long  len,
VALUE  str 
)
static

Definition at line 1036 of file pack.c.

References OBJ_INFECT, and rb_str_new().

Referenced by pack_unpack_internal().

◆ Init_pack()

void Init_pack ( void  )

◆ pack_pack()

static VALUE pack_pack ( int  argc,
VALUE argv,
VALUE  ary 
)
static

◆ pack_unpack()

static VALUE pack_unpack ( VALUE  str,
VALUE  fmt 
)
static

Definition at line 1881 of file pack.c.

References pack_unpack_internal(), rb_block_given_p(), UNPACK_ARRAY, and UNPACK_BLOCK.

Referenced by Init_pack().

◆ pack_unpack1()

static VALUE pack_unpack1 ( VALUE  str,
VALUE  fmt 
)
static

Definition at line 1897 of file pack.c.

References pack_unpack_internal(), and UNPACK_1.

Referenced by Init_pack().

◆ pack_unpack_internal()

static VALUE pack_unpack_internal ( VALUE  str,
VALUE  fmt,
int  mode 
)
static

◆ qpencode()

static void qpencode ( VALUE  str,
VALUE  from,
long  len 
)
static

Definition at line 949 of file pack.c.

References EOF, hex_table, rb_str_buf_cat(), RSTRING_LEN, and RSTRING_PTR.

Referenced by pack_pack().

◆ rb_str_associate()

void rb_str_associate ( VALUE  str,
VALUE  add 
)

Definition at line 130 of file pack.c.

References ONLY_FOR_INTERNAL_USE.

◆ rb_str_associated()

VALUE rb_str_associated ( VALUE  str)

Definition at line 136 of file pack.c.

References ONLY_FOR_INTERNAL_USE.

◆ rb_uv_to_utf8()

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

Definition at line 1903 of file pack.c.

References castchar, rb_eRangeError, rb_raise(), and UNREACHABLE.

Referenced by append_utf8(), and pack_pack().

◆ str_associate()

static void str_associate ( VALUE  str,
VALUE  add 
)
static

Definition at line 117 of file pack.c.

References id_associated, and rb_ivar_set().

Referenced by pack_pack(), and pack_unpack_internal().

◆ str_associated()

static VALUE str_associated ( VALUE  str)
static

Definition at line 124 of file pack.c.

References id_associated, Qfalse, and rb_ivar_lookup().

Referenced by pack_unpack_internal().

◆ utf8_to_uv()

static unsigned long utf8_to_uv ( const char *  p,
long *  lenp 
)
static

Definition at line 1960 of file pack.c.

References rb_eArgError, rb_raise(), and utf8_limits.

Referenced by pack_unpack_internal().

Variable Documentation

◆ b64_table

const char b64_table[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 894 of file pack.c.

Referenced by encodes(), and pack_unpack_internal().

◆ endstr

const char endstr[] = "sSiIlLqQjJ"
static

Definition at line 30 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ hex_table

const char hex_table[] = "0123456789ABCDEF"
static

Definition at line 946 of file pack.c.

Referenced by qpencode().

◆ id_associated

ID id_associated
static

Definition at line 114 of file pack.c.

Referenced by Init_pack(), str_associate(), and str_associated().

◆ natstr

const char natstr[] = "sSiIlLjJ"
static

Definition at line 28 of file pack.c.

Referenced by pack_pack(), and pack_unpack_internal().

◆ toofew

const char toofew[] = "too few arguments"
static

Definition at line 107 of file pack.c.

◆ utf8_limits

const unsigned long utf8_limits[]
static
Initial value:
= {
0x0,
0x80,
0x800,
0x10000,
0x200000,
0x4000000,
0x80000000,
}

Definition at line 1949 of file pack.c.

Referenced by utf8_to_uv().

◆ uu_table

const char uu_table[]
static
Initial value:
=
"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"

Definition at line 892 of file pack.c.

Referenced by encodes().