From patchwork Thu May 7 13:50:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 26675 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 82930BDCB5 for ; Thu, 7 May 2026 13:50:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2283062FE1; Thu, 7 May 2026 15:50:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WHiaXJRj"; 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 2A16862010 for ; Thu, 7 May 2026 15:50:23 +0200 (CEST) Received: from pb-laptop.local (185.221.140.217.nat.pool.zt.hu [185.221.140.217]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F257A9CE for ; Thu, 7 May 2026 15:50:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778161819; bh=Cbz7nGOmKR6jtyclUktyqIFsQT2l1B7AgHO3NPLOyY0=; h=From:To:Subject:Date:From; b=WHiaXJRjkJfxiojNCTTkBknEf8Rs40uHZoR/hhrsjmzC//LY2o+nZ6BJhI2d8CCKJ PyhNr+GX3X9KUECzjbRr/ekMq7h4egA1pOrFrIVx9u1DoX/6W8jqMC45YDNlA1v6Up 29IEqM/cFj/hSc0zOfbQs8LbdtaP7sNV4UFaGIsM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1 1/2] libcamera: base: log: Remove log level check for "Fatal" messages Date: Thu, 7 May 2026 15:50:18 +0200 Message-ID: <20260507135019.231615-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 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" When a fatal log message is used, it is expected that it will be displayed and will in some way abort the execution. Since the log level of each message is known at compile time, the log level check can be short-circuited if a fatal message is intended. This also essentially reverts 2318a2863baa ("libcamera: base: log: Inline `LOG()` into `ASSERT()`") as there is no need to inline the `_log()` calls to avoid the runtime condition. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/base/log.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index 0751387a4..5cb14311e 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -108,10 +108,22 @@ LogMessage _log(const LogCategory &category, LogSeverity severity, #ifndef __DOXYGEN__ #define _LOG_CATEGORY(name) logCategory##name -#define _LOG(cat, sev) \ - switch (const auto &_logCategory = (cat); \ - static_cast(_logCategory.severity() <= Log##sev)) \ - case 1: \ +/* Returns `int` to avoid `-Wswitch-bool` below. */ +template +constexpr int isLogSeverityEnabled(const LogCategory &category) +{ + static_assert(LogDebug <= Severity && Severity <= LogFatal); + + if constexpr (Severity < LogFatal) + return static_cast(category.severity()) <= Severity; + else + return true; +} + +#define _LOG(cat, sev) \ + switch (const auto &_logCategory = (cat); \ + isLogSeverityEnabled(_logCategory)) \ + case 1: \ _log(_logCategory, Log##sev).stream() #define _LOG1(severity) \ @@ -130,11 +142,11 @@ LogMessage _log(const LogCategory &category, LogSeverity severity, #endif /* __DOXYGEN__ */ #ifndef NDEBUG -#define ASSERT(condition) static_cast(({ \ - if (!(condition)) \ - _log(LogCategory::defaultCategory(), LogFatal).stream() \ - << "assertion \"" #condition "\" failed in " \ - << __func__ << "()"; \ +#define ASSERT(condition) static_cast(({ \ + if (!(condition)) \ + LOG(Fatal) \ + << "assertion \"" #condition "\" failed in " \ + << __func__ << "()"; \ })) #else #define ASSERT(condition) static_cast(false && (condition))