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): replace brk_string with Str_Words
details: https://anonhg.NetBSD.org/src/rev/80ccf3c55791
branches: trunk
changeset: 943311:80ccf3c55791
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Aug 30 19:56:02 2020 +0000
description:
make(1): replace brk_string with Str_Words
The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
diffstat:
usr.bin/make/compat.c | 13 ++-
usr.bin/make/for.c | 23 +++---
usr.bin/make/job.c | 12 ++-
usr.bin/make/main.c | 19 ++---
usr.bin/make/nonints.h | 16 ++++-
usr.bin/make/str.c | 39 ++++-------
usr.bin/make/var.c | 155 ++++++++++++++++++++----------------------------
7 files changed, 128 insertions(+), 149 deletions(-)
diffs (truncated from 693 to 300 lines):
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/compat.c Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.137 2020/08/30 14:11:42 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.138 2020/08/30 19:56:02 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: compat.c,v 1.137 2020/08/30 14:11:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.138 2020/08/30 19:56:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: compat.c,v 1.137 2020/08/30 14:11:42 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.138 2020/08/30 19:56:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -336,17 +336,18 @@
else
shargv[shargc++] = "-c";
shargv[shargc++] = cmd;
- shargv[shargc++] = NULL;
+ shargv[shargc] = NULL;
av = shargv;
bp = NULL;
mav = NULL;
} else {
- size_t argc;
/*
* No meta-characters, so no need to exec a shell. Break the command
* into words to form an argument vector we can execute.
*/
- mav = brk_string(cmd, TRUE, &argc, &bp);
+ Words words = Str_Words(cmd, TRUE);
+ mav = words.words;
+ bp = words.freeIt;
if (mav == NULL) {
useShell = 1;
goto again;
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/for.c
--- a/usr.bin/make/for.c Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/for.c Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.66 2020/08/29 10:32:00 rillig Exp $ */
+/* $NetBSD: for.c,v 1.67 2020/08/30 19:56:02 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.66 2020/08/29 10:32:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.67 2020/08/30 19:56:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: for.c,v 1.66 2020/08/29 10:32:00 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.67 2020/08/30 19:56:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -133,8 +133,7 @@
size_t len;
int escapes;
unsigned char ch;
- char **words, *word_buf;
- size_t nwords;
+ Words words;
/* Skip the '.' and any following whitespace */
for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)
@@ -203,15 +202,15 @@
/*
* Split into words allowing for quoted strings.
*/
- words = brk_string(sub, FALSE, &nwords, &word_buf);
+ words = Str_Words(sub, FALSE);
free(sub);
- if (words != NULL) {
+ {
size_t n;
- for (n = 0; n < nwords; n++) {
- ptr = words[n];
+ for (n = 0; n < words.len; n++) {
+ ptr = words.words[n];
if (!*ptr)
continue;
escapes = 0;
@@ -234,11 +233,11 @@
* We have to dup words[n] to maintain the semantics of
* strlist.
*/
- strlist_add_str(&new_for->items, bmake_strdup(words[n]), escapes);
+ strlist_add_str(&new_for->items, bmake_strdup(words.words[n]),
+ escapes);
}
- free(words);
- free(word_buf);
+ Words_Free(words);
if ((len = strlist_num(&new_for->items)) > 0 &&
len % (n = strlist_num(&new_for->vars))) {
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/job.c
--- a/usr.bin/make/job.c Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/job.c Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.226 2020/08/30 13:53:02 rillig Exp $ */
+/* $NetBSD: job.c,v 1.227 2020/08/30 19:56:02 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: job.c,v 1.226 2020/08/30 13:53:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.227 2020/08/30 19:56:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: job.c,v 1.226 2020/08/30 13:53:02 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.227 2020/08/30 19:56:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -2414,6 +2414,7 @@
Boolean
Job_ParseShell(char *line)
{
+ Words wordsList;
char **words;
char **argv;
size_t argc;
@@ -2433,7 +2434,10 @@
/*
* Parse the specification by keyword
*/
- words = brk_string(line, TRUE, &argc, &path);
+ wordsList = Str_Words(line, TRUE);
+ words = wordsList.words;
+ argc = wordsList.len;
+ path = wordsList.freeIt;
if (words == NULL) {
Error("Unterminated quoted string [%s]", line);
return FALSE;
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/main.c
--- a/usr.bin/make/main.c Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/main.c Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.330 2020/08/30 11:15:05 rillig Exp $ */
+/* $NetBSD: main.c,v 1.331 2020/08/30 19:56:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.330 2020/08/30 11:15:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.331 2020/08/30 19:56:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.330 2020/08/30 11:15:05 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.331 2020/08/30 19:56:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -690,9 +690,7 @@
void
Main_ParseArgLine(const char *line)
{
- char **argv; /* Manufactured argument vector */
- size_t argc; /* Number of arguments in argv */
- char *args; /* Space used by the args */
+ Words words;
char *p1;
const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
char *buf;
@@ -707,17 +705,16 @@
buf = str_concat3(argv0, " ", line);
free(p1);
- argv = brk_string(buf, TRUE, &argc, &args);
- if (argv == NULL) {
+ words = Str_Words(buf, TRUE);
+ if (words.words == NULL) {
Error("Unterminated quoted string [%s]", buf);
free(buf);
return;
}
free(buf);
- MainParseArgs((int)argc, argv);
+ MainParseArgs((int)words.len, words.words);
- free(args);
- free(argv);
+ Words_Free(words);
}
Boolean
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/nonints.h Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.101 2020/08/29 12:01:46 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.102 2020/08/30 19:56:02 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -133,10 +133,22 @@
Lst Parse_MainName(void);
/* str.c */
+typedef struct {
+ char **words;
+ size_t len;
+ void *freeIt;
+} Words;
+
+Words Str_Words(const char *, Boolean);
+static inline void MAKE_ATTR_UNUSED
+Words_Free(Words w) {
+ free(w.words);
+ free(w.freeIt);
+}
+
char *str_concat2(const char *, const char *);
char *str_concat3(const char *, const char *, const char *);
char *str_concat4(const char *, const char *, const char *, const char *);
-char **brk_string(const char *, Boolean, size_t *, char **);
char *Str_FindSubstring(const char *, const char *);
Boolean Str_Match(const char *, const char *);
diff -r 92854c9b1bf8 -r 80ccf3c55791 usr.bin/make/str.c
--- a/usr.bin/make/str.c Sun Aug 30 19:45:05 2020 +0000
+++ b/usr.bin/make/str.c Sun Aug 30 19:56:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.63 2020/08/29 07:52:55 rillig Exp $ */
+/* $NetBSD: str.c,v 1.64 2020/08/30 19:56:02 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.63 2020/08/29 07:52:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.64 2020/08/30 19:56:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
-__RCSID("$NetBSD: str.c,v 1.63 2020/08/29 07:52:55 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.64 2020/08/30 19:56:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -125,25 +125,19 @@
return result;
}
-/*-
- * brk_string --
- * Fracture a string into an array of words (as delineated by tabs or
- * spaces) taking quotation marks into account. Leading tabs/spaces
- * are ignored.
+/* Fracture a string into an array of words (as delineated by tabs or spaces)
+ * taking quotation marks into account. Leading tabs/spaces are ignored.
*
- * If expand is TRUE, quotes are removed and escape sequences
- * such as \r, \t, etc... are expanded. In this case, the return value
- * is NULL on parse errors.
+ * If expand is TRUE, quotes are removed and escape sequences such as \r, \t,
Home |
Main Index |
Thread Index |
Old Index