wrong test for magicalness
[p5sagit/Devel-Size.git] / Size.xs
diff --git a/Size.xs b/Size.xs
index 3226910..109dd15 100644 (file)
--- a/Size.xs
+++ b/Size.xs
@@ -518,9 +518,16 @@ op_size(pTHX_ const OP * const baseop, struct state *st)
 #endif
 #ifdef USE_ITHREADS
           check_new_and_strlen(st, basecop->cop_file);
+#if PERL_VERSION < 17 || (PERL_VERSION == 17 && PERL_SUBVERSION == 0)
+         /* This pointer is owned by the COP, and freed with it.  */
           check_new_and_strlen(st, basecop->cop_stashpv);
 #else
-         sv_size(aTHX_ st, (SV *)basecop->cop_stash, SOME_RECURSION);
+         /* A per-interpreter pointer for this stash is allocated in
+            PL_stashpad. */
+         if (check_new(st, PL_stashpad + basecop->cop_stashoff))
+             st->total_size += sizeof(PL_stashpad[basecop->cop_stashoff]);
+#endif
+#else
          sv_size(aTHX_ st, (SV *)basecop->cop_filegv, SOME_RECURSION);
 #endif
 
@@ -660,6 +667,30 @@ const U8 body_sizes[SVt_LAST] = {
 #endif
 };
 
+#ifdef PadlistNAMES
+static void
+padlist_size(pTHX_ struct state *const st, const PADLIST * const padl,
+       const int recurse) {
+    SSize_t i;
+    if (!check_new(st, padl))
+       return;
+    /* This relies on PADNAMELIST and PAD being typedefed to AV.  If that
+       ever changes, this code will need an update. */
+    st->total_size += sizeof(PADLIST);
+    sv_size(aTHX_ st, (SV*)PadlistNAMES(padl), recurse);
+    i = PadlistMAX(padl) + 1;
+    st->total_size += sizeof(PAD*) * i;
+    while (--i)
+       sv_size(aTHX_ st, (SV*)PadlistARRAY(padl)[i], recurse);
+}
+#else 
+static void
+padlist_size(pTHX_ struct state *const st, const AV * const padl,
+       const int recurse) {
+    sv_size(aTHX_ st, (SV*)padl, recurse);
+}
+#endif
+
 static void
 sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
        const int recurse) {
@@ -676,7 +707,7 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
   }
   st->total_size += sizeof(SV) + body_sizes[type];
 
-  if (type >= SVt_PVMG) {
+  if (SvMAGICAL(thing)) {
       magic_size(aTHX_ thing, st);
   }
 
@@ -785,7 +816,7 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
 
 
   case SVt_PVFM: TAG;
-    sv_size(aTHX_ st, (SV *)CvPADLIST(thing), SOME_RECURSION);
+    padlist_size(aTHX_ st, CvPADLIST(thing), SOME_RECURSION);
     sv_size(aTHX_ st, (SV *)CvOUTSIDE(thing), recurse);
 
     if (st->go_yell && !st->fm_whine) {
@@ -798,7 +829,7 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
     sv_size(aTHX_ st, (SV *)CvSTASH(thing), SOME_RECURSION);
     sv_size(aTHX_ st, (SV *)SvSTASH(thing), SOME_RECURSION);
     sv_size(aTHX_ st, (SV *)CvGV(thing), SOME_RECURSION);
-    sv_size(aTHX_ st, (SV *)CvPADLIST(thing), SOME_RECURSION);
+    padlist_size(aTHX_ st, CvPADLIST(thing), SOME_RECURSION);
     sv_size(aTHX_ st, (SV *)CvOUTSIDE(thing), recurse);
     if (CvISXSUB(thing)) {
        sv_size(aTHX_ st, cv_const_sv((CV *)thing), recurse);