Mon Mar 15 16:45:30 2021 UTC ()
make: fix documentation of Lst_MoveAll

In CLEANUP mode, was originally meant to track memory allocations but is
useful during debugging as well, initialize the list.  There is no
distinct constant representing an invalid pointer, otherwise that would
have been an even better choice.


(rillig)
diff -r1.104 -r1.105 src/usr.bin/make/lst.c

cvs diff -r1.104 -r1.105 src/usr.bin/make/lst.c (expand / switch to unified diff)

--- src/usr.bin/make/lst.c 2021/02/01 19:39:31 1.104
+++ src/usr.bin/make/lst.c 2021/03/15 16:45:30 1.105
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.c,v 1.104 2021/02/01 19:39:31 rillig Exp $ */ 1/* $NetBSD: lst.c,v 1.105 2021/03/15 16:45:30 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "make.h" 35#include "make.h"
36 36
37MAKE_RCSID("$NetBSD: lst.c,v 1.104 2021/02/01 19:39:31 rillig Exp $"); 37MAKE_RCSID("$NetBSD: lst.c,v 1.105 2021/03/15 16:45:30 rillig Exp $");
38 38
39static ListNode * 39static ListNode *
40LstNodeNew(ListNode *prev, ListNode *next, void *datum) 40LstNodeNew(ListNode *prev, ListNode *next, void *datum)
41{ 41{
42 ListNode *ln = bmake_malloc(sizeof *ln); 42 ListNode *ln = bmake_malloc(sizeof *ln);
43 43
44 ln->prev = prev; 44 ln->prev = prev;
45 ln->next = next; 45 ln->next = next;
46 ln->datum = datum; 46 ln->datum = datum;
47 47
48 return ln; 48 return ln;
49} 49}
50 50
@@ -195,40 +195,44 @@ Lst_FindDatum(List *list, const void *da @@ -195,40 +195,44 @@ Lst_FindDatum(List *list, const void *da
195 ListNode *ln; 195 ListNode *ln;
196 196
197 assert(datum != NULL); 197 assert(datum != NULL);
198 198
199 for (ln = list->first; ln != NULL; ln = ln->next) 199 for (ln = list->first; ln != NULL; ln = ln->next)
200 if (ln->datum == datum) 200 if (ln->datum == datum)
201 return ln; 201 return ln;
202 202
203 return NULL; 203 return NULL;
204} 204}
205 205
206/* 206/*
207 * Move all nodes from src to the end of dst. 207 * Move all nodes from src to the end of dst.
208 * The source list becomes empty but is not freed. 208 * The source list becomes indeterminate.
209 */ 209 */
210void 210void
211Lst_MoveAll(List *dst, List *src) 211Lst_MoveAll(List *dst, List *src)
212{ 212{
213 if (src->first != NULL) { 213 if (src->first != NULL) {
214 src->first->prev = dst->last; 214 src->first->prev = dst->last;
215 if (dst->last != NULL) 215 if (dst->last != NULL)
216 dst->last->next = src->first; 216 dst->last->next = src->first;
217 else 217 else
218 dst->first = src->first; 218 dst->first = src->first;
219 219
220 dst->last = src->last; 220 dst->last = src->last;
221 } 221 }
 222#ifdef CLEANUP
 223 src->first = NULL;
 224 src->last = NULL;
 225#endif
222} 226}
223 227
224/* Copy the element data from src to the start of dst. */ 228/* Copy the element data from src to the start of dst. */
225void 229void
226Lst_PrependAll(List *dst, List *src) 230Lst_PrependAll(List *dst, List *src)
227{ 231{
228 ListNode *ln; 232 ListNode *ln;
229 233
230 for (ln = src->last; ln != NULL; ln = ln->prev) 234 for (ln = src->last; ln != NULL; ln = ln->prev)
231 Lst_Prepend(dst, ln->datum); 235 Lst_Prepend(dst, ln->datum);
232} 236}
233 237
234/* Copy the element data from src to the end of dst. */ 238/* Copy the element data from src to the end of dst. */