Ruby  2.0.0p598(2014-11-13revision48408)
Macros | Functions | Variables
pack.c File Reference
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>

Go to the source code of this file.

Macros

#define GCC_VERSION_SINCE(major, minor, patchlevel)
 
#define NATINT_PACK
 
#define BIGENDIAN_P()   0
 
#define NATINT_LEN(type, len)   (natint?(int)sizeof(type):(int)(len))
 
#define define_swapx(x, xtype)
 
#define swap16(x)   ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))
 
#define swap32(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(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_PTR(ary)[idx] : TOO_FEW)
 
#define NEXTFROM   (items-- > 0 ? RARRAY_PTR(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

static unsigned long num2i32 (VALUE x)
 
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 VALUE pack_pack (VALUE ary, VALUE fmt)
 
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)
 
void Init_pack (void)
 

Variables

static const char toofew [] = "too few arguments"
 
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

#define BIGENDIAN_P ( )    0

Definition at line 46 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define BYTEWIDTH   8

Definition at line 2164 of file pack.c.

#define castchar (   from)    (char)((from) & 0xff)
#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); \
}
VP_EXPORT int
Definition: bigdecimal.c:5071
return
Definition: bigdecimal.c:5821
ssize_t i
Definition: bigdecimal.c:5676
#define xfree
r
Definition: bigdecimal.c:1210
#define xmalloc
for(v/=shifter=1)
Definition: bigdecimal.c:5698
register char * s
Definition: os2.c:56
int t
Definition: ripper.c:14654

Definition at line 63 of file pack.c.

#define DOUBLE_CONVWITH (   y)

Definition at line 233 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define FLOAT_CONVWITH (   y)

Definition at line 207 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define GCC_VERSION_SINCE (   major,
  minor,
  patchlevel 
)
Value:
(defined(__GNUC__) && !defined(__INTEL_COMPILER) && \
((__GNUC__ > (major)) || \
(__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
(__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))
int minor
Definition: tcltklib.c:110
int patchlevel
Definition: tcltklib.c:112
int major
Definition: tcltklib.c:109

Definition at line 18 of file pack.c.

#define HTOND (   x,
 
)    rb_htond(x)

Definition at line 234 of file pack.c.

Referenced by pack_pack().

#define HTONF (   x,
 
)    rb_htonf(x)

Definition at line 208 of file pack.c.

Referenced by pack_pack().

#define HTOVD (   x,
 
)    rb_htovd(x)

Definition at line 235 of file pack.c.

Referenced by pack_pack().

#define HTOVF (   x,
 
)    rb_htovf(x)

Definition at line 209 of file pack.c.

Referenced by pack_pack().

#define MAX_INTEGER_PACK_SIZE   8

Definition at line 254 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

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

Definition at line 50 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define NATINT_PACK

Definition at line 24 of file pack.c.

#define NEXTFROM   (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW)

Referenced by pack_pack().

#define NTOHD (   x,
 
)    rb_ntohd(x)

Definition at line 236 of file pack.c.

Referenced by pack_unpack().

#define NTOHF (   x,
 
)    rb_ntohf(x)

Definition at line 210 of file pack.c.

Referenced by pack_unpack().

#define PACK_ITEM_ADJUST ( )
Value:
do { \
if (tmp_len > 0 && !block_p) \
} while (0)
volatile VALUE ary
Definition: tcltklib.c:9712
#define RARRAY_LEN(a)
#define Qnil
Definition: tcltklib.c:1895
void rb_ary_store(VALUE ary, long idx, VALUE val)
Definition: array.c:719
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1200

Definition at line 1194 of file pack.c.

Referenced by pack_unpack().

#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 char * s
Definition: os2.c:56
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1200
size_t len
Definition: tcltklib.c:3567

Definition at line 1184 of file pack.c.

Referenced by pack_unpack().

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

Definition at line 182 of file pack.c.

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

Definition at line 181 of file pack.c.

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

Definition at line 184 of file pack.c.

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

Definition at line 183 of file pack.c.

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

Definition at line 180 of file pack.c.

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

Definition at line 179 of file pack.c.

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

Definition at line 186 of file pack.c.

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

Definition at line 185 of file pack.c.

#define swap16 (   x)    ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))

Definition at line 91 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define swap32 (   x)
Value:
((uint32_t)((((x)&0xFF)<<24) \
|(((x)>>24)&0xFF) \
|(((x)&0x0000FF00)<<8) \
|(((x)&0x00FF0000)>>8) ))
unsigned int uint32_t
Definition: sha2.h:101

Definition at line 95 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define THISFROM   (items > 0 ? RARRAY_PTR(ary)[idx] : TOO_FEW)

Referenced by pack_pack().

#define TOO_FEW   (rb_raise(rb_eArgError, toofew), 0)
#define UNPACK_PUSH (   item)
Value:
do {\
VALUE item_val = (item);\
if (block_p) {\
rb_yield(item_val);\
}\
rb_ary_push(ary, item_val);\
}\
} while (0)
volatile VALUE ary
Definition: tcltklib.c:9712
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
VALUE rb_yield(VALUE)
Definition: vm_eval.c:933
else
Definition: bigdecimal.c:1206
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1200
unsigned long VALUE
Definition: ripper.y:104

Referenced by pack_unpack().

#define VTOHD (   x,
 
)    rb_vtohd(x)

Definition at line 237 of file pack.c.

Referenced by pack_unpack().

#define VTOHF (   x,
 
)    rb_vtohf(x)

Definition at line 211 of file pack.c.

Referenced by pack_unpack().

Function Documentation

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

Definition at line 1064 of file pack.c.

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

Referenced by pack_pack().

static int hex2num ( char  c)
inlinestatic

Definition at line 1167 of file pack.c.

Referenced by pack_unpack().

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

Definition at line 1200 of file pack.c.

References OBJ_INFECT, rb_str_new(), and s.

Referenced by pack_unpack().

void Init_pack ( void  )

Definition at line 2274 of file pack.c.

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

static unsigned long num2i32 ( VALUE  x)
static
static VALUE pack_pack ( VALUE  ary,
VALUE  fmt 
)
static
static VALUE pack_unpack ( VALUE  str,
VALUE  fmt 
)
static
static void qpencode ( VALUE  str,
VALUE  from,
long  len 
)
static

Definition at line 1114 of file pack.c.

References EOF, i, n, rb_str_buf_cat(), RSTRING_LEN, RSTRING_PTR, and s.

Referenced by pack_pack().

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

Definition at line 2167 of file pack.c.

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

Referenced by append_utf8(), and pack_pack().

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

Definition at line 2224 of file pack.c.

References c, n, rb_eArgError, and rb_raise().

Referenced by pack_unpack().

Variable Documentation

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

Definition at line 1060 of file pack.c.

Referenced by encodes().

const char hex_table[] = "0123456789ABCDEF"
static

Definition at line 1111 of file pack.c.

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

Definition at line 257 of file pack.c.

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

Definition at line 2213 of file pack.c.

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

Definition at line 1058 of file pack.c.