[augeas-devel] [PATCH] Proper typecheck for lens unions
David Lutterkort
dlutter at redhat.com
Sat May 10 01:13:32 UTC 2008
4 files changed, 22 insertions(+), 24 deletions(-)
lenses/sshd.aug | 3 ++-
lenses/xinetd.aug | 5 +++--
src/lens.c | 37 ++++++++++++++++---------------------
src/regexp.c | 1 +
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1210382003 25200
# Node ID 23c4e169bfadf0f7436af259b32e41f810387de5
# Parent 2049984893424b72354a4fe11c345bd90682b70e
Proper typecheck for lens unions
Check that lenses have disjoint ctypes and atypes in a union.
Fix up the existing lenses that violate that.
diff -r 204998489342 -r 23c4e169bfad lenses/sshd.aug
--- a/lenses/sshd.aug Fri May 09 17:39:27 2008 -0700
+++ b/lenses/sshd.aug Fri May 09 18:13:23 2008 -0700
@@ -6,7 +6,8 @@ module Sshd =
let sep = Util.del_ws_spc
- let key_re = /[A-Za-z0-9]+/
+ let key_re = /[A-Za-z0-9]+/
+ - /MACs|Match|AcceptEnv|AllowGroups|DenyGroups|AllowUsers|DenyUsers/
let comment = [ del /(#.*|[ \t]*)\n/ "\n" ]
diff -r 204998489342 -r 23c4e169bfad lenses/xinetd.aug
--- a/lenses/xinetd.aug Fri May 09 17:39:27 2008 -0700
+++ b/lenses/xinetd.aug Fri May 09 18:13:23 2008 -0700
@@ -80,8 +80,9 @@ module Xinetd =
let includes = [ key /include|includedir/
. Util.del_ws_spc . store /[^ \t\n]+/ . eol ]
- let service = [ del /service[ \t]+/ "service " . key /[^ \t\n\/]+/
- . body service_attr ]
+ let service =
+ let key_re = /[^ \t\n\/]+/ - /include|includedir|defaults/ in
+ [ del /service[ \t]+/ "service " . key key_re . body service_attr ]
let defaults = [ key "defaults" . del /[ \t]*/ "" . body default_attr ]
diff -r 204998489342 -r 23c4e169bfad src/lens.c
--- a/src/lens.c Fri May 09 17:39:27 2008 -0700
+++ b/src/lens.c Fri May 09 18:13:23 2008 -0700
@@ -260,49 +260,44 @@ struct value *lns_make_prim(enum lens_ta
/*
* Typechecking of lenses
*/
-static struct value *useless_union(struct info *info, const char *msg,
- struct regexp *r1, struct regexp *r2) {
+static struct value *disjoint_check(struct info *info, const char *msg,
+ struct regexp *r1, struct regexp *r2) {
fa_t fa1 = regexp_to_fa(r1);
fa_t fa2 = regexp_to_fa(r2);
+ fa_t fa = NULL;
struct value *exn = NULL;
if (fa1 == NULL || fa2 == NULL) {
fa_free(fa1);
fa_free(fa2);
return make_exn_value(ref(info),
- "internal error: compile in useless_union failed");
+ "internal error: compile in disjoint_check failed");
}
- if (fa_contains(fa2, fa1)) {
+ fa = fa_intersect(fa1, fa2);
+ if (! fa_is_basic(fa, FA_EMPTY)) {
+ char *xmpl = fa_example(fa);
exn = make_exn_value(ref(info),
- "%s: the first lens completely shadows the second lens", msg);
+ "overlapping lenses in %s", msg);
+
+ exn_printf_line(exn, "Example matched by both: '%s'", xmpl);
+ free(xmpl);
}
+
+ fa_free(fa);
fa_free(fa1);
fa_free(fa2);
+
return exn;
-
}
static struct value *typecheck_union(struct info *info,
struct lens *l1, struct lens *l2) {
struct value *exn = NULL;
- /* Boomerang checks unions by requiring that FA1 and FA2 are disjoint. This
- is a pain in Augeas, since it usually requires that the user specifiy
- a regexp in the second part of the union that is essentially FA2\FA1.
- We can't support that, since that would require that we either use
- libfa for regexp matching instead of the much much more optimized
- GNU regexp, or that we support set minus in the language; that in turn
- requires that we are able to turn an automaton back into a regexp.
-
- As a compromise/stopgap, we just check that L2 isn't entirely
- useless in the union L1 | L2, by making sure L2 is not completely
- shadowed by L1. It's weaker than disjointness, but usually what the
- user has in mind, anyway */
-
- exn = useless_union(info, "useless union", l1->ctype, l2->ctype);
+ exn = disjoint_check(info, "union.get", l1->ctype, l2->ctype);
if (exn == NULL) {
- exn = useless_union(info, "useless tree union", l1->atype, l2->atype);
+ exn = disjoint_check(info, "tree union.put", l1->atype, l2->atype);
}
if (exn != NULL) {
char *fi = format_info(l1->info);
diff -r 204998489342 -r 23c4e169bfad src/regexp.c
--- a/src/regexp.c Fri May 09 17:39:27 2008 -0700
+++ b/src/regexp.c Fri May 09 18:13:23 2008 -0700
@@ -123,6 +123,7 @@ regexp_minus(struct info *info, struct r
if (fa == NULL)
goto error;
+ fa_minimize(fa);
r = fa_as_regexp(fa, &s);
if (r < 0)
goto error;
More information about the augeas-devel
mailing list