develooper Front page | perl.perl5.porters | Postings from February 2008

Re: [perl #51092] [PATCH] Segfault when calling ->next::method on non-existing package

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
February 24, 2008 23:40
Subject:
Re: [perl #51092] [PATCH] Segfault when calling ->next::method on non-existing package
Message ID:
b77c1dce0802242340u2f5e8f8anfab977b6443b9397@mail.gmail.com
On 22/02/2008, via RT ilmari @ vesla. ilmari. org
<perlbug-followup@perl.org> wrote:
>  When calling ->next::can on a package name that hasn't been defined at
>  all, perl segfaults when it tries to do HvNAME_get(NULL).
>
>  Here's a patch with a test. I'm not entirely sure whether it should die
>  or just return undef if !throw_nomethod (like UNIVERSAL->can does).

Thanks for this patch. Another alternative would be probably to
autovivify the package name, if possible.

Besides this, I don't like the wording of the error message, because
an "undefined package" isn't something that is well-defined in the
perl documentation.

>  --- a/mro.c
>  +++ b/mro.c
>  @@ -953,8 +953,11 @@ XS(XS_mro_nextcan)
>
>      if(sv_isobject(self))
>          selfstash = SvSTASH(SvRV(self));
>  -    else
>  +    else {
>          selfstash = gv_stashsv(self, 0);
>  +        if(!selfstash)
>  +            Perl_croak(aTHX_ "Can't call next::method/next::can/maybe::next::method on undefined package \"%s\".", SvPV_nolen_const(self));
>  +    }
>
>      assert(selfstash);
>
>  diff --git a/t/mro/next_edgecases.t b/t/mro/next_edgecases.t
>  index 91c2c85..9b872b6 100644
>  --- a/t/mro/next_edgecases.t
>  +++ b/t/mro/next_edgecases.t
>  @@ -3,7 +3,7 @@
>   use strict;
>   use warnings;
>
>  -require q(./test.pl); plan(tests => 11);
>  +require q(./test.pl); plan(tests => 12);
>
>   {
>
>  @@ -79,4 +79,16 @@ require q(./test.pl); plan(tests => 11);
>          eval { $baz->bar() };
>          ok($@, '... calling bar() with next::method failed') || diag $@;
>      }
>  +
>  +    # Test it failing (instead of segfaulting) with non-existing class
>  +    {
>  +        package Qux;
>  +        use mro;
>  +        sub foo { No::Such::Class->next::can }
>  +    }
>  +
>  +    eval { Qux->foo() };
>  +    like($@, qr{Can't call next::method/next::can/maybe::next::method on undefined package},
>  +         "->next::can on non-existing package name dies correctly")
>  +
>   }

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About