From df1d955d24d113771bd8fedc3bde7f230c059fb7 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 14 Apr 2021 00:26:39 +0300 Subject: libcamera: log: Use compiler builtins to retrieve file and line number 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 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h index 0fdacc47..be0bab3c 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 -- cgit v1.2.1