mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
pack/unpack unsigned
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
71ad3aa4ff
commit
dde6b7dd06
11 changed files with 74 additions and 25 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
Fri May 8 12:26:37 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* pack.c (pack_unpack): should be unsigned int (was signed int).
|
||||
|
||||
Thu May 7 16:34:10 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* pack.c (pack_pack): `V', `N' uses newly created NUM2UINT().
|
||||
|
||||
* ruby.h (NUM2UINT): new macro.
|
||||
|
||||
* bignum.c (big2uint): try to convert bignum into UINT.
|
||||
|
||||
* re.c (reg_match): needed to return false for match with nil.
|
||||
|
||||
* gc.c (obj_free): wrong condition to free string.
|
||||
|
||||
Wed May 6 21:08:08 1998 WATANABE Hirofumi <watanabe@ase.ptg.sony.co.jp>
|
||||
|
||||
* ruby.c (ruby_process_options): modified for DJGPP.
|
||||
|
||||
Wed May 6 15:48:03 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* experimental release 1.1b9_17.
|
||||
|
|
15
bignum.c
15
bignum.c
|
@ -342,8 +342,8 @@ big_to_s(x)
|
|||
return big2str(x, 10);
|
||||
}
|
||||
|
||||
INT
|
||||
big2int(x)
|
||||
UINT
|
||||
big2uint(x)
|
||||
VALUE x;
|
||||
{
|
||||
UINT num;
|
||||
|
@ -351,13 +351,22 @@ big2int(x)
|
|||
USHORT *ds;
|
||||
|
||||
if (len > sizeof(INT)/sizeof(USHORT))
|
||||
ArgError("bignum too big to convert into `int'");
|
||||
ArgError("bignum too big to convert into `uint'");
|
||||
ds = BDIGITS(x);
|
||||
num = 0;
|
||||
while (len--) {
|
||||
num = BIGUP(num);
|
||||
num += ds[len];
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
INT
|
||||
big2int(x)
|
||||
VALUE x;
|
||||
{
|
||||
UINT num = big2uint(x);
|
||||
|
||||
if ((INT)num < 0) {
|
||||
ArgError("bignum too big to convert into `int'");
|
||||
}
|
||||
|
|
|
@ -12,12 +12,18 @@
|
|||
# include <ncurses/curses.h>
|
||||
# else
|
||||
# include <curses.h>
|
||||
# if defined(__NetBSD__) && !defined(_maxx)
|
||||
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_maxx)
|
||||
# define _maxx maxx
|
||||
# endif
|
||||
# if defined(__NetBSD__) && !defined(_maxy)
|
||||
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_maxy)
|
||||
# define _maxy maxy
|
||||
# endif
|
||||
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_begx)
|
||||
# define _begx begx
|
||||
# endif
|
||||
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_begy)
|
||||
# define _begy begy
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
|
4
gc.c
4
gc.c
|
@ -658,7 +658,7 @@ obj_free(obj)
|
|||
break;
|
||||
case T_STRING:
|
||||
#define STR_NO_ORIG FL_USER3 /* copied from string.c */
|
||||
if (!RANY(obj)->as.string.orig && FL_TEST(obj, STR_NO_ORIG))
|
||||
if (!RANY(obj)->as.string.orig || FL_TEST(obj, STR_NO_ORIG))
|
||||
free(RANY(obj)->as.string.ptr);
|
||||
break;
|
||||
case T_ARRAY:
|
||||
|
@ -1022,7 +1022,7 @@ static VALUE
|
|||
id2ref(obj, id)
|
||||
VALUE obj, id;
|
||||
{
|
||||
INT ptr = NUM2INT(id);
|
||||
INT ptr = NUM2UINT(id);
|
||||
|
||||
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
||||
if (ptr == TRUE) return TRUE;
|
||||
|
|
1
intern.h
1
intern.h
|
@ -41,6 +41,7 @@ VALUE int2inum _((INT));
|
|||
VALUE str2inum _((UCHAR *, int));
|
||||
VALUE big2str _((VALUE, int));
|
||||
INT big2int _((VALUE));
|
||||
UINT big2uint _((VALUE));
|
||||
VALUE big_to_i _((VALUE));
|
||||
VALUE dbl2big _((double));
|
||||
double big2dbl _((VALUE));
|
||||
|
|
22
numeric.c
22
numeric.c
|
@ -649,6 +649,16 @@ num2int(val)
|
|||
}
|
||||
}
|
||||
|
||||
UINT
|
||||
num2uint(val)
|
||||
VALUE val;
|
||||
{
|
||||
if (TYPE(val) == T_BIGNUM) {
|
||||
return big2uint(val);
|
||||
}
|
||||
return (UINT)num2int(val);
|
||||
}
|
||||
|
||||
VALUE
|
||||
num2fix(val)
|
||||
VALUE val;
|
||||
|
@ -956,7 +966,7 @@ fix_rev(num)
|
|||
unsigned long val = FIX2UINT(num);
|
||||
|
||||
val = ~val;
|
||||
return INT2FIX(val);
|
||||
return int2inum(val);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -968,7 +978,7 @@ fix_and(x, y)
|
|||
if (TYPE(y) == T_BIGNUM) {
|
||||
return big_and(y, x);
|
||||
}
|
||||
val = NUM2INT(x) & NUM2INT(y);
|
||||
val = FIX2INT(x) & NUM2INT(y);
|
||||
return int2inum(val);
|
||||
}
|
||||
|
||||
|
@ -981,8 +991,8 @@ fix_or(x, y)
|
|||
if (TYPE(y) == T_BIGNUM) {
|
||||
return big_or(y, x);
|
||||
}
|
||||
val = NUM2INT(x) | NUM2INT(y);
|
||||
return INT2FIX(val);
|
||||
val = FIX2INT(x) | NUM2INT(y);
|
||||
return int2inum(val);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -994,8 +1004,8 @@ fix_xor(x, y)
|
|||
if (TYPE(y) == T_BIGNUM) {
|
||||
return big_xor(y, x);
|
||||
}
|
||||
val = NUM2INT(x) ^ NUM2INT(y);
|
||||
return INT2FIX(val);
|
||||
val = FIX2INT(x) ^ NUM2INT(y);
|
||||
return int2inum(val);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
10
pack.c
10
pack.c
|
@ -308,7 +308,7 @@ pack_pack(ary, fmt)
|
|||
from = NEXTFROM;
|
||||
if (NIL_P(from)) i = 0;
|
||||
else {
|
||||
i = NUM2INT(from);
|
||||
i = NUM2UINT(from);
|
||||
}
|
||||
str_cat(res, (UCHAR*)&i, sizeof(int));
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ pack_pack(ary, fmt)
|
|||
from = NEXTFROM;
|
||||
if (NIL_P(from)) l = 0;
|
||||
else {
|
||||
l = NUM2INT(from);
|
||||
l = NUM2UINT(from);
|
||||
}
|
||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ pack_pack(ary, fmt)
|
|||
from = NEXTFROM;
|
||||
if (NIL_P(from)) l = 0;
|
||||
else {
|
||||
l = NUM2INT(from);
|
||||
l = NUM2UINT(from);
|
||||
}
|
||||
l = htonl(l);
|
||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||
|
@ -377,7 +377,7 @@ pack_pack(ary, fmt)
|
|||
from = NEXTFROM;
|
||||
if (NIL_P(from)) l = 0;
|
||||
else {
|
||||
l = NUM2INT(from);
|
||||
l = NUM2UINT(from);
|
||||
}
|
||||
l = htovl(l);
|
||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||
|
@ -743,7 +743,7 @@ pack_unpack(str, fmt)
|
|||
unsigned int tmp;
|
||||
memcpy(&tmp, s, sizeof(int));
|
||||
s += sizeof(int);
|
||||
ary_push(ary, int2inum(tmp));
|
||||
ary_push(ary, uint2inum(tmp));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
2
random.c
2
random.c
|
@ -50,7 +50,7 @@ f_srand(argc, argv, obj)
|
|||
seed = tv.tv_sec ^ tv.tv_usec;
|
||||
}
|
||||
else {
|
||||
seed = NUM2INT(seed);
|
||||
seed = NUM2UINT(seed);
|
||||
}
|
||||
|
||||
#ifdef HAVE_RANDOM
|
||||
|
|
1
re.c
1
re.c
|
@ -725,6 +725,7 @@ reg_match(re, str)
|
|||
{
|
||||
int start;
|
||||
|
||||
if (NIL_P(str)) return FALSE;
|
||||
str = str_to_str(str);
|
||||
start = reg_search(re, str, 0, 0);
|
||||
if (start < 0) {
|
||||
|
|
12
ruby.c
12
ruby.c
|
@ -567,7 +567,7 @@ load_file(fname, script)
|
|||
if (script) {
|
||||
rb_define_global_const("DATA", f);
|
||||
}
|
||||
else if (f != rb_stdin) {
|
||||
if (f != rb_stdin) {
|
||||
io_close(f);
|
||||
}
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ ruby_process_options(argc, argv)
|
|||
{
|
||||
origargc = argc; origargv = argv;
|
||||
ruby_script(argv[0]); /* for the time being */
|
||||
rb_argv0 = str_taint(str_new2(argv[0]));
|
||||
rb_argv0 = rb_progname;
|
||||
#if defined(USE_DLN_A_OUT)
|
||||
dln_argv0 = argv[0];
|
||||
#endif
|
||||
|
@ -801,12 +801,12 @@ ruby_process_options(argc, argv)
|
|||
if (do_loop) {
|
||||
yywhile_loop(do_line, do_split);
|
||||
}
|
||||
if (e_tmpname) {
|
||||
unlink(e_tmpname);
|
||||
e_tmpname = NULL;
|
||||
}
|
||||
if (e_fp) {
|
||||
fclose(e_fp);
|
||||
e_fp = NULL;
|
||||
}
|
||||
if (e_tmpname) {
|
||||
unlink(e_tmpname);
|
||||
e_tmpname = NULL;
|
||||
}
|
||||
}
|
||||
|
|
2
ruby.h
2
ruby.h
|
@ -172,6 +172,8 @@ void rb_secure _((int));
|
|||
|
||||
INT num2int _((VALUE));
|
||||
#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):num2int((VALUE)x))
|
||||
UINT num2uint _((VALUE));
|
||||
#define NUM2UINT(x) num2uint((VALUE)x)
|
||||
|
||||
double num2dbl _((VALUE));
|
||||
#define NUM2DBL(x) num2dbl((VALUE)(x))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue