[Pkg-gnupg-commit] [gnupg2] 22/292: tests: Implement interpreter shutdown using exceptions.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:22 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 9a0659a65c52378de1c4736a0eddf8518eb20948
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 19 18:42:36 2016 +0200

    tests: Implement interpreter shutdown using exceptions.
    
    * tests/gpgscm/ffi.c (ffi_init): Rename 'exit' to '_exit'.
    * tests/gpgscm/ffi.scm (*interpreter-exit*): New variable.
    (throw): New function.
    (exit): New function.
    --
    This allows a proper cleanup of resources.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 tests/gpgscm/ffi.c   |  2 +-
 tests/gpgscm/ffi.scm | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c
index 0816067..4559f10 100644
--- a/tests/gpgscm/ffi.c
+++ b/tests/gpgscm/ffi.c
@@ -1255,7 +1255,7 @@ ffi_init (scheme *sc, const char *argv0, const char *scriptname,
   ffi_define_function (sc, strerror);
   ffi_define_function (sc, getenv);
   ffi_define_function (sc, setenv);
-  ffi_define_function (sc, exit);
+  ffi_define_function_name (sc, "_exit", exit);
   ffi_define_function (sc, open);
   ffi_define_function (sc, fdopen);
   ffi_define_function (sc, close);
diff --git a/tests/gpgscm/ffi.scm b/tests/gpgscm/ffi.scm
index 7c2f93a..72a2a8f 100644
--- a/tests/gpgscm/ffi.scm
+++ b/tests/gpgscm/ffi.scm
@@ -42,3 +42,25 @@
 ;; Pseudo-definitions for foreign functions.  Evaluates to no code,
 ;; but serves as documentation.
 (macro (ffi-define form))
+
+;; Runtime support.
+
+;; Low-level mechanism to terminate the process.
+(ffi-define (_exit status))
+
+;; High-level mechanism to terminate the process is to throw an error
+;; of the form (*interpreter-exit* status).  This gives automatic
+;; resource management a chance to clean up.
+(define *interpreter-exit* (gensym))
+(define (throw . x)
+  (cond
+   ((more-handlers?)
+    (apply (pop-handler) x))
+   ((and (= 2 (length x)) (equal? *interpreter-exit* (car x)))
+    (_exit (cadr x)))
+   (else
+    (apply error x))))
+
+;; Terminate the process returning STATUS to the parent.
+(define (exit status)
+  (throw *interpreter-exit* status))

-- 
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