unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* exit-hook never executed
@ 2022-09-22 16:25 Olivier Dion via General Guile related discussions
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2022-09-22 16:25 UTC (permalink / raw)
  To: guile-user

Hi,

`exit-hook' seems to only be executed when in a REPL.  Is there a way for
it to be executed at the end of a none interactive program?

My intend here is that I have a module that load a foreign extension and
initialize its runtime so that other modules of that extension can be
used.  I then add a hook for finalizing the extension, which is
important to save data.

Here's the snippet:
--8<---------------cut here---------------start------------->8---
(define-module (jami)
  #:use-module (system foreing-library))

(let* ((libjami (load-foreign-library "libguile-jami"))
       (init (foreign-library-function libjami "init"))
       (fini (foreign-library-function libjami "fini")))
  (init)
  (add-hook! exit-hook fini))
--8<---------------cut here---------------end--------------->8---

So I guess the trivial solution would be to ask the user to manually
call the `init' and `fini' procedure before using any procedures of the
extension.

Something like this:
--8<---------------cut here---------------start------------->8---
(define-syntax-rule (with-jami body body* ...)
  (dynamic-wind
    init
    (lambda () body body* ...)
    fini))
--8<---------------cut here---------------end--------------->8---

But it would be nice to a have a hook for finalization like `exit-hook'
that is hidden from the user.

Though?

-- 
Olivier Dion
oldiob.dev




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: exit-hook never executed
       [not found] <87tu4okh8q.fsf@laura>
@ 2022-09-30 15:48 ` Jean Abou Samra
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Abou Samra @ 2022-09-30 15:48 UTC (permalink / raw)
  To: Olivier Dion; +Cc: Lilypond-User Mailing List, guile-user

Oh dear, I sent my reply to the wrong list and now we’re discussing on lilypond-user instead of guile-user. Sorry LilyPond folks, this was not for this list. Forwarding to guile-user, please remove lilypond-user when replying.



> Le 30 sept. 2022 à 17:35, Olivier Dion <olivier.dion@polymtl.ca> a écrit :
> 
> On Sun, 25 Sep 2022, Jean Abou Samra <jean@abou-samra.fr> wrote:
> 
>> It looks like Guile only uses exit-hook for (ice-9 readline), so it
>> doesn't bother to call it when not running as REPL.
> 
> Right it looks like it.
> 
>> Maybe you could use a finalizer attached to a C global variable?
>> (I didn't test.)
> 
> I don't think finalizer would be good enough since there's no guaranteed
> that it's called?  I've opted for a syntax rule that expand into a
> dynamic wind.
> 




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-30 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87tu4okh8q.fsf@laura>
2022-09-30 15:48 ` exit-hook never executed Jean Abou Samra
2022-09-22 16:25 Olivier Dion via General Guile related discussions

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).