[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

BUG in File

leon breedt

10/29/2004 9:45:00 AM

hi,

module X
class TestFile < ::File
def initialize
$stderr.puts self.path
end
end
end
f = X::TestFile.new

granted, this isn't a very likely piece of code. but still :)

leon


3 Answers

nobu.nokada

10/29/2004 10:03:00 AM

0

Hi,

At Fri, 29 Oct 2004 18:45:20 +0900,
leon breedt wrote in [ruby-talk:118234]:
> module X
> class TestFile < ::File
> def initialize
> $stderr.puts self.path
> end
> end
> end
> f = X::TestFile.new

Should it return Qnil or raise an exception?


Index: file.c
===================================================================
RCS file: /cvs/ruby/src/ruby/file.c,v
retrieving revision 1.189
diff -U2 -p -d -r1.189 file.c
--- file.c 23 Oct 2004 15:40:58 -0000 1.189
+++ file.c 29 Oct 2004 10:02:09 -0000
@@ -139,4 +139,7 @@ rb_file_path(obj)

fptr = RFILE(rb_io_taint_check(obj))->fptr;
+ if (!fptr) {
+ rb_raise(rb_eIOError, "uninitialized stream");
+ }
if (!fptr->path) return Qnil;
return rb_tainted_str_new2(fptr->path);


--
Nobu Nakada


ts

10/29/2004 10:06:00 AM

0

>>>>> "l" == leon breedt <bitserf@gmail.com> writes:

l> $stderr.puts self.path

same with IO#closed?


Guy Decoux





nobu.nokada

10/29/2004 10:27:00 AM

0

Hi,

At Fri, 29 Oct 2004 19:05:43 +0900,
ts wrote in [ruby-talk:118237]:
> >>>>> "l" == leon breedt <bitserf@gmail.com> writes:
>
> l> $stderr.puts self.path
>
> same with IO#closed?

Yes.


Index: file.c
===================================================================
RCS file: /cvs/ruby/src/ruby/file.c,v
retrieving revision 1.189
diff -U2 -p -d -r1.189 file.c
--- file.c 23 Oct 2004 15:40:58 -0000 1.189
+++ file.c 29 Oct 2004 10:15:05 -0000
@@ -139,4 +139,5 @@ rb_file_path(obj)

fptr = RFILE(rb_io_taint_check(obj))->fptr;
+ rb_io_check_initialized(fptr);
if (!fptr->path) return Qnil;
return rb_tainted_str_new2(fptr->path);
Index: io.c
===================================================================
RCS file: /cvs/ruby/src/ruby/io.c,v
retrieving revision 1.311
diff -U2 -p -d -r1.311 io.c
--- io.c 29 Oct 2004 01:06:36 -0000 1.311
+++ io.c 29 Oct 2004 10:15:59 -0000
@@ -183,5 +183,5 @@ rb_io_taint_check(io)

void
-rb_io_check_closed(fptr)
+rb_io_check_initialized(fptr)
OpenFile *fptr;
{
@@ -189,4 +189,11 @@ rb_io_check_closed(fptr)
rb_raise(rb_eIOError, "uninitialized stream");
}
+}
+
+void
+rb_io_check_closed(fptr)
+ OpenFile *fptr;
+{
+ rb_io_check_initialized(fptr);
if (!fptr->f && !fptr->f2) {
rb_raise(rb_eIOError, "closed stream");
@@ -2029,4 +2036,5 @@ rb_io_closed(io)

fptr = RFILE(io)->fptr;
+ rb_io_check_initialized(fptr);
return (fptr->f || fptr->f2)?Qfalse:Qtrue;
}
Index: rubyio.h
===================================================================
RCS file: /cvs/ruby/src/ruby/rubyio.h,v
retrieving revision 1.28
diff -U2 -p -d -r1.28 rubyio.h
--- rubyio.h 18 Oct 2004 02:29:43 -0000 1.28
+++ rubyio.h 29 Oct 2004 10:14:41 -0000
@@ -70,4 +70,5 @@ void rb_io_check_readable _((OpenFile*))
int rb_io_fptr_finalize _((OpenFile*));
void rb_io_synchronized _((OpenFile*));
+void rb_io_check_initialized _((OpenFile*));
void rb_io_check_closed _((OpenFile*));
int rb_io_wait_readable _((int));


--
Nobu Nakada