Skip to content

Commit 8f8d746

Browse files
committed
Code review for inline-list patch.
Make foreach macros less syntactically dangerous, and fix some typos in evidently-never-tested ones. Add missing slist_next_node and slist_head_node functions. Fix broken dlist_check code. Assorted comment improvements.
1 parent 2f2be74 commit 8f8d746

File tree

2 files changed

+213
-219
lines changed

2 files changed

+213
-219
lines changed

src/backend/lib/ilist.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
#include "lib/ilist.h"
2525

2626
/*
27-
* removes a node from a list
27+
* Delete 'node' from list.
2828
*
29-
* Attention: O(n)
29+
* It is not allowed to delete a 'node' which is is not in the list 'head'
30+
*
31+
* Caution: this is O(n)
3032
*/
3133
void
3234
slist_delete(slist_head *head, slist_node *node)
@@ -47,9 +49,9 @@ slist_delete(slist_head *head, slist_node *node)
4749
}
4850
last = cur;
4951
}
52+
Assert(found);
5053

5154
slist_check(head);
52-
Assert(found);
5355
}
5456

5557
#ifdef ILIST_DEBUG
@@ -61,8 +63,11 @@ dlist_check(dlist_head *head)
6163
{
6264
dlist_node *cur;
6365

64-
if (head == NULL || !(&head->head))
65-
elog(ERROR, "doubly linked list head is not properly initialized");
66+
if (head == NULL)
67+
elog(ERROR, "doubly linked list head address is NULL");
68+
69+
if (head->head.next == NULL && head->head.prev == NULL)
70+
return; /* OK, initialized as zeroes */
6671

6772
/* iterate in forward direction */
6873
for (cur = head->head.next; cur != &head->head; cur = cur->next)
@@ -96,10 +101,10 @@ slist_check(slist_head *head)
96101
slist_node *cur;
97102

98103
if (head == NULL)
99-
elog(ERROR, "singly linked is NULL");
104+
elog(ERROR, "singly linked list head address is NULL");
100105

101106
/*
102-
* there isn't much we can test in a singly linked list other that it
107+
* there isn't much we can test in a singly linked list except that it
103108
* actually ends sometime, i.e. hasn't introduced a cycle or similar
104109
*/
105110
for (cur = head->head.next; cur != NULL; cur = cur->next)

0 commit comments

Comments
 (0)