From nobody Wed Feb 08 06:10:24 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 4PBV3P12n5z3km7d; Wed, 8 Feb 2023 06:10:25 +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 4PBV3N6W6Hz3Fw4; Wed, 8 Feb 2023 06:10:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675836624; 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=ngB6VurBbmrMXZCC/yHd2rN80QUi+1s+TBFUpKcAt2A=; b=VZ2r471XKZe8Zeadb4D1VvtUYz1O5wr6Dsq+BFPQttDP/FyvuRIavqiCFRRne80RqTvNBN IBsBpXcCQUXnlrLhwq+lPbcI/P/UlE0a9ip4pgiEqd6ECVbQZjZSUj6EfFrifpdVIW3b75 PRERjgdK8s16DnbKZV0QUGf+X5pW/y1TKTUbu1acT5//vCERkqAX8ToiOv3BgUWHO51G+j q5RD6H2FV1WyIn27CSWyw+dkWO/jxROwIi9/Ux14chsUss6W+8ny7ySrW5VsHpIVp+ag9F AN4o7nHMmiO5UUwz9+BnmIgvKNCmsSe1X8m2FjfqOTQilB7iNMjRc4EQr9eCHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675836624; 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=ngB6VurBbmrMXZCC/yHd2rN80QUi+1s+TBFUpKcAt2A=; b=Ywp3l1GTNbz6qMLohpG2wWt9lrP2vMN8+Uz9YaCY7AOJek8FXPzINOhD1B4lq4027/eMxn 8mW4eJTXzxhQI/ltFNen4LYJNUPeTJSujekEDEfVaRLCGb9t5OqCiuk9HSpyF1yaw3y7kr 0q2Hb6qHwuIHYNd98Z1ZUQvi7kcpA5V3jigKL0MO/c9Y4fB+53r0WEGk5kNgnOHfNPAz1Y DjGoCp3a6dbJKOXeUuzYR1emtPV5di46EoptHiGM/v47Irn+xgZ0iyJFpBeknUbX249UEP nM9wZdPKY59olO3NwG2FVB7u3ZrEOQlJ1froaebd2CZchI9fu1s2u0JoALoVqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675836624; a=rsa-sha256; cv=none; b=vMTUG2zw1HHxf+50fX2z1xgKlitlQngLbSVFYDYLnU/YSU0UaxbrHpGEkQEchDSP3rb1/7 SrUTZ+RbVbPDWe15epU3334COIwpaxH8pa155OwA8aNbmHjWX7kh1ccukpOT3tlh1EJgdB oE8Eu1whtx6mJ6ihTVogyPWLel9g44sn+IE1Fk3dqgIcr5Li4tBwr/+SmKX84ysiZ4jnZZ TrCVfHF8bLAOeOVgSU7Pg+09he9yZ6o+misBP6DdNMmHOyfYmt6Cn0UkOoYc35jqw8CNFt Erc6oZ6/bePLT/vZSVElaYtJWI7DZuezgyvGUig2/jREtjXbwD/UxhAw9wWqMg== 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 4PBV3N5MP7zmS7; Wed, 8 Feb 2023 06:10:24 +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 3186AOQb091193; Wed, 8 Feb 2023 06:10:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3186AOCE091192; Wed, 8 Feb 2023 06:10:24 GMT (envelope-from git) Date: Wed, 8 Feb 2023 06:10:24 GMT Message-Id: <202302080610.3186AOCE091192@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: 29c5f8bf9a01 - main - config: drop dependency on libnv 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: 29c5f8bf9a011d92462977bae59b4889ec5d95ad Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=29c5f8bf9a011d92462977bae59b4889ec5d95ad commit 29c5f8bf9a011d92462977bae59b4889ec5d95ad Author: Kyle Evans AuthorDate: 2023-02-08 06:02:56 +0000 Commit: Kyle Evans CommitDate: 2023-02-08 06:09:19 +0000 config: drop dependency on libnv Compile mkmakefile.c as C++ instead and use an std::unordered_map to accomplish the same goal. Reviewed by: imp Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D38275 --- usr.sbin/config/Makefile | 6 +-- usr.sbin/config/{mkmakefile.c => mkmakefile.cc} | 52 ++++++++++--------------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/usr.sbin/config/Makefile b/usr.sbin/config/Makefile index 32bfa8de0a0e..241a501f52af 100644 --- a/usr.sbin/config/Makefile +++ b/usr.sbin/config/Makefile @@ -3,9 +3,9 @@ SRCDIR:=${.PARSEDIR:tA} -PROG= config +PROG_CXX= config MAN= config.5 config.8 -SRCS= config.y main.c lang.l mkmakefile.c mkheaders.c \ +SRCS= config.y main.c lang.l mkmakefile.cc mkheaders.c \ mkoptions.c y.tab.h kernconf.c FILE2C?=file2c @@ -18,7 +18,7 @@ CFLAGS+= -I. -I${SRCDIR} NO_WMISSING_VARIABLE_DECLARATIONS= -LIBADD= nv sbuf +LIBADD= sbuf CLEANFILES+= kernconf.c diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.cc similarity index 95% rename from usr.sbin/config/mkmakefile.c rename to usr.sbin/config/mkmakefile.cc index 9f103c0e5214..2aabb9e0f347 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.cc @@ -42,6 +42,7 @@ static const char rcsid[] = * the information in the files files and the * additional files for the machine being compiled to. */ +#include #include #include @@ -49,13 +50,15 @@ static const char rcsid[] = #include #include #include -#include -#include -#include +#include +#include + #include "y.tab.h" #include "config.h" #include "configvers.h" +typedef std::unordered_map env_map; + static char *tail(char *); static void do_clean(FILE *); static void do_rules(FILE *); @@ -66,8 +69,8 @@ static void read_files(void); static void sanitize_envline(char *result, const char *src); static bool preprocess(char *line, char *result); static void process_into_file(char *line, FILE *ofp); -static void process_into_nvlist(char *line, nvlist_t *nvl); -static void dump_nvlist(nvlist_t *nvl, FILE *ofp); +static void process_into_map(char *line, env_map &emap); +static void dump_map(env_map &emap, FILE *ofp); static void errout(const char *fmt, ...) { @@ -267,35 +270,24 @@ process_into_file(char *line, FILE *ofp) } static void -process_into_nvlist(char *line, nvlist_t *nvl) +process_into_map(char *line, env_map &emap) { char result[BUFSIZ], *s; if (preprocess(line, result)) { s = strchr(result, '='); *s = '\0'; - if (nvlist_exists(nvl, result)) - nvlist_free(nvl, result); - nvlist_add_string(nvl, result, s + 1); + emap[result] = s + 1; } } static void -dump_nvlist(nvlist_t *nvl, FILE *ofp) +dump_map(env_map &emap, FILE *ofp) { - const char *name; - void *cookie; - - if (nvl == NULL) - return; - - while (!nvlist_empty(nvl)) { - cookie = NULL; - name = nvlist_next(nvl, NULL, &cookie); - fprintf(ofp, "\"%s=%s\\0\"\n", name, - cnvlist_get_string(cookie)); - cnvlist_free_string(cookie); + for (auto iter : emap) { + fprintf(ofp, "\"%s=%s\\0\"\n", iter.first.c_str(), + iter.second.c_str()); } } @@ -306,7 +298,7 @@ void makehints(void) { FILE *ifp, *ofp; - nvlist_t *nvl; + env_map emap; char line[BUFSIZ]; struct hint *hint; @@ -324,17 +316,15 @@ makehints(void) fprintf(ofp, "int hintmode = %d;\n", !STAILQ_EMPTY(&hints) ? 1 : 0); fprintf(ofp, "char static_hints[] = {\n"); - nvl = nvlist_create(0); STAILQ_FOREACH(hint, &hints, hint_next) { ifp = fopen(hint->hint_name, "r"); if (ifp == NULL) err(1, "%s", hint->hint_name); while (fgets(line, BUFSIZ, ifp) != NULL) - process_into_nvlist(line, nvl); - dump_nvlist(nvl, ofp); + process_into_map(line, emap); + dump_map(emap, ofp); fclose(ifp); } - nvlist_destroy(nvl); fprintf(ofp, "\"\\0\"\n};\n"); fclose(ofp); moveifchanged(path("hints.c.new"), path("hints.c")); @@ -347,7 +337,7 @@ void makeenv(void) { FILE *ifp, *ofp; - nvlist_t *nvl; + env_map emap; char line[BUFSIZ]; struct envvar *envvar; @@ -365,20 +355,18 @@ makeenv(void) fprintf(ofp, "int envmode = %d;\n", !STAILQ_EMPTY(&envvars) ? 1 : 0); fprintf(ofp, "char static_env[] = {\n"); - nvl = nvlist_create(0); STAILQ_FOREACH(envvar, &envvars, envvar_next) { if (envvar->env_is_file) { ifp = fopen(envvar->env_str, "r"); if (ifp == NULL) err(1, "%s", envvar->env_str); while (fgets(line, BUFSIZ, ifp) != NULL) - process_into_nvlist(line, nvl); - dump_nvlist(nvl, ofp); + process_into_map(line, emap); + dump_map(emap, ofp); fclose(ifp); } else process_into_file(envvar->env_str, ofp); } - nvlist_destroy(nvl); fprintf(ofp, "\"\\0\"\n};\n"); fclose(ofp); moveifchanged(path("env.c.new"), path("env.c"));