[plt-scheme] reliable exit handlers for foreign functions

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Tue Dec 9 19:08:52 EST 2008

On Tue, 9 Dec 2008, Eli Barzilay wrote:

> On Dec  9, Matthew Flatt wrote:
>> At Tue, 9 Dec 2008 18:44:03 -0500 (EST), Dimitris Vyzovitis wrote:
>>> Is there any reliable way to register atexit callbacks with ffi?
>>> I am trying to register a native thunk with atexit, but I am not getting
>>> anywhere:
>>>> (get-ffi-obj "atexit" #f _pointer)
>>> ffi-obj: couldn't get "atexit" from #f (/usr/local/plt/bin/mzscheme:
>>> undefined symbol: atexit)
>> ...
>> I'm not sure why atexit() is unavailable,
> I'm not sure either, but these "invalid ELF header" files are usually
> some text file that describes how to actually look for the real .so
> file.  In any case, I couldn't find it either on my system -- the only
> place that had it is /usr/lib64/dietlibc/lib-x86_64/libc.so.  But I
> did get on_exit() in the usual way, except that the man page says that
> atexit() should be used instead...

Yes, on_exit is deprecated bsdism and it won't exist on non-unix platforms 
(hey, I want some portability here :)
Let alone that it has the wrong prototype!

I suspect that atexit is coming from gcc's crt, but I still expected 
it to be visible in the mzscheme system table.

Also, for using scheme_at_exit_closer: that sounds quite inconvenient. 
What are the exact callback semantics? Do I have to manually call the 
closers I get in the callbacks? And does the closer get overwritten next 
time a closer is added?

-- vyzo

Posted on the users mailing list.