[{"id":33160,"web_url":"https://patchwork.libcamera.org/comment/33160/","msgid":"<20250124165722.GC13689@pendragon.ideasonboard.com>","date":"2025-01-24T16:57:22","subject":"Re: [RFC PATCH v1 2/7] libcamera: base: log: Use `std::from_chars()`","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 Tue, Jan 21, 2025 at 06:50:58PM +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\nNitpicking, you can reflow your commit messages up to 72 columns.\n\n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\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 61a43d525..1024fed7f 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> @@ -686,12 +687,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, 10);\n\nHere it would be nice to shorten the string :-)\n\n\t\tauto [end, ec] = std::from_chars(level.data(), level.data() + level.size(),\n\t\t\t\t\t\t severity, 10);\n\nYou can also drop the last argument, as it's the default.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\tif (ec != std::errc() || *end != '\\0' || severity > LogFatal)\n>  \t\t\tseverity = LogInvalid;\n>  \t} else {\n>  \t\tseverity = LogInvalid;\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 52B9DC322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Jan 2025 16:57:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3FCC86855D;\n\tFri, 24 Jan 2025 17:57:34 +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 36AE468556\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jan 2025 17:57:32 +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 A5B2921C;\n\tFri, 24 Jan 2025 17:56:27 +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=\"tcgtBtCc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737737787;\n\tbh=qWwpx0bCVB7vYynmV9hyr8E1YJGnwlOiHzKCNXoiJIs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tcgtBtCcexByKRnmkdfx37ZnEyj5EVDFzfRAufSXIfIMjNu8KeLkPL80CasING7Uq\n\tEdhV4bOERo2MqP1CX/zm+nGZVQduuQWhjBRFLtzhK6cif3/JzWdPRixV95a9+BMg1F\n\tXOXIrVzOZXduv5SxN5WtDoJr75YbIh9jPLGnIoPY=","Date":"Fri, 24 Jan 2025 18:57:22 +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: [RFC PATCH v1 2/7] libcamera: base: log: Use `std::from_chars()`","Message-ID":"<20250124165722.GC13689@pendragon.ideasonboard.com>","References":"<20250121185044.300816-1-pobrn@protonmail.com>\n\t<20250121185044.300816-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":"<20250121185044.300816-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>"}}]