Module Name: src
Committed By: rillig
Date: Sun Sep 27 16:10:07 UTC 2020
Modified Files:
src/usr.bin/make: buf.h var.c
Log Message:
make(1): replace direct access to Buffer fields with inline function
This way, renaming the fields of the buffer is restricted to only buf.h
and buf.c.
To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/make/buf.h
cvs rdiff -u -r1.543 -r1.544 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.h
diff -u src/usr.bin/make/buf.h:1.29 src/usr.bin/make/buf.h:1.30
--- src/usr.bin/make/buf.h:1.29 Sun Sep 13 15:27:25 2020
+++ src/usr.bin/make/buf.h Sun Sep 27 16:10:07 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.29 2020/09/13 15:27:25 rillig Exp $ */
+/* $NetBSD: buf.h,v 1.30 2020/09/27 16:10:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -112,6 +112,12 @@ Buf_Size(const Buffer *bp)
return bp->count;
}
+static inline MAKE_ATTR_UNUSED Boolean
+Buf_EndsWith(const Buffer *bp, char ch)
+{
+ return bp->count > 0 && bp->buffer[bp->count - 1] == ch;
+}
+
void Buf_AddBytes(Buffer *, const char *, size_t);
void Buf_AddBytesBetween(Buffer *, const char *, const char *);
void Buf_AddStr(Buffer *, const char *);
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.543 src/usr.bin/make/var.c:1.544
--- src/usr.bin/make/var.c:1.543 Sat Sep 26 16:00:12 2020
+++ src/usr.bin/make/var.c Sun Sep 27 16:10:07 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $ */
+/* $NetBSD: var.c,v 1.544 2020/09/27 16:10:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.544 2020/09/27 16:10:07 rillig Exp $");
#define VAR_DEBUG_IF(cond, fmt, ...) \
if (!(DEBUG(VAR) && (cond))) \
@@ -1433,8 +1433,7 @@ ModifyWord_Loop(const char *word, SepBuf
"to \"%s\"\n",
word, args->tvar, args->str, s);
- if (s[0] == '\n' || (buf->buf.count > 0 &&
- buf->buf.buffer[buf->buf.count - 1] == '\n'))
+ if (s[0] == '\n' || Buf_EndsWith(&buf->buf, '\n'))
buf->needSep = FALSE;
SepBuf_AddStr(buf, s);
free(s);
@@ -1552,7 +1551,7 @@ ModifyWords(GNode *ctx, char sep, Boolea
for (i = 0; i < words.len; i++) {
modifyWord(words.words[i], &result, modifyWord_args);
- if (result.buf.count > 0)
+ if (Buf_Size(&result.buf) > 0)
SepBuf_Sep(&result);
}