summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--bignum.c42
-rw-r--r--file.c1
-rw-r--r--io.c16
-rw-r--r--lib/shell.rb6
5 files changed, 49 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index c2f08137c2..638404c8b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Feb 22 03:34:38 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (get2comp): need to specify to carry or not.
+
+ * io.c (rb_io_inspect): embed path info.
+
Fri Feb 22 11:30:01 2002 Tanaka Akira <akr@m17n.org>
* prettyprint.rb: FillGroup implemented.
diff --git a/bignum.c b/bignum.c
index 90a4c77012..d778406487 100644
--- a/bignum.c
+++ b/bignum.c
@@ -69,9 +69,10 @@ rb_big_clone(x)
return z;
}
-void
-rb_big_2comp(x) /* get 2's complement */
+static void
+get2comp(x, carry) /* get 2's complement */
VALUE x;
+ int carry;
{
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
@@ -84,7 +85,9 @@ rb_big_2comp(x) /* get 2's complement */
ds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < RBIGNUM(x)->len);
+ if (!carry) return;
if (ds[0] == 1 || ds[0] == 0) {
+ if (RBIGNUM(x)->len == 1) return;
for (i=1; i<RBIGNUM(x)->len; i++) {
if (ds[i] != 0) return;
}
@@ -94,6 +97,13 @@ rb_big_2comp(x) /* get 2's complement */
}
}
+void
+rb_big_2comp(x) /* get 2's complement */
+ VALUE x;
+{
+ return get2comp(x, Qtrue);
+}
+
static VALUE
bignorm(x)
VALUE x;
@@ -795,9 +805,9 @@ rb_big_neg(x)
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(z);
- if (!RBIGNUM(x)->sign) rb_big_2comp(z);
+ if (!RBIGNUM(x)->sign) get2comp(z, Qtrue);
while (i--) ds[i] = ~ds[i];
- if (RBIGNUM(x)->sign) rb_big_2comp(z);
+ if (RBIGNUM(x)->sign) get2comp(z, Qfalse);
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
return bignorm(z);
@@ -1284,11 +1294,11 @@ rb_big_and(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
- rb_big_2comp(y);
+ get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
- rb_big_2comp(x);
+ get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1313,7 +1323,7 @@ rb_big_and(x, y)
for (; i<l2; i++) {
zds[i] = sign?0:ds2[i];
}
- if (!RBIGNUM(z)->sign) rb_big_2comp(z);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@@ -1335,11 +1345,11 @@ rb_big_or(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
- rb_big_2comp(y);
+ get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
- rb_big_2comp(x);
+ get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1364,7 +1374,7 @@ rb_big_or(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:(BIGRAD-1);
}
- if (!RBIGNUM(z)->sign) rb_big_2comp(z);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@@ -1387,11 +1397,11 @@ rb_big_xor(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
- rb_big_2comp(y);
+ get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
- rb_big_2comp(x);
+ get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1418,7 +1428,7 @@ rb_big_xor(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:~ds2[i];
}
- if (!RBIGNUM(z)->sign) rb_big_2comp(z);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@@ -1477,7 +1487,7 @@ rb_big_rshift(x, y)
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
- rb_big_2comp(x);
+ get2comp(x, Qtrue);
}
xds = BDIGITS(x);
i = RBIGNUM(x)->len; j = i - s1;
@@ -1489,7 +1499,7 @@ rb_big_rshift(x, y)
num = BIGUP(xds[i]);
}
if (!RBIGNUM(x)->sign) {
- rb_big_2comp(z);
+ get2comp(z, Qfalse);
}
return bignorm(z);
}
@@ -1515,7 +1525,7 @@ rb_big_aref(x, y)
if (!RBIGNUM(x)->sign) {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
x = rb_big_clone(x);
- rb_big_2comp(x);
+ get2comp(x, Qtrue);
}
else {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);
diff --git a/file.c b/file.c
index 1b0ad93a57..d797a786da 100644
--- a/file.c
+++ b/file.c
@@ -2593,7 +2593,6 @@ Init_File()
rb_file_const("LOCK_NB", INT2FIX(LOCK_NB));
rb_define_method(rb_cFile, "path", rb_file_path, 0);
-
rb_define_global_function("test", rb_f_test, -1);
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
diff --git a/io.c b/io.c
index b028d08bc8..6829efff1c 100644
--- a/io.c
+++ b/io.c
@@ -491,6 +491,21 @@ rb_io_pid(io)
}
static VALUE
+rb_io_inspect(obj)
+ VALUE obj;
+{
+ OpenFile *fptr;
+ char *buf, *cname;
+
+ GetOpenFile(obj, fptr);
+ if (!fptr->path) return rb_any_to_s(obj);
+ cname = rb_class2name(CLASS_OF(obj));
+ buf = ALLOCA_N(char, strlen(cname) + strlen(fptr->path) + 5);
+ sprintf(buf, "#<%s:%s>", cname, fptr->path);
+ return rb_str_new2(buf);
+}
+
+static VALUE
rb_io_to_io(io)
VALUE io;
{
@@ -3691,6 +3706,7 @@ Init_IO()
rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
+ rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
rb_stdin = orig_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_stdin);
diff --git a/lib/shell.rb b/lib/shell.rb
index d641657cbe..bed9c052e8 100644
--- a/lib/shell.rb
+++ b/lib/shell.rb
@@ -116,11 +116,7 @@ class Shell
attr_reader :process_controller
def expand_path(path)
- if /^[\/~]/ =~ path
- File.expand_path(path)
- else
- File.expand_path(File.join(@cwd, path))
- end
+ File.expand_path(path)
end
# Most Shell commands are defined via CommandProcessor