From patchwork Tue Apr 13 21:51:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11923 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 55245BD224 for ; Tue, 13 Apr 2021 21:52:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 993B268809; Tue, 13 Apr 2021 23:52:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KNA/IAUj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB210602D1 for ; Tue, 13 Apr 2021 23:52:16 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FA51AF3 for ; Tue, 13 Apr 2021 23:52:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618350736; bh=OdOA7I3TFg4bsd78NxG1PZOAetj2BcqE6eUm8PeQvps=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KNA/IAUjP+tzamuhtYIsaOcTtR+vkWtu6/Blz0cHoJFV/bJxAXfzYYerSpeA4RQ// OrFfU7CffBO/eZ+TLrMU7Y27l8AaMbWlo71RNtJrng1BeRfZCD/pcOzSui82+vNXGr wWV31d2Im/ZE/KVpGTVPnLeM2+xUa0aynlK0h/lY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Apr 2021 00:51:21 +0300 Message-Id: <20210413215121.15538-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210413215121.15538-1-laurent.pinchart@ideasonboard.com> References: <20210413215121.15538-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: log: Use compiler builtins to retrieve file and line number X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the __FILE__ and __LINE__ values passed to the _log() function with default parameters, taking their values from the __builtin_FILE() and __builtin_LINE() functions. This moves handling of the file and line from the preprocessor to the compiler, which is generally preferred as it increases type safety. Signed-off-by: Laurent Pinchart Tested-by: Sebastian Fricke Reviewed-by: Kieran Bingham --- include/libcamera/internal/log.h | 15 ++++++++------- src/libcamera/log.cpp | 17 ++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h index 0fdacc4733fe..be0bab3c1272 100644 --- a/include/libcamera/internal/log.h +++ b/include/libcamera/internal/log.h @@ -89,21 +89,22 @@ public: protected: virtual std::string logPrefix() const = 0; - LogMessage _log(const char *file, unsigned int line, - const LogCategory *category, - LogSeverity severity) const; + LogMessage _log(const LogCategory *category, LogSeverity severity, + const char *fileName = __builtin_FILE(), + unsigned int line = __builtin_LINE()) const; }; -LogMessage _log(const char *file, unsigned int line, - const LogCategory *category, LogSeverity severity); +LogMessage _log(const LogCategory *category, LogSeverity severity, + const char *fileName = __builtin_FILE(), + unsigned int line = __builtin_LINE()); #ifndef __DOXYGEN__ #define _LOG_CATEGORY(name) logCategory##name #define _LOG1(severity) \ - _log(__FILE__, __LINE__, nullptr, Log##severity).stream() + _log(nullptr, Log##severity).stream() #define _LOG2(category, severity) \ - _log(__FILE__, __LINE__, &_LOG_CATEGORY(category)(), Log##severity).stream() + _log(&_LOG_CATEGORY(category)(), Log##severity).stream() /* * Expand the LOG() macro to _LOG1() or _LOG2() based on the number of diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index 9f86e645ac58..94175ab34535 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -897,19 +897,18 @@ Loggable::~Loggable() /** * \brief Create a temporary LogMessage object to log a message - * \param[in] fileName The file name where the message is logged from - * \param[in] line The line number where the message is logged from * \param[in] category The log message category * \param[in] severity The log message severity + * \param[in] fileName The file name where the message is logged from + * \param[in] line The line number where the message is logged from * * This method is used as a backeng by the LOG() macro to create a log message * for locations inheriting from the Loggable class. * * \return A log message */ -LogMessage Loggable::_log(const char *fileName, unsigned int line, - const LogCategory *category, - LogSeverity severity) const +LogMessage Loggable::_log(const LogCategory *category, LogSeverity severity, + const char *fileName, unsigned int line) const { LogMessage msg(fileName, line, category ? *category : LogCategory::defaultCategory(), @@ -921,18 +920,18 @@ LogMessage Loggable::_log(const char *fileName, unsigned int line, /** * \brief Create a temporary LogMessage object to log a message - * \param[in] fileName The file name where the message is logged from - * \param[in] line The line number where the message is logged from * \param[in] category The log message category * \param[in] severity The log message severity + * \param[in] fileName The file name where the message is logged from + * \param[in] line The line number where the message is logged from * * This function is used as a backeng by the LOG() macro to create a log * message for locations not inheriting from the Loggable class. * * \return A log message */ -LogMessage _log(const char *fileName, unsigned int line, - const LogCategory *category, LogSeverity severity) +LogMessage _log(const LogCategory *category, LogSeverity severity, + const char *fileName, unsigned int line) { return LogMessage(fileName, line, category ? *category : LogCategory::defaultCategory(),