From: Dan Winship Date: Fri, 15 Feb 2008 20:08:38 +0000 (-0500) Subject: misc fixes for edge cases X-Git-Tag: 0.1~236 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=b76c44568d662e64c5270491b4652ae30a25f5b8;p=razor.git misc fixes for edge cases 1) sets with only one package 2) packages with only one property 3) sets with only one property --- diff --git a/razor.c b/razor.c index 1f9e8d3..b5fbf88 100644 --- a/razor.c +++ b/razor.c @@ -248,7 +248,8 @@ razor_importer_finish_package(struct razor_importer *importer) { list_set_array(&importer->package->properties, &importer->set->property_pool, - &importer->properties); + &importer->properties, + 1); array_release(&importer->properties); } @@ -510,11 +511,12 @@ uniqueify_properties(struct razor_set *set) } free(map); - up++; + if (up != rp) + up++; set->properties.size = (void *) up - set->properties.data; rp_end = up; for (rp = set->properties.data, p = pkgs; rp < rp_end; rp++, p++) { - list_set_array(&rp->packages, &set->package_pool, p); + list_set_array(&rp->packages, &set->package_pool, p, 0); array_release(p); } @@ -565,7 +567,7 @@ serialize_files(struct razor_set *set, e->start = p->count > 0 ? s : 0; s += p->count; - list_set_array(&e->packages, &set->package_pool, &p->packages); + list_set_array(&e->packages, &set->package_pool, &p->packages, 0); array_release(&p->packages); p++; } @@ -687,7 +689,7 @@ build_package_file_lists(struct razor_set *set, uint32_t *rmap) packages = set->packages.data; for (i = 0; i < count; i++) { - list_set_array(&packages[i].files, &set->file_pool, &pkgs[i]); + list_set_array(&packages[i].files, &set->file_pool, &pkgs[i], 0); array_release(&pkgs[i]); } free(pkgs); @@ -1210,12 +1212,16 @@ merge_packages(struct razor_merger *merger, struct array *packages) send = source1->set->packages.data + source1->set->packages.size; spool = source1->set->string_pool.data; - while (s < send) { + while (s < send || u < uend) { p = upstream_packages + *u; - if (u < uend) + if (s < send && u < uend) cmp = strcmp(&spool[s->name], &upool[p->name]); - if (u >= uend || cmp < 0) { + else if (s < send) + cmp = -1; + else + cmp = 1; + if (cmp < 0) { add_package(merger, s, source1, 0); s++; } else if (cmp == 0) { @@ -1364,7 +1370,7 @@ rebuild_package_lists(struct razor_set *set) prop_end = set->properties.data + set->properties.size; a = pkgs; for (prop = set->properties.data; prop < prop_end; prop++, a++) { - list_set_array(&prop->packages, pool, a); + list_set_array(&prop->packages, pool, a, 0); array_release(a); } free(pkgs); diff --git a/types.c b/types.c index 87bdbcc..adb5b89 100644 --- a/types.c +++ b/types.c @@ -63,21 +63,26 @@ list_set_ptr(struct list_head *head, uint32_t ptr) } void -list_set_array(struct list_head *head, struct array *pool, struct array *items) +list_set_array(struct list_head *head, struct array *pool, + struct array *items, int force_indirect) { struct list *p; - if (items->size == 0) { - list_set_empty(head); - } else if (items->size == sizeof (uint32_t)) { - head->list_ptr = *(uint32_t *) items->data; - head->flags = RAZOR_IMMEDIATE; - } else { - p = array_add(pool, items->size); - memcpy(p, items->data, items->size); - p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST; - list_set_ptr(head, p - (struct list *) pool->data); + if (!force_indirect) { + if (items->size == 0) { + list_set_empty(head); + return; + } else if (items->size == sizeof (uint32_t)) { + head->list_ptr = *(uint32_t *) items->data; + head->flags = RAZOR_IMMEDIATE; + return; + } } + + p = array_add(pool, items->size); + memcpy(p, items->data, items->size); + p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST; + list_set_ptr(head, p - (struct list *) pool->data); } struct list * diff --git a/types.h b/types.h index 90e7790..d9de315 100644 --- a/types.h +++ b/types.h @@ -25,7 +25,7 @@ struct list { void list_set_empty(struct list_head *head); void list_set_ptr(struct list_head *head, uint32_t ptr); -void list_set_array(struct list_head *head, struct array *pool, struct array *items); +void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect); struct list *list_first(struct list_head *head, struct array *pool); struct list *list_next(struct list *list);