2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
pack.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Thu Feb 10 15:17:05 JST 1994
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
2008-10-29 03:41:21 -04:00
|
|
|
#include "ruby/encoding.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <sys/types.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <ctype.h>
|
2008-05-17 13:56:41 -04:00
|
|
|
#include <errno.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-27 17:00:15 -05:00
|
|
|
#define GCC_VERSION_SINCE(major, minor, patchlevel) \
|
|
|
|
(defined(__GNUC__) && !defined(__INTEL_COMPILER) && \
|
|
|
|
((__GNUC__ > (major)) || \
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))
|
1999-08-13 01:45:20 -04:00
|
|
|
#if SIZEOF_SHORT != 2 || SIZEOF_LONG != 4
|
|
|
|
# define NATINT_PACK
|
|
|
|
#endif
|
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
#ifdef DYNAMIC_ENDIAN
|
|
|
|
/* for universal binary of NEXTSTEP and MacOS X */
|
2010-03-11 08:39:29 -05:00
|
|
|
/* useless since autoconf 2.63? */
|
2010-02-25 09:00:48 -05:00
|
|
|
static int
|
|
|
|
is_bigendian(void)
|
|
|
|
{
|
|
|
|
static int init = 0;
|
|
|
|
static int endian_value;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (init) return endian_value;
|
|
|
|
init = 1;
|
|
|
|
p = (char*)&init;
|
|
|
|
return endian_value = p[0]?0:1;
|
|
|
|
}
|
|
|
|
# define BIGENDIAN_P() (is_bigendian())
|
|
|
|
#elif defined(WORDS_BIGENDIAN)
|
|
|
|
# define BIGENDIAN_P() 1
|
2010-02-24 10:32:06 -05:00
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
# define BIGENDIAN_P() 0
|
2010-02-24 10:32:06 -05:00
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
2009-10-04 02:00:33 -04:00
|
|
|
# define NATINT_LEN(type,len) (natint?(int)sizeof(type):(int)(len))
|
1999-08-13 01:45:20 -04:00
|
|
|
#else
|
2009-10-04 02:00:33 -04:00
|
|
|
# define NATINT_LEN(type,len) ((int)sizeof(type))
|
2004-01-05 05:01:54 -05:00
|
|
|
#endif
|
1999-10-04 00:51:08 -04:00
|
|
|
|
2010-02-27 10:39:20 -05:00
|
|
|
#if SIZEOF_LONG == 8
|
|
|
|
# define INT64toNUM(x) LONG2NUM(x)
|
|
|
|
# define UINT64toNUM(x) ULONG2NUM(x)
|
|
|
|
#elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
|
|
|
|
# define INT64toNUM(x) LL2NUM(x)
|
|
|
|
# define UINT64toNUM(x) ULL2NUM(x)
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#define define_swapx(x, xtype) \
|
|
|
|
static xtype \
|
2006-07-17 09:59:09 -04:00
|
|
|
TOKEN_PASTE(swap,x)(xtype z) \
|
1999-08-13 01:45:20 -04:00
|
|
|
{ \
|
|
|
|
xtype r; \
|
|
|
|
xtype *zp; \
|
|
|
|
unsigned char *s, *t; \
|
|
|
|
int i; \
|
|
|
|
\
|
2006-07-17 09:59:09 -04:00
|
|
|
zp = xmalloc(sizeof(xtype)); \
|
1999-08-13 01:45:20 -04:00
|
|
|
*zp = z; \
|
2003-01-14 02:45:19 -05:00
|
|
|
s = (unsigned char*)zp; \
|
2006-07-17 09:59:09 -04:00
|
|
|
t = xmalloc(sizeof(xtype)); \
|
1999-08-13 01:45:20 -04:00
|
|
|
for (i=0; i<sizeof(xtype); i++) { \
|
|
|
|
t[sizeof(xtype)-i-1] = s[i]; \
|
|
|
|
} \
|
|
|
|
r = *(xtype *)t; \
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 06:01:40 -04:00
|
|
|
xfree(t); \
|
|
|
|
xfree(zp); \
|
1999-08-13 01:45:20 -04:00
|
|
|
return r; \
|
|
|
|
}
|
|
|
|
|
2010-02-27 17:00:15 -05:00
|
|
|
#if GCC_VERSION_SINCE(4,3,0)
|
|
|
|
# define swap32(x) __builtin_bswap32(x)
|
|
|
|
# define swap64(x) __builtin_bswap64(x)
|
|
|
|
#endif
|
|
|
|
|
2003-12-07 22:47:04 -05:00
|
|
|
#ifndef swap16
|
2010-02-25 09:00:48 -05:00
|
|
|
# define swap16(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
|
2003-12-07 22:47:04 -05:00
|
|
|
#endif
|
2010-02-24 10:32:06 -05:00
|
|
|
|
|
|
|
#ifndef swap32
|
2010-02-25 09:00:48 -05:00
|
|
|
# define swap32(x) ((((x)&0xFF)<<24) \
|
2010-02-24 10:32:06 -05:00
|
|
|
|(((x)>>24)&0xFF) \
|
|
|
|
|(((x)&0x0000FF00)<<8) \
|
|
|
|
|(((x)&0x00FF0000)>>8) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef swap64
|
2010-02-27 10:39:20 -05:00
|
|
|
# ifdef HAVE_INT64_T
|
2010-02-27 17:00:15 -05:00
|
|
|
# define byte_in_64bit(n) ((uint64_t)0xff << (n))
|
2010-02-26 02:49:21 -05:00
|
|
|
# define swap64(x) ((((x)&byte_in_64bit(0))<<56) \
|
|
|
|
|(((x)>>56)&0xFF) \
|
|
|
|
|(((x)&byte_in_64bit(8))<<40) \
|
|
|
|
|(((x)&byte_in_64bit(48))>>40) \
|
|
|
|
|(((x)&byte_in_64bit(16))<<24) \
|
|
|
|
|(((x)&byte_in_64bit(40))>>24) \
|
|
|
|
|(((x)&byte_in_64bit(24))<<8) \
|
|
|
|
|(((x)&byte_in_64bit(32))>>8))
|
2010-02-25 09:00:48 -05:00
|
|
|
# endif
|
2010-02-24 10:32:06 -05:00
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#if SIZEOF_SHORT == 2
|
2010-02-25 09:00:48 -05:00
|
|
|
# define swaps(x) swap16(x)
|
|
|
|
#elif SIZEOF_SHORT == 4
|
|
|
|
# define swaps(x) swap32(x)
|
1999-08-13 01:45:20 -04:00
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
define_swapx(s,short)
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
|
2010-02-24 10:32:06 -05:00
|
|
|
#if SIZEOF_INT == 2
|
2010-02-25 09:00:48 -05:00
|
|
|
# define swapi(x) swap16(x)
|
|
|
|
#elif SIZEOF_INT == 4
|
|
|
|
# define swapi(x) swap32(x)
|
2010-02-24 10:32:06 -05:00
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
define_swapx(i,int)
|
2003-12-07 22:47:04 -05:00
|
|
|
#endif
|
2010-02-24 10:32:06 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
#if SIZEOF_LONG == 4
|
2010-02-25 09:00:48 -05:00
|
|
|
# define swapl(x) swap32(x)
|
|
|
|
#elif SIZEOF_LONG == 8
|
|
|
|
# define swapl(x) swap64(x)
|
1999-08-13 01:45:20 -04:00
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
define_swapx(l,long)
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
|
2010-02-24 10:32:06 -05:00
|
|
|
#ifdef HAVE_LONG_LONG
|
2010-02-25 09:00:48 -05:00
|
|
|
# if SIZEOF_LONG_LONG == 8
|
|
|
|
# define swapll(x) swap64(x)
|
|
|
|
# else
|
|
|
|
define_swapx(ll,LONG_LONG)
|
|
|
|
# endif
|
2010-02-24 10:32:06 -05:00
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#if SIZEOF_FLOAT == 4
|
2010-02-25 09:00:48 -05:00
|
|
|
# ifdef HAVE_UINT32_T
|
|
|
|
# define swapf(x) swap32(x)
|
|
|
|
# define FLOAT_SWAPPER uint32_t
|
|
|
|
# else /* SIZEOF_FLOAT == 4 but undivide by known size of int */
|
|
|
|
define_swapx(f,float)
|
|
|
|
# endif
|
1999-08-13 01:45:20 -04:00
|
|
|
#else /* SIZEOF_FLOAT != 4 */
|
2010-02-25 09:00:48 -05:00
|
|
|
define_swapx(f,float)
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif /* #if SIZEOF_FLOAT == 4 */
|
|
|
|
|
|
|
|
#if SIZEOF_DOUBLE == 8
|
2010-02-25 09:00:48 -05:00
|
|
|
# ifdef HAVE_UINT64_T /* SIZEOF_DOUBLE == 8 == SIZEOF_UINT64_T */
|
|
|
|
# define swapd(x) swap64(x)
|
|
|
|
# define DOUBLE_SWAPPER uint64_t
|
|
|
|
# else
|
|
|
|
# if SIZEOF_LONG == 4 /* SIZEOF_DOUBLE == 8 && 4 == SIZEOF_LONG */
|
|
|
|
static double
|
|
|
|
swapd(const double d)
|
|
|
|
{
|
|
|
|
double dtmp = d;
|
|
|
|
unsigned long utmp[2];
|
|
|
|
unsigned long utmp0;
|
|
|
|
|
|
|
|
utmp[0] = 0; utmp[1] = 0;
|
|
|
|
memcpy(utmp,&dtmp,sizeof(double));
|
|
|
|
utmp0 = utmp[0];
|
|
|
|
utmp[0] = swapl(utmp[1]);
|
|
|
|
utmp[1] = swapl(utmp0);
|
|
|
|
memcpy(&dtmp,utmp,sizeof(double));
|
|
|
|
return dtmp;
|
|
|
|
}
|
|
|
|
# elif SIZEOF_SHORT == 4 /* SIZEOF_DOUBLE == 8 && 4 == SIZEOF_SHORT */
|
|
|
|
static double
|
|
|
|
swapd(const double d)
|
|
|
|
{
|
|
|
|
double dtmp = d;
|
|
|
|
unsigned short utmp[2];
|
|
|
|
unsigned short utmp0;
|
|
|
|
|
|
|
|
utmp[0] = 0; utmp[1] = 0;
|
|
|
|
memcpy(utmp,&dtmp,sizeof(double));
|
|
|
|
utmp0 = utmp[0];
|
|
|
|
utmp[0] = swaps(utmp[1]);
|
|
|
|
utmp[1] = swaps(utmp0);
|
|
|
|
memcpy(&dtmp,utmp,sizeof(double));
|
|
|
|
return dtmp;
|
|
|
|
}
|
|
|
|
# else /* SIZEOF_DOUBLE == 8 but undivide by known size of int */
|
|
|
|
define_swapx(d, double)
|
|
|
|
# endif
|
|
|
|
# endif /* #if SIZEOF_LONG == 8 */
|
1999-08-13 01:45:20 -04:00
|
|
|
#else /* SIZEOF_DOUBLE != 8 */
|
2010-02-25 09:00:48 -05:00
|
|
|
define_swapx(d, double)
|
2004-11-10 02:17:53 -05:00
|
|
|
#endif /* #if SIZEOF_DOUBLE == 8 */
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
#undef define_swapx
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
#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))
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
#ifdef FLOAT_SWAPPER
|
2010-02-25 09:00:48 -05:00
|
|
|
# define FLOAT_CONVWITH(y) FLOAT_SWAPPER y;
|
|
|
|
# define HTONF(x,y) (memcpy(&y,&x,sizeof(float)), \
|
|
|
|
y = rb_htonf((FLOAT_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(float)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define HTOVF(x,y) (memcpy(&y,&x,sizeof(float)), \
|
|
|
|
y = rb_htovf((FLOAT_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(float)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define NTOHF(x,y) (memcpy(&y,&x,sizeof(float)), \
|
|
|
|
y = rb_ntohf((FLOAT_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(float)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define VTOHF(x,y) (memcpy(&y,&x,sizeof(float)), \
|
|
|
|
y = rb_vtohf((FLOAT_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(float)), \
|
|
|
|
x)
|
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
# 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)
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DOUBLE_SWAPPER
|
2010-02-25 09:00:48 -05:00
|
|
|
# define DOUBLE_CONVWITH(y) DOUBLE_SWAPPER y;
|
|
|
|
# define HTOND(x,y) (memcpy(&y,&x,sizeof(double)), \
|
|
|
|
y = rb_htond((DOUBLE_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(double)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define HTOVD(x,y) (memcpy(&y,&x,sizeof(double)), \
|
|
|
|
y = rb_htovd((DOUBLE_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(double)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define NTOHD(x,y) (memcpy(&y,&x,sizeof(double)), \
|
|
|
|
y = rb_ntohd((DOUBLE_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(double)), \
|
|
|
|
x)
|
2010-02-25 09:00:48 -05:00
|
|
|
# define VTOHD(x,y) (memcpy(&y,&x,sizeof(double)), \
|
|
|
|
y = rb_vtohd((DOUBLE_SWAPPER)y), \
|
1999-08-13 01:45:20 -04:00
|
|
|
memcpy(&x,&y,sizeof(double)), \
|
|
|
|
x)
|
|
|
|
#else
|
2010-02-25 09:00:48 -05:00
|
|
|
# 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)
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
2004-01-22 13:06:38 -05:00
|
|
|
static unsigned long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num2i32(VALUE x)
|
2002-11-22 09:30:33 -05:00
|
|
|
{
|
2004-01-22 13:06:38 -05:00
|
|
|
x = rb_to_int(x); /* is nil OK? (should not) */
|
2002-11-22 09:30:33 -05:00
|
|
|
|
2004-01-22 13:06:38 -05:00
|
|
|
if (FIXNUM_P(x)) return FIX2LONG(x);
|
|
|
|
if (TYPE(x) == T_BIGNUM) {
|
|
|
|
return rb_big2ulong_pack(x);
|
2002-11-22 09:30:33 -05:00
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
rb_raise(rb_eTypeError, "can't convert %s to `integer'", rb_obj_classname(x));
|
2004-01-22 13:06:38 -05:00
|
|
|
return 0; /* not reached */
|
2002-11-22 09:30:33 -05:00
|
|
|
}
|
2000-10-16 05:13:20 -04:00
|
|
|
|
2010-02-27 21:32:09 -05:00
|
|
|
#define MAX_INTEGER_PACK_SIZE 8
|
2010-02-26 13:51:02 -05:00
|
|
|
/* #define FORCE_BIG_PACK */
|
2010-02-27 21:32:09 -05:00
|
|
|
|
2006-08-04 00:58:25 -04:00
|
|
|
static const char toofew[] = "too few arguments";
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2008-09-25 08:24:54 -04:00
|
|
|
static void encodes(VALUE,const char*,long,int,int);
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
static void qpencode(VALUE,VALUE,long);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2006-03-01 05:06:03 -05:00
|
|
|
static unsigned long utf8_to_uv(const char*,long*);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2003-12-18 16:08:25 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* arr.pack ( aTemplateString ) -> aBinaryString
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-18 16:08:25 -05:00
|
|
|
* Packs the contents of <i>arr</i> into a binary sequence according to
|
|
|
|
* the directives in <i>aTemplateString</i> (see the table below)
|
|
|
|
* Directives ``A,'' ``a,'' and ``Z'' may be followed by a count,
|
|
|
|
* which gives the width of the resulting field. The remaining
|
|
|
|
* directives also may take a count, indicating the number of array
|
|
|
|
* elements to convert. If the count is an asterisk
|
|
|
|
* (``<code>*</code>''), all remaining array elements will be
|
|
|
|
* converted. Any of the directives ``<code>sSiIlL</code>'' may be
|
2010-06-28 09:05:07 -04:00
|
|
|
* followed by an underscore (``<code>_</code>'') or
|
|
|
|
* exclamation mark (``<code>!</code>'') to use the underlying
|
2003-12-18 16:08:25 -05:00
|
|
|
* platform's native size for the specified type; otherwise, they use a
|
|
|
|
* platform-independent size. Spaces are ignored in the template
|
|
|
|
* string. See also <code>String#unpack</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-18 16:08:25 -05:00
|
|
|
* a = [ "a", "b", "c" ]
|
|
|
|
* n = [ 65, 66, 67 ]
|
|
|
|
* a.pack("A3A3A3") #=> "a b c "
|
|
|
|
* a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000"
|
|
|
|
* n.pack("ccc") #=> "ABC"
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2004-07-09 09:38:34 -04:00
|
|
|
* Directives for +pack+.
|
2003-12-18 16:08:25 -05:00
|
|
|
*
|
2010-06-28 09:05:07 -04:00
|
|
|
* Integer | Array |
|
|
|
|
* Directive | Element | Meaning
|
|
|
|
* ---------------------------------------------------------------------------
|
2010-08-09 09:13:31 -04:00
|
|
|
* C | Integer | 8-bit unsigned (unsigned char)
|
|
|
|
* S | Integer | 16-bit unsigned, native endian (uint16_t)
|
|
|
|
* L | Integer | 32-bit unsigned, native endian (uint32_t)
|
|
|
|
* Q | Integer | 64-bit unsigned, native endian (uint64_t)
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
2010-08-09 09:13:31 -04:00
|
|
|
* c | Integer | 8-bit signed (char)
|
|
|
|
* s | Integer | 16-bit signed, native endian (int16_t)
|
|
|
|
* l | Integer | 32-bit signed, native endian (int32_t)
|
|
|
|
* q | Integer | 64-bit signed, native endian (int64_t)
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
2010-10-15 03:35:50 -04:00
|
|
|
* S_, S! | Integer | unsigned short, native endian
|
|
|
|
* I, I_, I! | Integer | unsigned int, native endian
|
|
|
|
* L_, L! | Integer | unsigned long, native endian
|
|
|
|
* | |
|
|
|
|
* s_, s! | Integer | signed short, native endian
|
|
|
|
* i, i_, i! | Integer | signed int, native endian
|
|
|
|
* l_, l! | Integer | signed long, native endian
|
|
|
|
* | |
|
2010-10-17 23:59:53 -04:00
|
|
|
* S> L> Q> | Integer | same as the directives without ">" except
|
|
|
|
* s> l> q> | | big endian
|
|
|
|
* S!> I!> | | (available since Ruby 1.9.3)
|
2010-10-18 02:33:50 -04:00
|
|
|
* L!> | | "S>" is same as "n"
|
2010-10-17 23:59:53 -04:00
|
|
|
* s!> i!> | | "L>" is same as "N"
|
2010-10-18 02:33:50 -04:00
|
|
|
* l!> | |
|
2010-10-15 03:35:50 -04:00
|
|
|
* | |
|
2010-10-17 23:59:53 -04:00
|
|
|
* S< L< Q< | Integer | same as the directives without "<" except
|
|
|
|
* s< l< q< | | little endian
|
|
|
|
* S!< I!< | | (available since Ruby 1.9.3)
|
2010-10-18 02:33:50 -04:00
|
|
|
* L!< | | "S<" is same as "v"
|
2010-10-17 23:59:53 -04:00
|
|
|
* s!< i!< | | "L<" is same as "V"
|
2010-10-18 02:33:50 -04:00
|
|
|
* l!< | |
|
2010-10-15 03:35:50 -04:00
|
|
|
* | |
|
2010-08-09 09:13:31 -04:00
|
|
|
* n | Integer | 16-bit unsigned, network (big-endian) byte order
|
|
|
|
* N | Integer | 32-bit unsigned, network (big-endian) byte order
|
|
|
|
* v | Integer | 16-bit unsigned, VAX (little-endian) byte order
|
|
|
|
* V | Integer | 32-bit unsigned, VAX (little-endian) byte order
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
|
|
|
* U | Integer | UTF-8 character
|
|
|
|
* w | Integer | BER-compressed integer
|
|
|
|
*
|
|
|
|
* Float | |
|
|
|
|
* Directive | | Meaning
|
|
|
|
* ---------------------------------------------------------------------------
|
2010-08-09 09:13:31 -04:00
|
|
|
* D, d | Float | double-precision, native format
|
|
|
|
* F, f | Float | single-precision, native format
|
|
|
|
* E | Float | double-precision, little-endian byte order
|
|
|
|
* e | Float | single-precision, little-endian byte order
|
|
|
|
* G | Float | double-precision, network (big-endian) byte order
|
|
|
|
* g | Float | single-precision, network (big-endian) byte order
|
2010-06-28 09:05:07 -04:00
|
|
|
*
|
|
|
|
* String | |
|
|
|
|
* Directive | | Meaning
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
* A | String | arbitrary binary string (space padded, count is width)
|
|
|
|
* a | String | arbitrary binary string (null padded, count is width)
|
|
|
|
* Z | String | same as ``a'', except that null is added with *
|
|
|
|
* B | String | bit string (MSB first)
|
|
|
|
* b | String | bit string (LSB first)
|
|
|
|
* H | String | hex string (high nibble first)
|
|
|
|
* h | String | hex string (low nibble first)
|
|
|
|
* u | String | UU-encoded string
|
|
|
|
* M | String | quoted printable, MIME encoding (see RFC2045)
|
|
|
|
* m | String | base64 encoded string (see RFC 2045, count is width)
|
|
|
|
* | | (if count is 0, no line feed are added, see RFC 4648)
|
|
|
|
* P | String | pointer to a structure (fixed-length string)
|
|
|
|
* p | String | pointer to a null-terminated string
|
|
|
|
*
|
|
|
|
* Misc. | |
|
|
|
|
* Directive | | Meaning
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
* @ | --- | moves to absolute position
|
|
|
|
* X | --- | back up a byte
|
|
|
|
* x | --- | null byte
|
2003-12-18 16:08:25 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
pack_pack(VALUE ary, VALUE fmt)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-03-01 05:06:03 -05:00
|
|
|
static const char nul10[] = "\0\0\0\0\0\0\0\0\0\0";
|
|
|
|
static const char spc10[] = " ";
|
|
|
|
const char *p, *pend;
|
2001-08-06 11:05:50 -04:00
|
|
|
VALUE res, from, associates = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
char type;
|
2002-08-21 11:47:54 -04:00
|
|
|
long items, len, idx, plen;
|
2006-03-01 05:06:03 -05:00
|
|
|
const char *ptr;
|
2008-12-23 10:30:05 -05:00
|
|
|
int enc_info = 1; /* 0 - BINARY, 1 - US-ASCII, 2 - UTF-8 */
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
|
|
|
int natint; /* native integer */
|
|
|
|
#endif
|
2010-02-25 09:00:48 -05:00
|
|
|
int signed_p, integer_size, bigendian_p;
|
2001-05-02 00:22:21 -04:00
|
|
|
|
|
|
|
StringValue(fmt);
|
2006-08-31 06:47:44 -04:00
|
|
|
p = RSTRING_PTR(fmt);
|
|
|
|
pend = p + RSTRING_LEN(fmt);
|
2001-05-30 05:12:34 -04:00
|
|
|
res = rb_str_buf_new(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-09-02 10:42:08 -04:00
|
|
|
items = RARRAY_LEN(ary);
|
1998-01-16 07:13:05 -05:00
|
|
|
idx = 0;
|
|
|
|
|
2006-08-04 00:58:25 -04:00
|
|
|
#define TOO_FEW (rb_raise(rb_eArgError, toofew), 0)
|
2006-09-02 10:42:08 -04:00
|
|
|
#define THISFROM (items > 0 ? RARRAY_PTR(ary)[idx] : TOO_FEW)
|
|
|
|
#define NEXTFROM (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW)
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (p < pend) {
|
2010-10-15 03:42:21 -04:00
|
|
|
int explicit_endian = 0;
|
2006-08-31 06:47:44 -04:00
|
|
|
if (RSTRING_PTR(fmt) + RSTRING_LEN(fmt) != pend) {
|
2004-10-07 23:36:54 -04:00
|
|
|
rb_raise(rb_eRuntimeError, "format string modified");
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
type = *p++; /* get data type */
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
|
|
|
natint = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ISSPACE(type)) continue;
|
2002-02-18 04:52:48 -05:00
|
|
|
if (type == '#') {
|
2002-02-18 06:51:10 -05:00
|
|
|
while ((p < pend) && (*p != '\n')) {
|
2002-02-18 04:52:48 -05:00
|
|
|
p++;
|
|
|
|
}
|
2002-02-21 02:15:06 -05:00
|
|
|
continue;
|
2002-02-18 04:52:48 -05:00
|
|
|
}
|
2010-10-14 09:12:56 -04:00
|
|
|
|
|
|
|
{
|
2010-10-18 02:33:50 -04:00
|
|
|
static const char natstr[] = "sSiIlL";
|
2010-10-14 09:12:56 -04:00
|
|
|
static const char endstr[] = "sSiIlLqQ";
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-10-14 09:12:56 -04:00
|
|
|
modifiers:
|
|
|
|
switch (*p) {
|
|
|
|
case '_':
|
|
|
|
case '!':
|
|
|
|
if (strchr(natstr, type)) {
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
2010-10-14 09:12:56 -04:00
|
|
|
natint = 1;
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
2010-10-14 09:12:56 -04:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eArgError, "'%c' allowed only after types %s", *p, natstr);
|
|
|
|
}
|
|
|
|
goto modifiers;
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
if (!strchr(endstr, type)) {
|
|
|
|
rb_raise(rb_eArgError, "'%c' allowed only after types %s", *p, endstr);
|
|
|
|
}
|
|
|
|
if (explicit_endian) {
|
|
|
|
rb_raise(rb_eRangeError, "Can't use both '<' and '>'");
|
|
|
|
}
|
|
|
|
explicit_endian = *p++;
|
|
|
|
goto modifiers;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
2010-10-14 09:12:56 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (*p == '*') { /* set data length */
|
2008-12-08 09:41:44 -05:00
|
|
|
len = strchr("@Xxu", type) ? 0
|
|
|
|
: strchr("PMm", type) ? 1
|
|
|
|
: items;
|
2006-08-04 00:58:25 -04:00
|
|
|
p++;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
else if (ISDIGIT(*p)) {
|
2008-05-17 13:56:41 -04:00
|
|
|
errno = 0;
|
2008-01-02 01:24:27 -05:00
|
|
|
len = STRTOUL(p, (char**)&p, 10);
|
2008-05-17 13:56:41 -04:00
|
|
|
if (errno) {
|
|
|
|
rb_raise(rb_eRangeError, "pack length too big");
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
|
2008-12-23 10:30:05 -05:00
|
|
|
switch (type) {
|
|
|
|
case 'U':
|
|
|
|
/* if encoding is US-ASCII, upgrade to UTF-8 */
|
|
|
|
if (enc_info == 1) enc_info = 2;
|
|
|
|
break;
|
|
|
|
case 'm': case 'M': case 'u':
|
|
|
|
/* keep US-ASCII (do nothing) */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* fall back to BINARY */
|
|
|
|
enc_info = 0;
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (type) {
|
1999-08-13 01:45:20 -04:00
|
|
|
case 'A': case 'a': case 'Z':
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'B': case 'b':
|
|
|
|
case 'H': case 'h':
|
|
|
|
from = NEXTFROM;
|
|
|
|
if (NIL_P(from)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
ptr = "";
|
1998-01-16 07:13:05 -05:00
|
|
|
plen = 0;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-02 00:22:21 -04:00
|
|
|
StringValue(from);
|
2006-08-31 06:47:44 -04:00
|
|
|
ptr = RSTRING_PTR(from);
|
|
|
|
plen = RSTRING_LEN(from);
|
2002-05-21 01:39:19 -04:00
|
|
|
OBJ_INFECT(res, from);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p[-1] == '*')
|
|
|
|
len = plen;
|
|
|
|
|
|
|
|
switch (type) {
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'a': /* arbitrary binary string (null padded) */
|
2007-12-11 09:05:34 -05:00
|
|
|
case 'A': /* arbitrary binary string (ASCII space padded) */
|
|
|
|
case 'Z': /* null terminated string */
|
2004-05-12 22:04:20 -04:00
|
|
|
if (plen >= len) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, ptr, len);
|
2004-05-12 22:04:20 -04:00
|
|
|
if (p[-1] == '*' && type == 'Z')
|
|
|
|
rb_str_buf_cat(res, nul10, 1);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
else {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, ptr, plen);
|
1998-01-16 07:13:05 -05:00
|
|
|
len -= plen;
|
|
|
|
while (len >= 10) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (type == 'A')?spc10:nul10, 10);
|
1998-01-16 07:13:05 -05:00
|
|
|
len -= 10;
|
|
|
|
}
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (type == 'A')?spc10:nul10, len);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'b': /* bit string (ascending) */
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int byte = 0;
|
2002-08-28 04:05:23 -04:00
|
|
|
long i, j = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (len > plen) {
|
|
|
|
j = (len - plen + 1)/2;
|
|
|
|
len = plen;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i++ < len; ptr++) {
|
|
|
|
if (*ptr & 1)
|
|
|
|
byte |= 128;
|
|
|
|
if (i & 7)
|
|
|
|
byte >>= 1;
|
|
|
|
else {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
byte = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 7) {
|
|
|
|
char c;
|
|
|
|
byte >>= 7 - (len & 7);
|
|
|
|
c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-03-29 06:17:55 -05:00
|
|
|
len = j;
|
|
|
|
goto grow;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'B': /* bit string (descending) */
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int byte = 0;
|
2002-08-28 04:05:23 -04:00
|
|
|
long i, j = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (len > plen) {
|
|
|
|
j = (len - plen + 1)/2;
|
|
|
|
len = plen;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i++ < len; ptr++) {
|
|
|
|
byte |= *ptr & 1;
|
|
|
|
if (i & 7)
|
|
|
|
byte <<= 1;
|
|
|
|
else {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
byte = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 7) {
|
|
|
|
char c;
|
|
|
|
byte <<= 7 - (len & 7);
|
|
|
|
c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-03-29 06:17:55 -05:00
|
|
|
len = j;
|
|
|
|
goto grow;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'h': /* hex string (low nibble first) */
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int byte = 0;
|
2002-08-28 04:05:23 -04:00
|
|
|
long i, j = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (len > plen) {
|
2008-12-08 04:31:44 -05:00
|
|
|
j = (len + 1) / 2 - (plen + 1) / 2;
|
1999-08-13 01:45:20 -04:00
|
|
|
len = plen;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i++ < len; ptr++) {
|
1999-08-13 01:45:20 -04:00
|
|
|
if (ISALPHA(*ptr))
|
|
|
|
byte |= (((*ptr & 15) + 9) & 15) << 4;
|
|
|
|
else
|
|
|
|
byte |= (*ptr & 15) << 4;
|
|
|
|
if (i & 1)
|
|
|
|
byte >>= 4;
|
|
|
|
else {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1999-08-13 01:45:20 -04:00
|
|
|
byte = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 1) {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-04-07 02:58:31 -04:00
|
|
|
len = j;
|
2003-03-29 06:17:55 -05:00
|
|
|
goto grow;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'H': /* hex string (high nibble first) */
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int byte = 0;
|
2002-08-28 04:05:23 -04:00
|
|
|
long i, j = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (len > plen) {
|
2008-12-08 04:31:44 -05:00
|
|
|
j = (len + 1) / 2 - (plen + 1) / 2;
|
1999-08-13 01:45:20 -04:00
|
|
|
len = plen;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i++ < len; ptr++) {
|
1999-08-13 01:45:20 -04:00
|
|
|
if (ISALPHA(*ptr))
|
|
|
|
byte |= ((*ptr & 15) + 9) & 15;
|
|
|
|
else
|
|
|
|
byte |= *ptr & 15;
|
|
|
|
if (i & 1)
|
|
|
|
byte <<= 4;
|
|
|
|
else {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1999-08-13 01:45:20 -04:00
|
|
|
byte = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 1) {
|
|
|
|
char c = byte & 0xff;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-03-29 06:17:55 -05:00
|
|
|
len = j;
|
|
|
|
goto grow;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'c': /* signed char */
|
|
|
|
case 'C': /* unsigned char */
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
c = (char)num2i32(from);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, sizeof(char));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 's': /* signed short */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 1;
|
|
|
|
integer_size = NATINT_LEN(short, 2);
|
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
case 'S': /* unsigned short */
|
|
|
|
signed_p = 0;
|
|
|
|
integer_size = NATINT_LEN(short, 2);
|
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'i': /* signed int */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 1;
|
2010-02-26 00:17:13 -05:00
|
|
|
integer_size = (int)sizeof(int);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
case 'I': /* unsigned int */
|
|
|
|
signed_p = 0;
|
2010-02-26 00:17:13 -05:00
|
|
|
integer_size = (int)sizeof(int);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'l': /* signed long */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 1;
|
|
|
|
integer_size = NATINT_LEN(long, 4);
|
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
case 'L': /* unsigned long */
|
|
|
|
signed_p = 0;
|
|
|
|
integer_size = NATINT_LEN(long, 4);
|
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'q': /* signed quad (64bit) int */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 1;
|
2010-10-18 02:33:50 -04:00
|
|
|
integer_size = 8;
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
2002-02-13 04:01:11 -05:00
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
case 'Q': /* unsigned quad (64bit) int */
|
|
|
|
signed_p = 0;
|
2010-10-18 02:33:50 -04:00
|
|
|
integer_size = 8;
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
|
|
|
goto pack_integer;
|
2002-02-13 04:01:11 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'n': /* unsigned short (network byte-order) */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 2;
|
|
|
|
bigendian_p = 1;
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'N': /* unsigned long (network byte-order) */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 4;
|
|
|
|
bigendian_p = 1;
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'v': /* unsigned short (VAX byte-order) */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 2;
|
|
|
|
bigendian_p = 0;
|
|
|
|
goto pack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'V': /* unsigned long (VAX byte-order) */
|
2010-02-25 09:00:48 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 4;
|
|
|
|
bigendian_p = 0;
|
|
|
|
goto pack_integer;
|
|
|
|
|
|
|
|
pack_integer:
|
2010-10-14 09:12:56 -04:00
|
|
|
if (explicit_endian) {
|
2010-10-15 04:28:18 -04:00
|
|
|
bigendian_p = explicit_endian == '>';
|
2010-10-14 09:12:56 -04:00
|
|
|
}
|
|
|
|
|
2010-02-25 09:00:48 -05:00
|
|
|
switch (integer_size) {
|
2010-02-27 21:32:09 -05:00
|
|
|
#if defined(HAVE_INT16_T) && !defined(FORCE_BIG_PACK)
|
2010-02-27 10:39:20 -05:00
|
|
|
case SIZEOF_INT16_T:
|
2010-02-25 09:00:48 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int16_t i;
|
|
|
|
char a[sizeof(int16_t)];
|
|
|
|
} v;
|
2010-02-25 09:00:48 -05:00
|
|
|
|
|
|
|
from = NEXTFROM;
|
2010-02-28 01:08:50 -05:00
|
|
|
v.i = (int16_t)num2i32(from);
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap16(v.i);
|
|
|
|
rb_str_buf_cat(res, v.a, sizeof(int16_t));
|
2010-02-25 09:00:48 -05:00
|
|
|
}
|
|
|
|
break;
|
2010-02-27 10:39:20 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-02-27 21:32:09 -05:00
|
|
|
#if defined(HAVE_INT32_T) && !defined(FORCE_BIG_PACK)
|
2010-02-27 10:39:20 -05:00
|
|
|
case SIZEOF_INT32_T:
|
2010-02-25 09:00:48 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int32_t i;
|
|
|
|
char a[sizeof(int32_t)];
|
|
|
|
} v;
|
2010-02-25 09:00:48 -05:00
|
|
|
|
|
|
|
from = NEXTFROM;
|
2010-02-28 01:08:50 -05:00
|
|
|
v.i = (int32_t)num2i32(from);
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap32(v.i);
|
|
|
|
rb_str_buf_cat(res, v.a, sizeof(int32_t));
|
2010-02-25 09:00:48 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-02-27 10:39:20 -05:00
|
|
|
#if defined(HAVE_INT64_T) && SIZEOF_LONG == SIZEOF_INT64_T && !defined(FORCE_BIG_PACK)
|
|
|
|
case SIZEOF_INT64_T:
|
2010-02-25 09:00:48 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int64_t i;
|
|
|
|
char a[sizeof(int64_t)];
|
|
|
|
} v;
|
2010-02-25 09:00:48 -05:00
|
|
|
|
|
|
|
from = NEXTFROM;
|
2010-02-28 01:08:50 -05:00
|
|
|
v.i = num2i32(from); /* can return 64bit value if SIZEOF_LONG == SIZEOF_INT64_T */
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap64(v.i);
|
|
|
|
rb_str_buf_cat(res, v.a, sizeof(int64_t));
|
2010-02-25 09:00:48 -05:00
|
|
|
}
|
|
|
|
break;
|
2010-02-27 21:32:09 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (integer_size > MAX_INTEGER_PACK_SIZE)
|
|
|
|
rb_bug("unexpected intger size for pack: %d", integer_size);
|
2010-02-25 09:00:48 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
unsigned long i[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG];
|
|
|
|
char a[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG*SIZEOF_LONG];
|
|
|
|
} v;
|
2010-02-27 21:32:09 -05:00
|
|
|
int num_longs = (integer_size+SIZEOF_LONG-1)/SIZEOF_LONG;
|
|
|
|
int i;
|
2010-02-25 09:00:48 -05:00
|
|
|
|
|
|
|
from = NEXTFROM;
|
2010-02-28 01:08:50 -05:00
|
|
|
rb_big_pack(from, v.i, num_longs);
|
2010-02-27 21:32:09 -05:00
|
|
|
if (bigendian_p) {
|
|
|
|
for (i = 0; i < num_longs/2; i++) {
|
2010-02-28 01:08:50 -05:00
|
|
|
unsigned long t = v.i[i];
|
|
|
|
v.i[i] = v.i[num_longs-1-i];
|
|
|
|
v.i[num_longs-1-i] = t;
|
2010-02-26 13:51:02 -05:00
|
|
|
}
|
|
|
|
}
|
2010-02-27 21:32:09 -05:00
|
|
|
if (bigendian_p != BIGENDIAN_P()) {
|
|
|
|
for (i = 0; i < num_longs; i++)
|
2010-02-28 01:08:50 -05:00
|
|
|
v.i[i] = swapl(v.i[i]);
|
2010-02-27 21:32:09 -05:00
|
|
|
}
|
|
|
|
rb_str_buf_cat(res,
|
|
|
|
bigendian_p ?
|
2010-02-28 01:08:50 -05:00
|
|
|
v.a + sizeof(long)*num_longs - integer_size :
|
|
|
|
v.a,
|
2010-02-27 21:32:09 -05:00
|
|
|
integer_size);
|
2010-02-25 09:00:48 -05:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'f': /* single precision float in native format */
|
|
|
|
case 'F': /* ditto */
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
float f;
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
f = (float)RFLOAT_VALUE(rb_to_float(from));
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&f, sizeof(float));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'e': /* single precision float in VAX byte-order */
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
float f;
|
|
|
|
FLOAT_CONVWITH(ftmp);
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
f = (float)RFLOAT_VALUE(rb_to_float(from));
|
1999-08-13 01:45:20 -04:00
|
|
|
f = HTOVF(f,ftmp);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&f, sizeof(float));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'E': /* double precision float in VAX byte-order */
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
double d;
|
|
|
|
DOUBLE_CONVWITH(dtmp);
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
2008-12-30 11:10:23 -05:00
|
|
|
d = RFLOAT_VALUE(rb_to_float(from));
|
1999-08-13 01:45:20 -04:00
|
|
|
d = HTOVD(d,dtmp);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&d, sizeof(double));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'd': /* double precision float in native format */
|
|
|
|
case 'D': /* ditto */
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
double d;
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
2008-12-30 11:10:23 -05:00
|
|
|
d = RFLOAT_VALUE(rb_to_float(from));
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&d, sizeof(double));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'g': /* single precision float in network byte-order */
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
float f;
|
|
|
|
FLOAT_CONVWITH(ftmp);
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
f = (float)RFLOAT_VALUE(rb_to_float(from));
|
1999-08-13 01:45:20 -04:00
|
|
|
f = HTONF(f,ftmp);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&f, sizeof(float));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'G': /* double precision float in network byte-order */
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
double d;
|
|
|
|
DOUBLE_CONVWITH(dtmp);
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
2008-12-30 11:10:23 -05:00
|
|
|
d = RFLOAT_VALUE(rb_to_float(from));
|
1999-08-13 01:45:20 -04:00
|
|
|
d = HTOND(d,dtmp);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&d, sizeof(double));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'x': /* null byte */
|
1998-01-16 07:13:05 -05:00
|
|
|
grow:
|
|
|
|
while (len >= 10) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, nul10, 10);
|
1998-01-16 07:13:05 -05:00
|
|
|
len -= 10;
|
|
|
|
}
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, nul10, len);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'X': /* back up byte */
|
1998-01-16 07:13:05 -05:00
|
|
|
shrink:
|
2006-08-31 06:47:44 -04:00
|
|
|
plen = RSTRING_LEN(res);
|
2001-05-30 05:12:34 -04:00
|
|
|
if (plen < len)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "X outside of string");
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_set_len(res, plen - len);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case '@': /* null fill to absolute position */
|
2006-08-31 06:47:44 -04:00
|
|
|
len -= RSTRING_LEN(res);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (len > 0) goto grow;
|
|
|
|
len = -len;
|
|
|
|
if (len > 0) goto shrink;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
1999-10-04 00:51:08 -04:00
|
|
|
rb_raise(rb_eArgError, "%% is not supported");
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'U': /* Unicode character */
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
2007-12-24 13:12:24 -05:00
|
|
|
SIGNED_VALUE l;
|
1999-08-13 01:45:20 -04:00
|
|
|
char buf[8];
|
|
|
|
int le;
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
2004-03-30 21:59:57 -05:00
|
|
|
from = rb_to_int(from);
|
2007-12-24 13:12:24 -05:00
|
|
|
l = NUM2LONG(from);
|
2004-04-06 22:51:05 -04:00
|
|
|
if (l < 0) {
|
2004-03-30 21:59:57 -05:00
|
|
|
rb_raise(rb_eRangeError, "pack(U): value out of range");
|
|
|
|
}
|
2007-12-01 11:56:19 -05:00
|
|
|
le = rb_uv_to_utf8(buf, l);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)buf, le);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'u': /* uuencoded string */
|
|
|
|
case 'm': /* base64 encoded string */
|
2001-05-02 00:22:21 -04:00
|
|
|
from = NEXTFROM;
|
|
|
|
StringValue(from);
|
2006-08-31 06:47:44 -04:00
|
|
|
ptr = RSTRING_PTR(from);
|
|
|
|
plen = RSTRING_LEN(from);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2008-12-06 03:55:57 -05:00
|
|
|
if (len == 0 && type == 'm') {
|
2008-09-25 08:24:54 -04:00
|
|
|
encodes(res, ptr, plen, type, 0);
|
|
|
|
ptr += plen;
|
|
|
|
break;
|
|
|
|
}
|
2001-01-05 10:24:13 -05:00
|
|
|
if (len <= 2)
|
1998-01-16 07:13:05 -05:00
|
|
|
len = 45;
|
|
|
|
else
|
|
|
|
len = len / 3 * 3;
|
|
|
|
while (plen > 0) {
|
2002-08-28 04:05:23 -04:00
|
|
|
long todo;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (plen > len)
|
|
|
|
todo = len;
|
|
|
|
else
|
|
|
|
todo = plen;
|
2008-09-25 08:24:54 -04:00
|
|
|
encodes(res, ptr, todo, type, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
plen -= todo;
|
|
|
|
ptr += todo;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'M': /* quoted-printable encoded string */
|
1999-01-19 23:59:39 -05:00
|
|
|
from = rb_obj_as_string(NEXTFROM);
|
|
|
|
if (len <= 1)
|
|
|
|
len = 72;
|
|
|
|
qpencode(res, from, len);
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'P': /* pointer to packed byte string */
|
2001-05-02 00:22:21 -04:00
|
|
|
from = THISFROM;
|
|
|
|
if (!NIL_P(from)) {
|
|
|
|
StringValue(from);
|
2006-08-31 06:47:44 -04:00
|
|
|
if (RSTRING_LEN(from) < len) {
|
2002-05-28 14:11:07 -04:00
|
|
|
rb_raise(rb_eArgError, "too short buffer for P(%ld for %ld)",
|
2006-08-31 06:47:44 -04:00
|
|
|
RSTRING_LEN(from), len);
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
len = 1;
|
|
|
|
/* FALL THROUGH */
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'p': /* pointer to string */
|
1999-01-19 23:59:39 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
char *t;
|
|
|
|
from = NEXTFROM;
|
2001-01-15 02:01:00 -05:00
|
|
|
if (NIL_P(from)) {
|
2001-05-02 00:22:21 -04:00
|
|
|
t = 0;
|
|
|
|
}
|
|
|
|
else {
|
2003-06-23 02:52:39 -04:00
|
|
|
t = StringValuePtr(from);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2001-08-06 11:05:50 -04:00
|
|
|
if (!associates) {
|
|
|
|
associates = rb_ary_new();
|
|
|
|
}
|
|
|
|
rb_ary_push(associates, from);
|
2006-07-18 03:02:35 -04:00
|
|
|
rb_obj_taint(from);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, (char*)&t, sizeof(char*));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
case 'w': /* BER compressed integer */
|
2000-05-12 05:07:57 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
unsigned long ul;
|
|
|
|
VALUE buf = rb_str_new(0, 0);
|
|
|
|
char c, *bufs, *bufe;
|
|
|
|
|
|
|
|
from = NEXTFROM;
|
|
|
|
if (TYPE(from) == T_BIGNUM) {
|
|
|
|
VALUE big128 = rb_uint2big(128);
|
|
|
|
while (TYPE(from) == T_BIGNUM) {
|
|
|
|
from = rb_big_divmod(from, big128);
|
2006-09-02 10:42:08 -04:00
|
|
|
c = NUM2INT(RARRAY_PTR(from)[1]) | 0x80; /* mod */
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(buf, &c, sizeof(char));
|
2006-09-02 10:42:08 -04:00
|
|
|
from = RARRAY_PTR(from)[0]; /* div */
|
2000-05-12 05:07:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-22 13:06:38 -05:00
|
|
|
{
|
2003-10-09 13:45:53 -04:00
|
|
|
long l = NUM2LONG(from);
|
|
|
|
if (l < 0) {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
rb_raise(rb_eArgError, "can't compress negative numbers");
|
2003-10-09 13:45:53 -04:00
|
|
|
}
|
|
|
|
ul = l;
|
2000-05-12 05:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (ul) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
c = (char)(ul & 0x7f) | 0x80;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(buf, &c, sizeof(char));
|
2000-05-12 05:07:57 -04:00
|
|
|
ul >>= 7;
|
|
|
|
}
|
|
|
|
|
2006-08-31 06:47:44 -04:00
|
|
|
if (RSTRING_LEN(buf)) {
|
|
|
|
bufs = RSTRING_PTR(buf);
|
|
|
|
bufe = bufs + RSTRING_LEN(buf) - 1;
|
2000-05-12 05:07:57 -04:00
|
|
|
*bufs &= 0x7f; /* clear continue bit */
|
|
|
|
while (bufs < bufe) { /* reverse */
|
|
|
|
c = *bufs;
|
|
|
|
*bufs++ = *bufe;
|
|
|
|
*bufe-- = c;
|
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_buf_cat(res, RSTRING_PTR(buf), RSTRING_LEN(buf));
|
2000-05-12 05:07:57 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c = 0;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(res, &c, sizeof(char));
|
2000-05-12 05:07:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-06 11:05:50 -04:00
|
|
|
|
|
|
|
if (associates) {
|
|
|
|
rb_str_associate(res, associates);
|
|
|
|
}
|
2008-12-04 11:20:02 -05:00
|
|
|
OBJ_INFECT(res, fmt);
|
2008-12-23 10:30:05 -05:00
|
|
|
switch (enc_info) {
|
|
|
|
case 1:
|
|
|
|
ENCODING_CODERANGE_SET(res, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rb_enc_set_index(res, rb_utf8_encindex());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do nothing, keep ASCII-8BIT */
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-03-01 05:06:03 -05:00
|
|
|
static const char uu_table[] =
|
1998-01-16 07:19:22 -05:00
|
|
|
"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
|
2006-03-01 05:06:03 -05:00
|
|
|
static const char b64_table[] =
|
1998-01-16 07:19:22 -05:00
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
2008-09-25 08:24:54 -04:00
|
|
|
encodes(VALUE str, const char *s, long len, int type, int tail_lf)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2008-09-04 11:06:34 -04:00
|
|
|
char buff[4096];
|
2002-08-28 04:05:23 -04:00
|
|
|
long i = 0;
|
2006-03-01 05:06:03 -05:00
|
|
|
const char *trans = type == 'u' ? uu_table : b64_table;
|
1998-01-16 07:19:22 -05:00
|
|
|
int padding;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (type == 'u') {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buff[i++] = (char)len + ' ';
|
1998-01-16 07:19:22 -05:00
|
|
|
padding = '`';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
padding = '=';
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
while (len >= 3) {
|
2008-09-04 11:06:34 -04:00
|
|
|
while (len >= 3 && sizeof(buff)-i >= 4) {
|
|
|
|
buff[i++] = trans[077 & (*s >> 2)];
|
|
|
|
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
|
|
|
|
buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
|
|
|
|
buff[i++] = trans[077 & s[2]];
|
|
|
|
s += 3;
|
|
|
|
len -= 3;
|
|
|
|
}
|
|
|
|
if (sizeof(buff)-i < 4) {
|
|
|
|
rb_str_buf_cat(str, buff, i);
|
|
|
|
i = 0;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2008-09-04 11:06:34 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (len == 2) {
|
|
|
|
buff[i++] = trans[077 & (*s >> 2)];
|
|
|
|
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
|
|
|
|
buff[i++] = trans[077 & (((s[1] << 2) & 074) | (('\0' >> 6) & 03))];
|
|
|
|
buff[i++] = padding;
|
|
|
|
}
|
|
|
|
else if (len == 1) {
|
|
|
|
buff[i++] = trans[077 & (*s >> 2)];
|
|
|
|
buff[i++] = trans[077 & (((*s << 4) & 060) | (('\0' >> 4) & 017))];
|
|
|
|
buff[i++] = padding;
|
|
|
|
buff[i++] = padding;
|
|
|
|
}
|
2008-09-25 08:24:54 -04:00
|
|
|
if (tail_lf) buff[i++] = '\n';
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, buff, i);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2006-03-01 05:06:03 -05:00
|
|
|
static const char hex_table[] = "0123456789ABCDEF";
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
qpencode(VALUE str, VALUE from, long len)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
char buff[1024];
|
2002-08-28 04:05:23 -04:00
|
|
|
long i = 0, n = 0, prev = EOF;
|
2006-08-31 06:47:44 -04:00
|
|
|
unsigned char *s = (unsigned char*)RSTRING_PTR(from);
|
|
|
|
unsigned char *send = s + RSTRING_LEN(from);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
while (s < send) {
|
|
|
|
if ((*s > 126) ||
|
|
|
|
(*s < 32 && *s != '\n' && *s != '\t') ||
|
|
|
|
(*s == '=')) {
|
|
|
|
buff[i++] = '=';
|
|
|
|
buff[i++] = hex_table[*s >> 4];
|
|
|
|
buff[i++] = hex_table[*s & 0x0f];
|
|
|
|
n += 3;
|
|
|
|
prev = EOF;
|
|
|
|
}
|
|
|
|
else if (*s == '\n') {
|
|
|
|
if (prev == ' ' || prev == '\t') {
|
|
|
|
buff[i++] = '=';
|
|
|
|
buff[i++] = *s;
|
|
|
|
}
|
|
|
|
buff[i++] = *s;
|
|
|
|
n = 0;
|
|
|
|
prev = *s;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buff[i++] = *s;
|
|
|
|
n++;
|
|
|
|
prev = *s;
|
|
|
|
}
|
|
|
|
if (n > len) {
|
|
|
|
buff[i++] = '=';
|
|
|
|
buff[i++] = '\n';
|
|
|
|
n = 0;
|
|
|
|
prev = '\n';
|
|
|
|
}
|
|
|
|
if (i > 1024 - 5) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, buff, i);
|
1999-01-19 23:59:39 -05:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
buff[i++] = '=';
|
|
|
|
buff[i++] = '\n';
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (i > 0) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, buff, i);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-10 05:07:31 -05:00
|
|
|
static inline int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
hex2num(char c)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
switch (c) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
1999-01-19 23:59:39 -05:00
|
|
|
return c - '0';
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 'a': case 'b': case 'c':
|
|
|
|
case 'd': case 'e': case 'f':
|
1999-01-19 23:59:39 -05:00
|
|
|
return c - 'a' + 10;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 'A': case 'B': case 'C':
|
|
|
|
case 'D': case 'E': case 'F':
|
1999-01-19 23:59:39 -05:00
|
|
|
return c - 'A' + 10;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return -1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-13 04:01:11 -05:00
|
|
|
#define PACK_LENGTH_ADJUST_SIZE(sz) do { \
|
2010-02-26 00:17:13 -05:00
|
|
|
tmp_len = 0; \
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
if (len > (long)((send-s)/sz)) { \
|
1999-08-13 01:45:20 -04:00
|
|
|
if (!star) { \
|
2010-02-26 00:17:13 -05:00
|
|
|
tmp_len = len-(send-s)/sz; \
|
1999-08-13 01:45:20 -04:00
|
|
|
} \
|
2002-02-13 04:01:11 -05:00
|
|
|
len = (send-s)/sz; \
|
1999-08-13 01:45:20 -04:00
|
|
|
} \
|
|
|
|
} while (0)
|
2002-02-13 04:01:11 -05:00
|
|
|
|
2010-02-26 00:17:13 -05:00
|
|
|
#define PACK_ITEM_ADJUST() do { \
|
|
|
|
if (tmp_len > 0) \
|
|
|
|
rb_ary_store(ary, RARRAY_LEN(ary)+tmp_len-1, Qnil); \
|
|
|
|
} while (0)
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2002-05-21 01:39:19 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
infected_str_new(const char *ptr, long len, VALUE str)
|
2002-05-21 01:39:19 -04:00
|
|
|
{
|
|
|
|
VALUE s = rb_str_new(ptr, len);
|
|
|
|
|
|
|
|
OBJ_INFECT(s, str);
|
|
|
|
return s;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
|
2003-12-18 16:08:25 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-17 17:07:33 -04:00
|
|
|
* str.unpack(format) -> anArray
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-18 16:08:25 -05:00
|
|
|
* Decodes <i>str</i> (which may contain binary data) according to the
|
|
|
|
* format string, returning an array of each value extracted. The
|
|
|
|
* format string consists of a sequence of single-character directives,
|
|
|
|
* summarized in the table at the end of this entry.
|
|
|
|
* Each directive may be followed
|
|
|
|
* by a number, indicating the number of times to repeat with this
|
|
|
|
* directive. An asterisk (``<code>*</code>'') will use up all
|
|
|
|
* remaining elements. The directives <code>sSiIlL</code> may each be
|
2010-06-28 09:05:07 -04:00
|
|
|
* followed by an underscore (``<code>_</code>'') or
|
|
|
|
* exclamation mark (``<code>!</code>'') to use the underlying
|
2003-12-18 16:08:25 -05:00
|
|
|
* platform's native size for the specified type; otherwise, it uses a
|
|
|
|
* platform-independent consistent size. Spaces are ignored in the
|
|
|
|
* format string. See also <code>Array#pack</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-18 16:08:25 -05:00
|
|
|
* "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
|
|
|
|
* "abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"]
|
2004-05-12 22:04:20 -04:00
|
|
|
* "abc \0abc \0".unpack('Z*Z*') #=> ["abc ", "abc "]
|
2003-12-18 16:08:25 -05:00
|
|
|
* "aa".unpack('b8B8') #=> ["10000110", "01100001"]
|
|
|
|
* "aaa".unpack('h2H2c') #=> ["16", "61", 97]
|
|
|
|
* "\xfe\xff\xfe\xff".unpack('sS') #=> [-2, 65534]
|
|
|
|
* "now=20is".unpack('M*') #=> ["now is"]
|
|
|
|
* "whole".unpack('xax2aX2aX1aX2a') #=> ["h", "e", "l", "l", "o"]
|
|
|
|
*
|
|
|
|
* This table summarizes the various formats and the Ruby classes
|
|
|
|
* returned by each.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2010-06-28 09:05:07 -04:00
|
|
|
* Integer | |
|
|
|
|
* Directive | Returns | Meaning
|
|
|
|
* -----------------------------------------------------------------
|
2010-08-09 09:13:31 -04:00
|
|
|
* C | Integer | 8-bit unsigned (unsigned char)
|
|
|
|
* S | Integer | 16-bit unsigned, native endian (uint16_t)
|
|
|
|
* L | Integer | 32-bit unsigned, native endian (uint32_t)
|
|
|
|
* Q | Integer | 64-bit unsigned, native endian (uint64_t)
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
2010-08-09 09:13:31 -04:00
|
|
|
* c | Integer | 8-bit signed (signed char)
|
|
|
|
* s | Integer | 16-bit signed, native endian (int16_t)
|
|
|
|
* l | Integer | 32-bit signed, native endian (int32_t)
|
|
|
|
* q | Integer | 64-bit signed, native endian (int64_t)
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
|
|
|
* S_, S! | Integer | unsigned short, native endian
|
|
|
|
* I, I_, I! | Integer | unsigned int, native endian
|
|
|
|
* L_, L! | Integer | unsigned long, native endian
|
|
|
|
* | |
|
|
|
|
* s_, s! | Integer | signed short, native endian
|
|
|
|
* i, i_, i! | Integer | signed int, native endian
|
|
|
|
* l_, l! | Integer | signed long, native endian
|
|
|
|
* | |
|
2010-10-17 23:59:53 -04:00
|
|
|
* S> L> Q> | Integer | same as the directives without ">" except
|
|
|
|
* s> l> q> | | big endian
|
|
|
|
* S!> I!> | | (available since Ruby 1.9.3)
|
|
|
|
* L!> Q!> | | "S>" is same as "n"
|
|
|
|
* s!> i!> | | "L>" is same as "N"
|
|
|
|
* l!> q!> | |
|
|
|
|
* | |
|
|
|
|
* S< L< Q< | Integer | same as the directives without "<" except
|
|
|
|
* s< l< q< | | little endian
|
|
|
|
* S!< I!< | | (available since Ruby 1.9.3)
|
|
|
|
* L!< Q!< | | "S<" is same as "v"
|
|
|
|
* s!< i!< | | "L<" is same as "V"
|
|
|
|
* l!< q!< | |
|
|
|
|
* | |
|
2010-08-09 09:13:31 -04:00
|
|
|
* n | Integer | 16-bit unsigned, network (big-endian) byte order
|
|
|
|
* N | Integer | 32-bit unsigned, network (big-endian) byte order
|
|
|
|
* v | Integer | 16-bit unsigned, VAX (little-endian) byte order
|
|
|
|
* V | Integer | 32-bit unsigned, VAX (little-endian) byte order
|
2010-06-28 09:05:07 -04:00
|
|
|
* | |
|
|
|
|
* U | Integer | UTF-8 character
|
|
|
|
* w | Integer | BER-compressed integer (see Array.pack)
|
|
|
|
*
|
|
|
|
* Float | |
|
|
|
|
* Directive | Returns | Meaning
|
|
|
|
* -----------------------------------------------------------------
|
2010-08-09 09:13:31 -04:00
|
|
|
* D, d | Float | double-precision, native format
|
|
|
|
* F, f | Float | single-precision, native format
|
|
|
|
* E | Float | double-precision, little-endian byte order
|
|
|
|
* e | Float | single-precision, little-endian byte order
|
|
|
|
* G | Float | double-precision, network (big-endian) byte order
|
|
|
|
* g | Float | single-precision, network (big-endian) byte order
|
2010-06-28 09:05:07 -04:00
|
|
|
*
|
|
|
|
* String | |
|
|
|
|
* Directive | Returns | Meaning
|
|
|
|
* -----------------------------------------------------------------
|
|
|
|
* A | String | arbitrary binary string (remove trailing nulls and ASCII spaces)
|
|
|
|
* a | String | arbitrary binary string
|
|
|
|
* Z | String | null-terminated string
|
|
|
|
* B | String | bit string (MSB first)
|
|
|
|
* b | String | bit string (LSB first)
|
|
|
|
* H | String | hex string (high nibble first)
|
|
|
|
* h | String | hex string (low nibble first)
|
|
|
|
* u | String | UU-encoded string
|
|
|
|
* M | String | quoted-printable, MIME encoding (see RFC2045)
|
|
|
|
* m | String | base64 encoded string (RFC 2045) (default)
|
|
|
|
* | | base64 encoded string (RFC 4648) if followed by 0
|
|
|
|
* P | String | pointer to a structure (fixed-length string)
|
|
|
|
* p | String | pointer to a null-terminated string
|
|
|
|
*
|
|
|
|
* Misc. | |
|
|
|
|
* Directive | Returns | Meaning
|
|
|
|
* -----------------------------------------------------------------
|
|
|
|
* @ | --- | skip to the offset given by the length argument
|
|
|
|
* X | --- | skip backward one byte
|
|
|
|
* x | --- | skip forward one byte
|
2003-12-18 16:08:25 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
pack_unpack(VALUE str, VALUE fmt)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2008-07-30 23:23:55 -04:00
|
|
|
static const char hexdigits[] = "0123456789abcdef";
|
1999-01-19 23:59:39 -05:00
|
|
|
char *s, *send;
|
|
|
|
char *p, *pend;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE ary;
|
|
|
|
char type;
|
2010-02-26 00:17:13 -05:00
|
|
|
long len, tmp_len;
|
|
|
|
int star;
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
|
|
|
int natint; /* native integer */
|
|
|
|
#endif
|
2006-10-15 18:57:37 -04:00
|
|
|
int block_p = rb_block_given_p();
|
2010-02-24 10:32:06 -05:00
|
|
|
int signed_p, integer_size, bigendian_p;
|
2006-10-15 18:57:37 -04:00
|
|
|
#define UNPACK_PUSH(item) do {\
|
|
|
|
VALUE item_val = (item);\
|
|
|
|
if (block_p) {\
|
|
|
|
rb_yield(item_val);\
|
|
|
|
}\
|
|
|
|
else {\
|
|
|
|
rb_ary_push(ary, item_val);\
|
|
|
|
}\
|
|
|
|
} while (0)
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
StringValue(str);
|
2004-10-07 00:06:41 -04:00
|
|
|
StringValue(fmt);
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(str);
|
|
|
|
send = s + RSTRING_LEN(str);
|
|
|
|
p = RSTRING_PTR(fmt);
|
|
|
|
pend = p + RSTRING_LEN(fmt);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-10-15 18:57:37 -04:00
|
|
|
ary = block_p ? Qnil : rb_ary_new();
|
1998-01-16 07:13:05 -05:00
|
|
|
while (p < pend) {
|
2010-10-15 03:42:21 -04:00
|
|
|
int explicit_endian = 0;
|
2002-02-18 04:52:48 -05:00
|
|
|
type = *p++;
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
|
|
|
natint = 0;
|
|
|
|
#endif
|
2002-02-18 04:52:48 -05:00
|
|
|
|
|
|
|
if (ISSPACE(type)) continue;
|
|
|
|
if (type == '#') {
|
2002-02-18 06:51:10 -05:00
|
|
|
while ((p < pend) && (*p != '\n')) {
|
2002-02-18 04:52:48 -05:00
|
|
|
p++;
|
|
|
|
}
|
2002-02-21 02:15:06 -05:00
|
|
|
continue;
|
2002-02-18 04:52:48 -05:00
|
|
|
}
|
2010-10-14 09:12:56 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
star = 0;
|
2010-10-14 09:12:56 -04:00
|
|
|
{
|
2010-10-18 02:33:50 -04:00
|
|
|
static const char natstr[] = "sSiIlL";
|
2010-10-14 09:12:56 -04:00
|
|
|
static const char endstr[] = "sSiIlLqQ";
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2010-10-14 09:12:56 -04:00
|
|
|
modifiers:
|
|
|
|
switch (*p) {
|
|
|
|
case '_':
|
|
|
|
case '!':
|
|
|
|
|
|
|
|
if (strchr(natstr, type)) {
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef NATINT_PACK
|
2010-10-14 09:12:56 -04:00
|
|
|
natint = 1;
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
2010-10-14 09:12:56 -04:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eArgError, "'%c' allowed only after types %s", *p, natstr);
|
|
|
|
}
|
|
|
|
goto modifiers;
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
if (!strchr(endstr, type)) {
|
|
|
|
rb_raise(rb_eArgError, "'%c' allowed only after types %s", *p, endstr);
|
|
|
|
}
|
|
|
|
if (explicit_endian) {
|
|
|
|
rb_raise(rb_eRangeError, "Can't use both '<' and '>'");
|
|
|
|
}
|
|
|
|
explicit_endian = *p++;
|
|
|
|
goto modifiers;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
2010-10-14 09:12:56 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (p >= pend)
|
|
|
|
len = 1;
|
|
|
|
else if (*p == '*') {
|
|
|
|
star = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
len = send - s;
|
|
|
|
p++;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
else if (ISDIGIT(*p)) {
|
2008-05-17 13:56:41 -04:00
|
|
|
errno = 0;
|
2008-01-02 01:24:27 -05:00
|
|
|
len = STRTOUL(p, (char**)&p, 10);
|
2008-05-17 13:56:41 -04:00
|
|
|
if (errno) {
|
|
|
|
rb_raise(rb_eRangeError, "pack length too big");
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = (type != '@');
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case '%':
|
1999-10-04 00:51:08 -04:00
|
|
|
rb_raise(rb_eArgError, "%% is not supported");
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
if (len > send - s) len = send - s;
|
|
|
|
{
|
2002-08-28 04:05:23 -04:00
|
|
|
long end = len;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t = s + len - 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (t >= s) {
|
|
|
|
if (*t != ' ' && *t != '\0') break;
|
1999-08-13 01:45:20 -04:00
|
|
|
t--; len--;
|
|
|
|
}
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(infected_str_new(s, len, str));
|
1999-08-13 01:45:20 -04:00
|
|
|
s += end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
{
|
2004-05-12 22:04:20 -04:00
|
|
|
char *t = s;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2004-05-12 22:04:20 -04:00
|
|
|
if (len > send-s) len = send-s;
|
|
|
|
while (t < s+len && *t) t++;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(infected_str_new(s, t-s, str));
|
2004-05-12 22:04:20 -04:00
|
|
|
if (t < send) t++;
|
|
|
|
s = star ? t : s+len;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
if (len > send - s) len = send - s;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(infected_str_new(s, len, str));
|
1998-01-16 07:13:05 -05:00
|
|
|
s += len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
VALUE bitstr;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2002-08-28 04:05:23 -04:00
|
|
|
int bits;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (p[-1] == '*' || len > (send - s) * 8)
|
|
|
|
len = (send - s) * 8;
|
|
|
|
bits = 0;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(bitstr = rb_str_new(0, len));
|
2006-08-31 06:47:44 -04:00
|
|
|
t = RSTRING_PTR(bitstr);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
if (i & 7) bits >>= 1;
|
|
|
|
else bits = *s++;
|
|
|
|
*t++ = (bits & 1) ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
{
|
|
|
|
VALUE bitstr;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2002-08-28 04:05:23 -04:00
|
|
|
int bits;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (p[-1] == '*' || len > (send - s) * 8)
|
|
|
|
len = (send - s) * 8;
|
|
|
|
bits = 0;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(bitstr = rb_str_new(0, len));
|
2006-08-31 06:47:44 -04:00
|
|
|
t = RSTRING_PTR(bitstr);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
if (i & 7) bits <<= 1;
|
|
|
|
else bits = *s++;
|
|
|
|
*t++ = (bits & 128) ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
{
|
|
|
|
VALUE bitstr;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2002-08-28 04:05:23 -04:00
|
|
|
int bits;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (p[-1] == '*' || len > (send - s) * 2)
|
|
|
|
len = (send - s) * 2;
|
|
|
|
bits = 0;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(bitstr = rb_str_new(0, len));
|
2006-08-31 06:47:44 -04:00
|
|
|
t = RSTRING_PTR(bitstr);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
if (i & 1)
|
|
|
|
bits >>= 4;
|
|
|
|
else
|
|
|
|
bits = *s++;
|
|
|
|
*t++ = hexdigits[bits & 15];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
{
|
|
|
|
VALUE bitstr;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2002-08-28 04:05:23 -04:00
|
|
|
int bits;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (p[-1] == '*' || len > (send - s) * 2)
|
|
|
|
len = (send - s) * 2;
|
|
|
|
bits = 0;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(bitstr = rb_str_new(0, len));
|
2006-08-31 06:47:44 -04:00
|
|
|
t = RSTRING_PTR(bitstr);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
if (i & 1)
|
|
|
|
bits <<= 4;
|
|
|
|
else
|
|
|
|
bits = *s++;
|
|
|
|
*t++ = hexdigits[(bits >> 4) & 15];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(char));
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
int c = *s++;
|
|
|
|
if (c > (char)127) c-=256;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(INT2FIX(c));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
PACK_ITEM_ADJUST();
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(unsigned char));
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
unsigned char c = *s++;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(INT2FIX(c));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
PACK_ITEM_ADJUST();
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 1;
|
|
|
|
integer_size = NATINT_LEN(short, 2);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'S':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = NATINT_LEN(short, 2);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'i':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 1;
|
2010-02-26 00:17:13 -05:00
|
|
|
integer_size = (int)sizeof(int);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'I':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
2010-02-26 00:17:13 -05:00
|
|
|
integer_size = (int)sizeof(int);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'l':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 1;
|
|
|
|
integer_size = NATINT_LEN(long, 4);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
2010-02-18 07:53:31 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'L':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = NATINT_LEN(long, 4);
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-02-13 04:01:11 -05:00
|
|
|
case 'q':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 1;
|
2010-10-18 02:33:50 -04:00
|
|
|
integer_size = 8;
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
2010-05-29 14:51:39 -04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 'Q':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
2010-10-18 02:33:50 -04:00
|
|
|
integer_size = 8;
|
2010-02-25 09:00:48 -05:00
|
|
|
bigendian_p = BIGENDIAN_P();
|
2010-02-24 10:32:06 -05:00
|
|
|
goto unpack_integer;
|
2002-02-13 04:01:11 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'n':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 2;
|
|
|
|
bigendian_p = 1;
|
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'N':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 4;
|
|
|
|
bigendian_p = 1;
|
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'v':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 2;
|
|
|
|
bigendian_p = 0;
|
|
|
|
goto unpack_integer;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'V':
|
2010-02-24 10:32:06 -05:00
|
|
|
signed_p = 0;
|
|
|
|
integer_size = 4;
|
|
|
|
bigendian_p = 0;
|
|
|
|
goto unpack_integer;
|
|
|
|
|
|
|
|
unpack_integer:
|
2010-10-14 09:12:56 -04:00
|
|
|
if (explicit_endian) {
|
2010-10-15 04:28:18 -04:00
|
|
|
bigendian_p = explicit_endian == '>';
|
2010-10-14 09:12:56 -04:00
|
|
|
}
|
|
|
|
|
2010-02-24 10:32:06 -05:00
|
|
|
switch (integer_size) {
|
2010-02-27 21:32:09 -05:00
|
|
|
#if defined(HAVE_INT16_T) && !defined(FORCE_BIG_PACK)
|
2010-02-27 10:39:20 -05:00
|
|
|
case SIZEOF_INT16_T:
|
2010-02-24 10:32:06 -05:00
|
|
|
if (signed_p) {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(int16_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int16_t i;
|
|
|
|
char a[sizeof(int16_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(int16_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap16(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(int16_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(INT2FIX(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
else {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(uint16_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
uint16_t i;
|
|
|
|
char a[sizeof(uint16_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(uint16_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap16(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(uint16_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(INT2FIX(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
break;
|
2010-02-27 10:39:20 -05:00
|
|
|
#endif
|
2010-02-24 10:32:06 -05:00
|
|
|
|
2010-02-27 21:32:09 -05:00
|
|
|
#if defined(HAVE_INT32_T) && !defined(FORCE_BIG_PACK)
|
2010-02-27 10:39:20 -05:00
|
|
|
case SIZEOF_INT32_T:
|
2010-02-24 10:32:06 -05:00
|
|
|
if (signed_p) {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(int32_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int32_t i;
|
|
|
|
char a[sizeof(int32_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(int32_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap32(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(int32_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(INT2NUM(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
else {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(uint32_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
uint32_t i;
|
|
|
|
char a[sizeof(uint32_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(uint32_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap32(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(uint32_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(UINT2NUM(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-02-27 10:39:20 -05:00
|
|
|
#if defined(HAVE_INT64_T) && !defined(FORCE_BIG_PACK)
|
|
|
|
case SIZEOF_INT64_T:
|
2010-02-24 10:32:06 -05:00
|
|
|
if (signed_p) {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(int64_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
int64_t i;
|
|
|
|
char a[sizeof(int64_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(int64_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap64(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(int64_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(INT64toNUM(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
else {
|
2010-02-27 10:39:20 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(uint64_t));
|
2010-02-24 10:32:06 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
uint64_t i;
|
|
|
|
char a[sizeof(uint64_t)];
|
|
|
|
} v;
|
|
|
|
memcpy(v.a, s, sizeof(uint64_t));
|
|
|
|
if (bigendian_p != BIGENDIAN_P()) v.i = swap64(v.i);
|
2010-02-27 10:39:20 -05:00
|
|
|
s += sizeof(uint64_t);
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(UINT64toNUM(v.i));
|
2010-02-24 10:32:06 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
}
|
|
|
|
break;
|
2010-02-27 21:32:09 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (integer_size > MAX_INTEGER_PACK_SIZE)
|
|
|
|
rb_bug("unexpected intger size for pack: %d", integer_size);
|
|
|
|
PACK_LENGTH_ADJUST_SIZE(integer_size);
|
2010-02-26 13:51:02 -05:00
|
|
|
while (len-- > 0) {
|
2010-02-28 01:08:50 -05:00
|
|
|
union {
|
|
|
|
unsigned long i[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG)/SIZEOF_LONG];
|
|
|
|
char a[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG)/SIZEOF_LONG*SIZEOF_LONG];
|
|
|
|
} v;
|
2010-02-27 21:32:09 -05:00
|
|
|
int num_longs = (integer_size+SIZEOF_LONG)/SIZEOF_LONG;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (signed_p && (signed char)s[bigendian_p ? 0 : (integer_size-1)] < 0)
|
2010-02-28 01:08:50 -05:00
|
|
|
memset(v.a, 0xff, sizeof(long)*num_longs);
|
2010-02-27 21:32:09 -05:00
|
|
|
else
|
2010-02-28 01:08:50 -05:00
|
|
|
memset(v.a, 0, sizeof(long)*num_longs);
|
2010-02-27 21:32:09 -05:00
|
|
|
if (bigendian_p)
|
2010-02-28 01:08:50 -05:00
|
|
|
memcpy(v.a + sizeof(long)*num_longs - integer_size, s, integer_size);
|
2010-02-27 21:32:09 -05:00
|
|
|
else
|
2010-02-28 01:08:50 -05:00
|
|
|
memcpy(v.a, s, integer_size);
|
2010-02-27 21:32:09 -05:00
|
|
|
if (bigendian_p) {
|
|
|
|
for (i = 0; i < num_longs/2; i++) {
|
2010-02-28 01:08:50 -05:00
|
|
|
unsigned long t = v.i[i];
|
|
|
|
v.i[i] = v.i[num_longs-1-i];
|
|
|
|
v.i[num_longs-1-i] = t;
|
2010-02-26 13:51:02 -05:00
|
|
|
}
|
|
|
|
}
|
2010-02-27 21:32:09 -05:00
|
|
|
if (bigendian_p != BIGENDIAN_P()) {
|
|
|
|
for (i = 0; i < num_longs; i++)
|
2010-02-28 01:08:50 -05:00
|
|
|
v.i[i] = swapl(v.i[i]);
|
2010-02-26 13:51:02 -05:00
|
|
|
}
|
2010-02-27 21:32:09 -05:00
|
|
|
s += integer_size;
|
2010-02-28 01:08:50 -05:00
|
|
|
UNPACK_PUSH(rb_big_unpack(v.i, num_longs));
|
2010-02-26 13:51:02 -05:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
2010-02-24 10:32:06 -05:00
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2010-05-10 10:52:16 -04:00
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(float));
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
float tmp;
|
|
|
|
memcpy(&tmp, s, sizeof(float));
|
|
|
|
s += sizeof(float);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM((double)tmp));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
PACK_ITEM_ADJUST();
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
case 'e':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(float));
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
float tmp;
|
|
|
|
FLOAT_CONVWITH(ftmp);
|
|
|
|
|
|
|
|
memcpy(&tmp, s, sizeof(float));
|
|
|
|
s += sizeof(float);
|
|
|
|
tmp = VTOHF(tmp,ftmp);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM((double)tmp));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
break;
|
2007-06-05 00:49:54 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
case 'E':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(double));
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
double tmp;
|
|
|
|
DOUBLE_CONVWITH(dtmp);
|
|
|
|
|
|
|
|
memcpy(&tmp, s, sizeof(double));
|
|
|
|
s += sizeof(double);
|
|
|
|
tmp = VTOHD(tmp,dtmp);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM(tmp));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
break;
|
2007-06-05 00:49:54 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'D':
|
|
|
|
case 'd':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(double));
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
double tmp;
|
|
|
|
memcpy(&tmp, s, sizeof(double));
|
|
|
|
s += sizeof(double);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM(tmp));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(float));
|
1999-08-13 01:45:20 -04:00
|
|
|
while (len-- > 0) {
|
|
|
|
float tmp;
|
|
|
|
FLOAT_CONVWITH(ftmp;)
|
|
|
|
|
|
|
|
memcpy(&tmp, s, sizeof(float));
|
|
|
|
s += sizeof(float);
|
|
|
|
tmp = NTOHF(tmp,ftmp);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM((double)tmp));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
break;
|
2007-06-05 00:49:54 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
case 'G':
|
2010-02-25 09:00:48 -05:00
|
|
|
PACK_LENGTH_ADJUST_SIZE(sizeof(double));
|
1998-01-16 07:13:05 -05:00
|
|
|
while (len-- > 0) {
|
|
|
|
double tmp;
|
1999-08-13 01:45:20 -04:00
|
|
|
DOUBLE_CONVWITH(dtmp);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
memcpy(&tmp, s, sizeof(double));
|
|
|
|
s += sizeof(double);
|
1999-08-13 01:45:20 -04:00
|
|
|
tmp = NTOHD(tmp,dtmp);
|
2008-09-05 14:24:21 -04:00
|
|
|
UNPACK_PUSH(DBL2NUM(tmp));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
PACK_ITEM_ADJUST();
|
|
|
|
break;
|
2007-06-05 00:49:54 -04:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
case 'U':
|
|
|
|
if (len > send - s) len = send - s;
|
2001-11-19 00:03:03 -05:00
|
|
|
while (len > 0 && s < send) {
|
2002-08-28 04:05:23 -04:00
|
|
|
long alen = send - s;
|
1999-08-13 01:45:20 -04:00
|
|
|
unsigned long l;
|
|
|
|
|
|
|
|
l = utf8_to_uv(s, &alen);
|
2002-04-15 03:48:47 -04:00
|
|
|
s += alen; len--;
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(ULONG2NUM(l));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
{
|
2002-06-28 10:53:03 -04:00
|
|
|
VALUE buf = infected_str_new(0, (send - s)*3/4, str);
|
2006-08-31 06:47:44 -04:00
|
|
|
char *ptr = RSTRING_PTR(buf);
|
2002-08-21 11:47:54 -04:00
|
|
|
long total = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (s < send && *s > ' ' && *s < 'a') {
|
|
|
|
long a,b,c,d;
|
|
|
|
char hunk[4];
|
|
|
|
|
|
|
|
hunk[3] = '\0';
|
|
|
|
len = (*s++ - ' ') & 077;
|
|
|
|
total += len;
|
2006-08-31 06:47:44 -04:00
|
|
|
if (total > RSTRING_LEN(buf)) {
|
|
|
|
len -= total - RSTRING_LEN(buf);
|
|
|
|
total = RSTRING_LEN(buf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while (len > 0) {
|
2002-08-28 04:05:23 -04:00
|
|
|
long mlen = len > 3 ? 3 : len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (s < send && *s >= ' ')
|
|
|
|
a = (*s++ - ' ') & 077;
|
|
|
|
else
|
|
|
|
a = 0;
|
|
|
|
if (s < send && *s >= ' ')
|
|
|
|
b = (*s++ - ' ') & 077;
|
|
|
|
else
|
|
|
|
b = 0;
|
|
|
|
if (s < send && *s >= ' ')
|
|
|
|
c = (*s++ - ' ') & 077;
|
|
|
|
else
|
|
|
|
c = 0;
|
|
|
|
if (s < send && *s >= ' ')
|
|
|
|
d = (*s++ - ' ') & 077;
|
|
|
|
else
|
|
|
|
d = 0;
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
hunk[0] = (char)(a << 2 | b >> 4);
|
|
|
|
hunk[1] = (char)(b << 4 | c >> 2);
|
|
|
|
hunk[2] = (char)(c << 6 | d);
|
1998-01-16 07:13:05 -05:00
|
|
|
memcpy(ptr, hunk, mlen);
|
|
|
|
ptr += mlen;
|
|
|
|
len -= mlen;
|
|
|
|
}
|
|
|
|
if (*s == '\r') s++;
|
|
|
|
if (*s == '\n') s++;
|
|
|
|
else if (s < send && (s+1 == send || s[1] == '\n'))
|
|
|
|
s += 2; /* possible checksum byte */
|
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
|
|
|
|
rb_str_set_len(buf, total);
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(buf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
case 'm':
|
|
|
|
{
|
2002-06-28 10:53:03 -04:00
|
|
|
VALUE buf = infected_str_new(0, (send - s)*3/4, str);
|
2006-08-31 06:47:44 -04:00
|
|
|
char *ptr = RSTRING_PTR(buf);
|
2008-09-25 08:24:54 -04:00
|
|
|
int a = -1,b = -1,c = 0,d = 0;
|
2008-07-30 11:58:36 -04:00
|
|
|
static signed char b64_xtable[256];
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2008-07-30 11:58:36 -04:00
|
|
|
if (b64_xtable['/'] <= 0) {
|
1998-01-16 07:19:22 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
b64_xtable[i] = -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 64; i++) {
|
2008-07-30 11:58:36 -04:00
|
|
|
b64_xtable[(unsigned char)b64_table[i]] = i;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
}
|
2008-09-25 08:24:54 -04:00
|
|
|
if (len == 0) {
|
|
|
|
while (s < send) {
|
|
|
|
a = b = c = d = -1;
|
|
|
|
a = b64_xtable[(unsigned char)*s++];
|
|
|
|
if (s >= send || a == -1) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
b = b64_xtable[(unsigned char)*s++];
|
|
|
|
if (s >= send || b == -1) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
if (*s == '=') {
|
|
|
|
if (s + 2 == send && *(s + 1) == '=') break;
|
|
|
|
rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
}
|
|
|
|
c = b64_xtable[(unsigned char)*s++];
|
|
|
|
if (s >= send || c == -1) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
if (s + 1 == send && *s == '=') break;
|
|
|
|
d = b64_xtable[(unsigned char)*s++];
|
|
|
|
if (d == -1) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
*ptr++ = a << 2 | b >> 4;
|
|
|
|
*ptr++ = b << 4 | c >> 2;
|
|
|
|
*ptr++ = c << 6 | d;
|
|
|
|
}
|
|
|
|
if (c == -1) {
|
2003-06-23 02:52:39 -04:00
|
|
|
*ptr++ = a << 2 | b >> 4;
|
2008-09-25 08:24:54 -04:00
|
|
|
if (b & 0xf) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
}
|
|
|
|
else if (d == -1) {
|
|
|
|
*ptr++ = a << 2 | b >> 4;
|
|
|
|
*ptr++ = b << 4 | c >> 2;
|
|
|
|
if (c & 0x3) rb_raise(rb_eArgError, "invalid base64");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (s < send) {
|
|
|
|
a = b = c = d = -1;
|
|
|
|
while ((a = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
|
|
|
|
if (s >= send) break;
|
|
|
|
s++;
|
|
|
|
while ((b = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
|
|
|
|
if (s >= send) break;
|
|
|
|
s++;
|
|
|
|
while ((c = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if (*s == '=') break; s++;}
|
|
|
|
if (*s == '=' || s >= send) break;
|
|
|
|
s++;
|
|
|
|
while ((d = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if (*s == '=') break; s++;}
|
|
|
|
if (*s == '=' || s >= send) break;
|
|
|
|
s++;
|
2003-06-23 02:52:39 -04:00
|
|
|
*ptr++ = a << 2 | b >> 4;
|
|
|
|
*ptr++ = b << 4 | c >> 2;
|
2008-09-25 08:24:54 -04:00
|
|
|
*ptr++ = c << 6 | d;
|
|
|
|
}
|
|
|
|
if (a != -1 && b != -1) {
|
|
|
|
if (c == -1 && *s == '=')
|
|
|
|
*ptr++ = a << 2 | b >> 4;
|
|
|
|
else if (c != -1 && *s == '=') {
|
|
|
|
*ptr++ = a << 2 | b >> 4;
|
|
|
|
*ptr++ = b << 4 | c >> 2;
|
|
|
|
}
|
2003-06-23 02:52:39 -04:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(buf);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
{
|
2002-06-28 10:53:03 -04:00
|
|
|
VALUE buf = infected_str_new(0, send - s, str);
|
2006-08-31 06:47:44 -04:00
|
|
|
char *ptr = RSTRING_PTR(buf);
|
1999-01-19 23:59:39 -05:00
|
|
|
int c1, c2;
|
|
|
|
|
|
|
|
while (s < send) {
|
|
|
|
if (*s == '=') {
|
|
|
|
if (++s == send) break;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
if (s+1 < send && *s == '\r' && *(s+1) == '\n')
|
|
|
|
s++;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (*s != '\n') {
|
|
|
|
if ((c1 = hex2num(*s)) == -1) break;
|
|
|
|
if (++s == send) break;
|
|
|
|
if ((c2 = hex2num(*s)) == -1) break;
|
|
|
|
*ptr++ = c1 << 4 | c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*ptr++ = *s;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
|
2008-12-06 00:37:20 -05:00
|
|
|
ENCODING_CODERANGE_SET(buf, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(buf);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case '@':
|
2006-08-31 06:47:44 -04:00
|
|
|
if (len > RSTRING_LEN(str))
|
2003-06-23 02:52:39 -04:00
|
|
|
rb_raise(rb_eArgError, "@ outside of string");
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(str) + len;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
2006-08-31 06:47:44 -04:00
|
|
|
if (len > s - RSTRING_PTR(str))
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "X outside of string");
|
1998-01-16 07:13:05 -05:00
|
|
|
s -= len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
if (len > send - s)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "x outside of string");
|
1998-01-16 07:13:05 -05:00
|
|
|
s += len;
|
|
|
|
break;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
case 'P':
|
2010-02-26 00:17:13 -05:00
|
|
|
if (sizeof(char *) <= (size_t)(send - s)) {
|
2008-04-22 09:49:43 -04:00
|
|
|
VALUE tmp = Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2001-01-15 02:01:00 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
memcpy(&t, s, sizeof(char *));
|
|
|
|
s += sizeof(char *);
|
2001-01-15 02:01:00 -05:00
|
|
|
|
|
|
|
if (t) {
|
2001-05-02 00:22:21 -04:00
|
|
|
VALUE a, *p, *pend;
|
2001-01-15 02:01:00 -05:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
if (!(a = rb_str_associated(str))) {
|
|
|
|
rb_raise(rb_eArgError, "no associated pointer");
|
|
|
|
}
|
2006-09-02 10:42:08 -04:00
|
|
|
p = RARRAY_PTR(a);
|
|
|
|
pend = p + RARRAY_LEN(a);
|
2001-01-15 02:01:00 -05:00
|
|
|
while (p < pend) {
|
2006-08-31 06:47:44 -04:00
|
|
|
if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
|
|
|
|
if (len < RSTRING_LEN(*p)) {
|
2006-07-18 03:02:35 -04:00
|
|
|
tmp = rb_tainted_str_new(t, len);
|
|
|
|
rb_str_associate(tmp, a);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = *p;
|
2001-01-18 03:43:14 -05:00
|
|
|
}
|
2001-01-15 02:01:00 -05:00
|
|
|
break;
|
2001-01-18 03:43:14 -05:00
|
|
|
}
|
2001-01-15 02:01:00 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (p == pend) {
|
|
|
|
rb_raise(rb_eArgError, "non associated pointer");
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(tmp);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
if (len > (long)((send - s) / sizeof(char *)))
|
1999-01-19 23:59:39 -05:00
|
|
|
len = (send - s) / sizeof(char *);
|
|
|
|
while (len-- > 0) {
|
2010-02-26 00:17:13 -05:00
|
|
|
if ((size_t)(send - s) < sizeof(char *))
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
else {
|
2008-04-22 09:49:43 -04:00
|
|
|
VALUE tmp = Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *t;
|
2001-01-18 03:43:14 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
memcpy(&t, s, sizeof(char *));
|
|
|
|
s += sizeof(char *);
|
2001-01-18 03:43:14 -05:00
|
|
|
|
2000-04-10 01:48:43 -04:00
|
|
|
if (t) {
|
2001-08-05 23:05:23 -04:00
|
|
|
VALUE a, *p, *pend;
|
2001-05-02 00:22:21 -04:00
|
|
|
|
|
|
|
if (!(a = rb_str_associated(str))) {
|
|
|
|
rb_raise(rb_eArgError, "no associated pointer");
|
|
|
|
}
|
2006-09-02 10:42:08 -04:00
|
|
|
p = RARRAY_PTR(a);
|
|
|
|
pend = p + RARRAY_LEN(a);
|
2001-01-18 03:43:14 -05:00
|
|
|
while (p < pend) {
|
2006-08-31 06:47:44 -04:00
|
|
|
if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
|
2006-07-18 03:02:35 -04:00
|
|
|
tmp = *p;
|
2001-01-18 03:43:14 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (p == pend) {
|
|
|
|
rb_raise(rb_eArgError, "non associated pointer");
|
|
|
|
}
|
2000-04-10 01:48:43 -04:00
|
|
|
}
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(tmp);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
case 'w':
|
|
|
|
{
|
|
|
|
unsigned long ul = 0;
|
2006-02-16 21:21:39 -05:00
|
|
|
unsigned long ulmask = 0xfeUL << ((sizeof(unsigned long) - 1) * 8);
|
2000-05-12 05:07:57 -04:00
|
|
|
|
|
|
|
while (len > 0 && s < send) {
|
|
|
|
ul <<= 7;
|
|
|
|
ul |= (*s & 0x7f);
|
|
|
|
if (!(*s++ & 0x80)) {
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(ULONG2NUM(ul));
|
2000-05-12 05:07:57 -04:00
|
|
|
len--;
|
|
|
|
ul = 0;
|
|
|
|
}
|
|
|
|
else if (ul & ulmask) {
|
|
|
|
VALUE big = rb_uint2big(ul);
|
|
|
|
VALUE big128 = rb_uint2big(128);
|
|
|
|
while (s < send) {
|
|
|
|
big = rb_big_mul(big, big128);
|
|
|
|
big = rb_big_plus(big, rb_uint2big(*s & 0x7f));
|
|
|
|
if (!(*s++ & 0x80)) {
|
2006-10-15 18:57:37 -04:00
|
|
|
UNPACK_PUSH(big);
|
2000-05-12 05:07:57 -04:00
|
|
|
len--;
|
|
|
|
ul = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#define BYTEWIDTH 8
|
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
int
|
|
|
|
rb_uv_to_utf8(char buf[6], unsigned long uv)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
if (uv <= 0x7f) {
|
|
|
|
buf[0] = (char)uv;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (uv <= 0x7ff) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buf[0] = (char)((uv>>6)&0xff)|0xc0;
|
|
|
|
buf[1] = (char)(uv&0x3f)|0x80;
|
1999-08-13 01:45:20 -04:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (uv <= 0xffff) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buf[0] = (char)((uv>>12)&0xff)|0xe0;
|
|
|
|
buf[1] = (char)((uv>>6)&0x3f)|0x80;
|
|
|
|
buf[2] = (char)(uv&0x3f)|0x80;
|
1999-08-13 01:45:20 -04:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (uv <= 0x1fffff) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buf[0] = (char)((uv>>18)&0xff)|0xf0;
|
|
|
|
buf[1] = (char)((uv>>12)&0x3f)|0x80;
|
|
|
|
buf[2] = (char)((uv>>6)&0x3f)|0x80;
|
|
|
|
buf[3] = (char)(uv&0x3f)|0x80;
|
1999-08-13 01:45:20 -04:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (uv <= 0x3ffffff) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buf[0] = (char)((uv>>24)&0xff)|0xf8;
|
|
|
|
buf[1] = (char)((uv>>18)&0x3f)|0x80;
|
|
|
|
buf[2] = (char)((uv>>12)&0x3f)|0x80;
|
|
|
|
buf[3] = (char)((uv>>6)&0x3f)|0x80;
|
|
|
|
buf[4] = (char)(uv&0x3f)|0x80;
|
1999-08-13 01:45:20 -04:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
if (uv <= 0x7fffffff) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
buf[0] = (char)((uv>>30)&0xff)|0xfc;
|
|
|
|
buf[1] = (char)((uv>>24)&0x3f)|0x80;
|
|
|
|
buf[2] = (char)((uv>>18)&0x3f)|0x80;
|
|
|
|
buf[3] = (char)((uv>>12)&0x3f)|0x80;
|
|
|
|
buf[4] = (char)((uv>>6)&0x3f)|0x80;
|
|
|
|
buf[5] = (char)(uv&0x3f)|0x80;
|
1999-08-13 01:45:20 -04:00
|
|
|
return 6;
|
|
|
|
}
|
2004-03-30 21:59:57 -05:00
|
|
|
rb_raise(rb_eRangeError, "pack(U): value out of range");
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2005-10-13 10:30:54 -04:00
|
|
|
static const unsigned long utf8_limits[] = {
|
2002-12-04 02:39:32 -05:00
|
|
|
0x0, /* 1 */
|
|
|
|
0x80, /* 2 */
|
|
|
|
0x800, /* 3 */
|
2002-12-10 03:32:54 -05:00
|
|
|
0x10000, /* 4 */
|
2002-12-04 02:39:32 -05:00
|
|
|
0x200000, /* 5 */
|
|
|
|
0x4000000, /* 6 */
|
|
|
|
0x80000000, /* 7 */
|
|
|
|
};
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static unsigned long
|
2006-03-01 05:06:03 -05:00
|
|
|
utf8_to_uv(const char *p, long *lenp)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2002-12-02 02:13:56 -05:00
|
|
|
int c = *p++ & 0xff;
|
2003-07-09 18:28:42 -04:00
|
|
|
unsigned long uv = c;
|
2002-12-02 02:13:56 -05:00
|
|
|
long n;
|
|
|
|
|
|
|
|
if (!(uv & 0x80)) {
|
|
|
|
*lenp = 1;
|
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
if (!(uv & 0x40)) {
|
|
|
|
*lenp = 1;
|
2002-12-10 01:23:44 -05:00
|
|
|
rb_raise(rb_eArgError, "malformed UTF-8 character");
|
2002-12-02 02:13:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(uv & 0x20)) { n = 2; uv &= 0x1f; }
|
|
|
|
else if (!(uv & 0x10)) { n = 3; uv &= 0x0f; }
|
|
|
|
else if (!(uv & 0x08)) { n = 4; uv &= 0x07; }
|
|
|
|
else if (!(uv & 0x04)) { n = 5; uv &= 0x03; }
|
|
|
|
else if (!(uv & 0x02)) { n = 6; uv &= 0x01; }
|
2002-12-10 01:23:44 -05:00
|
|
|
else {
|
|
|
|
*lenp = 1;
|
|
|
|
rb_raise(rb_eArgError, "malformed UTF-8 character");
|
|
|
|
}
|
2002-12-02 02:13:56 -05:00
|
|
|
if (n > *lenp) {
|
2005-09-23 20:17:43 -04:00
|
|
|
rb_raise(rb_eArgError, "malformed UTF-8 character (expected %ld bytes, given %ld bytes)",
|
2002-12-10 01:23:44 -05:00
|
|
|
n, *lenp);
|
2002-12-02 02:13:56 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
*lenp = n--;
|
|
|
|
if (n != 0) {
|
|
|
|
while (n--) {
|
2002-12-02 02:13:56 -05:00
|
|
|
c = *p++ & 0xff;
|
|
|
|
if ((c & 0xc0) != 0x80) {
|
|
|
|
*lenp -= n + 1;
|
2002-12-10 01:23:44 -05:00
|
|
|
rb_raise(rb_eArgError, "malformed UTF-8 character");
|
2002-12-02 02:13:56 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c &= 0x3f;
|
|
|
|
uv = uv << 6 | c;
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
2002-12-04 02:39:32 -05:00
|
|
|
n = *lenp - 1;
|
2002-12-10 01:23:44 -05:00
|
|
|
if (uv < utf8_limits[n]) {
|
|
|
|
rb_raise(rb_eArgError, "redundant UTF-8 sequence");
|
2002-12-04 02:39:32 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_pack(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cArray, "pack", pack_pack, 1);
|
|
|
|
rb_define_method(rb_cString, "unpack", pack_unpack, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|