> From: Sanghyeon Seo [EMAIL PROTECTED]
> Sent: Friday, 29 February 2008 2:23 PM
> To: [email protected]
> Subject: Re: [Ironruby-core] digest.so implemented
>
> Hash implementations are fully managed (in .NET and Mono), and shallow
> copying by MemberwiseClone does give the correct semantics *now*.

Are you sure? Which version of the .NET framework are you assuming? Are you 
claiming it works on .NET 2.0?

Consider the following C# snippet:

    HashAlgorithm digest = MD5.Create();
    HashAlgorithm clone = 
(HashAlgorithm)digest.GetType().GetMethod("MemberwiseClone", 
BindingFlags.Instance | BindingFlags.NonPublic).Invoke(digest, null);
    clone.TransformFinalBlock(new byte[0], 0, 0);
    byte[] block = new byte[] {1, 2, 3, 4};
    digest.TransformBlock(block, 0, block.Length, block, 0);

On .NET 2.0, the final line fails despite the fact that only the clone has been 
finalized.

This corresponds to the following Ruby use case:

  digest = Digest::MD5.new
  digest << 'Initial'
  puts digest.hexdigest
  digest << 'add some more'
  puts digest.hexdigest

You could argue that such useage is unlikely in practice, but it seems to me 
that the CRuby implementation was specifically designed to support this case - 
why else would they bother cloning?

Cheers, Wayne.

BTW, how does one code (BindingFlags.Instance | BindingFlags.NonPublic) in 
IronRuby?
I had to resort to 
System::Enum.ToObject(System::Reflection::BindingFlags.Instance.GetType(), 36)
Is there a simplier/more elegant solution?
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to