[augeas-devel] augeas: master - * src/syntax.h (exn_error): produce an exception to indicate an error

David Lutterkort lutter at fedoraproject.org
Fri Nov 13 19:26:46 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=d53671ceef962c3351fcf01bf50658acb58ea72c
Commit:        d53671ceef962c3351fcf01bf50658acb58ea72c
Parent:        0ee252f97c269ecd1c1e65cc6748dc83feaeaade
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Oct 28 16:13:29 2009 +0100
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Fri Nov 13 10:43:17 2009 -0800

* src/syntax.h (exn_error): produce an exception to indicate an error

exn_error returns a special exception that indicates that an error has
happened (e.g., out-of-memory) that has already been reported in the
central augeas->error instance.
---
 src/syntax.c |   12 ++++++++++++
 src/syntax.h |   11 ++++++++++-
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/src/syntax.c b/src/syntax.c
index edaa873..77a4dd1 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -436,6 +436,18 @@ void exn_printf_line(struct value *exn, const char *format, ...) {
         exn_add_lines(exn, 1, line);
 }
 
+struct value *exn_error(void) {
+    static const struct exn exn = {
+        .info = NULL, .seen = 1, .error = 1,
+        .message = (char *) "Error during evaluation",
+        .nlines = 0, .lines = NULL };
+    static const struct value value = {
+        .ref = REF_MAX, /* Protect against being freed */
+        .info = NULL, .tag = V_EXN,
+        { .exn = (struct exn *) &exn } };
+    return (struct value *) &value;
+}
+
 /*
  * Modules
  */
diff --git a/src/syntax.h b/src/syntax.h
index cf5024a..067eba8 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -122,10 +122,16 @@ struct native {
     struct value *(*impl)(void);
 };
 
-/* An exception in the interpreter */
+/* An exception in the interpreter. Some exceptions are reported directly
+ * into the central struct error; an exception for those is only generated
+ * to follow the control flow for exceptions. Such exceptions have both
+ * seen and error set to 1. They are the only exceptions with error == 1.
+ * When error == 1, none of the other fields in the exn will be usable.
+ */
 struct exn {
     struct info *info;
     unsigned int seen : 1;      /* Whether the user has seen this EXN */
+    unsigned int error : 1;
     char        *message;
     size_t       nlines;
     char       **lines;
@@ -168,6 +174,9 @@ struct value {
     };
 };
 
+/* Return an exception value with error == 1 (and seen == 1) */
+struct value *exn_error(void);
+
 /* All types except for T_ARROW (functions) are simple. Subtype relations
  * for the simple types:
  *   T_STRING <: T_REGEXP




More information about the augeas-devel mailing list