From nobody Wed Feb 08 06:10:23 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PBV3M6nM3z3km7c; Wed, 8 Feb 2023 06:10:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PBV3M66Lrz3Fp3; Wed, 8 Feb 2023 06:10:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675836623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BPu2H8/hOARO7vcbpWtdkrBuJ7U6i8CYAUCjsbupdBQ=; b=csQNeXq+akw+zr4eln1z2didiBbafxA+KRcDSriXZhPui9veZ8rZx3qxV/nlxFhFYgbsct RgODPmFuehHq9VxalwsxfDGj+FA1+Pn8fUMl9A/oOCrirr9/+ieq8z5LsC8M9EjAv2vtFt XQcyY/Y2ogbWpyY6YBoI7yiCtBb5ORsS71B26ELprivLpJhjPFAKOnOR86wCqw65AgAtOH vZUXDaaE6JqhJER9jtbwAY8pu1j42B05GTkvpjrRIRvu57rVBM5fJUcF0ci+6Y45AFb169 J/E8wr58u3gwWy4Mop1de9FWSUKGrAzJD2iSnjh+JwX7V32OvoHgeYUMEndxnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675836623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BPu2H8/hOARO7vcbpWtdkrBuJ7U6i8CYAUCjsbupdBQ=; b=Ma/DyJ81uCJAar+tzwE29J2ae/vwYHBn9gIHYncdzbZrtEFom2KFRxwH7XlFgeKntzVEWA YTZcXGYIFDMYqwHHY/n/9knvdmJFVSbiPQio5BZK5NL9Z+KDmkw8Khrv66rVQd9A4xKQ2l K0zHD8Qndj4Xk6NGpQ1pnR1DPNPFhwomCsrpSRrHDlnPNBdlruMa8KpHncgVhPsYgIdtr2 UkJnaRGP99gF0cscfpMtXph/SyC8NzYHc/JFIIUbcxriuLVJBcuyxDNN/7r7jvQjm/3nB6 h5SYjiUgGAm015ycbdsYFFJZmMLDTkbBGPU3eY0NnNu9+8ATWDWT2XTu7q2J1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675836623; a=rsa-sha256; cv=none; b=Ie+tZYPfcOQTjY9w7OqevAQI4e9mdDFmcPGg3s0GwjYwBJiqPhfl0vwk2apmyEXRomzcy9 jtsX1NSOOMI+AFFRDk+cW75ePgH30+gpGkgIVcfK8RX3Mebpyv8PsJFnZ6B9CUtAOfUrq2 y770m4tyg6h+K5qlTwC4TqarI4kdeNPEtfrdColcARdgs44zyWErCxvcAvJ5/lP+FKj1rE LRmKH9G9VMjKiNmmviLJ+ttZZzLzfxth8Dh5VdLzg+ScJzZ2f+ewuwYpWlVBUtiXMq77jo EJrQWYYPWP3isuH1nOKeIfznDJLVlhTKhrPS/lZqZqUFgZrHFetyEqzjRS3DGQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PBV3M4tlQzmPX; Wed, 8 Feb 2023 06:10:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 3186ANPW091169; Wed, 8 Feb 2023 06:10:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3186ANQd091168; Wed, 8 Feb 2023 06:10:23 GMT (envelope-from git) Date: Wed, 8 Feb 2023 06:10:23 GMT Message-Id: <202302080610.3186ANQd091168@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 2ffdc21324bd - main - config: make changes to allow some parts to build as C++ List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2ffdc21324bd1772fa2f40efed3987afecabf5cb Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=2ffdc21324bd1772fa2f40efed3987afecabf5cb commit 2ffdc21324bd1772fa2f40efed3987afecabf5cb Author: Kyle Evans AuthorDate: 2023-02-08 06:02:56 +0000 Commit: Kyle Evans CommitDate: 2023-02-08 06:09:10 +0000 config: make changes to allow some parts to build as C++ Highlights: - Avoid keywords (this, not) as variable names - Move yyparse into config.h with other declarations - All declarations in config.h are assumed guilty until proven innocent - Some const-correctness - Casting malloc/calloc returns Note that we're not building any C++ here yet, this will be introduced in other commits to replace some of the lib dependencies. Reducing the number of FreeBSD-specific dependencies we have reduces some friction for building our bootstrap tools independently in other environments. Reviewed by: imp Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D38274 --- usr.sbin/config/config.h | 6 ++++++ usr.sbin/config/main.c | 19 ++++++++++--------- usr.sbin/config/mkmakefile.c | 44 ++++++++++++++++++++++---------------------- usr.sbin/config/mkoptions.c | 28 ++++++++++++++-------------- 4 files changed, 52 insertions(+), 45 deletions(-) diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 79d0a788bae7..7d97d66979e2 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -35,12 +35,15 @@ /* * Config. */ +#include /* __BEGIN_DECLS/__END_DECLS */ #include #include #include #include #include +__BEGIN_DECLS + struct cfgfile { STAILQ_ENTRY(cfgfile) cfg_next; char *cfg_path; @@ -190,6 +193,7 @@ char *raisestr(char *); void remember(const char *); void moveifchanged(const char *, const char *); int yylex(void); +int yyparse(void); void options(void); void makefile(void); void makeenv(void); @@ -218,5 +222,7 @@ extern int versreq; extern char *PREFIX; /* Config file name - for error messages */ extern char srcdir[]; /* root of the kernel source tree */ +__END_DECLS; + #define eq(a,b) (!strcmp(a,b)) #define ns(s) strdup(s) diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 60bafb0b46ba..988c296d97ce 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -105,10 +105,9 @@ static void cleanheaders(char *); static void kernconfdump(const char *); static void badversion(void); static void checkversion(void); -extern int yyparse(void); struct hdr_list { - char *h_name; + const char *h_name; struct hdr_list *h_next; } *htab; @@ -620,10 +619,12 @@ moveifchanged(const char *from_name, const char *to_name) tsize = (size_t)from_sb.st_size; if (!changed) { - p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0); + p = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, + (off_t)0); if (p == MAP_FAILED) err(EX_OSERR, "mmap %s", from_name); - q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0); + q = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, + (off_t)0); if (q == MAP_FAILED) err(EX_OSERR, "mmap %s", to_name); @@ -688,7 +689,7 @@ cleanheaders(char *p) void remember(const char *file) { - char *s; + const char *s; struct hdr_list *hl; if ((s = strrchr(file, '/')) != NULL) @@ -697,16 +698,16 @@ remember(const char *file) s = ns(file); if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) { - free(s); + free(__DECONST(char *, s)); return; } for (hl = htab; hl != NULL; hl = hl->h_next) { if (eq(s, hl->h_name)) { - free(s); + free(__DECONST(char *, s)); return; } } - hl = calloc(1, sizeof(*hl)); + hl = (struct hdr_list *)calloc(1, sizeof(*hl)); if (hl == NULL) err(EXIT_FAILURE, "calloc"); hl->h_name = s; @@ -740,7 +741,7 @@ kernconfdump(const char *file) if (fp == NULL) err(EXIT_FAILURE, "fdopen() failed"); osz = 1024; - o = calloc(1, osz); + o = (char *)calloc(1, osz); if (o == NULL) err(EXIT_FAILURE, "Couldn't allocate memory"); /* ELF note section header. */ diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 4f3bd13ffca3..9f103c0e5214 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -392,9 +392,9 @@ read_file(char *fname) struct file_list *tp; struct device *dp; struct opt *op; - char *wd, *this, *compilewith, *depends, *clean, *warning; + char *wd, *rfile, *compilewith, *depends, *clean, *warning; const char *objprefix; - int compile, match, nreqs, std, filetype, not, + int compile, match, nreqs, std, filetype, negate, imp_rule, no_ctfconvert, no_obj, before_depend, nowerror; fp = fopen(fname, "r"); @@ -434,13 +434,13 @@ next: ; goto next; } - this = ns(wd); + rfile = ns(wd); wd = get_word(fp); if (wd == (char *)EOF) return; if (wd == NULL) - errout("%s: No type for %s.\n", fname, this); - tp = fl_lookup(this); + errout("%s: No type for %s.\n", fname, rfile); + tp = fl_lookup(rfile); compile = 0; match = 1; nreqs = 0; @@ -454,25 +454,25 @@ next: no_obj = 0; before_depend = 0; nowerror = 0; - not = 0; + negate = 0; filetype = NORMAL; objprefix = ""; if (eq(wd, "standard")) std = 1; else if (!eq(wd, "optional")) errout("%s: \"%s\" %s must be optional or standard\n", - fname, wd, this); + fname, wd, rfile); for (wd = get_word(fp); wd; wd = get_word(fp)) { if (wd == (char *)EOF) return; if (eq(wd, "!")) { - not = 1; + negate = 1; continue; } if (eq(wd, "|")) { if (nreqs == 0) errout("%s: syntax error describing %s\n", - fname, this); + fname, rfile); compile += match; match = 1; nreqs = 0; @@ -491,7 +491,7 @@ next: errout("%s: alternate rule required when " "\"no-implicit-rule\" is specified for" " %s.\n", - fname, this); + fname, rfile); imp_rule++; continue; } @@ -503,7 +503,7 @@ next: wd = get_quoted_word(fp); if (wd == (char *)EOF || wd == NULL) errout("%s: %s missing dependency string.\n", - fname, this); + fname, rfile); depends = ns(wd); continue; } @@ -511,7 +511,7 @@ next: wd = get_quoted_word(fp); if (wd == (char *)EOF || wd == NULL) errout("%s: %s missing clean file list.\n", - fname, this); + fname, rfile); clean = ns(wd); continue; } @@ -519,7 +519,7 @@ next: wd = get_quoted_word(fp); if (wd == (char *)EOF || wd == NULL) errout("%s: %s missing compile command string.\n", - fname, this); + fname, rfile); compilewith = ns(wd); continue; } @@ -527,7 +527,7 @@ next: wd = get_quoted_word(fp); if (wd == (char *)EOF || wd == NULL) errout("%s: %s missing warning text string.\n", - fname, this); + fname, rfile); warning = ns(wd); continue; } @@ -535,7 +535,7 @@ next: wd = get_quoted_word(fp); if (wd == (char *)EOF || wd == NULL) errout("%s: %s missing object prefix string.\n", - fname, this); + fname, rfile); objprefix = ns(wd); continue; } @@ -554,10 +554,10 @@ next: nreqs++; if (std) errout("standard entry %s has optional inclusion specifier %s!\n", - this, wd); + rfile, wd); STAILQ_FOREACH(dp, &dtab, d_next) if (eq(dp->d_name, wd)) { - if (not) + if (negate) match = 0; else dp->d_done |= DEVDONE; @@ -566,21 +566,21 @@ next: SLIST_FOREACH(op, &opt, op_next) if (op->op_value == 0 && strcasecmp(op->op_name, wd) == 0) { - if (not) + if (negate) match = 0; goto nextparam; } - match &= not; + match &= negate; nextparam:; - not = 0; + negate = 0; } compile += match; if (compile && tp == NULL) { if (std == 0 && nreqs == 0) errout("%s: what is %s optional on?\n", - fname, this); + fname, rfile); tp = new_fent(); - tp->f_fn = this; + tp->f_fn = rfile; tp->f_type = filetype; if (filetype == LOCAL) tp->f_srcprefix = ""; diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c index bf611cdb12c3..b93e56e3a491 100644 --- a/usr.sbin/config/mkoptions.c +++ b/usr.sbin/config/mkoptions.c @@ -312,41 +312,41 @@ tooption(char *name) static void -check_duplicate(const char *fname, const char *this) +check_duplicate(const char *fname, const char *chkopt) { struct opt_list *po; SLIST_FOREACH(po, &otab, o_next) { - if (eq(po->o_name, this)) { + if (eq(po->o_name, chkopt)) { fprintf(stderr, "%s: Duplicate option %s.\n", - fname, this); + fname, chkopt); exit(1); } } } static void -insert_option(const char *fname, char *this, char *val) +insert_option(const char *fname, char *optname, char *val) { struct opt_list *po; - check_duplicate(fname, this); + check_duplicate(fname, optname); po = (struct opt_list *) calloc(1, sizeof *po); if (po == NULL) err(EXIT_FAILURE, "calloc"); - po->o_name = this; + po->o_name = optname; po->o_file = val; po->o_flags = 0; SLIST_INSERT_HEAD(&otab, po, o_next); } static void -update_option(const char *this, char *val, int flags) +update_option(const char *optname, char *val, int flags) { struct opt_list *po; SLIST_FOREACH(po, &otab, o_next) { - if (eq(po->o_name, this)) { + if (eq(po->o_name, optname)) { free(po->o_file); po->o_file = val; po->o_flags = flags; @@ -364,7 +364,7 @@ static int read_option_file(const char *fname, int flags) { FILE *fp; - char *wd, *this, *val; + char *wd, *optname, *val; char genopt[MAXPATHLEN]; fp = fopen(fname, "r"); @@ -378,17 +378,17 @@ read_option_file(const char *fname, int flags) continue; continue; } - this = ns(wd); + optname = ns(wd); val = get_word(fp); if (val == (char *)EOF) return (1); if (val == NULL) { if (flags) { fprintf(stderr, "%s: compat file requires two" - " words per line at %s\n", fname, this); + " words per line at %s\n", fname, optname); exit(1); } - char *s = ns(this); + char *s = ns(optname); (void)snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s)); val = genopt; @@ -396,9 +396,9 @@ read_option_file(const char *fname, int flags) } val = ns(val); if (flags == 0) - insert_option(fname, this, val); + insert_option(fname, optname, val); else - update_option(this, val, flags); + update_option(optname, val, flags); } (void)fclose(fp); return (1);