[augeas-devel] [PATCH 2 of 2] Fix a bug with transferring skeletons

David Lutterkort lutter at redhat.com
Fri Aug 29 04:39:20 UTC 2008


4 files changed, 18 insertions(+), 6 deletions(-)
src/get.c                    |    1 -
src/lens.h                   |    1 -
src/put.c                    |    5 +----
tests/modules/pass_array.aug |   17 +++++++++++++++++


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1219984691 25200
# Node ID 09dcb70fa72447aab1aabd9ca28d2d32f6b2c547
# Parent  e0d63caa8d36b1abec2a47c4e5e59d54a8d6d6c8
Fix a bug with transferring skeletons

It is possible for a skeleton to move from one subtree lens to another, if
both use the same key; since the lenses might have different skeleton
types, we need to detect this and discard the skeleton if its type does not
match the lens that is used during put.

diff -r e0d63caa8d36 -r 09dcb70fa724 src/get.c
--- a/src/get.c	Thu Aug 28 21:38:08 2008 -0700
+++ b/src/get.c	Thu Aug 28 21:38:11 2008 -0700
@@ -95,7 +95,6 @@
     enum lens_tag tag = lens->tag;
     CALLOC(skel, 1);
     skel->tag = tag;
-    skel->lens = lens;
     return skel;
 }
 
diff -r e0d63caa8d36 -r 09dcb70fa724 src/lens.h
--- a/src/lens.h	Thu Aug 28 21:38:08 2008 -0700
+++ b/src/lens.h	Thu Aug 28 21:38:11 2008 -0700
@@ -86,7 +86,6 @@
 /* Auxiliary data structures used during get/put/create */
 struct skel {
     struct skel *next;
-    struct lens *lens;
     enum lens_tag tag;
     union {
         char        *text;    /* L_DEL */
diff -r e0d63caa8d36 -r 09dcb70fa724 src/put.c
--- a/src/put.c	Thu Aug 28 21:38:08 2008 -0700
+++ b/src/put.c	Thu Aug 28 21:38:11 2008 -0700
@@ -400,7 +400,7 @@
     set_split(state, split);
 
     dict_lookup(tree->label, state->dict, &state->skel, &state->dict);
-    if (state->skel == NULL) {
+    if (state->skel == NULL || ! skel_instance_of(lens->child, state->skel)) {
         create_lens(lens->child, state);
     } else {
         put_lens(lens->child, state);
@@ -440,7 +440,6 @@
 
 static void put_concat(struct lens *lens, struct state *state) {
     assert(lens->tag == L_CONCAT);
-    assert(state->skel->lens == lens);
     struct split *oldsplit = state->split;
     struct skel *oldskel = state->skel;
 
@@ -466,7 +465,6 @@
 
 static void put_quant_star(struct lens *lens, struct state *state) {
     assert(lens->tag == L_STAR);
-    assert(state->skel->lens == lens);
     struct split *oldsplit = state->split;
     struct skel *oldskel = state->skel;
 
@@ -493,7 +491,6 @@
 
 static void put_quant_maybe(struct lens *lens, struct state *state) {
     assert(lens->tag == L_MAYBE);
-    assert(state->skel->lens == lens);
 
     if (applies(lens->child, state->split)) {
         if (skel_instance_of(lens->child, state->skel))
diff -r e0d63caa8d36 -r 09dcb70fa724 tests/modules/pass_array.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/pass_array.aug	Thu Aug 28 21:38:11 2008 -0700
@@ -0,0 +1,17 @@
+(* Check that we properly discard skeletons when we shift subtrees   *)
+(* across lenses. The test shifts a subtree parsed with SND to one   *)
+(* that is put with FST. Since the two have different skeleton types *)
+(* we need to ignore the skeleton that comes with it.                *)
+module Pass_array =
+
+  let array = 
+    let array_value = store /[a-z0-9]+/ in
+    let fst = seq "values" . array_value . del /[ \t]+/ "\t" in
+    let snd = seq "values" . array_value in
+    del "(" "(" . counter "values" .
+    [ fst ] * . [ snd ] . del ")" ")"
+
+  let lns = [ key /[a-z]+/ . del "=" "=" . array ]
+
+  test lns put "var=(v1 v2)" after
+    set "var/3" "v3" = "var=(v1 v2\tv3)"




More information about the augeas-devel mailing list