From 44e4434b4cb8b5dde5b72f0e6726b5323ed3c853 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 03:07:48 -0300 Subject: [PATCH] qpkg: towards "struct id" without jrb reference - change ID creation - id.h, id.c (make_id): return a "struct jrb *", so that we have access to key and value - gobble.c (ID, gobble_buf): adapt to above change - gobble.c (compact_pkg, gobble_buf): keep the RB node reference instead of awkwardly regenerating it via pkg->id->jrb --- qpkg/gobble.c | 22 ++++++++++++---------- qpkg/id.c | 9 ++++----- qpkg/id.h | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qpkg/gobble.c b/qpkg/gobble.c index 68297a7..dfcbb64 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -92,7 +92,7 @@ #define DONE goto done -static void compact_pkg(struct pkg *new) +static void compact_pkg(struct pkg *new, struct jrb *jrb) { struct pkg *old; @@ -102,7 +102,7 @@ static void compact_pkg(struct pkg *new) return; compact: - new->id->jrb->val = new->more; + jrb->val = new->more; old->flags |= new->flags; /* @@@ we may leak a little */ free(new); @@ -114,6 +114,7 @@ static void gobble_buf(const char *name, const char *buf, size_t len) const char *end = buf+len; int lineno = 1; struct pkg *pkg = NULL; /* current package */ + struct jrb *jrb = NULL; /* RB tree node of current package */ struct ref **anchor = NULL; int i, failed_at = 0; @@ -280,13 +281,14 @@ depends: package: if (pkg) - compact_pkg(pkg); + compact_pkg(pkg, jrb); WHITESPACE; pkg = alloc_type(struct pkg); - pkg->id = ID(packages); - pkg->more = pkg->id->jrb->val; - pkg->id->jrb->val = pkg; + jrb = ID(packages); + pkg->id = jrb->key; + pkg->more = jrb->val; + jrb->val = pkg; pkg->version = NULL; pkg->conflicts = pkg->depends = NULL; pkg->filename = NULL; @@ -298,7 +300,7 @@ version: WHITESPACE; if (pkg->version) FAIL; - pkg->version = ID(versions); + pkg->version = ID(versions)->key; goto eol; provides: @@ -350,7 +352,7 @@ list_with_version: WHITESPACE; ref = alloc_type(struct ref); - ref->pkg = ID(packages); + ref->pkg = ID(packages)->key; /* * Work around the Wireshark Anomaly @@ -380,7 +382,7 @@ list_with_version: FAIL; } WHITESPACE; - ref->version = ID(versions); + ref->version = ID(versions)->key; EXPECT(")"); } ref->next = *anchor; @@ -396,7 +398,7 @@ list_with_version: done: if (pkg) - compact_pkg(pkg); + compact_pkg(pkg, jrb); return; fail: diff --git a/qpkg/id.c b/qpkg/id.c index 6c935c1..0cea00e 100644 --- a/qpkg/id.c +++ b/qpkg/id.c @@ -50,7 +50,7 @@ struct tree *make_tree(int (*comp)(const void *a, const void *b)) } -struct id *make_id(struct tree *tree, const char *s, size_t len) +struct jrb *make_id(struct tree *tree, const char *s, size_t len) { struct id *id; @@ -60,10 +60,9 @@ struct id *make_id(struct tree *tree, const char *s, size_t len) id->s = s; id->len = len; id->jrb = jrb_find_or_insert(tree->root, id, NULL, tree->comp); - if (id->jrb->key != id) - return id->jrb->key; - free_id = NULL; - return id; + if (id->jrb->key == id) + free_id = NULL; + return id->jrb; } diff --git a/qpkg/id.h b/qpkg/id.h index a9943b2..0614266 100644 --- a/qpkg/id.h +++ b/qpkg/id.h @@ -62,7 +62,7 @@ struct id { int comp_id(const void *a, const void *b); struct tree *make_tree(int (*comp)(const void *a, const void *b)); -struct id *make_id(struct tree *tree, const char *s, size_t len); +struct jrb *make_id(struct tree *tree, const char *s, size_t len); const struct jrb *find_id(const struct tree *tree, const char *s, size_t len); #endif /* !ID_H */