[Cleanup] Int vs Long #3
From:
Michal Rokos <m.rokos@...>
Date:
2002-08-22 16:16:15 UTC
List:
ruby-core #340
Hi,
this is the 3rd part of int x long cleanups.
I think I also find some leftover from off_t transition.
Thanks for reviewing.
Michal
Index: error.c
===================================================================
RCS file: /src/ruby/error.c,v
retrieving revision 1.47
diff -u -r1.47 error.c
--- error.c 2002/08/21 15:47:54 1.47
+++ error.c 2002/08/22 16:07:10
@@ -35,10 +35,10 @@
static void
err_snprintf(buf, len, fmt, args)
char *buf, *fmt;
- int len;
+ long len;
va_list args;
{
- int n;
+ long n;
ruby_set_current_source();
if (!ruby_sourcefile) {
Index: eval.c
===================================================================
RCS file: /src/ruby/eval.c,v
retrieving revision 1.318
diff -u -r1.318 eval.c
--- eval.c 2002/08/21 15:47:54 1.318
+++ eval.c 2002/08/22 16:07:25
@@ -1006,7 +1006,7 @@
}
else {
char *tail = 0;
- int len = elen;
+ long len = elen;
if (RSTRING(epath)->ptr[0] == '#') epath = 0;
if (tail = strchr(einfo, '\n')) {
@@ -3513,12 +3513,12 @@
return Qfalse;
}
-NORETURN(static void terminate_process _((int, const char*, int)));
+NORETURN(static void terminate_process _((int, const char*, long)));
static void
terminate_process(status, mesg, mlen)
int status;
const char *mesg;
- int mlen;
+ long mlen;
{
VALUE exit = rb_exc_new(rb_eSystemExit, mesg, mlen);
Index: file.c
===================================================================
RCS file: /src/ruby/file.c,v
retrieving revision 1.105
diff -u -r1.105 file.c
--- file.c 2002/08/21 15:47:54 1.105
+++ file.c 2002/08/22 16:07:28
@@ -79,7 +79,7 @@
VALUE rb_mFileTest;
static VALUE rb_cStat;
-static int
+static long
apply2files(func, vargs, arg)
void (*func)();
VALUE vargs;
@@ -844,7 +844,7 @@
if (rb_stat(fname, &st) < 0)
rb_sys_fail(RSTRING(fname)->ptr);
- return rb_int2inum(st.st_size);
+ return OFFT2NUM(st.st_size);
}
static VALUE
@@ -994,14 +994,15 @@
{
VALUE vmode;
VALUE rest;
- int mode, n;
+ int mode;
+ long n;
rb_secure(2);
rb_scan_args(argc, argv, "1*", &vmode, &rest);
mode = NUM2INT(vmode);
n = apply2files(chmod_internal, rest, mode);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
static VALUE
@@ -1044,14 +1045,15 @@
{
VALUE vmode;
VALUE rest;
- int mode, n;
+ int mode;
+ long n;
rb_secure(2);
rb_scan_args(argc, argv, "1*", &vmode, &rest);
mode = NUM2INT(vmode);
n = apply2files(lchmod_internal, rest, mode);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
#else
static VALUE
@@ -1083,7 +1085,7 @@
{
VALUE o, g, rest;
struct chown_args arg;
- int n;
+ long n;
rb_secure(2);
rb_scan_args(argc, argv, "2*", &o, &g, &rest);
@@ -1101,7 +1103,7 @@
}
n = apply2files(chown_internal, rest, &arg);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
static VALUE
@@ -1141,7 +1143,7 @@
{
VALUE o, g, rest;
struct chown_args arg;
- int n;
+ long n;
rb_secure(2);
rb_scan_args(argc, argv, "2*", &o, &g, &rest);
@@ -1159,7 +1161,7 @@
}
n = apply2files(lchown_internal, rest, &arg);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
#else
static VALUE
@@ -1191,7 +1193,7 @@
{
VALUE atime, mtime, rest;
struct timeval tvp[2];
- int n;
+ long n;
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
@@ -1199,7 +1201,7 @@
tvp[1] = rb_time_timeval(mtime);
n = apply2files(utime_internal, rest, tvp);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
#else
@@ -1237,7 +1239,7 @@
VALUE *argv;
{
VALUE atime, mtime, rest;
- int n;
+ long n;
struct timeval tv;
struct utimbuf utbuf;
@@ -1249,7 +1251,7 @@
utbuf.modtime = tv.tv_sec;
n = apply2files(utime_internal, rest, &utbuf);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
#endif
@@ -1322,11 +1324,11 @@
rb_file_s_unlink(klass, args)
VALUE klass, args;
{
- int n;
+ long n;
rb_secure(2);
n = apply2files(unlink_internal, args, 0);
- return INT2FIX(n);
+ return LONG2FIX(n);
}
static VALUE
@@ -2266,10 +2268,10 @@
rb_stat_s(obj)
VALUE obj;
{
- int size = get_stat(obj)->st_size;
+ off_t size = get_stat(obj)->st_size;
if (size == 0) return Qnil;
- return INT2FIX(size);
+ return OFFT2NUM(size);
}
static VALUE
Index: gc.c
===================================================================
RCS file: /src/ruby/gc.c,v
retrieving revision 1.97
diff -u -r1.97 gc.c
--- gc.c 2002/08/21 15:47:54 1.97
+++ gc.c 2002/08/22 16:07:30
@@ -777,7 +777,7 @@
case T_ARRAY:
{
- int i, len = obj->as.array.len;
+ long i, len = obj->as.array.len;
VALUE *ptr = obj->as.array.ptr;
for (i=0; i < len; i++)
@@ -839,7 +839,7 @@
case T_STRUCT:
{
- int i, len = obj->as.rstruct.len;
+ long i, len = obj->as.rstruct.len;
VALUE *ptr = obj->as.rstruct.ptr;
for (i=0; i < len; i++)
Index: io.c
===================================================================
RCS file: /src/ruby/io.c,v
retrieving revision 1.148
diff -u -r1.148 io.c
--- io.c 2002/08/21 15:47:54 1.148
+++ io.c 2002/08/22 16:07:41
@@ -555,7 +555,7 @@
while (n > 0) {
#ifdef READ_DATA_PENDING_COUNT
- int i = READ_DATA_PENDING_COUNT(f);
+ long i = READ_DATA_PENDING_COUNT(f);
if (i <= 0) {
rb_thread_wait_fd(fileno(f));
i = READ_DATA_PENDING_COUNT(f);
@@ -599,7 +599,6 @@
*ptr++ = c;
n--;
}
-
return len - n;
}
@@ -722,7 +721,7 @@
do {
#ifdef READ_DATA_PENDING_PTR
- int pending = READ_DATA_PENDING_COUNT(f);
+ long pending = READ_DATA_PENDING_COUNT(f);
if (pending > 0) {
const char *p = READ_DATA_PENDING_PTR(f);
const char *e = memchr(p, delim, pending);
@@ -796,7 +795,7 @@
do {
#ifdef READ_DATA_PENDING_PTR
- int cnt;
+ long cnt;
while ((cnt = READ_DATA_PENDING_COUNT(f)) > 0) {
char buf[1024];
const char *p = READ_DATA_PENDING_PTR(f);
Index: numeric.c
===================================================================
RCS file: /src/ruby/numeric.c,v
retrieving revision 1.56
diff -u -r1.56 numeric.c
--- numeric.c 2002/08/21 15:47:54 1.56
+++ numeric.c 2002/08/22 16:07:44
@@ -1022,7 +1022,7 @@
{
if (FIXNUM_P(num)) {
long i = FIX2LONG(num) + 1;
- return rb_int2inum(i);
+ return LONG2FIX(i);
}
return rb_funcall(num, '+', 1, INT2FIX(1));
}
@@ -1083,7 +1083,7 @@
fix_uminus(num)
VALUE num;
{
- return rb_int2inum(-FIX2LONG(num));
+ return LONG2NUM(-FIX2LONG(num));
}
VALUE
@@ -1385,7 +1385,7 @@
long val = FIX2LONG(num);
val = ~val;
- return rb_int2inum(val);
+ return LONG2NUM(val);
}
static VALUE
@@ -1398,7 +1398,7 @@
return rb_big_and(y, x);
}
val = FIX2LONG(x) & NUM2LONG(y);
- return rb_int2inum(val);
+ return LONG2NUM(val);
}
static VALUE
@@ -1411,7 +1411,7 @@
return rb_big_or(y, x);
}
val = FIX2LONG(x) | NUM2LONG(y);
- return rb_int2inum(val);
+ return LONG2NUM(val);
}
static VALUE
@@ -1424,7 +1424,7 @@
return rb_big_xor(y, x);
}
val = FIX2LONG(x) ^ NUM2LONG(y);
- return rb_int2inum(val);
+ return LONG2NUM(val);
}
static VALUE fix_rshift _((VALUE, VALUE));
@@ -1444,7 +1444,7 @@
return rb_big_lshift(rb_int2big(val), y);
}
val = val << width;
- return rb_int2inum(val);
+ return LONG2NUM(val);
}
static VALUE
@@ -1512,7 +1512,7 @@
if (i < 0) i = -i;
- return rb_int2inum(i);
+ return LONG2NUM(i);
}
static VALUE
Index: pack.c
===================================================================
RCS file: /src/ruby/pack.c,v
retrieving revision 1.42
diff -u -r1.42 pack.c
--- pack.c 2002/08/21 15:47:54 1.42
+++ pack.c 2002/08/22 16:07:47
@@ -323,11 +323,11 @@
#endif
static char *toofew = "too few arguments";
-static void encodes _((VALUE,char*,int,int));
-static void qpencode _((VALUE,VALUE,int));
+static void encodes _((VALUE,char*,long,int));
+static void qpencode _((VALUE,VALUE,long));
static int uv_to_utf8 _((char*,unsigned long));
-static unsigned long utf8_to_uv _((char*,int*));
+static unsigned long utf8_to_uv _((char*,long*));
static VALUE
pack_pack(ary, fmt)
@@ -431,7 +431,7 @@
case 'b':
{
int byte = 0;
- int i, j = 0;
+ long i, j = 0;
if (len > plen) {
j = (len - plen + 1)/2;
@@ -461,7 +461,7 @@
case 'B':
{
int byte = 0;
- int i, j = 0;
+ long i, j = 0;
if (len > plen) {
j = (len - plen + 1)/2;
@@ -490,7 +490,7 @@
case 'h':
{
int byte = 0;
- int i, j = 0;
+ long i, j = 0;
if (len > plen) {
j = (len - plen + 1)/2;
@@ -520,7 +520,7 @@
case 'H':
{
int byte = 0;
- int i, j = 0;
+ long i, j = 0;
if (len > plen) {
j = (len - plen + 1)/2;
@@ -800,7 +800,7 @@
else
len = len / 3 * 3;
while (plen > 0) {
- int todo;
+ long todo;
if (plen > len)
todo = len;
@@ -915,11 +915,11 @@
encodes(str, s, len, type)
VALUE str;
char *s;
- int len;
+ long len;
int type;
{
char *buff = ALLOCA_N(char, len * 4 / 3 + 6);
- int i = 0;
+ long i = 0;
char *trans = type == 'u' ? uu_table : b64_table;
int padding;
@@ -959,10 +959,10 @@
static void
qpencode(str, from, len)
VALUE str, from;
- int len;
+ long len;
{
char buff[1024];
- int i = 0, n = 0, prev = EOF;
+ long i = 0, n = 0, prev = EOF;
unsigned char *s = (unsigned char*)RSTRING(from)->ptr;
unsigned char *send = s + RSTRING(from)->len;
@@ -1136,7 +1136,7 @@
case 'A':
if (len > send - s) len = send - s;
{
- int end = len;
+ long end = len;
char *t = s + len - 1;
while (t >= s) {
@@ -1151,7 +1151,7 @@
case 'Z':
if (len > send - s) len = send - s;
{
- int end = len;
+ long end = len;
char *t = s + len - 1;
while (t >= s) {
@@ -1174,7 +1174,8 @@
{
VALUE bitstr;
char *t;
- int bits, i;
+ int bits;
+ long i;
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
@@ -1193,7 +1194,8 @@
{
VALUE bitstr;
char *t;
- int bits, i;
+ int bits;
+ long i;
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
@@ -1212,7 +1214,8 @@
{
VALUE bitstr;
char *t;
- int bits, i;
+ int bits;
+ long i;
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
@@ -1233,7 +1236,8 @@
{
VALUE bitstr;
char *t;
- int bits, i;
+ int bits;
+ long i;
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
@@ -1297,7 +1301,7 @@
int tmp;
memcpy(&tmp, s, sizeof(int));
s += sizeof(int);
- rb_ary_push(ary, rb_int2inum(tmp));
+ rb_ary_push(ary, INT2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1308,7 +1312,7 @@
unsigned int tmp;
memcpy(&tmp, s, sizeof(unsigned int));
s += sizeof(unsigned int);
- rb_ary_push(ary, rb_uint2inum(tmp));
+ rb_ary_push(ary, UINT2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1319,7 +1323,7 @@
long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(long,4));
s += NATINT_LEN(long,4);
- rb_ary_push(ary, rb_int2inum(tmp));
+ rb_ary_push(ary, LONG2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1330,7 +1334,7 @@
unsigned long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4));
s += NATINT_LEN(unsigned long,4);
- rb_ary_push(ary, rb_uint2inum(tmp));
+ rb_ary_push(ary, ULONG2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1359,7 +1363,7 @@
unsigned short tmp = 0;
memcpy(OFF16B(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
- rb_ary_push(ary, rb_uint2inum(ntohs(tmp)));
+ rb_ary_push(ary, UINT2NUM(ntohs(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1370,7 +1374,7 @@
unsigned long tmp = 0;
memcpy(OFF32B(&tmp), s, NATINT_LEN(unsigned long,4));
s += NATINT_LEN(unsigned long,4);
- rb_ary_push(ary, rb_uint2inum(ntohl(tmp)));
+ rb_ary_push(ary, ULONG2NUM(ntohl(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1381,7 +1385,7 @@
unsigned short tmp = 0;
memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
- rb_ary_push(ary, rb_uint2inum(vtohs(tmp)));
+ rb_ary_push(ary, UINT2NUM(vtohs(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1392,7 +1396,7 @@
unsigned long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(long,4));
s += NATINT_LEN(long,4);
- rb_ary_push(ary, rb_uint2inum(vtohl(tmp)));
+ rb_ary_push(ary, ULONG2NUM(vtohl(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1480,12 +1484,12 @@
case 'U':
if (len > send - s) len = send - s;
while (len > 0 && s < send) {
- int alen = send - s;
+ long alen = send - s;
unsigned long l;
l = utf8_to_uv(s, &alen);
s += alen; len--;
- rb_ary_push(ary, rb_uint2inum(l));
+ rb_ary_push(ary, ULONG2NUM(l));
}
break;
@@ -1508,7 +1512,7 @@
}
while (len > 0) {
- int mlen = len > 3 ? 3 : len;
+ long mlen = len > 3 ? 3 : len;
if (s < send && *s >= ' ')
a = (*s++ - ' ') & 077;
@@ -1718,7 +1722,7 @@
ul <<= 7;
ul |= (*s & 0x7f);
if (!(*s++ & 0x80)) {
- rb_ary_push(ary, rb_uint2inum(ul));
+ rb_ary_push(ary, ULONG2NUM(ul));
len--;
ul = 0;
}
@@ -1814,11 +1818,11 @@
static unsigned long
utf8_to_uv(p, lenp)
char *p;
- int *lenp;
+ long *lenp;
{
int c = (*p++)&0xff;
unsigned long uv;
- int n = 1;
+ long n = 1;
if (c < 0xc0) n = 1;
else if (c < 0xe0) n = 2;
Index: process.c
===================================================================
RCS file: /src/ruby/process.c,v
retrieving revision 1.54
diff -u -r1.54 process.c
--- process.c 2002/08/21 15:47:54 1.54
+++ process.c 2002/08/22 16:07:50
@@ -831,8 +831,7 @@
if (status == 0) return Qtrue;
return Qfalse;
-#else
-#ifdef DJGPP
+#elif defined(DJGPP)
VALUE cmd;
int status;
@@ -855,10 +854,8 @@
if (status == 0) return Qtrue;
return Qfalse;
-#else
-#if defined(__human68k__)
+#elif defined(__human68k__)
VALUE prog = 0;
- int i;
int status;
fflush(stdin);
@@ -885,8 +882,7 @@
}
last_status_set(status == -1 ? 127 : status);
return status == 0 ? Qtrue : Qfalse;
-#else
-#if defined(__VMS)
+#elif defined(__VMS)
VALUE cmd;
int status;
@@ -962,10 +958,7 @@
if (NUM2INT(rb_last_status) == 0)
return Qtrue;
return Qfalse;
-#endif /* __VMS */
-#endif /* __human68k__ */
-#endif /* DJGPP */
-#endif /* NT */
+#endif
}
static VALUE
Index: re.c
===================================================================
RCS file: /src/ruby/re.c,v
retrieving revision 1.75
diff -u -r1.75 re.c
--- re.c 2002/08/21 15:47:54 1.75
+++ re.c 2002/08/22 16:07:53
@@ -765,7 +765,7 @@
VALUE match;
{
VALUE str;
- int start, end, len;
+ long start, end, len;
if (NIL_P(match)) return Qnil;
if (nth >= RMATCH(match)->regs->num_regs) {
@@ -1077,7 +1077,7 @@
rb_reg_match(re, str)
VALUE re, str;
{
- int start;
+ long start;
if (NIL_P(str)) {
rb_backref_set(Qnil);
@@ -1088,14 +1088,14 @@
if (start < 0) {
return Qnil;
}
- return INT2FIX(start);
+ return LONG2FIX(start);
}
VALUE
rb_reg_match2(re)
VALUE re;
{
- int start;
+ long start;
VALUE line = rb_lastline_get();
if (TYPE(line) != T_STRING) {
@@ -1107,7 +1107,7 @@
if (start < 0) {
return Qnil;
}
- return INT2FIX(start);
+ return LONG2FIX(start);
}
static VALUE
Index: sprintf.c
===================================================================
RCS file: /src/ruby/sprintf.c,v
retrieving revision 1.24
diff -u -r1.24 sprintf.c
--- sprintf.c 2002/08/21 15:47:54 1.24
+++ sprintf.c 2002/08/22 16:07:54
@@ -26,7 +26,7 @@
int base;
{
char *s, *t, *end;
- int len;
+ unsigned long len;
s = t = str;
len = strlen(str);
Index: string.c
===================================================================
RCS file: /src/ruby/string.c,v
retrieving revision 1.111
diff -u -r1.111 string.c
--- string.c 2002/08/21 15:47:54 1.111
+++ string.c 2002/08/22 16:07:59
@@ -1055,7 +1055,7 @@
VALUE str;
char *sbeg, *s;
int c = -1;
- int n = 0;
+ long n = 0;
str = rb_str_new5(orig,RSTRING(orig)->ptr, RSTRING(orig)->len);
OBJ_INFECT(str, orig);
@@ -1255,7 +1255,7 @@
VALUE val;
{
VALUE match;
- int start, end, len;
+ long start, end, len;
if (rb_reg_search(re, str, 0, 0) < 0) {
rb_raise(rb_eIndexError, "regexp not matched");
@@ -3029,7 +3029,7 @@
VALUE str;
{
VALUE vbits;
- int bits;
+ int bits;
char *p, *pend;
if (rb_scan_args(argc, argv, "01", &vbits) == 0) {
Index: time.c
===================================================================
RCS file: /src/ruby/time.c,v
retrieving revision 1.63
diff -u -r1.63 time.c
--- time.c 2002/08/21 15:47:54 1.63
+++ time.c 2002/08/22 16:08:01
@@ -1191,7 +1191,7 @@
#else
struct tm *u, *l;
time_t t;
- int off;
+ long off;
l = &tobj->tm;
t = tobj->tv.tv_sec;
u = gmtime(&t);
@@ -1208,7 +1208,7 @@
off = off * 24 + l->tm_hour - u->tm_hour;
off = off * 60 + l->tm_min - u->tm_min;
off = off * 60 + l->tm_sec - u->tm_sec;
- return INT2FIX(off);
+ return LONG2FIX(off);
#endif
}
}
Index: util.c
===================================================================
RCS file: /src/ruby/util.c,v
retrieving revision 1.28
diff -u -r1.28 util.c
--- util.c 2002/08/21 15:47:54 1.28
+++ util.c 2002/08/22 16:08:02
@@ -27,9 +27,9 @@
unsigned long
scan_oct(start, len, retlen)
-const char *start;
-int len;
-int *retlen;
+ const char *start;
+ int len;
+ int *retlen;
{
register const char *s = start;
register unsigned long retval = 0;
@@ -44,9 +44,9 @@
unsigned long
scan_hex(start, len, retlen)
-const char *start;
-int len;
-int *retlen;
+ const char *start;
+ int len;
+ int *retlen;
{
static char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
register const char *s = start;
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos Czech Technical University, Prague
E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-