Module Name: src
Committed By: rillig
Date: Thu Aug 13 04:12:13 UTC 2020
Modified Files:
src/usr.bin/make: buf.c buf.h var.c
Log Message:
make(1): remove type alias Byte = char
This alias was only actually used in very few places, and changing it to
unsigned char or any other type would not be possible without generating
lots of compile-time errors. Therefore there was no abstraction, only
unnecessary complexity.
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/buf.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/buf.h
cvs rdiff -u -r1.448 -r1.449 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.34 src/usr.bin/make/buf.c:1.35
--- src/usr.bin/make/buf.c:1.34 Sun Aug 9 19:51:02 2020
+++ src/usr.bin/make/buf.c Thu Aug 13 04:12:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 rillig Exp $ */
+/* $NetBSD: buf.c,v 1.35 2020/08/13 04:12:13 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: buf.c,v 1.35 2020/08/13 04:12:13 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 rillig Exp $");
+__RCSID("$NetBSD: buf.c,v 1.35 2020/08/13 04:12:13 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -104,10 +104,10 @@ Buf_Expand_1(Buffer *bp)
/* Add the given bytes to the buffer. */
void
-Buf_AddBytes(Buffer *bp, const Byte *bytesPtr, size_t numBytes)
+Buf_AddBytes(Buffer *bp, const char *bytesPtr, size_t numBytes)
{
size_t count = bp->count;
- Byte *ptr;
+ char *ptr;
if (__predict_false(count + numBytes >= bp->size)) {
bp->size += max(bp->size, numBytes + 16);
@@ -159,7 +159,7 @@ Buf_AddInt(Buffer *bp, int n)
*
* Returns the pointer to the data and optionally the length of the
* data in the buffer. */
-Byte *
+char *
Buf_GetAll(Buffer *bp, size_t *numBytesPtr)
{
if (numBytesPtr != NULL)
@@ -192,10 +192,10 @@ Buf_Init(Buffer *bp, size_t size)
/* Reset the buffer.
* If freeData is TRUE, the data from the buffer is freed as well.
* Otherwise it is kept and returned. */
-Byte *
+char *
Buf_Destroy(Buffer *buf, Boolean freeData)
{
- Byte *data = buf->buffer;
+ char *data = buf->buffer;
if (freeData) {
free(data);
data = NULL;
@@ -216,13 +216,13 @@ Buf_Destroy(Buffer *buf, Boolean freeDat
*
* If the buffer size is much greater than its content,
* a new buffer will be allocated and the old one freed. */
-Byte *
+char *
Buf_DestroyCompact(Buffer *buf)
{
#if BUF_COMPACT_LIMIT > 0
if (buf->size - buf->count >= BUF_COMPACT_LIMIT) {
/* We trust realloc to be smart */
- Byte *data = bmake_realloc(buf->buffer, buf->count + 1);
+ char *data = bmake_realloc(buf->buffer, buf->count + 1);
data[buf->count] = 0;
Buf_Destroy(buf, FALSE);
return data;
Index: src/usr.bin/make/buf.h
diff -u src/usr.bin/make/buf.h:1.23 src/usr.bin/make/buf.h:1.24
--- src/usr.bin/make/buf.h:1.23 Sat Aug 8 18:54:04 2020
+++ src/usr.bin/make/buf.h Thu Aug 13 04:12:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.23 2020/08/08 18:54:04 rillig Exp $ */
+/* $NetBSD: buf.h,v 1.24 2020/08/13 04:12:13 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -74,7 +74,7 @@
/*-
* buf.h --
- * Header for users of the buf library.
+ * Automatically growing null-terminated buffer of characters.
*/
#ifndef MAKE_BUF_H
@@ -82,12 +82,10 @@
#include <stddef.h>
-typedef char Byte;
-
typedef struct Buffer {
size_t size; /* Current size of the buffer */
size_t count; /* Number of bytes in buffer */
- Byte *buffer; /* The buffer itself (zero terminated) */
+ char *buffer; /* The buffer itself (zero terminated) */
} Buffer;
/* If we aren't on NetBSD, __predict_false() might not be defined. */
@@ -98,7 +96,7 @@ typedef struct Buffer {
/* Buf_AddByte adds a single byte to a buffer. */
#define Buf_AddByte(bp, byte) do { \
size_t _count = ++(bp)->count; \
- Byte *_ptr; \
+ char *_ptr; \
if (__predict_false(_count >= (bp)->size)) \
Buf_Expand_1(bp); \
_ptr = (bp)->buffer + _count; \
@@ -111,14 +109,14 @@ typedef struct Buffer {
#define Buf_Size(bp) ((bp)->count)
void Buf_Expand_1(Buffer *);
-void Buf_AddBytes(Buffer *, const Byte *, size_t);
-void Buf_AddBytesBetween(Buffer *, const Byte *, const Byte *);
+void Buf_AddBytes(Buffer *, const char *, size_t);
+void Buf_AddBytesBetween(Buffer *, const char *, const char *);
void Buf_AddStr(Buffer *, const char *);
void Buf_AddInt(Buffer *, int);
-Byte *Buf_GetAll(Buffer *, size_t *);
+char *Buf_GetAll(Buffer *, size_t *);
void Buf_Empty(Buffer *);
void Buf_Init(Buffer *, size_t);
-Byte *Buf_Destroy(Buffer *, Boolean);
-Byte *Buf_DestroyCompact(Buffer *);
+char *Buf_Destroy(Buffer *, Boolean);
+char *Buf_DestroyCompact(Buffer *);
#endif /* MAKE_BUF_H */
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.448 src/usr.bin/make/var.c:1.449
--- src/usr.bin/make/var.c:1.448 Wed Aug 12 19:14:38 2020
+++ src/usr.bin/make/var.c Thu Aug 13 04:12:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.448 2020/08/12 19:14:38 rillig Exp $ */
+/* $NetBSD: var.c,v 1.449 2020/08/13 04:12:13 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.448 2020/08/12 19:14:38 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.449 2020/08/13 04:12:13 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.448 2020/08/12 19:14:38 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.449 2020/08/13 04:12:13 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -1474,7 +1474,7 @@ ModifyWord_Loop(const char *word, SepBuf
* to scan the list backwards if first > last.
*/
static char *
-VarSelectWords(Byte sep, Boolean oneBigWord, const char *str, int first,
+VarSelectWords(char sep, Boolean oneBigWord, const char *str, int first,
int last)
{
char **av; /* word list */
@@ -1561,7 +1561,7 @@ ModifyWord_Realpath(const char *word, Se
*-----------------------------------------------------------------------
*/
static char *
-ModifyWords(GNode *ctx, Byte sep, Boolean oneBigWord,
+ModifyWords(GNode *ctx, char sep, Boolean oneBigWord,
const char *str, ModifyWordsCallback modifyWord, void *data)
{
SepBuf result;
@@ -1927,7 +1927,7 @@ typedef struct {
* to the expression */
char missing_delim; /* For error reporting */
- Byte sep; /* Word separator in expansions
+ char sep; /* Word separator in expansions
* (see the :ts modifier) */
Boolean oneBigWord; /* TRUE if the variable value is treated as a
* single big word, even if it contains
@@ -2487,7 +2487,7 @@ ApplyModifier_ToSep(const char **pp, App
get_numeric:
{
char *end;
- st->sep = (Byte)strtoul(xp, &end, base);
+ st->sep = (char)strtoul(xp, &end, base);
if (*end != ':' && *end != st->endc)
return AMR_BAD;
*pp = end;