Compare commits

..

1 Commits

View File

@@ -184,16 +184,18 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_push(aksl_ListNode *list, aksl_List
FAIL_ZERO_RETURN(e, obj, AKERR_NULLPOINTER, "obj"); FAIL_ZERO_RETURN(e, obj, AKERR_NULLPOINTER, "obj");
aksl_ListNode *slow = list; aksl_ListNode *slow = list;
aksl_ListNode *fast = list; aksl_ListNode *fast = list;
while ( slow->next != NULL || fast->next != NULL ) { aksl_ListNode *tail = list;
if ( fast->next != NULL ) { do {
if ( fast != NULL && fast->next != NULL ) {
fast = fast->next->next; fast = fast->next->next;
} }
tail = slow;
slow = slow->next; slow = slow->next;
if ( fast == slow ) { if ( fast != NULL && fast == slow) {
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list); FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
} }
} } while ( slow != NULL || (fast != NULL && fast->next != NULL) );
slow->next = obj; tail->next = obj;
obj->next = NULL; obj->next = NULL;
obj->prev = slow; obj->prev = slow;
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
@@ -203,9 +205,12 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_pop(aksl_ListNode *node)
{ {
PREPARE_ERROR(e); PREPARE_ERROR(e);
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node"); FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
FAIL_ZERO_RETURN(e, node->prev, AKERR_NULLPOINTER, "node->prev"); if ( node->prev != NULL ) {
node->prev->next = node->next; node->prev->next = node->next;
}
if ( node->next != NULL ) {
node->next->prev = node->prev; node->next->prev = node->prev;
}
node->next = NULL; node->next = NULL;
node->prev = NULL; node->prev = NULL;
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
@@ -301,15 +306,16 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_iterate(aksl_ListNode *list, aksl_L
FAIL_ZERO_RETURN(e, iter, AKERR_NULLPOINTER, "iter"); FAIL_ZERO_RETURN(e, iter, AKERR_NULLPOINTER, "iter");
aksl_ListNode *slow = list; aksl_ListNode *slow = list;
aksl_ListNode *fast = list; aksl_ListNode *fast = list;
while ( slow->next != NULL || fast->next != NULL ) { aksl_ListNode *tail = list;
if ( fast->next != NULL ) { do {
if ( fast != NULL && fast->next != NULL ) {
fast = fast->next->next; fast = fast->next->next;
} }
PASS(e, iter(slow, data)); PASS(e, iter(slow, data));
slow = slow->next; slow = slow->next;
if ( fast == slow && fast->next != NULL ) { if ( fast != NULL && fast == slow) {
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list); FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
} }
} } while ( slow != NULL || (fast != NULL && fast->next != NULL) );
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
} }