Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): split Buf_Destroy into Buf_Done and Bu...
details: https://anonhg.NetBSD.org/src/rev/c78af47c78f3
branches: trunk
changeset: 950760:c78af47c78f3
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 30 20:53:29 2021 +0000
description:
make(1): split Buf_Destroy into Buf_Done and Buf_DoneData
In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.
The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.
Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
diffstat:
usr.bin/make/buf.c | 35 ++++++++++++++++++++++-------------
usr.bin/make/buf.h | 7 ++++---
usr.bin/make/cond.c | 12 ++++++------
usr.bin/make/dir.c | 6 +++---
usr.bin/make/for.c | 8 ++++----
usr.bin/make/main.c | 8 ++++----
usr.bin/make/parse.c | 6 +++---
usr.bin/make/var.c | 43 +++++++++++++++++++++++--------------------
8 files changed, 69 insertions(+), 56 deletions(-)
diffs (truncated from 433 to 300 lines):
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/buf.c
--- a/usr.bin/make/buf.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/buf.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.47 2020/12/30 10:03:16 rillig Exp $ */
+/* $NetBSD: buf.c,v 1.48 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,7 +75,7 @@
#include "make.h"
/* "@(#)buf.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: buf.c,v 1.47 2020/12/30 10:03:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.48 2021/01/30 20:53:29 rillig Exp $");
/* Make space in the buffer for adding at least 16 more bytes. */
void
@@ -175,18 +175,27 @@
}
/*
- * Reset the buffer.
- * If freeData is TRUE, the data from the buffer is freed as well.
- * Otherwise it is kept and returned.
+ * Free the data from the buffer.
+ * The buffer is left in an indeterminate state.
+ */
+void
+Buf_Done(Buffer *buf)
+{
+ free(buf->data);
+
+ buf->cap = 0;
+ buf->len = 0;
+ buf->data = NULL;
+}
+
+/*
+ * Return the data from the buffer.
+ * The buffer is left in an indeterminate state.
*/
char *
-Buf_Destroy(Buffer *buf, Boolean freeData)
+Buf_DoneData(Buffer *buf)
{
char *data = buf->data;
- if (freeData) {
- free(data);
- data = NULL;
- }
buf->cap = 0;
buf->len = 0;
@@ -206,16 +215,16 @@
* a new buffer will be allocated and the old one freed.
*/
char *
-Buf_DestroyCompact(Buffer *buf)
+Buf_DoneDataCompact(Buffer *buf)
{
#if BUF_COMPACT_LIMIT > 0
if (buf->cap - buf->len >= BUF_COMPACT_LIMIT) {
/* We trust realloc to be smart */
char *data = bmake_realloc(buf->data, buf->len + 1);
data[buf->len] = '\0'; /* XXX: unnecessary */
- Buf_Destroy(buf, FALSE);
+ Buf_DoneData(buf);
return data;
}
#endif
- return Buf_Destroy(buf, FALSE);
+ return Buf_DoneData(buf);
}
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/buf.h
--- a/usr.bin/make/buf.h Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/buf.h Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.38 2020/12/28 15:42:53 rillig Exp $ */
+/* $NetBSD: buf.h,v 1.39 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -126,7 +126,8 @@
void Buf_Empty(Buffer *);
void Buf_Init(Buffer *);
void Buf_InitSize(Buffer *, size_t);
-char *Buf_Destroy(Buffer *, Boolean);
-char *Buf_DestroyCompact(Buffer *);
+void Buf_Done(Buffer *);
+char *Buf_DoneData(Buffer *);
+char *Buf_DoneDataCompact(Buffer *);
#endif /* MAKE_BUF_H */
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/cond.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.253 2021/01/22 00:12:01 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.254 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.253 2021/01/22 00:12:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.254 2021/01/30 20:53:29 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -282,8 +282,8 @@
p++;
}
- *out_arg = Buf_GetAll(&argBuf, &argLen);
- Buf_Destroy(&argBuf, FALSE);
+ argLen = argBuf.len;
+ *out_arg = Buf_DoneData(&argBuf);
cpp_skip_hspace(&p);
@@ -539,9 +539,9 @@
}
}
got_str:
- str = FStr_InitOwn(Buf_GetAll(&buf, NULL));
+ str = FStr_InitOwn(buf.data);
cleanup:
- Buf_Destroy(&buf, FALSE);
+ Buf_DoneData(&buf);
*out_str = str;
}
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/dir.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.264 2021/01/24 20:11:55 rillig Exp $ */
+/* $NetBSD: dir.c,v 1.265 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -138,7 +138,7 @@
#include "job.h"
/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: dir.c,v 1.264 2021/01/24 20:11:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.265 2021/01/30 20:53:29 rillig Exp $");
/*
* A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -1645,7 +1645,7 @@
}
}
- return Buf_Destroy(&buf, FALSE);
+ return Buf_DoneData(&buf);
}
/* Free the search path and all directories mentioned in it. */
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/for.c
--- a/usr.bin/make/for.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/for.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.138 2021/01/25 19:39:34 rillig Exp $ */
+/* $NetBSD: for.c,v 1.139 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.138 2021/01/25 19:39:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.139 2021/01/30 20:53:29 rillig Exp $");
/* One of the variables to the left of the "in" in a .for loop. */
@@ -103,7 +103,7 @@
static void
ForLoop_Free(ForLoop *f)
{
- Buf_Destroy(&f->body, TRUE);
+ Buf_Done(&f->body);
while (f->vars.len > 0) {
ForVar *var = Vector_Pop(&f->vars);
@@ -112,7 +112,7 @@
Vector_Done(&f->vars);
Words_Free(f->items);
- Buf_Destroy(&f->curBody, TRUE);
+ Buf_Done(&f->curBody);
free(f);
}
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/main.c
--- a/usr.bin/make/main.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/main.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.517 2021/01/24 20:11:55 rillig Exp $ */
+/* $NetBSD: main.c,v 1.518 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -110,7 +110,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.517 2021/01/24 20:11:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.518 2021/01/30 20:53:29 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1841,7 +1841,7 @@
JobReapChild(pid, status, FALSE);
res_len = Buf_Len(&buf);
- res = Buf_Destroy(&buf, FALSE);
+ res = Buf_DoneData(&buf);
if (savederr != 0)
*errfmt = "Couldn't read shell's output for \"%s\"";
@@ -2027,7 +2027,7 @@
write_all(STDERR_FILENO, Buf_GetAll(&buf, NULL), Buf_Len(&buf));
- Buf_Destroy(&buf, TRUE);
+ Buf_Done(&buf);
_exit(1);
}
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/parse.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.533 2021/01/27 00:02:38 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.534 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.533 2021/01/27 00:02:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.534 2021/01/30 20:53:29 rillig Exp $");
/* types and constants */
@@ -455,7 +455,7 @@
{
struct loadedfile *lf = loadedfile_create(path,
buf.data, buf.len);
- Buf_Destroy(&buf, FALSE);
+ Buf_DoneData(&buf);
return lf;
}
}
diff -r e25302943257 -r c78af47c78f3 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Jan 30 19:20:44 2021 +0000
+++ b/usr.bin/make/var.c Sat Jan 30 20:53:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.783 2021/01/30 15:48:42 rillig Exp $ */
+/* $NetBSD: var.c,v 1.784 2021/01/30 20:53:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.783 2021/01/30 15:48:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.784 2021/01/30 20:53:29 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -456,7 +456,10 @@
return FALSE;
FStr_Done(&v->name);
- Buf_Destroy(&v->val, freeValue);
+ if (freeValue)
+ Buf_Done(&v->val);
+ else
+ Buf_DoneData(&v->val);
free(v);
return TRUE;
}
@@ -499,7 +502,7 @@
var_exportedVars = VAR_EXPORTED_NONE;
assert(v->name.freeIt == NULL);
HashTable_DeleteEntry(&ctxt->vars, he);
- Buf_Destroy(&v->val, TRUE);
+ Buf_Done(&v->val);
free(v);
}
Home |
Main Index |
Thread Index |
Old Index