From patchwork Fri Apr 26 15:01:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1109 Return-Path: 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 4AE5060E9D for ; Fri, 26 Apr 2019 17:02:10 +0200 (CEST) Received: from pendragon.station (net-37-182-44-227.cust.vodafonedsl.it [37.182.44.227]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DAE845F for ; Fri, 26 Apr 2019 17:02:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1556290930; bh=CWhpKrRm0/rXUC2F3qc0D6NMeUmhc48wGmzSSiqj2ek=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ze+tjT7B9boZqaTHk/havQubzbSrjzptxkx8AF2/XPBCmW/S7pdKJLNlJKkNelU2O 0s657hV20pSI7sGZm5HGLQro53OVOgPl2uohYyfsz7HVNCcWbIS0qX3HVY71M6bqhN w0UTEVIWs8TdfRZfO77AxfFCL6J8tRdUIOlt8fHg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Apr 2019 18:01:50 +0300 Message-Id: <20190426150155.18652-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190426150155.18652-1-laurent.pinchart@ideasonboard.com> References: <20190426150155.18652-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] libcamera: log: Add a LogInvalid entry to LogSeverity X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 15:02:10 -0000 enum LogSeverity values are assigned or compared to -1 to flag invalid log severities. This generates compilation warnings with clang. Fix it by adding an explicit LogInvalid entry to the enumeration. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/include/log.h | 3 ++- src/libcamera/log.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h index 35a6fc105448..802836d23bf2 100644 --- a/src/libcamera/include/log.h +++ b/src/libcamera/include/log.h @@ -12,7 +12,8 @@ namespace libcamera { enum LogSeverity { - LogDebug, + LogInvalid = -1, + LogDebug = 0, LogInfo, LogWarning, LogError, diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index ebf553300f5b..0ba276e5707f 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -174,7 +174,7 @@ void Logger::parseLogLevels() continue; LogSeverity severity = parseLogLevel(level); - if (severity == -1) + if (severity == LogInvalid) continue; levels_.push_back({ category, severity }); @@ -189,7 +189,7 @@ void Logger::parseLogLevels() * LogFatal, or as a string corresponding to the severity name in uppercase. Any * other value is invalid. * - * \return The log severity, or -1 if the string is invalid + * \return The log severity, or LogInvalid if the string is invalid */ LogSeverity Logger::parseLogLevel(const std::string &level) { @@ -207,9 +207,9 @@ LogSeverity Logger::parseLogLevel(const std::string &level) char *endptr; severity = strtoul(level.c_str(), &endptr, 10); if (*endptr != '\0' || severity > LogFatal) - severity = -1; + severity = LogInvalid; } else { - severity = -1; + severity = LogInvalid; for (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) { if (names[i] == level) { severity = i; @@ -416,13 +416,13 @@ LogMessage::LogMessage(const char *fileName, unsigned int line, * on the compiler type and version, and optimization level, the move * constructor is defined even if it will likely never be called, and ensures * that the destructor of the \a other message will not output anything to the - * log by setting the severity to -1. + * log by setting the severity to LogInvalid. */ LogMessage::LogMessage(LogMessage &&other) : msgStream_(std::move(other.msgStream_)), category_(other.category_), severity_(other.severity_) { - other.severity_ = static_cast(-1); + other.severity_ = LogInvalid; } void LogMessage::init(const char *fileName, unsigned int line) @@ -445,7 +445,7 @@ void LogMessage::init(const char *fileName, unsigned int line) LogMessage::~LogMessage() { /* Don't print anything if we have been moved to another LogMessage. */ - if (severity_ == -1) + if (severity_ == LogInvalid) return; msgStream_ << std::endl;