From: alegrand Date: Mon, 29 Aug 2005 17:02:41 +0000 (+0000) Subject: Removed awful bugs noticed by Henri. And this code is 5 years old... can you X-Git-Tag: v3.3~3683 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8c574e7124773444482fd2db9a7af8228f16e04a?hp=5119d31da6d329bfcf55d56333e554e1ce1de5e1 Removed awful bugs noticed by Henri. And this code is 5 years old... can you believe it ? :) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1674 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index 3ea147bfaf..252d2d1e2e 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -119,6 +119,7 @@ void *xbt_fifo_shift(xbt_fifo_t l) */ void xbt_fifo_push_item(xbt_fifo_t l, xbt_fifo_item_t new) { + xbt_assert0((new->next == NULL)&&(new->prev == NULL),"Invalid item!"); (l->count)++; if (l->head == NULL) { l->head = new; @@ -144,7 +145,7 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) return NULL; item = l->tail; - + l->tail = item->prev; if (l->tail == NULL) l->head = NULL; @@ -152,6 +153,9 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) l->tail->next = NULL; (l->count)--; + + item->prev = NULL; + return item; } @@ -163,6 +167,7 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) */ void xbt_fifo_unshift_item(xbt_fifo_t l, xbt_fifo_item_t new) { + xbt_assert0((new->next == NULL)&&(new->prev == NULL),"Invalid item!"); (l->count)++; if (l->head == NULL) { l->head = new; @@ -197,6 +202,9 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l) l->head->prev = NULL; (l->count)--; + + item->next = NULL; + return item; } @@ -229,28 +237,32 @@ void xbt_fifo_remove(xbt_fifo_t l, void *t) * \param l a list * \param current a bucket * - * removes a the bucket \a current from the list \a l + * removes a bucket \a current from the list \a l. This function implicitely + * assumes (and doesn't check!) that this item belongs to this list... */ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current) { if (l->head == l->tail) { /* special case */ - l->head = NULL; - l->tail = NULL; - (l->count)--; - return; - } - - if (current == l->head) { /* It's the head */ - l->head = current->next; - l->head->prev = NULL; - } else if (current == l->tail) { /* It's the tail */ - l->tail = current->prev; - l->tail->next = NULL; - } else { /* It's in the middle */ - current->prev->next = current->next; - current->next->prev = current->prev; - } + xbt_assert0((current==l->head),"This item is not in the list!"); + l->head = NULL; + l->tail = NULL; (l->count)--; + current->prev = current->next = NULL; + return; + } + + if (current == l->head) { /* It's the head */ + l->head = current->next; + l->head->prev = NULL; + } else if (current == l->tail) { /* It's the tail */ + l->tail = current->prev; + l->tail->next = NULL; + } else { /* It's in the middle */ + current->prev->next = current->next; + current->next->prev = current->prev; + } + (l->count)--; + current->prev = current->next = NULL; } /**