misc fixes for edge cases
authorDan Winship <danw@gnome.org>
Fri Feb 15 15:08:38 2008 -0500 (2008-02-15)
changeset 124feef7736a439
parent 123 4e699bd39b40
child 125 e56c83bda295
misc fixes for edge cases

1) sets with only one package
2) packages with only one property
3) sets with only one property
razor.c
types.c
types.h
     1.1 --- a/razor.c	Fri Feb 15 09:31:20 2008 -0500
     1.2 +++ b/razor.c	Fri Feb 15 15:08:38 2008 -0500
     1.3 @@ -248,7 +248,8 @@
     1.4  {
     1.5  	list_set_array(&importer->package->properties,
     1.6  		       &importer->set->property_pool,
     1.7 -		       &importer->properties);
     1.8 +		       &importer->properties,
     1.9 +		       1);
    1.10  
    1.11  	array_release(&importer->properties);
    1.12  }
    1.13 @@ -510,11 +511,12 @@
    1.14  	}
    1.15  	free(map);
    1.16  
    1.17 -	up++;
    1.18 +	if (up != rp)
    1.19 +		up++;
    1.20  	set->properties.size = (void *) up - set->properties.data;
    1.21  	rp_end = up;
    1.22  	for (rp = set->properties.data, p = pkgs; rp < rp_end; rp++, p++) {
    1.23 -		list_set_array(&rp->packages, &set->package_pool, p);
    1.24 +		list_set_array(&rp->packages, &set->package_pool, p, 0);
    1.25  		array_release(p);
    1.26  	}
    1.27  
    1.28 @@ -565,7 +567,7 @@
    1.29  		e->start = p->count > 0 ? s : 0;
    1.30  		s += p->count;
    1.31  
    1.32 -		list_set_array(&e->packages, &set->package_pool, &p->packages);
    1.33 +		list_set_array(&e->packages, &set->package_pool, &p->packages, 0);
    1.34  		array_release(&p->packages);
    1.35  		p++;
    1.36  	}		
    1.37 @@ -687,7 +689,7 @@
    1.38  
    1.39  	packages = set->packages.data;
    1.40  	for (i = 0; i < count; i++) {
    1.41 -		list_set_array(&packages[i].files, &set->file_pool, &pkgs[i]);
    1.42 +		list_set_array(&packages[i].files, &set->file_pool, &pkgs[i], 0);
    1.43  		array_release(&pkgs[i]);
    1.44  	}
    1.45  	free(pkgs);
    1.46 @@ -1210,12 +1212,16 @@
    1.47  	send = source1->set->packages.data + source1->set->packages.size;
    1.48  	spool = source1->set->string_pool.data;
    1.49  
    1.50 -	while (s < send) {
    1.51 +	while (s < send || u < uend) {
    1.52  		p = upstream_packages + *u;
    1.53  
    1.54 -		if (u < uend)
    1.55 +		if (s < send && u < uend)
    1.56  			cmp = strcmp(&spool[s->name], &upool[p->name]);
    1.57 -		if (u >= uend || cmp < 0) {
    1.58 +		else if (s < send)
    1.59 +			cmp = -1;
    1.60 +		else
    1.61 +			cmp = 1;
    1.62 +		if (cmp < 0) {
    1.63  			add_package(merger, s, source1, 0);
    1.64  			s++;
    1.65  		} else if (cmp == 0) {
    1.66 @@ -1364,7 +1370,7 @@
    1.67  	prop_end = set->properties.data + set->properties.size;
    1.68  	a = pkgs;
    1.69  	for (prop = set->properties.data; prop < prop_end; prop++, a++) {
    1.70 -		list_set_array(&prop->packages, pool, a);
    1.71 +		list_set_array(&prop->packages, pool, a, 0);
    1.72  		array_release(a);
    1.73  	}
    1.74  	free(pkgs);
     2.1 --- a/types.c	Fri Feb 15 09:31:20 2008 -0500
     2.2 +++ b/types.c	Fri Feb 15 15:08:38 2008 -0500
     2.3 @@ -63,21 +63,26 @@
     2.4  }
     2.5  
     2.6  void
     2.7 -list_set_array(struct list_head *head, struct array *pool, struct array *items)
     2.8 +list_set_array(struct list_head *head, struct array *pool,
     2.9 +	       struct array *items, int force_indirect)
    2.10  {
    2.11  	struct list *p;
    2.12  
    2.13 -	if (items->size == 0) {
    2.14 -		list_set_empty(head);
    2.15 -	} else if (items->size == sizeof (uint32_t)) {
    2.16 -		head->list_ptr = *(uint32_t *) items->data;
    2.17 -		head->flags = RAZOR_IMMEDIATE;
    2.18 -	} else {
    2.19 -		p = array_add(pool, items->size);
    2.20 -		memcpy(p, items->data, items->size);
    2.21 -		p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST;
    2.22 -		list_set_ptr(head, p - (struct list *) pool->data);
    2.23 +	if (!force_indirect) {
    2.24 +		if (items->size == 0) {
    2.25 +			list_set_empty(head);
    2.26 +			return;
    2.27 +		} else if (items->size == sizeof (uint32_t)) {
    2.28 +			head->list_ptr = *(uint32_t *) items->data;
    2.29 +			head->flags = RAZOR_IMMEDIATE;
    2.30 +			return;
    2.31 +		}
    2.32  	}
    2.33 +
    2.34 +	p = array_add(pool, items->size);
    2.35 +	memcpy(p, items->data, items->size);
    2.36 +	p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST;
    2.37 +	list_set_ptr(head, p - (struct list *) pool->data);
    2.38  }
    2.39  
    2.40  struct list *
     3.1 --- a/types.h	Fri Feb 15 09:31:20 2008 -0500
     3.2 +++ b/types.h	Fri Feb 15 15:08:38 2008 -0500
     3.3 @@ -25,7 +25,7 @@
     3.4  
     3.5  void list_set_empty(struct list_head *head);
     3.6  void list_set_ptr(struct list_head *head, uint32_t ptr);
     3.7 -void list_set_array(struct list_head *head, struct array *pool, struct array *items);
     3.8 +void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
     3.9  
    3.10  struct list *list_first(struct list_head *head, struct array *pool);
    3.11  struct list *list_next(struct list *list);