[Pkg-gnupg-commit] [gnupg2] 206/292: gpgscm: Implement 'atexit'.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 43f8006f5c75e3d15fe200e2fa41587a73bfb07b
Author: Justus Winter <justus at g10code.com>
Date:   Fri Nov 4 12:08:20 2016 +0100

    gpgscm: Implement 'atexit'.
    
    * tests/gpgscm/ffi.scm (throw): Run *run-atexit-handlers* when
    terminating the interpreter.
    (*atexit-handlers*): New variable.
    (*run-atexit-handlers*): New function.
    (atexit): Likewise.
    * tests/gpgscm/main.c (main): Run *run-atexit-handlers* at normal
    interpreter shutdown.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 tests/gpgscm/ffi.scm | 18 ++++++++++++++++++
 tests/gpgscm/main.c  |  1 +
 2 files changed, 19 insertions(+)

diff --git a/tests/gpgscm/ffi.scm b/tests/gpgscm/ffi.scm
index 72a2a8f..fb18538 100644
--- a/tests/gpgscm/ffi.scm
+++ b/tests/gpgscm/ffi.scm
@@ -57,6 +57,7 @@
    ((more-handlers?)
     (apply (pop-handler) x))
    ((and (= 2 (length x)) (equal? *interpreter-exit* (car x)))
+    (*run-atexit-handlers*)
     (_exit (cadr x)))
    (else
     (apply error x))))
@@ -64,3 +65,20 @@
 ;; Terminate the process returning STATUS to the parent.
 (define (exit status)
   (throw *interpreter-exit* status))
+
+;; A list of functions run at interpreter shutdown.
+(define *atexit-handlers* (list))
+
+;; Execute all these functions.
+(define (*run-atexit-handlers*)
+  (unless (null? *atexit-handlers*)
+	  (let ((proc (car *atexit-handlers*)))
+	    ;; Drop proc from the list so that it will not get
+	    ;; executed again even if it raises an exception.
+	    (set! *atexit-handlers* (cdr *atexit-handlers*))
+	    (proc)
+	    (*run-atexit-handlers*))))
+
+;; Register a function to be run at interpreter shutdown.
+(define (atexit proc)
+  (set! *atexit-handlers* (cons proc *atexit-handlers*)))
diff --git a/tests/gpgscm/main.c b/tests/gpgscm/main.c
index f7c6b0d..70ce855 100644
--- a/tests/gpgscm/main.c
+++ b/tests/gpgscm/main.c
@@ -291,6 +291,7 @@ main (int argc, char **argv)
         log_fatal ("%s: %s", script, gpg_strerror (err));
     }
 
+  scheme_load_string (sc, "(*run-atexit-handlers*)");
   scheme_deinit (sc);
   xfree (sc);
   return EXIT_SUCCESS;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list