fixed error in container.c, but still a weird bug on move

This commit is contained in:
garbeam 2005-12-07 18:58:04 +02:00
parent 4948c0db18
commit 8bc2c9fc0f
2 changed files with 19 additions and 5 deletions

View File

@ -20,6 +20,7 @@ static void detach_from_stack(Container *c, CItem *i)
/* remove from stack */
if (i == c->stack) {
c->stack = i->down;
if (c->stack)
c->stack->up = 0;
}
else {
@ -64,14 +65,18 @@ void cext_detach_item(Container *c, void *item)
CItem *i = c->list;
if (!i)
return;
/* remove from list */
if (i->item == item)
c->list = c->list->next;
c->list = i->next;
else {
CItem *tmp;
for (; i->next && (i->next->item != item); i = i->next);
if (!i->next)
return;
i->next = i->next->next;
tmp = i;
i = i->next;
tmp->next = tmp->next->next;
}
detach_from_stack(c, i);
free(i);

View File

@ -19,13 +19,22 @@ int main(int argc, char *argv[])
Container c = {0};
int i;
printf("--------------------------------\n");
{
int *e = cext_emalloc(sizeof(int));
cext_attach_item(&c, e);
cext_iterate(&c, nil, iter_print_container);
cext_detach_item(&c, e);
cext_iterate(&c, nil, iter_print_container);
}
printf("--------------------------------\n");
printf("--------------------------------\n");
for (i = 0; i < 10; i++) {
int *e = cext_emalloc(sizeof(int));
*e = i;
cext_attach_item(&c, e);
}
printf("--------------------------------\n");
cext_iterate(&c, nil, iter_print_container);
printf("--------------------------------\n");