Changeset 5f679702 in mainline for uspace/app/bithenge/tree.c
 Timestamp:
 20120607T04:03:16Z (9 years ago)
 Branches:
 lfn, master
 Children:
 5c925ce
 Parents:
 520acaf
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

uspace/app/bithenge/tree.c
r520acaf r5f679702 41 41 int bithenge_node_destroy(bithenge_node_t *node) 42 42 { 43 bithenge_string_node_t *string_node;44 43 switch (bithenge_node_type(node)) { 45 44 case BITHENGE_NODE_STRING: 46 string_node = bithenge_as_string_node(node); 47 if (string_node>needs_free) 48 free(string_node>value); 45 if (node>string_value.needs_free) 46 free(node>string_value.ptr); 49 47 break; 50 48 case BITHENGE_NODE_INTERNAL: … … 52 50 break; 53 51 case BITHENGE_NODE_BOOLEAN: 54 return EOK; 52 return EOK; // the boolean nodes are allocated statically below 55 53 case BITHENGE_NODE_INTEGER: /* passthrough */ 56 54 case BITHENGE_NODE_NONE: … … 63 61 typedef struct 64 62 { 65 bithenge_ internal_node_t base;63 bithenge_node_t base; 66 64 bithenge_node_t **nodes; 67 65 bithenge_int_t len; … … 69 67 } simple_internal_node_t; 70 68 71 static simple_internal_node_t * internal_as_simple(bithenge_internal_node_t *node)69 static simple_internal_node_t *node_as_simple(bithenge_node_t *node) 72 70 { 73 71 return (simple_internal_node_t *)node; 74 72 } 75 73 76 static int simple_internal_node_for_each(bithenge_ internal_node_t *base, bithenge_for_each_func_t func, void *data)74 static int simple_internal_node_for_each(bithenge_node_t *base, bithenge_for_each_func_t func, void *data) 77 75 { 78 76 int rc; 79 simple_internal_node_t *node = internal_as_simple(base);77 simple_internal_node_t *node = node_as_simple(base); 80 78 for (bithenge_int_t i = 0; i < node>len; i++) { 81 79 rc = func(node>nodes[2*i+0], node>nodes[2*i+1], data); … … 92 90 static bithenge_node_t *simple_internal_as_node(simple_internal_node_t *node) 93 91 { 94 return bithenge_internal_as_node(&node>base);92 return &node>base; 95 93 } 96 94 … … 101 99 if (!node) 102 100 return ENOMEM; 103 node>base. base.type = BITHENGE_NODE_INTERNAL;104 node>base. ops = &simple_internal_node_ops;101 node>base.type = BITHENGE_NODE_INTERNAL; 102 node>base.internal_ops = &simple_internal_node_ops; 105 103 node>nodes = nodes; 106 104 node>len = len; … … 110 108 } 111 109 112 static bithenge_ boolean_node_t false_node = { {BITHENGE_NODE_BOOLEAN},false };113 static bithenge_ boolean_node_t true_node = { {BITHENGE_NODE_BOOLEAN},true };110 static bithenge_node_t false_node = { BITHENGE_NODE_BOOLEAN, .boolean_value = false }; 111 static bithenge_node_t true_node = { BITHENGE_NODE_BOOLEAN, .boolean_value = true }; 114 112 115 113 int bithenge_new_boolean_node(bithenge_node_t **out, bool value) 116 114 { 117 115 assert(out); 118 *out = bithenge_boolean_as_node(value ? &true_node : &false_node);116 *out = value ? &true_node : &false_node; 119 117 return EOK; 120 118 } … … 123 121 { 124 122 assert(out); 125 bithenge_ integer_node_t *node = malloc(sizeof(*node));123 bithenge_node_t *node = malloc(sizeof(*node)); 126 124 if (!node) 127 125 return ENOMEM; 128 node> base.type = BITHENGE_NODE_INTEGER;129 node> value = value;130 *out = bithenge_integer_as_node(node);126 node>type = BITHENGE_NODE_INTEGER; 127 node>integer_value = value; 128 *out = node; 131 129 return EOK; 132 130 } … … 135 133 { 136 134 assert(out); 137 bithenge_ string_node_t *node = malloc(sizeof(*node));135 bithenge_node_t *node = malloc(sizeof(*node)); 138 136 if (!node) 139 137 return ENOMEM; 140 node> base.type = BITHENGE_NODE_STRING;141 node> value= value;142 node> needs_free = needs_free;143 *out = bithenge_string_as_node(node);138 node>type = BITHENGE_NODE_STRING; 139 node>string_value.ptr = value; 140 node>string_value.needs_free = needs_free; 141 *out = node; 144 142 return EOK; 145 143 }
Note: See TracChangeset
for help on using the changeset viewer.