Don't follow CvSTART() if CvROOT() is NULL.
[p5sagit/Devel-Size.git] / Size.xs
diff --git a/Size.xs b/Size.xs
index 2d0fc53..3226910 100644 (file)
--- a/Size.xs
+++ b/Size.xs
@@ -41,7 +41,7 @@
     functionality on other platforms.  */
 #  include <excpt.h>
 #  define TRY_TO_CATCH_SEGV __try
-#  define CAUGHT_EXCEPTION __except(EXCEPTION EXCEPTION_EXECUTE_HANDLER)
+#  define CAUGHT_EXCEPTION __except(EXCEPTION_EXECUTE_HANDLER)
 #else
 #  define TRY_TO_CATCH_SEGV if(1)
 #  define CAUGHT_EXCEPTION else
@@ -745,8 +745,24 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
     if (SvOOK(thing)) {
        /* This direct access is arguably "naughty": */
        struct mro_meta *meta = HvAUX(thing)->xhv_mro_meta;
+#if PERL_VERSION > 13 || PERL_SUBVERSION > 8
+       /* As is this: */
+       I32 count = HvAUX(thing)->xhv_name_count;
+
+       if (count) {
+           HEK **names = HvAUX(thing)->xhv_name_u.xhvnameu_names;
+           if (count < 0)
+               count = -count;
+           while (--count)
+               hek_size(aTHX_ st, names[count], 1);
+       }
+       else
+#endif
+       {
+           hek_size(aTHX_ st, HvNAME_HEK(thing), 1);
+       }
+
        st->total_size += sizeof(struct xpvhv_aux);
-       hek_size(aTHX_ st, HvNAME_HEK(thing), 1);
        if (meta) {
            st->total_size += sizeof(struct mro_meta);
            sv_size(aTHX_ st, (SV *)meta->mro_nextmethod, TOTAL_SIZE_RECURSION);
@@ -786,7 +802,7 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing,
     sv_size(aTHX_ st, (SV *)CvOUTSIDE(thing), recurse);
     if (CvISXSUB(thing)) {
        sv_size(aTHX_ st, cv_const_sv((CV *)thing), recurse);
-    } else {
+    } else if (CvROOT(thing)) {
        op_size(aTHX_ CvSTART(thing), st);
        op_size(aTHX_ CvROOT(thing), st);
     }