in reply to Tie::File - sorting array adds empty lines
From what I can tell of gdb stumblings through Perl_pp_sort(), in the particular event of a tied array in the above format, the code branch at line 1716 of pp_sort.c will be followed (code below):
if (av && !sorting_av) { /* simulate pp aassign of tied AV */ ... av_extend(av, max); ... }
When the av_extend is called, max has the correct value that was returned from FETCHSIZE. However, the code that deals with tied arrays at the top of av_extend ends up pushing max+1 onto the stack prior to the EXTEND call:
Perl_av_extend(pTHX_AV *av, I32 key) { MAGIC * const mg = SvTIED_mg((SV*)av, PERL_MAGIC_tied); if (msg) { ... PUSHs(SvTIED_obj((SV*)av, mg)); PUSHs(sv_2mortal(newSViv(key+1))); PUTBACK; call_method("EXTEND", G_SCALAR|G_DISCARD);
I haven't the foggiest why this is, as I'm no Perl internals expert. But the result appears to be an off-by-one in the module's implementation of the EXTEND.
I think the reason it doesn't affect many other modules is that the bulk of modules that use tied arrays (that I've tested at least) have EXTEND as a no-op function ({}). Tie::File, on the other hand, actually uses the EXTEND to determine the number of records in the file. Because of this, you always end up with an extra empty record (which in this case is a newline, since that is the default record separator) because of the off-by-one.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tie::File - sorting array adds empty lines
by ikegami (Patriarch) on Sep 11, 2008 at 23:58 UTC | |
by demerphq (Chancellor) on Jan 30, 2020 at 09:01 UTC |