Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Just to follow up for posterity...

It turns out that the wrapper strategy wasn't the problem at all. In fact, it's a bug in IO::Zlib... sort of. When XML::Parser::Expat calls read on a filehandle, it does something a bit unusual. You might think that it would use the read's return value to determine the amount of data actually read, but that's not what it does. Instead, it uses the len parameter of the SvPV macro (see perlguts) to determine the actual length of the buffer. But IO::Zlib's implementation of Tie::Handle's READ method doesn't touch the buffer if it's at the end of file: it just returns 0 to indicate no bytes are left. So when used together, X::P::E takes the value of the buffer from the most recent non-EOF read, and so in fact does attempt to read more than it should. What it reads is the last chunk of the file, again. Unsurprisingly, this addition of incomplete data past the closing document tag results in illegal XML, which is why I got the error I did.

You could almost call this odd behavior a bug in XML::Parser::Expat instead of IO::Zlib, except for this line in read: SCALAR will be grown or shrunk to the length actually read. So technically, IO::Zlib's read should set the buffer to "" before returning 0 at EOF.

Solving the problem is therefore just a matter of changing return 0 if $self->{'eof'}; to

if ( $self->{'eof'} ) { $$bufref = ""; return 0; };
in IO::Zlib. I'll submit the patch later today.

Relieved to be done debugging XS code with printf's,

--athomason


In reply to Re: IO::Zlib with XML::Twig/XML::Parser::Expat by athomason
in thread IO::Zlib with XML::Twig/XML::Parser::Expat by athomason

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (4)
    As of 2014-07-26 19:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (178 votes), past polls