From 002beaef76a1595af2e39ffd4cd55c595bd6c271 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 29 Jul 2010 18:57:11 +0100 Subject: [PATCH] Perl_do_sv_dump: alert when skipping elements When dumping an HV, we skip dumping the elements if the iterator is already in use. Explain this in the dump output so people like me aren't left wondering why the elements have vanished. --- dump.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/dump.c b/dump.c index 843eb88..eeb43be 100644 --- a/dump.c +++ b/dump.c @@ -1884,29 +1884,34 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo } } } - if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */ - HE *he; - HV * const hv = MUTABLE_HV(sv); - int count = maxnest - nest; - - hv_iterinit(hv); - while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) - && count--) { - STRLEN len; - const U32 hash = HeHASH(he); - SV * const keysv = hv_iterkeysv(he); - const char * const keypv = SvPV_const(keysv, len); - SV * const elt = hv_iterval(hv, he); - - Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim)); - if (SvUTF8(keysv)) - PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 6 * SvCUR(keysv), UNI_DISPLAY_QQ)); - if (HeKREHASH(he)) - PerlIO_printf(file, "[REHASH] "); - PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash); - do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim); + if (nest < maxnest) { + if (HvEITER_get(sv)) /* preserve iterator */ + Perl_dump_indent(aTHX_ level, file, + " (*** Active iterator; skipping element dump ***)\n"); + else { + HE *he; + HV * const hv = MUTABLE_HV(sv); + int count = maxnest - nest; + + hv_iterinit(hv); + while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) + && count--) { + STRLEN len; + const U32 hash = HeHASH(he); + SV * const keysv = hv_iterkeysv(he); + const char * const keypv = SvPV_const(keysv, len); + SV * const elt = hv_iterval(hv, he); + + Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim)); + if (SvUTF8(keysv)) + PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 6 * SvCUR(keysv), UNI_DISPLAY_QQ)); + if (HeKREHASH(he)) + PerlIO_printf(file, "[REHASH] "); + PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash); + do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim); + } + hv_iterinit(hv); /* Return to status quo */ } - hv_iterinit(hv); /* Return to status quo */ } break; case SVt_PVCV: -- 2.7.4