{"id":11923,"url":"https://patchwork.libcamera.org/api/1.1/patches/11923/?format=json","web_url":"https://patchwork.libcamera.org/patch/11923/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210413215121.15538-3-laurent.pinchart@ideasonboard.com>","date":"2021-04-13T21:51:21","name":"[libcamera-devel,2/2] libcamera: log: Use compiler builtins to retrieve file and line number","commit_ref":"df1d955d24d113771bd8fedc3bde7f230c059fb7","pull_url":null,"state":"accepted","archived":false,"hash":"e80b0ba7c0b7a39d4c24fd82eab5dfceb4809489","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11923/mbox/","series":[{"id":1924,"url":"https://patchwork.libcamera.org/api/1.1/series/1924/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1924","date":"2021-04-13T21:51:19","name":"libcamera: log: Small improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/1924/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11923/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11923/checks/","tags":{},"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 55245BD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 21:52:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 993B268809;\n\tTue, 13 Apr 2021 23:52:18 +0200 (CEST)","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 EB210602D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 23:52:16 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FA51AF3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 23:52:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KNA/IAUj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1618350736;\n\tbh=OdOA7I3TFg4bsd78NxG1PZOAetj2BcqE6eUm8PeQvps=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=KNA/IAUjP+tzamuhtYIsaOcTtR+vkWtu6/Blz0cHoJFV/bJxAXfzYYerSpeA4RQ//\n\tOrFfU7CffBO/eZ+TLrMU7Y27l8AaMbWlo71RNtJrng1BeRfZCD/pcOzSui82+vNXGr\n\twWV31d2Im/ZE/KVpGTVPnLeM2+xUa0aynlK0h/lY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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\n\tto retrieve file and line number","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Replace the __FILE__ and __LINE__ values passed to the _log() function\nwith default parameters, taking their values from the __builtin_FILE()\nand __builtin_LINE() functions. This moves handling of the file and line\nfrom the preprocessor to the compiler, which is generally preferred as\nit increases type safety.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/log.h | 15 ++++++++-------\n src/libcamera/log.cpp            | 17 ++++++++---------\n 2 files changed, 16 insertions(+), 16 deletions(-)","diff":"diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h\nindex 0fdacc4733fe..be0bab3c1272 100644\n--- a/include/libcamera/internal/log.h\n+++ b/include/libcamera/internal/log.h\n@@ -89,21 +89,22 @@ public:\n protected:\n \tvirtual std::string logPrefix() const = 0;\n \n-\tLogMessage _log(const char *file, unsigned int line,\n-\t\t\tconst LogCategory *category,\n-\t\t\tLogSeverity severity) const;\n+\tLogMessage _log(const LogCategory *category, LogSeverity severity,\n+\t\t\tconst char *fileName = __builtin_FILE(),\n+\t\t\tunsigned int line = __builtin_LINE()) const;\n };\n \n-LogMessage _log(const char *file, unsigned int line,\n-\t\tconst LogCategory *category, LogSeverity severity);\n+LogMessage _log(const LogCategory *category, LogSeverity severity,\n+\t\tconst char *fileName = __builtin_FILE(),\n+\t\tunsigned int line = __builtin_LINE());\n \n #ifndef __DOXYGEN__\n #define _LOG_CATEGORY(name) logCategory##name\n \n #define _LOG1(severity) \\\n-\t_log(__FILE__, __LINE__, nullptr, Log##severity).stream()\n+\t_log(nullptr, Log##severity).stream()\n #define _LOG2(category, severity) \\\n-\t_log(__FILE__, __LINE__, &_LOG_CATEGORY(category)(), Log##severity).stream()\n+\t_log(&_LOG_CATEGORY(category)(), Log##severity).stream()\n \n /*\n  * Expand the LOG() macro to _LOG1() or _LOG2() based on the number of\ndiff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex 9f86e645ac58..94175ab34535 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -897,19 +897,18 @@ Loggable::~Loggable()\n \n /**\n  * \\brief Create a temporary LogMessage object to log a message\n- * \\param[in] fileName The file name where the message is logged from\n- * \\param[in] line The line number where the message is logged from\n  * \\param[in] category The log message category\n  * \\param[in] severity The log message severity\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n  *\n  * This method is used as a backeng by the LOG() macro to create a log message\n  * for locations inheriting from the Loggable class.\n  *\n  * \\return A log message\n  */\n-LogMessage Loggable::_log(const char *fileName, unsigned int line,\n-\t\t\t  const LogCategory *category,\n-\t\t\t  LogSeverity severity) const\n+LogMessage Loggable::_log(const LogCategory *category, LogSeverity severity,\n+\t\t\t  const char *fileName, unsigned int line) const\n {\n \tLogMessage msg(fileName, line,\n \t\t       category ? *category : LogCategory::defaultCategory(),\n@@ -921,18 +920,18 @@ LogMessage Loggable::_log(const char *fileName, unsigned int line,\n \n /**\n  * \\brief Create a temporary LogMessage object to log a message\n- * \\param[in] fileName The file name where the message is logged from\n- * \\param[in] line The line number where the message is logged from\n  * \\param[in] category The log message category\n  * \\param[in] severity The log message severity\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n  *\n  * This function is used as a backeng by the LOG() macro to create a log\n  * message for locations not inheriting from the Loggable class.\n  *\n  * \\return A log message\n  */\n-LogMessage _log(const char *fileName, unsigned int line,\n-\t\tconst LogCategory *category, LogSeverity severity)\n+LogMessage _log(const LogCategory *category, LogSeverity severity,\n+\t\tconst char *fileName, unsigned int line)\n {\n \treturn LogMessage(fileName, line,\n \t\t\t  category ? *category : LogCategory::defaultCategory(),\n","prefixes":["libcamera-devel","2/2"]}