[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

exit-hook never executed

From: Olivier Dion
Subject: exit-hook never executed
Date: Thu, 22 Sep 2022 12:25:45 -0400


`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")))
  (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

Something like this:
--8<---------------cut here---------------start------------->8---
(define-syntax-rule (with-jami body body* ...)
    (lambda () body body* ...)
--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.


Olivier Dion

reply via email to

[Prev in Thread] Current Thread [Next in Thread]