This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In newXS, clear glob slot before lowering refcount.
authorFather Chrysostomos <sprout@cpan.org>
Sun, 10 Nov 2013 14:26:39 +0000 (06:26 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 12 Nov 2013 00:13:20 +0000 (16:13 -0800)
commit7004ee4937ce593571fd91b83a7a6e35906e5a05
tree6910bf22bb41270dc2ebbf6fd34145f26cb9cbf0
parent4571f4a728fcf420c04fe45a1566d6d2f38d76ae
In newXS, clear glob slot before lowering refcount.

Otherwise, when newXS redefines a sub, the previous sub’s DESTROY can
see the same sub still in the typeglob, but without a reference count,
so *typeglob = sub {} frees the sub currently in $_[0].

$ perl5.18.1 -le '
    sub re::regmust{}
    bless \&re::regmust;
    DESTROY {
        print "before: $_[0]"; *re::regmust=sub{}; print "after: $_[0]"
    }
    require re;
'
before: main=CODE(0x7ff7eb02d6d8)
before: main=CODE(0x7ff7eb02d6d8)
after: main=CODE(0x7ff7eb02d6d8)
after: UNKNOWN(0x7ff7eb02d6d8)
op.c
t/op/sub.t