summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-11-22 14:39:23 +1100
committerJon Loeliger <jdl@freescale.com>2007-11-26 16:00:19 -0600
commitdc941774e228779562379a221ddc489d289e8513 (patch)
treee90a244560f8ca8e1ffd8393f3c3ab74e420d37a /data.c
parentb16a2bd89dbf109b9c8d1c9e047b9afa72af6d2f (diff)
downloaddtc-dc941774e228779562379a221ddc489d289e8513.tar.gz
dtc: Merge refs and labels into single "markers" list (v2)
Currently, every 'data' object, used to represent property values, has two lists of fixup structures - one for labels and one for references. Sometimes we want to look at them separately, but other times we need to consider both types of fixup. I'm planning to implement string references, where a full path rather than a phandle is substituted into a property value. Adding yet another list of fixups for that would start to get silly. So, this patch merges the "refs" and "labels" lists into a single list of "markers", each of which has a type field indicating if it represents a label or a phandle reference. String references or any other new type of in-data marker will then just need a new type value - merging data blocks and other common manipulations will just work. While I was at it I made some cleanups to the handling of fixups which simplify things further. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'data.c')
-rw-r--r--data.c103
1 files changed, 29 insertions, 74 deletions
diff --git a/data.c b/data.c
index b6cd00e..46cc081 100644
--- a/data.c
+++ b/data.c
@@ -20,28 +20,16 @@
#include "dtc.h"
-void fixup_free(struct fixup *f)
-{
- free(f->ref);
- free(f);
-}
-
void data_free(struct data d)
{
- struct fixup *f, *nf;
-
- f = d.refs;
- while (f) {
- nf = f->next;
- fixup_free(f);
- f = nf;
- }
-
- f = d.labels;
- while (f) {
- nf = f->next;
- fixup_free(f);
- f = nf;
+ struct marker *m, *nm;
+
+ m = d.markers;
+ while (m) {
+ nm = m->next;
+ free(m->ref);
+ free(m);
+ m = nm;
}
assert(!d.val || d.asize);
@@ -214,37 +202,29 @@ struct data data_append_data(struct data d, void *p, int len)
return d;
}
-void fixup_merge(struct fixup **fd, struct fixup **fd2, int d1_len)
+struct data data_append_markers(struct data d, struct marker *m)
{
- struct fixup **ff;
- struct fixup *f, *f2;
-
- /* Extract d2's fixups */
- f2 = *fd2;
- *fd2 = NULL;
-
- /* Tack them onto d's list of fixups */
- ff = fd;
- while (*ff)
- ff = &((*ff)->next);
- *ff = f2;
-
- /* And correct them for their new position */
- for (f = f2; f; f = f->next)
- f->offset += d1_len;
-
+ struct marker **mp = &d.markers;
+ /* Find the end of the markerlist */
+ while (*mp)
+ mp = &((*mp)->next);
+ *mp = m;
+ return d;
}
struct data data_merge(struct data d1, struct data d2)
{
struct data d;
+ struct marker *m2 = d2.markers;
- d = data_append_data(d1, d2.val, d2.len);
+ d = data_append_markers(data_append_data(d1, d2.val, d2.len), m2);
- fixup_merge(&d.refs, &d2.refs, d1.len);
- fixup_merge(&d.labels, &d2.labels, d1.len);
+ /* Adjust for the length of d1 */
+ for_each_marker(m2)
+ m2->offset += d1.len;
+ d2.markers = NULL; /* So data_free() doesn't clobber them */
data_free(d2);
return d;
@@ -294,42 +274,17 @@ struct data data_append_align(struct data d, int align)
return data_append_zeroes(d, newlen - d.len);
}
-struct data data_add_fixup(struct data d, char *ref)
-{
- struct fixup *f;
- struct data nd;
-
- f = xmalloc(sizeof(*f));
- f->offset = d.len;
- f->ref = ref;
- f->next = d.refs;
-
- nd = d;
- nd.refs = f;
-
- return nd;
-}
-
-struct data data_add_label(struct data d, char *label)
+struct data data_add_marker(struct data d, enum markertype type, char *ref)
{
- struct fixup *f, **p;
- struct data nd;
-
- f = xmalloc(sizeof(*f));
- f->offset = d.len;
- f->ref = label;
-
- nd = d;
- p = &nd.labels;
-
- /* adding to end keeps them sorted */
- while (*p)
- p = &((*p)->next);
+ struct marker *m;
- f->next = *p;
- *p = f;
+ m = xmalloc(sizeof(*m));
+ m->offset = d.len;
+ m->type = type;
+ m->ref = ref;
+ m->next = NULL;
- return nd;
+ return data_append_markers(d, m);
}
int data_is_one_string(struct data d)