Following the suggestion of BrowserUk, I tried to write a bare-minimum example of this behavior. The code is below. The TieTest class is basically meant to remember an internal filehandle and then pass that along with the rest of the arguments through to the core Perl functions.

There are two interesting/questionable observations. First, with line 19 commented out as it is, Digest::MD5 croaks that it was not passed a filehandle. Maybe I'm doing something wrong here? The only way I have found to get around this is to open the filehandle on something before tie'ing it.

If I do that (by uncommenting line 19 and feeding the script two different filenames) the pure-Perl implementation acts on the last file opened, while the XS implementation is clearly reading from the first file opened on line 19 and not talking to the tied class (I added a debugging statement to the READ sub just to be sure). This does seem like a bug to me (although saying that out loud pretty much guarantees that I'll find an error in my own code within the next five minutes). Does anyone have any further thoughts on this? Otherwise I'll submit it as a possible bug as suggested.

Here is the test case

#!/usr/bin/perl package TieTest; sub TIEHANDLE { return bless {}, shift } sub OPEN { open my $fh, $_[1], $_[2]; $_[0]->{fh} = $fh; } sub READ { warn "...tied read\n"; read $_[0]->{fh}, $_[1], $_[2], + $_[3]; } sub SEEK { seek $_[0]->{fh}, $_[1], $_[2]; } package main; use strict; use warnings; use Digest::MD5; use Digest::Perl::MD5; open FH_PLAIN, '<', $ARGV[0]; #open FH_TIED, '<', $ARGV[1]; # try uncommenting this tie(*FH_TIED, 'TieTest'); open FH_TIED, '<', $ARGV[0]; my %handles = (PLAIN => \*FH_PLAIN, TIED => \*FH_TIED); for my $title (qw/PLAIN TIED/) { my $fh = $handles{$title}; for my $class (qw/Digest::Perl::MD5 Digest::MD5/) { my $sum = $class->new->addfile($fh)->hexdigest; printf "%-7s%-19s%-32s\n", $title, $class, $sum; seek $fh, 0, 0; } }

In reply to Re: Digest::MD5 addfile() w/ tied filehandle by jdv
in thread Digest::MD5 addfile() w/ tied filehandle by jdv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.