FIX: Remove llist_move again and 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-13 09:20:08 +02:00
parent 238218f776
commit 2f776858ee
3 changed files with 25 additions and 12 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,17 +309,6 @@ LLIST_FUNC (LList llist_relocate (LList self),
return self->next->prev = self->prev->next = self;
);
/**
* Move a node from one memory location to another.
* @param self target of the move, must be uninitialized or empty before this move
* @param source source of the move, will be initialized to a empty list after this call
* @return self
*/
LLIST_FUNC (LList llist_move (LList self, LList source),
*self = *source;
llist_init (source);
return llist_relocate (self);
);
/**
* Insert a node after another.

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