Goodbye AvFLAGS
[p5sagit/p5-mst-13.2.git] / dump.c
diff --git a/dump.c b/dump.c
index 0ae1a44..8bbacb1 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1,7 +1,7 @@
 /*    dump.c
  *
  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
+ *    2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -25,7 +25,7 @@
 #include "perl.h"
 #include "regcomp.h"
 
-static HV *Sequence;
+#define Sequence PL_op_sequence
 
 void
 Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
@@ -53,17 +53,17 @@ Perl_dump_all(pTHX)
 }
 
 void
-Perl_dump_packsubs(pTHX_ HV *stash)
+Perl_dump_packsubs(pTHX_ const HV *stash)
 {
     I32        i;
-    HE *entry;
 
     if (!HvARRAY(stash))
        return;
     for (i = 0; i <= (I32) HvMAX(stash); i++) {
+        const HE *entry;
        for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
-           GV *gv = (GV*)HeVAL(entry);
-           HV *hv;
+            const GV *gv = (GV*)HeVAL(entry);
+            const HV *hv;
            if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
                continue;
            if (GvCVu(gv))
@@ -78,7 +78,7 @@ Perl_dump_packsubs(pTHX_ HV *stash)
 }
 
 void
-Perl_dump_sub(pTHX_ GV *gv)
+Perl_dump_sub(pTHX_ const GV *gv)
 {
     SV *sv = sv_newmortal();
 
@@ -95,7 +95,7 @@ Perl_dump_sub(pTHX_ GV *gv)
 }
 
 void
-Perl_dump_form(pTHX_ GV *gv)
+Perl_dump_form(pTHX_ const GV *gv)
 {
     SV *sv = sv_newmortal();
 
@@ -114,15 +114,15 @@ Perl_dump_eval(pTHX)
 }
 
 char *
-Perl_pv_display(pTHX_ SV *dsv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
+Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
 {
-    int truncated = 0;
-    int nul_terminated = len > cur && pv[cur] == '\0';
+    const bool nul_terminated = len > cur && pv[cur] == '\0';
+    bool truncated = 0;
 
     sv_setpvn(dsv, "\"", 1);
     for (; cur--; pv++) {
        if (pvlim && SvCUR(dsv) >= pvlim) {
-            truncated++;
+            truncated = 1;
            break;
         }
        switch (*pv) {
@@ -153,6 +153,7 @@ Perl_pv_display(pTHX_ SV *dsv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
 char *
 Perl_sv_peek(pTHX_ SV *sv)
 {
+    dVAR;
     SV *t = sv_newmortal();
     STRLEN n_a;
     int unref = 0;
@@ -229,7 +230,7 @@ Perl_sv_peek(pTHX_ SV *sv)
     if (SvROK(sv)) {
        sv_catpv(t, "\\");
        if (SvCUR(t) + unref > 10) {
-           SvCUR(t) = unref + 3;
+           SvCUR_set(t, unref + 3);
            *SvEND(t) = '\0';
            sv_catpv(t, "...");
            goto finish;
@@ -334,7 +335,7 @@ Perl_sv_peek(pTHX_ SV *sv)
 }
 
 void
-Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm)
+Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
 {
     char ch;
 
@@ -402,17 +403,14 @@ Perl_pmop_dump(pTHX_ PMOP *pm)
 /* An op sequencer.  We visit the ops in the order they're to execute. */
 
 STATIC void
-sequence(pTHX_ register OP *o)
+sequence(pTHX_ register const OP *o)
 {
+    dVAR;
     SV      *op;
     char    *key;
     STRLEN   len;
-    static   UV seq;
-    OP      *oldop = 0,
-            *l;
-
-    if (!Sequence)
-       Sequence = newHV();
+    const OP *oldop = 0;
+    OP      *l;
 
     if (!o)
        return;
@@ -431,7 +429,7 @@ sequence(pTHX_ register OP *o)
        switch (o->op_type) {
        case OP_STUB:
            if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
-               hv_store(Sequence, key, len, newSVuv(++seq), 0);
+               hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
                break;
            }
            goto nothin;
@@ -445,7 +443,7 @@ sequence(pTHX_ register OP *o)
          nothin:
            if (oldop && o->op_next)
                continue;
-           hv_store(Sequence, key, len, newSVuv(++seq), 0);
+           hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
            break;
 
        case OP_MAPWHILE:
@@ -458,7 +456,7 @@ sequence(pTHX_ register OP *o)
        case OP_DORASSIGN:
        case OP_COND_EXPR:
        case OP_RANGE:
-           hv_store(Sequence, key, len, newSVuv(++seq), 0);
+           hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
            for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next)
                ;
            sequence(aTHX_ l);
@@ -466,7 +464,7 @@ sequence(pTHX_ register OP *o)
 
        case OP_ENTERLOOP:
        case OP_ENTERITER:
-           hv_store(Sequence, key, len, newSVuv(++seq), 0);
+           hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
            for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next)
                ;
            sequence(aTHX_ l);
@@ -481,7 +479,7 @@ sequence(pTHX_ register OP *o)
        case OP_QR:
        case OP_MATCH:
        case OP_SUBST:
-           hv_store(Sequence, key, len, newSVuv(++seq), 0);
+           hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
            for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next)
                ;
            sequence(aTHX_ l);
@@ -491,7 +489,7 @@ sequence(pTHX_ register OP *o)
            break;
 
        default:
-           hv_store(Sequence, key, len, newSVuv(++seq), 0);
+           hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
            break;
        }
        oldop = o;
@@ -499,8 +497,9 @@ sequence(pTHX_ register OP *o)
 }
 
 STATIC UV
-sequence_num(pTHX_ OP *o)
+sequence_num(pTHX_ const OP *o)
 {
+    dVAR;
     SV     *op,
           **seq;
     char   *key;
@@ -513,8 +512,9 @@ sequence_num(pTHX_ OP *o)
 }
 
 void
-Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
+Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
 {
+    dVAR;
     UV      seq;
     sequence(aTHX_ o);
     Perl_dump_indent(aTHX_ level, file, "{\n");
@@ -856,7 +856,7 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
 }
 
 void
-Perl_op_dump(pTHX_ OP *o)
+Perl_op_dump(pTHX_ const OP *o)
 {
     do_op_dump(0, Perl_debug_log, o);
 }
@@ -887,7 +887,7 @@ Perl_gv_dump(pTHX_ GV *gv)
  * (with the PERL_MAGIC_ prefixed stripped)
  */
 
-static struct { const char type; const char *name; } magic_names[] = {
+static const struct { const char type; const char *name; } magic_names[] = {
        { PERL_MAGIC_sv,             "sv(\\0)" },
        { PERL_MAGIC_arylen,         "arylen(#)" },
        { PERL_MAGIC_glob,           "glob(*)" },
@@ -932,7 +932,7 @@ static struct { const char type; const char *name; } magic_names[] = {
 };
 
 void
-Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
+Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
 {
     for (; mg; mg = mg->mg_moremagic) {
        Perl_dump_indent(aTHX_ level, file,
@@ -981,8 +981,8 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxne
 
        {
            int n;
-           char *name = 0;
-           for (n=0; magic_names[n].name; n++) {
+           const char *name = 0;
+           for (n = 0; magic_names[n].name; n++) {
                if (mg->mg_type == magic_names[n].type) {
                    name = magic_names[n].name;
                    break;
@@ -1050,13 +1050,13 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxne
 }
 
 void
-Perl_magic_dump(pTHX_ MAGIC *mg)
+Perl_magic_dump(pTHX_ const MAGIC *mg)
 {
     do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
 }
 
 void
-Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
+Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
 {
     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
     if (sv && HvNAME(sv))
@@ -1066,7 +1066,7 @@ Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
 }
 
 void
-Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
+Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
 {
     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
     if (sv && GvNAME(sv))
@@ -1076,7 +1076,7 @@ Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
 }
 
 void
-Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
+Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
 {
     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
     if (sv && GvNAME(sv)) {
@@ -1093,7 +1093,7 @@ void
 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
 {
     SV *d;
-    char *s;
+    const char *s;
     U32 flags;
     U32 type;
 
@@ -1136,7 +1136,8 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
     if (flags & SVp_IOK)       sv_catpv(d, "pIOK,");
     if (flags & SVp_NOK)       sv_catpv(d, "pNOK,");
     if (flags & SVp_POK)       sv_catpv(d, "pPOK,");
-    if (flags & SVp_SCREAM)    sv_catpv(d, "SCREAM,");
+    if (flags & SVp_SCREAM && type != SVt_PVHV)
+                               sv_catpv(d, "SCREAM,");
 
     switch (type) {
     case SVt_PVCV:
@@ -1159,6 +1160,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        if (HvLAZYDEL(sv))      sv_catpv(d, "LAZYDEL,");
        if (HvHASKFLAGS(sv))    sv_catpv(d, "HASKFLAGS,");
        if (HvREHASH(sv))       sv_catpv(d, "REHASH,");
+       if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,");
        break;
     case SVt_PVGV: case SVt_PVLV:
        if (GvINTRO(sv))        sv_catpv(d, "INTRO,");
@@ -1193,16 +1195,28 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        if (flags & SVpad_TYPED)
                                sv_catpv(d, "TYPED,");
        break;
+    case SVt_PVAV:
+       break;
     }
     /* SVphv_SHAREKEYS is also 0x20000000 */
     if ((type != SVt_PVHV) && SvUTF8(sv))
         sv_catpv(d, "UTF8");
 
-    if (*(SvEND(d) - 1) == ',')
-       SvPVX(d)[--SvCUR(d)] = '\0';
+    if (*(SvEND(d) - 1) == ',') {
+        SvCUR_set(d, SvCUR(d) - 1);
+       SvPVX(d)[SvCUR(d)] = '\0';
+    }
     sv_catpv(d, ")");
     s = SvPVX(d);
 
+#ifdef DEBUG_LEAKING_SCALARS
+    Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n",
+       sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
+       sv->sv_debug_line,
+       sv->sv_debug_inpad ? "for" : "by",
+       sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
+       sv->sv_debug_cloned ? " (cloned)" : "");
+#endif
     Perl_dump_indent(aTHX_ level, file, "SV = ");
     switch (type) {
     case SVt_NULL:
@@ -1330,11 +1344,9 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        Perl_dump_indent(aTHX_ level, file, "  FILL = %"IVdf"\n", (IV)AvFILLp(sv));
        Perl_dump_indent(aTHX_ level, file, "  MAX = %"IVdf"\n", (IV)AvMAX(sv));
        Perl_dump_indent(aTHX_ level, file, "  ARYLEN = 0x%"UVxf"\n", PTR2UV(AvARYLEN(sv)));
-       flags = AvFLAGS(sv);
-       sv_setpv(d, "");
-       if (flags & AVf_REAL)   sv_catpv(d, ",REAL");
-       if (flags & AVf_REIFY)  sv_catpv(d, ",REIFY");
-       if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
+       sv_setpvn(d, "", 0);
+       if (AvREAL(sv)) sv_catpv(d, ",REAL");
+       if (AvREIFY(sv))        sv_catpv(d, ",REIFY");
        Perl_dump_indent(aTHX_ level, file, "  FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
        if (nest < maxnest && av_len((AV*)sv) >= 0) {
            int count;
@@ -1420,7 +1432,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
                    && count--) {
                SV *elt, *keysv;
-               char *keypv;
+                const char *keypv;
                STRLEN len;
                U32 hash = HeHASH(he);
 
@@ -1463,7 +1475,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            do_dump_pad(level+1, file, CvPADLIST(sv), 0);
        }
        {
-           CV *outside = CvOUTSIDE(sv);
+            const CV *outside = CvOUTSIDE(sv);
            Perl_dump_indent(aTHX_ level, file, "  OUTSIDE = 0x%"UVxf" (%s)\n",
                        PTR2UV(outside),
                        (!outside ? "null"
@@ -1578,12 +1590,8 @@ Perl_runops_debug(pTHX)
 }
 
 I32
-Perl_debop(pTHX_ OP *o)
+Perl_debop(pTHX_ const OP *o)
 {
-    AV *padlist, *comppad;
-    CV *cv;
-    SV *sv;
-
     if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
        return 0;
 
@@ -1595,7 +1603,7 @@ Perl_debop(pTHX_ OP *o)
     case OP_GVSV:
     case OP_GV:
        if (cGVOPo_gv) {
-           sv = NEWSV(0,0);
+           SV *sv = NEWSV(0,0);
            gv_fullname3(sv, cGVOPo_gv, Nullch);
            PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
            SvREFCNT_dec(sv);
@@ -1606,11 +1614,13 @@ Perl_debop(pTHX_ OP *o)
     case OP_PADSV:
     case OP_PADAV:
     case OP_PADHV:
+       {
        /* print the lexical's name */
-        cv = deb_curcv(cxstack_ix);
+       CV *cv = deb_curcv(cxstack_ix);
+       SV *sv;
         if (cv) {
-            padlist = CvPADLIST(cv);
-            comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
+            AV *padlist = CvPADLIST(cv);
+            AV *comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
             sv = *av_fetch(comppad, o->op_targ, FALSE);
         } else
             sv = Nullsv;
@@ -1618,6 +1628,7 @@ Perl_debop(pTHX_ OP *o)
            PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
         else
            PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
+       }
         break;
     default:
        break;
@@ -1629,7 +1640,7 @@ Perl_debop(pTHX_ OP *o)
 STATIC CV*
 S_deb_curcv(pTHX_ I32 ix)
 {
-    PERL_CONTEXT *cx = &cxstack[ix];
+    const PERL_CONTEXT *cx = &cxstack[ix];
     if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
         return cx->blk_sub.cv;
     else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
@@ -1652,7 +1663,7 @@ Perl_watch(pTHX_ char **addr)
 }
 
 STATIC void
-S_debprof(pTHX_ OP *o)
+S_debprof(pTHX_ const OP *o)
 {
     if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
        return;
@@ -1674,3 +1685,13 @@ Perl_debprofdump(pTHX)
                                        PL_op_name[i]);
     }
 }
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */