summaryrefslogtreecommitdiffstats
path: root/tests/gpgscm/ffi.scm
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2016-09-19 18:42:36 +0200
committerJustus Winter <justus@g10code.com>2016-09-19 18:49:17 +0200
commit9a0659a65c52378de1c4736a0eddf8518eb20948 (patch)
treeca0187e499e303017f69f9ba5631b50439544509 /tests/gpgscm/ffi.scm
parenttests: Correctly handle exceptions in resource handling macros. (diff)
downloadgnupg2-9a0659a65c52378de1c4736a0eddf8518eb20948.tar.xz
gnupg2-9a0659a65c52378de1c4736a0eddf8518eb20948.zip
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@g10code.com>
Diffstat (limited to '')
-rw-r--r--tests/gpgscm/ffi.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/gpgscm/ffi.scm b/tests/gpgscm/ffi.scm
index 7c2f93aba..72a2a8f1e 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))