Ruby  2.1.10p492(2016-04-01revision54464)
Macros | Functions | Variables
pack.c File Reference
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "internal.h"
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>

Go to the source code of this file.

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 define_swapx(x, xtype)
 
#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(y)
 
#define HTONF(x, y)   rb_htonf(x)
 
#define HTOVF(x, y)   rb_htovf(x)
 
#define NTOHF(x, y)   rb_ntohf(x)
 
#define VTOHF(x, y)   rb_vtohf(x)
 
#define DOUBLE_CONVWITH(y)
 
#define HTOND(x, y)   rb_htond(x)
 
#define HTOVD(x, y)   rb_htovd(x)
 
#define NTOHD(x, y)   rb_ntohd(x)
 
#define VTOHD(x, y)   rb_vtohd(x)
 
#define MAX_INTEGER_PACK_SIZE   8
 
#define TOO_FEW   (rb_raise(rb_eArgError, toofew), 0)
 
#define THISFROM   (items > 0 ? RARRAY_AREF(ary, idx) : TOO_FEW)
 
#define NEXTFROM   (items-- > 0 ? RARRAY_AREF(ary, idx++) : TOO_FEW)
 
#define castchar(from)   (char)((from) & 0xff)
 
#define PACK_LENGTH_ADJUST_SIZE(sz)
 
#define PACK_ITEM_ADJUST()
 
#define UNPACK_PUSH(item)
 
#define BYTEWIDTH   8
 

Functions

 define_swapx (s, short)
 
static void encodes (VALUE str, const char *s, long len, int type, int tail_lf)
 
static void qpencode (VALUE str, VALUE from, long len)
 
static int hex2num (char c)
 
static VALUE infected_str_new (const char *ptr, long len, VALUE str)
 
static VALUE pack_unpack (VALUE str, VALUE fmt)
 
int rb_uv_to_utf8 (char buf[6], unsigned long uv)
 
static unsigned long utf8_to_uv (const char *p, long *lenp)
 
void Init_pack (void)
 

Variables

static const char natstr [] = "sSiIlL"
 
static const char endstr [] = "sSiIlLqQ"
 
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

◆ BIGENDIAN_P

#define BIGENDIAN_P ( )    0

Definition at line 64 of file pack.c.

Referenced by pack_unpack().

◆ BYTEWIDTH

#define BYTEWIDTH   8

Definition at line 1897 of file pack.c.

◆ castchar

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

Referenced by pack_unpack(), and rb_uv_to_utf8().

◆ define_swapx

#define define_swapx (   x,
  xtype 
)
Value:
static xtype \
TOKEN_PASTE(swap,x)(xtype z) \
{ \
xtype r; \
xtype *zp; \
unsigned char *s, *t; \
int i; \
\
zp = xmalloc(sizeof(xtype)); \
*zp = z; \
s = (unsigned char*)zp; \
t = xmalloc(sizeof(xtype)); \
for (i=0; i<sizeof(xtype); i++) { \
t[sizeof(xtype)-i-1] = s[i]; \
} \
r = *(xtype *)t; \
xfree(t); \
xfree(zp); \
return r; \
}
int t(void)
Definition: conftest.c:13
#define xmalloc
Definition: defines.h:108

Definition at line 81 of file pack.c.

◆ DOUBLE_CONVWITH

#define DOUBLE_CONVWITH (   y)

Referenced by pack_unpack().

◆ FLOAT_CONVWITH

#define FLOAT_CONVWITH (   y)

Referenced by pack_unpack().

◆ HTOND

#define HTOND (   x,
 
)    rb_htond(x)

◆ HTONF

#define HTONF (   x,
 
)    rb_htonf(x)

◆ HTOVD

#define HTOVD (   x,
 
)    rb_htovd(x)

◆ HTOVF

#define HTOVF (   x,
 
)    rb_htovf(x)

◆ MAX_INTEGER_PACK_SIZE

#define MAX_INTEGER_PACK_SIZE   8

◆ NATINT_LEN

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

Definition at line 68 of file pack.c.

Referenced by pack_unpack().

◆ NATINT_LEN_Q

#define NATINT_LEN_Q   8

Definition at line 38 of file pack.c.

Referenced by pack_unpack().

◆ NATINT_PACK

#define NATINT_PACK

Definition at line 42 of file pack.c.

◆ NEXTFROM

#define NEXTFROM   (items-- > 0 ? RARRAY_AREF(ary, idx++) : TOO_FEW)

◆ NTOHD

#define NTOHD (   x,
 
)    rb_ntohd(x)

Referenced by pack_unpack().

◆ NTOHF

#define NTOHF (   x,
 
)    rb_ntohf(x)

Referenced by pack_unpack().

◆ PACK_ITEM_ADJUST

#define PACK_ITEM_ADJUST ( )
Value:
do { \
if (tmp_len > 0 && !block_p) \
rb_ary_store(ary, RARRAY_LEN(ary)+tmp_len-1, Qnil); \
} while (0)
#define RARRAY_LEN(a)
Definition: ruby.h:878
#define Qnil
Definition: ruby.h:427

Definition at line 1069 of file pack.c.

Referenced by pack_unpack().

◆ 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)

Definition at line 1059 of file pack.c.

Referenced by pack_unpack().

◆ rb_htond

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

◆ rb_htonf

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

◆ rb_htovd

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

◆ rb_htovf

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

◆ rb_ntohd

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

◆ rb_ntohf

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

◆ rb_vtohd

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

◆ rb_vtohf

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

◆ THISFROM

#define THISFROM   (items > 0 ? RARRAY_AREF(ary, idx) : TOO_FEW)

◆ TOO_FEW

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

◆ UNPACK_PUSH

#define UNPACK_PUSH (   item)
Value:
do {\
VALUE item_val = (item);\
if (block_p) {\
rb_yield(item_val);\
}\
else {\
rb_ary_push(ary, item_val);\
}\
} while (0)

Referenced by pack_unpack().

◆ VTOHD

#define VTOHD (   x,
 
)    rb_vtohd(x)

Referenced by pack_unpack().

◆ VTOHF

#define VTOHF (   x,
 
)    rb_vtohf(x)

Referenced by pack_unpack().

Function Documentation

◆ define_swapx()

define_swapx ( ,
short   
)

Definition at line 108 of file pack.c.

References swap32.

◆ encodes()

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

Definition at line 947 of file pack.c.

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

◆ hex2num()

static int hex2num ( char  c)
inlinestatic

Definition at line 1050 of file pack.c.

References ruby_digit36_to_number_table.

Referenced by pack_unpack().

◆ infected_str_new()

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

Definition at line 1075 of file pack.c.

References OBJ_INFECT, and rb_str_new().

Referenced by pack_unpack().

◆ Init_pack()

void Init_pack ( void  )

Definition at line 2007 of file pack.c.

References pack_unpack(), rb_cArray, rb_cString, and rb_define_method().

◆ pack_unpack()

static VALUE pack_unpack ( VALUE  str,
VALUE  fmt 
)
static

◆ qpencode()

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

Definition at line 997 of file pack.c.

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

◆ rb_uv_to_utf8()

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

Definition at line 1900 of file pack.c.

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

Referenced by append_utf8().

◆ utf8_to_uv()

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

Definition at line 1957 of file pack.c.

References rb_eArgError, rb_raise(), and utf8_limits.

Referenced by pack_unpack().

Variable Documentation

◆ b64_table

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

Definition at line 943 of file pack.c.

Referenced by encodes(), and pack_unpack().

◆ endstr

const char endstr[] = "sSiIlLqQ"
static

Definition at line 32 of file pack.c.

Referenced by pack_unpack().

◆ hex_table

const char hex_table[] = "0123456789ABCDEF"
static

Definition at line 994 of file pack.c.

Referenced by qpencode().

◆ natstr

const char natstr[] = "sSiIlL"
static

Definition at line 30 of file pack.c.

Referenced by pack_unpack().

◆ utf8_limits

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

Definition at line 1946 of file pack.c.

Referenced by utf8_to_uv().

◆ uu_table

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

Definition at line 941 of file pack.c.

Referenced by encodes().