[{"id":33493,"web_url":"https://patchwork.libcamera.org/comment/33493/","msgid":"<sagqmeqyy6mnjq3ksmj6wrvkq74acxtxwu7aice3os3pbfhjlj@kwjibohzi224>","date":"2025-02-26T07:55:33","subject":"Re: [PATCH v4 8/8] libcamera: base: log: Avoid manual `LogCategory`\n\tdeletion","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Tue, Feb 25, 2025 at 05:36:22PM +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> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.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 155355f0c..72614eeb1 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::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>  \tconst char *categoryName = category->name().c_str();\n>\n>  \tfor (const auto &[pattern, severity] : levels_) {\n> --\n> 2.48.1\n>\n>","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 BDE74C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Feb 2025 07:55:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EAAF268743;\n\tWed, 26 Feb 2025 08:55:39 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D428B6873F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Feb 2025 08:55:37 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F09E7502;\n\tWed, 26 Feb 2025 08:54:09 +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=\"vFVJaerC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740556450;\n\tbh=v7E6Nj8LBhUDSw4deOVSyzEkhcZSUUKHow3/p9O8cXM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=vFVJaerCh4B0U0DCQcT7R39X/0uZQvkKcf4v8Sqj9omkAkeXqrDQ2Z6pKvoJhKCQR\n\tEvh8b9s6vFE6bHDHDhvuQAi8a0duOkMN/W2tTLt2oUub/vuMxmhLxb07IFCxq0/4ot\n\tlC5a3tA9GWENSKd5wrSuAMuioMn3XZvS0ojPm/AU=","Date":"Wed, 26 Feb 2025 08:55:33 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v4 8/8] libcamera: base: log: Avoid manual `LogCategory`\n\tdeletion","Message-ID":"<sagqmeqyy6mnjq3ksmj6wrvkq74acxtxwu7aice3os3pbfhjlj@kwjibohzi224>","References":"<20250225173531.2595922-1-pobrn@protonmail.com>\n\t<20250225173531.2595922-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":"<20250225173531.2595922-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>"}}]