[{"id":33261,"web_url":"https://patchwork.libcamera.org/comment/33261/","msgid":"<n3yyswbr73cbac3oyf2ypxqcyfd45viucf5eagwzizi6gktqxy@3rhch57bmvyn>","date":"2025-02-03T16:25:51","subject":"Re: [RFC PATCH v2 2/9] libcamera: base: log: Use `std::from_chars()`","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 Thu, Jan 30, 2025 at 07:58:25PM +0000, Barnabás Pőcze wrote:\n> Use the `std::from_chars()` function from `<charconv>` to\n> parse the integral log level instead of `strtoul` as it\n> provides an easier to use interface and better type safety.\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\nThanks\n  j\n\n> ---\n>  src/libcamera/base/log.cpp | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index 1917c3254..31053aee1 100644\n> --- a/src/libcamera/base/log.cpp\n> +++ b/src/libcamera/base/log.cpp\n> @@ -8,6 +8,7 @@\n>  #include <libcamera/base/log.h>\n>\n>  #include <array>\n> +#include <charconv>\n>  #include <fstream>\n>  #include <iostream>\n>  #include <list>\n> @@ -685,12 +686,11 @@ LogSeverity Logger::parseLogLevel(const std::string &level)\n>  \t\t\"FATAL\",\n>  \t};\n>\n> -\tint severity;\n> +\tunsigned int severity;\n>\n>  \tif (std::isdigit(level[0])) {\n> -\t\tchar *endptr;\n> -\t\tseverity = strtoul(level.c_str(), &endptr, 10);\n> -\t\tif (*endptr != '\\0' || severity > LogFatal)\n> +\t\tauto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);\n> +\t\tif (ec != std::errc() || *end != '\\0' || severity > LogFatal)\n>  \t\t\tseverity = LogInvalid;\n>  \t} else {\n>  \t\tseverity = LogInvalid;\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 CA7B9BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  3 Feb 2025 16:25:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3186968599;\n\tMon,  3 Feb 2025 17:25:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D8F866858D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Feb 2025 17:25:54 +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 3F78C497;\n\tMon,  3 Feb 2025 17:24:43 +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=\"fWVL4JEa\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1738599883;\n\tbh=zeZffMkZPZjpftPPviF2eVHayFBw97+zmYwkPQff9fI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fWVL4JEaZZkgHF/9dSAQur4G0G7AskjyHqSYjrHOZuM5JnuEiKHdfINeACfEKA/Tr\n\t8lo/JRkmSuuHsODQkcVJNbgHICHydsCyK0xal5/2VBlxx1LuDxxiK7y3eDkXmbLTzt\n\tcPbhZQ2RQNQuvPLIOxQ5f6TLX8yKPnlSX/CCLjKA=","Date":"Mon, 3 Feb 2025 17:25:51 +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: [RFC PATCH v2 2/9] libcamera: base: log: Use `std::from_chars()`","Message-ID":"<n3yyswbr73cbac3oyf2ypxqcyfd45viucf5eagwzizi6gktqxy@3rhch57bmvyn>","References":"<20250130195811.1230581-1-pobrn@protonmail.com>\n\t<20250130195811.1230581-3-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250130195811.1230581-3-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>"}}]