Module Name:    src
Committed By:   rillig
Date:           Sat Jan 30 21:03:32 UTC 2021

Modified Files:
        src/usr.bin/make: buf.c buf.h main.c var.c

Log Message:
make(1): inline Buf_GetAll


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/make/buf.c
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/make/buf.h
cvs rdiff -u -r1.518 -r1.519 src/usr.bin/make/main.c
cvs rdiff -u -r1.784 -r1.785 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/buf.c
diff -u src/usr.bin/make/buf.c:1.49 src/usr.bin/make/buf.c:1.50
--- src/usr.bin/make/buf.c:1.49	Sat Jan 30 20:59:29 2021
+++ src/usr.bin/make/buf.c	Sat Jan 30 21:03:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.c,v 1.49 2021/01/30 20:59:29 rillig Exp $	*/
+/*	$NetBSD: buf.c,v 1.50 2021/01/30 21:03:32 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.49 2021/01/30 20:59:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.50 2021/01/30 21:03:32 rillig Exp $");
 
 /* Make space in the buffer for adding at least 16 more bytes. */
 void
@@ -135,21 +135,6 @@ Buf_AddInt(Buffer *buf, int n)
 	Buf_AddBytes(buf, str, len);
 }
 
-/*
- * Get the data (usually a string) from the buffer.
- * The returned data is valid until the next modifying operation
- * on the buffer.
- *
- * Returns the data and optionally the length of the data.
- */
-char *
-Buf_GetAll(Buffer *buf, size_t *out_len)
-{
-	if (out_len != NULL)
-		*out_len = buf->len;
-	return buf->data;
-}
-
 /* Mark the buffer as empty, so it can be filled with data again. */
 void
 Buf_Empty(Buffer *buf)

Index: src/usr.bin/make/buf.h
diff -u src/usr.bin/make/buf.h:1.39 src/usr.bin/make/buf.h:1.40
--- src/usr.bin/make/buf.h:1.39	Sat Jan 30 20:53:29 2021
+++ src/usr.bin/make/buf.h	Sat Jan 30 21:03:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.h,v 1.39 2021/01/30 20:53:29 rillig Exp $	*/
+/*	$NetBSD: buf.h,v 1.40 2021/01/30 21:03:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -122,7 +122,6 @@ void Buf_AddBytes(Buffer *, const char *
 void Buf_AddBytesBetween(Buffer *, const char *, const char *);
 void Buf_AddStr(Buffer *, const char *);
 void Buf_AddInt(Buffer *, int);
-char *Buf_GetAll(Buffer *, size_t *);
 void Buf_Empty(Buffer *);
 void Buf_Init(Buffer *);
 void Buf_InitSize(Buffer *, size_t);

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.518 src/usr.bin/make/main.c:1.519
--- src/usr.bin/make/main.c:1.518	Sat Jan 30 20:53:29 2021
+++ src/usr.bin/make/main.c	Sat Jan 30 21:03:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.518 2021/01/30 20:53:29 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.519 2021/01/30 21:03:32 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.518 2021/01/30 20:53:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.519 2021/01/30 21:03:32 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -2025,7 +2025,7 @@ execDie(const char *af, const char *av)
 	Buf_AddStr(&buf, strerror(errno));
 	Buf_AddStr(&buf, ")\n");
 
-	write_all(STDERR_FILENO, Buf_GetAll(&buf, NULL), Buf_Len(&buf));
+	write_all(STDERR_FILENO, buf.data, Buf_Len(&buf));
 
 	Buf_Done(&buf);
 	_exit(1);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.784 src/usr.bin/make/var.c:1.785
--- src/usr.bin/make/var.c:1.784	Sat Jan 30 20:53:29 2021
+++ src/usr.bin/make/var.c	Sat Jan 30 21:03:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.784 2021/01/30 20:53:29 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.785 2021/01/30 21:03:32 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.784 2021/01/30 20:53:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.785 2021/01/30 21:03:32 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1086,8 +1086,7 @@ Var_Append(const char *name, const char 
 		Buf_AddByte(&v->val, ' ');
 		Buf_AddStr(&v->val, val);
 
-		DEBUG3(VAR, "%s:%s = %s\n",
-		    ctxt->name, name, Buf_GetAll(&v->val, NULL));
+		DEBUG3(VAR, "%s:%s = %s\n", ctxt->name, name, v->val.data);
 
 		if (v->flags & VAR_FROM_ENV) {
 			/*
@@ -1160,7 +1159,7 @@ Var_Value(const char *name, GNode *ctxt)
 	if (v == NULL)
 		return FStr_InitRefer(NULL);
 
-	value = Buf_GetAll(&v->val, NULL);
+	value = v->val.data;
 	return VarFreeEnv(v, FALSE)
 	    ? FStr_InitOwn(value)
 	    : FStr_InitRefer(value);
@@ -1174,7 +1173,7 @@ const char *
 Var_ValueDirect(const char *name, GNode *ctxt)
 {
 	Var *v = VarFind(name, ctxt, FALSE);
-	return v != NULL ? Buf_GetAll(&v->val, NULL) : NULL;
+	return v != NULL ? v->val.data : NULL;
 }
 
 
@@ -4187,7 +4186,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
 	 * the then-current value of the variable.  This might also invoke
 	 * undefined behavior.
 	 */
-	value = FStr_InitRefer(Buf_GetAll(&v->val, NULL));
+	value = FStr_InitRefer(v->val.data);
 
 	/*
 	 * Before applying any modifiers, expand any nested expressions from
@@ -4243,7 +4242,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
 				    ? var_Error : varUndefined);
 			}
 		}
-		if (value.str != Buf_GetAll(&v->val, NULL))
+		if (value.str != v->val.data)
 			Buf_Done(&v->val);
 		FStr_Done(&v->name);
 		free(v);
@@ -4415,8 +4414,7 @@ Var_Dump(GNode *ctxt)
 	for (i = 0; i < vec.len; i++) {
 		const char *varname = varnames[i];
 		Var *var = HashTable_FindValue(&ctxt->vars, varname);
-		debug_printf("%-16s = %s\n",
-		    varname, Buf_GetAll(&var->val, NULL));
+		debug_printf("%-16s = %s\n", varname, var->val.data);
 	}
 
 	Vector_Done(&vec);

Reply via email to