This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv.c:S_curse: move assertions to make them useful
authorFather Chrysostomos <sprout@cpan.org>
Fri, 23 Nov 2012 03:18:57 +0000 (19:18 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 23 Nov 2012 20:26:41 +0000 (12:26 -0800)
I added these when debugging something, and decided to keep them, as
they could be useful.  So I committed them as 14eebc59.

But now I realise that they are quite useless where they are, as a
program will crash before the failed assertions are reached.

sv.c

diff --git a/sv.c b/sv.c
index 9aa2224..6a6de93 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6333,9 +6333,9 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
        HV* stash;
        do {
          stash = SvSTASH(sv);
+         assert(SvTYPE(stash) == SVt_PVHV);
          if (HvNAME(stash)) {
            CV* destructor = NULL;
-           assert(SvTYPE(stash) == SVt_PVHV);
            if (!SvOBJECT(stash)) destructor = (CV *)SvSTASH(stash);
            if (!destructor) {
                GV * const gv =
@@ -6345,6 +6345,8 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
                    SvSTASH(stash) =
                        destructor ? (HV *)destructor : ((HV *)0)+1;
            }
+           assert(!destructor || destructor == ((CV *)0)+1
+               || SvTYPE(destructor) == SVt_PVCV);
            if (destructor && destructor != ((CV *)0)+1
                /* A constant subroutine can have no side effects, so
                   don't bother calling it.  */
@@ -6364,7 +6366,6 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
               )
            {
                SV* const tmpref = newRV(sv);
-               assert(SvTYPE(destructor) == SVt_PVCV);
                SvREADONLY_on(tmpref); /* DESTROY() could be naughty */
                ENTER;
                PUSHSTACKi(PERLSI_DESTROY);