From 2f776858eeba6f3241b6cbc829d5a7ff916f4eb6 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 13 Aug 2008 09:20:08 +0200 Subject: [PATCH] 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. --- src/lib/llist.h | 14 +++----------- tests/15list.tests | 4 +++- tests/library/test-llist.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/lib/llist.h b/src/lib/llist.h index 3cb70f8ea..353fe4320 100644 --- a/src/lib/llist.h +++ b/src/lib/llist.h @@ -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. diff --git a/tests/15list.tests b/tests/15list.tests index 88aef3c49..e04044f27 100644 --- a/tests/15list.tests +++ b/tests/15list.tests @@ -44,9 +44,11 @@ out: . out: . END +TEST "llist_relocate" relocate <