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): reduce lifetime of regmatch_t for :C m...
details: https://anonhg.NetBSD.org/src/rev/edc92862c107
branches: trunk
changeset: 1012156:edc92862c107
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jul 24 08:12:43 2020 +0000
description:
make(1): reduce lifetime of regmatch_t for :C modifier
diffstat:
usr.bin/make/var.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
diffs (87 lines):
diff -r e154cb88a5ec -r edc92862c107 usr.bin/make/var.c
--- a/usr.bin/make/var.c Fri Jul 24 08:06:28 2020 +0000
+++ b/usr.bin/make/var.c Fri Jul 24 08:12:43 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.304 2020/07/24 08:06:28 rillig Exp $ */
+/* $NetBSD: var.c,v 1.305 2020/07/24 08:12:43 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.304 2020/07/24 08:06:28 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.305 2020/07/24 08:12:43 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.304 2020/07/24 08:06:28 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.305 2020/07/24 08:12:43 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -1378,7 +1378,6 @@
int nsub;
char *replace;
VarPatternFlags pflags;
- regmatch_t matches[10];
} ModifyWord_SubstRegexArgs;
/* Callback for ModifyWords to implement the :C/from/to/ modifier.
@@ -1391,19 +1390,20 @@
const char *wp = word;
char *rp;
int flags = 0;
+ regmatch_t m[10];
if ((args->pflags & (VARP_SUB_ONE | VARP_SUB_MATCHED)) ==
(VARP_SUB_ONE | VARP_SUB_MATCHED))
xrv = REG_NOMATCH;
else {
tryagain:
- xrv = regexec(&args->re, wp, args->nsub, args->matches, flags);
+ xrv = regexec(&args->re, wp, args->nsub, m, flags);
}
switch (xrv) {
case 0:
args->pflags |= VARP_SUB_MATCHED;
- SepBuf_AddBytes(buf, wp, args->matches[0].rm_so);
+ SepBuf_AddBytes(buf, wp, m[0].rm_so);
for (rp = args->replace; *rp; rp++) {
if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
@@ -1428,24 +1428,21 @@
if (n >= args->nsub) {
Error("No subexpression %s", errstr);
- } else if ((args->matches[n].rm_so == -1) &&
- (args->matches[n].rm_eo == -1)) {
+ } else if (m[n].rm_so == -1 && m[n].rm_eo == -1) {
Error("No match for subexpression %s", errstr);
} else {
- const char *subbuf = wp + args->matches[n].rm_so;
- int sublen = args->matches[n].rm_eo -
- args->matches[n].rm_so;
- SepBuf_AddBytes(buf, subbuf, sublen);
+ SepBuf_AddBytes(buf, wp + m[n].rm_so,
+ m[n].rm_eo - m[n].rm_so);
}
} else {
SepBuf_AddBytes(buf, rp, 1);
}
}
- wp += args->matches[0].rm_eo;
+ wp += m[0].rm_eo;
if (args->pflags & VARP_SUB_GLOBAL) {
flags |= REG_NOTBOL;
- if (args->matches[0].rm_so == 0 && args->matches[0].rm_eo == 0) {
+ if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
SepBuf_AddBytes(buf, wp, 1);
wp++;
}
Home |
Main Index |
Thread Index |
Old Index