[{"id":33420,"web_url":"https://patchwork.libcamera.org/comment/33420/","msgid":"<20250223235303.GB17974@pendragon.ideasonboard.com>","date":"2025-02-23T23:53:03","subject":"Re: [PATCH v3 8/8] libcamera: base: log: Avoid manual `LogCategory`\n\tdeletion","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Mon, Feb 17, 2025 at 06:55:10PM +0000, Barnabás Pőcze wrote:\n> Wrap the `LogCategory` pointers in `std::unique_ptr` to avoid\n> the need for manual deletion in the destructor.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/libcamera/base/log.cpp | 13 +++++--------\n>  1 file changed, 5 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index fd6c11716..e05ffc1c4 100644\n> --- a/src/libcamera/base/log.cpp\n> +++ b/src/libcamera/base/log.cpp\n> @@ -322,7 +322,7 @@ private:\n>  \tstatic bool destroyed_;\n>  \n>  \tMutex mutex_;\n> -\tstd::vector<LogCategory *> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n> +\tstd::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n>  \tstd::list<std::pair<std::string, LogSeverity>> levels_;\n>  \n>  \tstd::atomic<std::shared_ptr<LogOutput>> output_;\n> @@ -439,9 +439,6 @@ void logSetLevel(const char *category, const char *level)\n>  Logger::~Logger()\n>  {\n>  \tdestroyed_ = true;\n> -\n> -\tfor (LogCategory *category : categories_)\n> -\t\tdelete category;\n>  }\n>  \n>  /**\n> @@ -574,7 +571,7 @@ void Logger::logSetLevel(const char *category, const char *level)\n>  \n>  \tMutexLocker locker(mutex_);\n>  \n> -\tfor (LogCategory *c : categories_) {\n> +\tfor (const auto &c : categories_) {\n>  \t\tif (c->name() == category) {\n>  \t\t\tc->setSeverity(severity);\n>  \t\t\tbreak;\n> @@ -718,12 +715,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name)\n>  {\n>  \tMutexLocker locker(mutex_);\n>  \n> -\tfor (LogCategory *category : categories_) {\n> +\tfor (const auto &category : categories_) {\n>  \t\tif (category->name() == name)\n> -\t\t\treturn category;\n> +\t\t\treturn category.get();\n>  \t}\n>  \n> -\tLogCategory *category = categories_.emplace_back(new LogCategory(name));\n> +\tLogCategory *category = categories_.emplace_back(std::unique_ptr<LogCategory>(new LogCategory(name))).get();\n\nI was going to write\n\n\tLogCategory *category = categories_.emplace_back(std::make_unique<LogCategory>(name)).get();\n\nbut the constructor is private. If we want to shorten the line,\n\n\tstd::unique_ptr<LogCategory> cat{ new LogCategory(name) };\n\tLogCategory *category = categories_.emplace_back(std::move(cat)).get();\n\nUp to you.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \tconst char *name_cstr = category->name().c_str();\n>  \n>  \tfor (const auto &[pattern, severity] : levels_) {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 232E3C32A9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 23 Feb 2025 23:53:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1AA5A686BC;\n\tMon, 24 Feb 2025 00:53:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9984B6185A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Feb 2025 00:53:20 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 38C70353;\n\tMon, 24 Feb 2025 00:51:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nyfpoNx9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740354714;\n\tbh=U1BTgfn/X8v3g9r0x3vXjns+e4K8XP/ibkD81NuYy8U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nyfpoNx9JvaCYeWOtz59bnSITmFDEtvQSfBFBjllqabz/6mY1vPPvt1D60bgh8rla\n\t3bhMxmUeBoeIPmLj7VSytYaIp2hkNK1xcy0T7GuwTaOd3EWpJZrYVDqMUa7cVz18uW\n\tiR9UNVjEB6UvrhrO1La8/506RE7U4SC11pt28LIA=","Date":"Mon, 24 Feb 2025 01:53:03 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 8/8] libcamera: base: log: Avoid manual `LogCategory`\n\tdeletion","Message-ID":"<20250223235303.GB17974@pendragon.ideasonboard.com>","References":"<20250217185433.306833-1-pobrn@protonmail.com>\n\t<20250217185433.306833-9-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250217185433.306833-9-pobrn@protonmail.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]