[augeas-devel] augeas: master - * src/pathx.c (clone_value): new function

David Lutterkort lutter at fedoraproject.org
Tue Mar 24 23:07:38 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=3a54c70789dc2d881aed7946be5ed028b85cc0fc
Commit:        3a54c70789dc2d881aed7946be5ed028b85cc0fc
Parent:        b0b844226fe62a0aa54f2084c3e0741246ec43f3
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Fri Mar 20 17:07:00 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Sun Mar 22 22:12:58 2009 -0700

* src/pathx.c (clone_value): new function

---
 src/pathx.c |   92 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/src/pathx.c b/src/pathx.c
index ce08a7a..69ab28d 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -394,6 +394,49 @@ void free_pathx(struct pathx *pathx) {
 }
 
 /*
+ * Nodeset helpers
+ */
+static struct nodeset *make_nodeset(struct state *state) {
+    struct nodeset *result;
+    if (ALLOC(result) < 0)
+        STATE_ENOMEM;
+    return result;
+}
+
+static void ns_add(struct nodeset *ns, struct tree *node,
+                   struct state *state) {
+    if (ns->used >= ns->size) {
+        size_t size = 2 * ns->size;
+        if (size < 10) size = 10;
+        if (REALLOC_N(ns->nodes, size) < 0)
+            STATE_ENOMEM;
+        ns->size = size;
+    }
+    ns->nodes[ns->used] = node;
+    ns->used += 1;
+}
+
+static struct nodeset *
+clone_nodeset(struct nodeset *ns, struct state *state)
+{
+    struct nodeset *clone;
+    if (ALLOC(clone) < 0) {
+        STATE_ENOMEM;
+        return NULL;
+    }
+    if (ALLOC_N(clone->nodes, ns->used) < 0) {
+        free(clone);
+        STATE_ENOMEM;
+        return NULL;
+    }
+    clone->used = ns->used;
+    clone->size = ns->size;
+    for (int i=0; i < ns->used; i++)
+        clone->nodes[i] = ns->nodes[i];
+    return clone;
+}
+
+/*
  * Handling values
  */
 static value_ind_t make_value(enum type tag, struct state *state) {
@@ -415,6 +458,35 @@ static value_ind_t make_value(enum type tag, struct state *state) {
     return state->value_pool_used++;
 }
 
+ATTRIBUTE_UNUSED
+static value_ind_t clone_value(struct value *v, struct state *state) {
+    value_ind_t vind = make_value(v->tag, state);
+    CHECK_ERROR_RET0;
+    struct value *clone = state->value_pool + vind;
+
+    switch (v->tag) {
+    case T_NODESET:
+        clone->nodeset = clone_nodeset(v->nodeset, state);
+        break;
+    case T_NUMBER:
+        clone->number = v->number;
+        break;
+    case T_STRING:
+        clone->string = strdup(v->string);
+        if (clone->string == NULL) {
+            FREE(clone);
+            STATE_ENOMEM;
+        }
+        break;
+    case T_BOOLEAN:
+        clone->boolval = v->boolval;
+        break;
+    default:
+        assert(0);
+    }
+    return vind;
+}
+
 static value_ind_t pop_value_ind(struct state *state) {
     if (state->values_used > 0) {
         state->values_used -= 1;
@@ -691,26 +763,6 @@ static int eval_pred(struct expr *expr, struct state *state) {
     }
 }
 
-static struct nodeset *make_nodeset(struct state *state) {
-    struct nodeset *result;
-    if (ALLOC(result) < 0)
-        STATE_ENOMEM;
-    return result;
-}
-
-static void ns_add(struct nodeset *ns, struct tree *node,
-                   struct state *state) {
-    if (ns->used >= ns->size) {
-        size_t size = 2 * ns->size;
-        if (size < 10) size = 10;
-        if (REALLOC_N(ns->nodes, size) < 0)
-            STATE_ENOMEM;
-        ns->size = size;
-    }
-    ns->nodes[ns->used] = node;
-    ns->used += 1;
-}
-
 /* Return an array of nodesets, one for each step in the locpath.
  *
  * On return, (*NS)[0] will contain state->ctx, and (*NS)[*MAXNS] will




More information about the augeas-devel mailing list