From nobody Mon Aug 4 19:46:54 2025 X-Original-To: dev-commits-src-main@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 4bwnBR41Jlz63RGb; Mon, 04 Aug 2025 19:46:55 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bwnBR0cWFz4KwC; Mon, 04 Aug 2025 19:46:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754336815; 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=AL2UsqefGSgG0LEtvlfFVI+As81466u0EoHprb8Misw=; b=byQakSAH8yVQ7y1KalqBmKCKBvLxcD/LEGDrrJm6b/m1y3JcuEPRTTKBDvqA+loWwIsEkg x+/WlxFfxsBYnngdPRElaxiu9ETspJiKhW5kWZwFOq4pHBQEC9r/0kB0VAYx3IlqJWsTU9 mpLw8L6AKhRD96WZLezi1t2x8Fi8M5sbLlkGdo9ILtx1xeEMoTFGaF9yH/boUONJoLkGT/ Fbb7hLLGULg5AVsWULnfZ/BGIC5kDHsAgY4ZphG0F+MzgNaeLNjcS86SjzjpCbGxgaB3ND n2wQKHlZ5seW1ZCUi4PhluZddsxRjqlpgbu3bVyfxJWj/FowkOvRu6G7ksSPyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754336815; 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=AL2UsqefGSgG0LEtvlfFVI+As81466u0EoHprb8Misw=; b=WVdtNUDGWQfCkOtiZqIOTNJxUFYnTlx7icLwOvfc2ESnV2cod1lYlJ0yz1tYCx9uljejZn 2BDWbyEFmU/hs0NE9XYE9K7AaUDjF17PzYGwZ3EEkiaK4wIEeCxqpfBnOJPHg46QrdDFqY INVuhLtGDe+nmCVdIMyWWMC7FrAHpb/ExZNyfmjHQJhThmcYH6oXv2/Hx/9lX1kJoQqC0w 2hgw1OnnfxDs/8Qc5xyRePwv65X5HHeHOwANd1WQLcoRarwMoeLyTx+kooPIgix0ds9foc bJdZML+eDf5NGdn89QLxKe78Zw60wXGMWW6eAcZJ5d8oGlUj3lbKpgKwQxDDDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754336815; a=rsa-sha256; cv=none; b=UwLSkxY5m/SrpnNd1a7V7hDnjyxEPgLyTmEHihT610Jv9WaLHtsZabmcBJkWrudJAPHztD JV48xJomuxCcSx6X1t4vpVnaCkV1mEvF0rS2FSjwgVhYWVkmI2pObsAx5N1TCLSIdoJYcC nw/oEfIY47xM5qu4S9jzPBeGSorXzgMtNMz6eochfrTPHOAqByMciBZXLa+TWeiT6xdmin nFsVz6veaocxhOfRLRuBL2zny46Pu5/ZH3TIVNgpDG2UbN6D5r6RvOiPs2RGr4I6kc42sm zzaFqdtFPDBgnknk2Fy5PtygmfiRMARhQtRqI5QTSLWIokKMszjSKJ0Sa2lYbw== 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 4bwnBQ67MQz12f6; Mon, 04 Aug 2025 19:46:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 574Jksd5099286; Mon, 4 Aug 2025 19:46:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 574JksX9099283; Mon, 4 Aug 2025 19:46:54 GMT (envelope-from git) Date: Mon, 4 Aug 2025 19:46:54 GMT Message-Id: <202508041946.574JksX9099283@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 63ffcf6971a3 - main - libutil++: Add freebsd::nvlist_up wrapper class for std::unique_ptr<> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 63ffcf6971a36e00efc138c3261b499aa48e102f Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=63ffcf6971a36e00efc138c3261b499aa48e102f commit 63ffcf6971a36e00efc138c3261b499aa48e102f Author: John Baldwin AuthorDate: 2025-08-04 19:38:07 +0000 Commit: John Baldwin CommitDate: 2025-08-04 19:38:07 +0000 libutil++: Add freebsd::nvlist_up wrapper class for std::unique_ptr<> This class uses a custom deleter that calls nvlist_destroy(). Sponsored by: Chelsio Communications Pull Request: https://github.com/freebsd/freebsd-src/pull/1794 --- lib/libutil++/Makefile | 1 + lib/libutil++/freebsd::nvlist_up.3 | 37 +++++++++++++++++++++++++++++++++++++ lib/libutil++/libutil++.hh | 14 ++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/lib/libutil++/Makefile b/lib/libutil++/Makefile index e64c9fe6cb75..3389e7e21b11 100644 --- a/lib/libutil++/Makefile +++ b/lib/libutil++/Makefile @@ -8,6 +8,7 @@ MAN+= freebsd::FILE_up.3 \ freebsd::addrinfo_up.3 \ freebsd::fd_up.3 \ freebsd::malloc_up.3 \ + freebsd::nvlist_up.3 \ freebsd::stringf.3 .include diff --git a/lib/libutil++/freebsd::nvlist_up.3 b/lib/libutil++/freebsd::nvlist_up.3 new file mode 100644 index 000000000000..43f76cf3ead3 --- /dev/null +++ b/lib/libutil++/freebsd::nvlist_up.3 @@ -0,0 +1,37 @@ +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2025 Chelsio Communications, Inc. +.\" Written by: John Baldwin +.\" +.Dd July 31, 2025 +.Dt FREEBSD::NVLIST_UP 3 +.Os +.Sh NAME +.Nm freebsd::nvlist_up +.Nd std::unique_ptr specialization for name/value pairs +.Sh LIBRARY +.Lb libutil++ +.Sh SYNOPSIS +.In libutil++.hh +.Ft using nvlist_up = std::unique_ptr; +.Sh DESCRIPTION +This class is a specialization of +.Vt std::unique_ptr +for +.Vt nvlist_t +objects. +When an +.Vt nvlist_t +object managed by an instance of this class is disposed, +.Xr nvlist_destroy 3 +is invoked to dispose of the object. +.Sh EXAMPLES +.Bd -literal -offset indent +freebsd::nvlist_up nvl(nvlist_create(0)); +nvlist_add_number(nvl.get(), "answer", 42); +nvlist_add_bool(nvl.get(), "valid", true); +// `nvl' is implicitly destroyed +.Ed +.Sh SEE ALSO +.Xr nvlist_destroy 3 diff --git a/lib/libutil++/libutil++.hh b/lib/libutil++/libutil++.hh index 616bbecd8a12..121633c4deea 100644 --- a/lib/libutil++/libutil++.hh +++ b/lib/libutil++/libutil++.hh @@ -8,6 +8,7 @@ #ifndef __LIBUTILPP_HH__ #define __LIBUTILPP_HH__ +#include #include #include @@ -131,6 +132,19 @@ namespace freebsd { template using malloc_up = std::unique_ptr>; + /* + * nvlist_up is a std::unique_ptr<> for nvlist_t objects which + * uses nvlist_destroy() to destroy the wrapped pointer. + */ + struct nvlist_deleter { + void operator() (nvlist_t *nvl) const + { + nvlist_destroy(nvl); + } + }; + + using nvlist_up = std::unique_ptr; + /* * Returns a std::string containing the same output as * sprintf(). Throws std::bad_alloc if an error occurs.