develooper Front page | perl.perl5.porters | Postings from December 2004

Re: [perl #32714] Objects destroyed in the wrong order during glo bal destruction

Thread Previous | Thread Next
From:
Paul Johnson
Date:
December 2, 2004 16:01
Subject:
Re: [perl #32714] Objects destroyed in the wrong order during glo bal destruction
Message ID:
20041203000120.GU10383@pjcj.net
On Thu, Dec 02, 2004 at 10:03:59PM +0100, Elizabeth Mattijsen wrote:

> I think it would be possible to create a module (pragma) that would 
> ensure an orderly (as in lifo) destruction of objects.  The only 
> thing I miss is a way to make sure a specific END code block is 
> executed as the very last END block.  Is there a way to do this? 
> Possibly in XS?

Devel::Cover does just this.  It's something of an unholy mix of XS and
perl subs for various arcane reasons, at least some of which are
unlikely to be valid any more.

The way it works is that in a CHECK block an XS sub is called which
installs a perl sub as as the first END sub.  This is done by unshifting
onto PL_endav.  When that sub is called as the first END sub it calls
another XS sub which installs another perl sub as the last END sub by
pushing it onto PL_endav.  That newly installed sub should be the last
END sub called.  Unless one of the subsequent END subs installs another
END sub.

It's probably easier to look at the code.  It's on CPAN.

But if you do this, our two modules will fight.  Which means I'll have
to make my final END sub not really the final one any more, but have it
install another END sub which really will be the last ;-)

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

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