Well, the interface itself only contains the parameterless method. The
version with the parameter is part of a very common pattern that also
optimizes the finalization experience and plays nicely with derived
classes. If you’re really concerned about cleaning something up, you’ll
probably follow that pattern. But if you’re just interested in the
syntactic sugar of “using” and/or never expect the object’s lifespan to
exceed that of the current method, then there’s no real need to
implement the additional two methods or pay the cost of having a
finalizer. (Even if you suppress it later, creating an object with a
finalizer is more expensive than creating it without one iirc.)
IDisposable is one of my favorite topics. I believe that officially
makes me a masochist.
From: [email protected]
[mailto:[email protected]] On Behalf Of Ivan Porto
Carrero
Sent: Tuesday, September 09, 2008 4:34 AM
To: [email protected]
Subject: Re: [Ironruby-core] Mysteriously broken calls to dispose?
yep that is correct
http://github.com/casualjim/ironnails/tree/master/IronNails/vendor/iron_nails/lib/core_ext/kernel.rb
I figure you can wrap that in a begin…rescue block again and first try
the one with the bool and then the one without it.
Some implementations of Dispose don’t actually implement the method with
a bool as parameter.
Instead of FileStream you can use the ruby File class or you could write
a FileStreamAdapter in C# or something so you can safely use it from
IronRuby without the overloading mayhem.
Cheers
Ivan
On Tue, Sep 9, 2008 at 1:25 PM, Curt H.
<[email protected]mailto:[email protected]> wrote:
Yes, this has been reported before (in fact, I think it was when someone
was writing “using” ☺) and we haven’t yet worked out a resolution. I’ll
see if there’s something quick that can be fixed here later today.
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Orion E.
Sent: Monday, September 08, 2008 10:12 PM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Mysteriously broken calls to dispose?
Follow-up
If I call $fs.dispose(true), then it works.
It seems there’s a protected dispose(bool) in a derived class.
I can’t actually call Dispose(true) from C# as the compiler tells me
it’s protected.
It strikes me as somewhat broken that the method which ironruby actually
invokes is the one that you shouldn’t invoke…
At any rate, I’d be overjoyed if anyone could point me in the direction
of a fix. I’m trying to write ‘using’ (a la C#) in ruby as part of demo
for my local .NET user group. It should be trivial and showcase how
awesome IronRuby is
Orion E. wrote:
I don’t seem to be able to call Dispose on a filestream. Needless to say
this is problematic.
Here’s a paste, straight from the IR console (latest svn version 141)
require ‘mscorlib’
=> true
include System::IO
=> Object
$fs = FileStream.new( ‘file.txt’, FileMode.Open )
=> #System::IO::FileStream:0x000005c
$fs.Dispose
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\matchcaller.generated.cs:30:in
Call2': wrong number or type of arguments for
Dispose’ (ArgumentError)
from
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\callsite.cs:275:in
`UpdateAndExecute’
from
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\updatedelegates.generated.cs:38:in
`Update2’
from :0
All the other methods on the filestream object work fine (read_all_text,
and so on), but the call to dispose crashes.
Likewise, I get a crash calling methods with overloads, which looks like
it may (??) be related.
require ‘mscorlib’
=> true
include System::IO
=> Object
$bytes = System::IO::File.read_all_bytes( ‘file.txt’ ); nil # nil is to prevent ir from printing the GIANT ARRAY
=> nil
$text = System::Text::Encoding.UTF8.get_string($bytes)
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\matchcaller.generated.cs:35:in
Call3': wrong number or type of arguments for
get_string’
(ArgumentError)
from
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\callsite.cs:275:in
`UpdateAndExecute’
from
c:\development\ironruby\trunk\src\microsoft.scripting.core\actions\updatedelegates.generated.cs:45:in
`Update3’
from :0
$text = System::Text::Encoding.UTF8.get_string($bytes, 0, $bytes.length)
=> “PROPER TEXT GOES HERE”
It seems like it can’t figure out that there is GetString(bytes) and
GetString(bytes, index, length) and just uses the latter always.
Is there a solution for either of these problems?
Thanks a lot, Orion
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core