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>
|
Wed May 6 15:48:03 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||||
|
|
||||||
* experimental release 1.1b9_17.
|
* experimental release 1.1b9_17.
|
||||||
|
|
15
bignum.c
15
bignum.c
|
@ -342,8 +342,8 @@ big_to_s(x)
|
||||||
return big2str(x, 10);
|
return big2str(x, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT
|
UINT
|
||||||
big2int(x)
|
big2uint(x)
|
||||||
VALUE x;
|
VALUE x;
|
||||||
{
|
{
|
||||||
UINT num;
|
UINT num;
|
||||||
|
@ -351,13 +351,22 @@ big2int(x)
|
||||||
USHORT *ds;
|
USHORT *ds;
|
||||||
|
|
||||||
if (len > sizeof(INT)/sizeof(USHORT))
|
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);
|
ds = BDIGITS(x);
|
||||||
num = 0;
|
num = 0;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
num = BIGUP(num);
|
num = BIGUP(num);
|
||||||
num += ds[len];
|
num += ds[len];
|
||||||
}
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT
|
||||||
|
big2int(x)
|
||||||
|
VALUE x;
|
||||||
|
{
|
||||||
|
UINT num = big2uint(x);
|
||||||
|
|
||||||
if ((INT)num < 0) {
|
if ((INT)num < 0) {
|
||||||
ArgError("bignum too big to convert into `int'");
|
ArgError("bignum too big to convert into `int'");
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,18 @@
|
||||||
# include <ncurses/curses.h>
|
# include <ncurses/curses.h>
|
||||||
# else
|
# else
|
||||||
# include <curses.h>
|
# include <curses.h>
|
||||||
# if defined(__NetBSD__) && !defined(_maxx)
|
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_maxx)
|
||||||
# define _maxx maxx
|
# define _maxx maxx
|
||||||
# endif
|
# endif
|
||||||
# if defined(__NetBSD__) && !defined(_maxy)
|
# if (defined(__bsdi__) || defined(__NetBSD__)) && !defined(_maxy)
|
||||||
# define _maxy maxy
|
# define _maxy maxy
|
||||||
# endif
|
# 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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
4
gc.c
4
gc.c
|
@ -658,7 +658,7 @@ obj_free(obj)
|
||||||
break;
|
break;
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
#define STR_NO_ORIG FL_USER3 /* copied from string.c */
|
#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);
|
free(RANY(obj)->as.string.ptr);
|
||||||
break;
|
break;
|
||||||
case T_ARRAY:
|
case T_ARRAY:
|
||||||
|
@ -1022,7 +1022,7 @@ static VALUE
|
||||||
id2ref(obj, id)
|
id2ref(obj, id)
|
||||||
VALUE obj, id;
|
VALUE obj, id;
|
||||||
{
|
{
|
||||||
INT ptr = NUM2INT(id);
|
INT ptr = NUM2UINT(id);
|
||||||
|
|
||||||
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
||||||
if (ptr == TRUE) return TRUE;
|
if (ptr == TRUE) return TRUE;
|
||||||
|
|
1
intern.h
1
intern.h
|
@ -41,6 +41,7 @@ VALUE int2inum _((INT));
|
||||||
VALUE str2inum _((UCHAR *, int));
|
VALUE str2inum _((UCHAR *, int));
|
||||||
VALUE big2str _((VALUE, int));
|
VALUE big2str _((VALUE, int));
|
||||||
INT big2int _((VALUE));
|
INT big2int _((VALUE));
|
||||||
|
UINT big2uint _((VALUE));
|
||||||
VALUE big_to_i _((VALUE));
|
VALUE big_to_i _((VALUE));
|
||||||
VALUE dbl2big _((double));
|
VALUE dbl2big _((double));
|
||||||
double big2dbl _((VALUE));
|
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
|
VALUE
|
||||||
num2fix(val)
|
num2fix(val)
|
||||||
VALUE val;
|
VALUE val;
|
||||||
|
@ -956,7 +966,7 @@ fix_rev(num)
|
||||||
unsigned long val = FIX2UINT(num);
|
unsigned long val = FIX2UINT(num);
|
||||||
|
|
||||||
val = ~val;
|
val = ~val;
|
||||||
return INT2FIX(val);
|
return int2inum(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -968,7 +978,7 @@ fix_and(x, y)
|
||||||
if (TYPE(y) == T_BIGNUM) {
|
if (TYPE(y) == T_BIGNUM) {
|
||||||
return big_and(y, x);
|
return big_and(y, x);
|
||||||
}
|
}
|
||||||
val = NUM2INT(x) & NUM2INT(y);
|
val = FIX2INT(x) & NUM2INT(y);
|
||||||
return int2inum(val);
|
return int2inum(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -981,8 +991,8 @@ fix_or(x, y)
|
||||||
if (TYPE(y) == T_BIGNUM) {
|
if (TYPE(y) == T_BIGNUM) {
|
||||||
return big_or(y, x);
|
return big_or(y, x);
|
||||||
}
|
}
|
||||||
val = NUM2INT(x) | NUM2INT(y);
|
val = FIX2INT(x) | NUM2INT(y);
|
||||||
return INT2FIX(val);
|
return int2inum(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -994,8 +1004,8 @@ fix_xor(x, y)
|
||||||
if (TYPE(y) == T_BIGNUM) {
|
if (TYPE(y) == T_BIGNUM) {
|
||||||
return big_xor(y, x);
|
return big_xor(y, x);
|
||||||
}
|
}
|
||||||
val = NUM2INT(x) ^ NUM2INT(y);
|
val = FIX2INT(x) ^ NUM2INT(y);
|
||||||
return INT2FIX(val);
|
return int2inum(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
10
pack.c
10
pack.c
|
@ -308,7 +308,7 @@ pack_pack(ary, fmt)
|
||||||
from = NEXTFROM;
|
from = NEXTFROM;
|
||||||
if (NIL_P(from)) i = 0;
|
if (NIL_P(from)) i = 0;
|
||||||
else {
|
else {
|
||||||
i = NUM2INT(from);
|
i = NUM2UINT(from);
|
||||||
}
|
}
|
||||||
str_cat(res, (UCHAR*)&i, sizeof(int));
|
str_cat(res, (UCHAR*)&i, sizeof(int));
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ pack_pack(ary, fmt)
|
||||||
from = NEXTFROM;
|
from = NEXTFROM;
|
||||||
if (NIL_P(from)) l = 0;
|
if (NIL_P(from)) l = 0;
|
||||||
else {
|
else {
|
||||||
l = NUM2INT(from);
|
l = NUM2UINT(from);
|
||||||
}
|
}
|
||||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ pack_pack(ary, fmt)
|
||||||
from = NEXTFROM;
|
from = NEXTFROM;
|
||||||
if (NIL_P(from)) l = 0;
|
if (NIL_P(from)) l = 0;
|
||||||
else {
|
else {
|
||||||
l = NUM2INT(from);
|
l = NUM2UINT(from);
|
||||||
}
|
}
|
||||||
l = htonl(l);
|
l = htonl(l);
|
||||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||||
|
@ -377,7 +377,7 @@ pack_pack(ary, fmt)
|
||||||
from = NEXTFROM;
|
from = NEXTFROM;
|
||||||
if (NIL_P(from)) l = 0;
|
if (NIL_P(from)) l = 0;
|
||||||
else {
|
else {
|
||||||
l = NUM2INT(from);
|
l = NUM2UINT(from);
|
||||||
}
|
}
|
||||||
l = htovl(l);
|
l = htovl(l);
|
||||||
str_cat(res, (UCHAR*)&l, sizeof(long));
|
str_cat(res, (UCHAR*)&l, sizeof(long));
|
||||||
|
@ -743,7 +743,7 @@ pack_unpack(str, fmt)
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
memcpy(&tmp, s, sizeof(int));
|
memcpy(&tmp, s, sizeof(int));
|
||||||
s += sizeof(int);
|
s += sizeof(int);
|
||||||
ary_push(ary, int2inum(tmp));
|
ary_push(ary, uint2inum(tmp));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
2
random.c
2
random.c
|
@ -50,7 +50,7 @@ f_srand(argc, argv, obj)
|
||||||
seed = tv.tv_sec ^ tv.tv_usec;
|
seed = tv.tv_sec ^ tv.tv_usec;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
seed = NUM2INT(seed);
|
seed = NUM2UINT(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_RANDOM
|
#ifdef HAVE_RANDOM
|
||||||
|
|
1
re.c
1
re.c
|
@ -725,6 +725,7 @@ reg_match(re, str)
|
||||||
{
|
{
|
||||||
int start;
|
int start;
|
||||||
|
|
||||||
|
if (NIL_P(str)) return FALSE;
|
||||||
str = str_to_str(str);
|
str = str_to_str(str);
|
||||||
start = reg_search(re, str, 0, 0);
|
start = reg_search(re, str, 0, 0);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
|
|
12
ruby.c
12
ruby.c
|
@ -567,7 +567,7 @@ load_file(fname, script)
|
||||||
if (script) {
|
if (script) {
|
||||||
rb_define_global_const("DATA", f);
|
rb_define_global_const("DATA", f);
|
||||||
}
|
}
|
||||||
else if (f != rb_stdin) {
|
if (f != rb_stdin) {
|
||||||
io_close(f);
|
io_close(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -783,7 +783,7 @@ ruby_process_options(argc, argv)
|
||||||
{
|
{
|
||||||
origargc = argc; origargv = argv;
|
origargc = argc; origargv = argv;
|
||||||
ruby_script(argv[0]); /* for the time being */
|
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)
|
#if defined(USE_DLN_A_OUT)
|
||||||
dln_argv0 = argv[0];
|
dln_argv0 = argv[0];
|
||||||
#endif
|
#endif
|
||||||
|
@ -801,12 +801,12 @@ ruby_process_options(argc, argv)
|
||||||
if (do_loop) {
|
if (do_loop) {
|
||||||
yywhile_loop(do_line, do_split);
|
yywhile_loop(do_line, do_split);
|
||||||
}
|
}
|
||||||
if (e_tmpname) {
|
|
||||||
unlink(e_tmpname);
|
|
||||||
e_tmpname = NULL;
|
|
||||||
}
|
|
||||||
if (e_fp) {
|
if (e_fp) {
|
||||||
fclose(e_fp);
|
fclose(e_fp);
|
||||||
e_fp = NULL;
|
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));
|
INT num2int _((VALUE));
|
||||||
#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):num2int((VALUE)x))
|
#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):num2int((VALUE)x))
|
||||||
|
UINT num2uint _((VALUE));
|
||||||
|
#define NUM2UINT(x) num2uint((VALUE)x)
|
||||||
|
|
||||||
double num2dbl _((VALUE));
|
double num2dbl _((VALUE));
|
||||||
#define NUM2DBL(x) num2dbl((VALUE)(x))
|
#define NUM2DBL(x) num2dbl((VALUE)(x))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue