Re: Calling call_atexit() to clean up stuff initialized in BOOT

[email protected] (Nicholas Clark)
Newsgroups perl.xs
Message-ID <[email protected]>
On Thu, Mar 12, 2009 at 01:15:46PM +0100, Gregor Goldbach wrote:
> Nicholas Clark wrote:
> 
> >>> I understand initialization of an XS module may be modified using  
> >>> BOOT.
> >>> However, there seems to be no counterpart of BOOT. How do I e.g. free
> >>> memory I allocated in BOOT?
> [...]
> >>> Or is the current practice to write an XS function that e.g. frees the
> >>> memory allocate at BOOT and call it in an END handler in the module's
> >>> Perl code?
> [perl objects]
> 
> > Yes, but perl objects are going to be cleaned up (or at least, any with
> > DESTROY methods are going to get it called) before then, so that's somewhat
> > a red herring.
> > 
> > But possibly also a solution - anything allocated in BOOT that is stashed
> > inside an object will get that object's destroy method called soon after
> > END time, with a live interpreter.
> 
> I don't create any object in my XS module, it has a pure functional
> interface. Is there anything like a destroy function instead of a
> destroy method?

You can use the SAVE* macros to trigger events at scope exit, which is useful
for resources allocated inside a given XS function, that must be disposed of
when that function exits, normally or via an exception.

But that's not going to do what you want in your BOOT example - it would free
things at the exit from the BOOT routine.

Nicholas Clark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.