FIX: put a note to list_relocate, add test

There was a fatal thinko, llist_relocate NUST NOT be called on a empty
list, the pointers will just point to invaildated memory. This cant be
handled by the llist code. The programmer is responsible to take proper
actions.
This commit is contained in:
Christian Thaeter 2008-08-11 10:12:05 +02:00
parent 6c34fc63f1
commit e2b7561c76
3 changed files with 26 additions and 1 deletions

View file

@ -299,6 +299,9 @@ LLIST_FUNC (LList llist_unlink (LList self),
/**
* Fix a node which got relocated in memory.
* It is supported to realloc/move list nodes in memory but one must call 'list_relocate' after doing so.
* IMPORTANT: it is not possible to relocate nodes which are empty this way, nor can this be determined
* after the relocation, so either llist_init them afterwards or insert a bogus node before moving the node
* and relocating it and remove it afterwards.
* @param self node which got relocated
* @return self
*/
@ -306,6 +309,7 @@ LLIST_FUNC (LList llist_relocate (LList self),
return self->next->prev = self->prev->next = self;
);
/**
* Insert a node after another.
* @param self node after which we want to insert

View file

@ -44,9 +44,11 @@ out: .
out: .
END
TEST "llist_relocate" relocate <<END
END
# not yet tested functions, write tests when needed
PLANNED "llist_relocate"
PLANNED "llist_insertlist_next"
PLANNED "llist_insertlist_prev"
PLANNED "llist_insertafter_range"

View file

@ -185,4 +185,23 @@ TEST ("whiles")
}
TEST ("relocate")
{
llist source;
llist_init (&source);
llist something;
llist_init (&something);
llist_insert_head (&source, &something);
llist target = {NULL,NULL};
target = source;
llist_relocate (&target);
ENSURE (llist_is_head (&target, &something));
}
TESTS_END