| Message ID | 20260119113104.3560802-6-barnabas.pocze@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Quoting Barnabás Pőcze (2026-01-19 11:31:03) > Avoid the conditional logic in the expansion of `LOG()` inside `ASSERT()` by > directly calling `_log(...)` with the appropriate parameters. > Is this just a final optimisation ? Part of me thinks LOG(Fatal) is nicer as that's how we handle log messages, but ... this seems reasonable anyway, and if it prevents a double check - well it's all internal in here so: Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > include/libcamera/base/log.h | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h > index dbd14951c..8419300a5 100644 > --- a/include/libcamera/base/log.h > +++ b/include/libcamera/base/log.h > @@ -130,9 +130,11 @@ LogMessage _log(const LogCategory &category, LogSeverity severity, > > #ifndef NDEBUG > #define ASSERT(condition) static_cast<void>(({ \ > - if (!(condition)) \ > - LOG(Fatal) << "assertion \"" #condition "\" failed in " \ > - << __func__ << "()"; \ > + if (!(condition)) { \ > + _log(LogCategory::defaultCategory(), LogFatal).stream() \ > + << "assertion \"" #condition "\" failed in " \ > + << __func__ << "()"; \ > + } \ > })) > #else > #define ASSERT(condition) static_cast<void>(false && (condition)) > -- > 2.52.0 >
diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index dbd14951c..8419300a5 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -130,9 +130,11 @@ LogMessage _log(const LogCategory &category, LogSeverity severity, #ifndef NDEBUG #define ASSERT(condition) static_cast<void>(({ \ - if (!(condition)) \ - LOG(Fatal) << "assertion \"" #condition "\" failed in " \ - << __func__ << "()"; \ + if (!(condition)) { \ + _log(LogCategory::defaultCategory(), LogFatal).stream() \ + << "assertion \"" #condition "\" failed in " \ + << __func__ << "()"; \ + } \ })) #else #define ASSERT(condition) static_cast<void>(false && (condition))
Avoid the conditional logic in the expansion of `LOG()` inside `ASSERT()` by directly calling `_log(...)` with the appropriate parameters. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- include/libcamera/base/log.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)