aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--io.c22
-rw-r--r--test/ruby/test_io.rb2
3 files changed, 23 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index e3adaa1a39..566114343b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Dec 23 16:22:41 2008 Tanaka Akira <akr@fsij.org>
+
+ * io.c (rb_io_inspect): show fd number if there is no pathname.
+
Tue Dec 23 15:48:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* tool/file2lastrev.rb: shouldn't use single quote in shell's command
diff --git a/io.c b/io.c
index 632e3500c9..93855f917b 100644
--- a/io.c
+++ b/io.c
@@ -1353,15 +1353,29 @@ rb_io_inspect(VALUE obj)
{
rb_io_t *fptr;
const char *cname;
+ char fd_desc[256];
+ const char *path;
const char *st = "";
fptr = RFILE(rb_io_taint_check(obj))->fptr;
- if (!fptr || NIL_P(fptr->pathv)) return rb_any_to_s(obj);
cname = rb_obj_classname(obj);
- if (fptr->fd < 0) {
- st = " (closed)";
+ if (!fptr || NIL_P(fptr->pathv)) {
+ if (fptr->fd < 0) {
+ path = "";
+ st = "(closed)";
+ }
+ else {
+ snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
+ path = fd_desc;
+ }
+ }
+ else {
+ path = RSTRING_PTR(fptr->pathv);
+ if (fptr->fd < 0) {
+ st = " (closed)";
+ }
}
- return rb_sprintf("#<%s:%s%s>", cname, RSTRING_PTR(fptr->pathv), st);
+ return rb_sprintf("#<%s:%s%s>", cname, path, st);
}
/*
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index d00c0a3f7c..e0350452d5 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -705,7 +705,7 @@ class TestIO < Test::Unit::TestCase
def test_inspect
with_pipe do |r, w|
- assert(r.inspect =~ /^#<IO:0x[0-9a-f]+>$/)
+ assert(r.inspect =~ /^#<IO:fd \d+>$/)
assert_raise(SecurityError) do
safe_4 { r.inspect }
end