`close': Bad file descriptor - filename (Errno::EBADF)

S

Simon Strandgaard

While upgrading rubicon from 1.6 to 1.8, I bumped into
this problem in the builtin/TestIO.rb file.
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests


I have extracted the code which reproduces the problem.
Any ideas on how to solve it, would be nice.


server> rm testtest
server> ruby a.rb
a.rb:5:in `close': Bad file descriptor - testtest (Errno::EBADF)
from a.rb:5:in `open'
from a.rb:5
server> expand -t2 a.rb
file = "testtest"
File.open(file, "w") do |f|
10.times { |i| f.printf "%02d: This is a line\n", i }
end
File.open(file, "w") do |f|
io = IO.new(f.fileno, "w")
io << 1 << "\n" << "dummy" << "\n" << "cat\n"
io.close
end
server>
 
Y

Yukihiro Matsumoto

Hi,

In message "`close': Bad file descriptor - filename (Errno::EBADF)"

|While upgrading rubicon from 1.6 to 1.8, I bumped into
|this problem in the builtin/TestIO.rb file.
|http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

It's a bug in rubicon. Try test suites bundled with 1.8.1 or later.

|File.open(file, "w") do |f|
| io = IO.new(f.fileno, "w")
| io << 1 << "\n" << "dummy" << "\n" << "cat\n"
| io.close <= close io here.
|end <= open close io at the end of block (i.e. double close)

matz.
 
S

Simon Strandgaard

|While upgrading rubicon from 1.6 to 1.8, I bumped into
|this problem in the builtin/TestIO.rb file.
|http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

It's a bug in rubicon. Try test suites bundled with 1.8.1 or later. [snip code]

Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
We have made a transition from rubyunit to now use testunit.

I am working with the CVS version (I don't think there is a newer rubicon
suite?) ;-)

You can see the pending bugs here:
http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
Please comment on these :)


The code which I am looking at is

def test_LSHIFT # '<<'
File.open(@file, "w") do |file|
io = IO.new(file.fileno, "w")
io << 1 << "\n" << Dummy.new << "\n" << "cat\n"
io.close
end
expected = [ "1\n", "dummy\n", "cat\n"]
IO.foreach(@file) do |line|
assert_equal(expected.shift, line)
end
assert_equal([], expected)
end

Why make an instance of the IO class, when its the '<<' leftshift
operator we want to test?
 
S

Simon Strandgaard

Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
We have made a transition from rubyunit to now use testunit.

You can see the pending bugs here:
http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
Please comment on these :)

Ok I have one last problem with Bad File Descriptor.
The source code for TestIO.rb is here:
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests


server> ruby TestIO.rb
Loaded suite TestIO
Started
..S.....E....S......S....................................
Finished in 0.833549 seconds.

1) Error:
test_closed?(TestIO):
Errno::EBADF: Bad file descriptor - _test/_99lines
TestIO.rb:19:in `close'
TestIO.rb:19:in `open'
TestIO.rb:19:in `setup'

53 tests, 1242 assertions, 0 failures, 1 errors
server>
 
S

Simon Strandgaard

Ok I have one last problem with Bad File Descriptor.
[snip]

Solved.. It was a typo I had made, writing 'clone' where I meant 'close'.


Sorry for the noise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top