This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f55a0e723fa551bff974a5d69ae00dc5eb56d17d Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 23 05:48:25 2026 +0200 include/assert.h: Hide ASSERT() and VERIFY() with NUTTX_NO_EXTENSIONS. <assert.h> defines the NuttX macros PANIC(), PANIC_WITH_REGS(), ASSERT(), VERIFY(), COMPILE_TIME_ASSERT() and BUILD_BUG_ON_ZERO(), and removes a definition of PANIC, ASSERT or VERIFY that the program made before. The C standard does not reserve these names, and programs use them: a program that has its own ASSERT() macro gets the NuttX one instead. Most standard headers bring in <assert.h> through nuttx/mutex.h. With NUTTX_NO_EXTENSIONS, do not define these macros and do not remove the program's definitions. assert() and static_assert stay. The DEBUG* macros stay too, because the NuttX port of libmetal uses DEBUGASSERT in its headers, but with NUTTX_NO_EXTENSIONS a definition that the program made before is kept. Add the names to the list in nuttx/compiler.h. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/assert.h | 52 ++++++++++++++++++++++++++++++++++++++---------- include/nuttx/compiler.h | 10 ++++++---- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/include/assert.h b/include/assert.h index 1a8bd454b17..65b17631e65 100644 --- a/include/assert.h +++ b/include/assert.h @@ -36,14 +36,23 @@ * Pre-processor Definitions ****************************************************************************/ -/* Macro Name: PANIC, ASSERT, VERIFY, et al. */ +/* Macro Name: PANIC, ASSERT, VERIFY, et al. + * + * NUTTX_NO_EXTENSIONS (see nuttx/compiler.h) hides PANIC, PANIC_WITH_REGS, + * ASSERT, VERIFY, COMPILE_TIME_ASSERT and BUILD_BUG_ON_ZERO and keeps a + * definition of the program. The DEBUG* macros stay, because the NuttX + * port of libmetal uses DEBUGASSERT in its headers, but a definition of + * the program stays too. + */ +#ifndef NUTTX_NO_EXTENSIONS #undef PANIC /* Unconditional abort */ #undef ASSERT /* Assert if the condition is not true */ #undef VERIFY /* Assert if a function returns a negative value */ #undef DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG_ASSERTIONS is defined */ #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */ #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */ +#endif /* Macro to define the assertions file name and file line * | Function |CONFIG | Show name/line | @@ -75,9 +84,11 @@ # define __ASSERT_LINE__ 0 #endif +#ifndef NUTTX_NO_EXTENSIONS #define PANIC() __assert(__ASSERT_FILE__, __ASSERT_LINE__, "panic") #define PANIC_WITH_REGS(msg, regs) _assert(__ASSERT_FILE__, \ __ASSERT_LINE__, msg, regs) +#endif #define __ASSERT__(f, file, line, _f) \ (predict_false(!(f))) ? __assert(file, line, _f) : ((void)0) @@ -93,14 +104,31 @@ # define _VERIFY(f,file,line) __VERIFY__(f, file, line, NULL) #endif -#ifdef CONFIG_DEBUG_ASSERTIONS -# define DEBUGPANIC() __assert(__DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__, "panic") -# define DEBUGASSERT(f) _ASSERT(f, __DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__) -# define DEBUGVERIFY(f) _VERIFY(f, __DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__) -#else -# define DEBUGPANIC() -# define DEBUGASSERT(f) ((void)(1 || (f))) -# define DEBUGVERIFY(f) ((void)(f)) +#ifndef DEBUGPANIC +# ifdef CONFIG_DEBUG_ASSERTIONS +# define DEBUGPANIC() __assert(__DEBUG_ASSERT_FILE__, \ + __DEBUG_ASSERT_LINE__, "panic") +# else +# define DEBUGPANIC() +# endif +#endif + +#ifndef DEBUGASSERT +# ifdef CONFIG_DEBUG_ASSERTIONS +# define DEBUGASSERT(f) _ASSERT(f, __DEBUG_ASSERT_FILE__, \ + __DEBUG_ASSERT_LINE__) +# else +# define DEBUGASSERT(f) ((void)(1 || (f))) +# endif +#endif + +#ifndef DEBUGVERIFY +# ifdef CONFIG_DEBUG_ASSERTIONS +# define DEBUGVERIFY(f) _VERIFY(f, __DEBUG_ASSERT_FILE__, \ + __DEBUG_ASSERT_LINE__) +# else +# define DEBUGVERIFY(f) ((void)(f)) +# endif #endif /* ASSERT/VERIFY are NuttX-specific APIs. @@ -108,8 +136,10 @@ * The argument is evaluated exactly once. */ +#ifndef NUTTX_NO_EXTENSIONS #define ASSERT(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__) #define VERIFY(f) _VERIFY(f, __ASSERT_FILE__, __ASSERT_LINE__) +#endif /* Suppress 3rd party library redefine _assert/__assert */ @@ -130,7 +160,7 @@ # endif #endif -#ifndef COMPILE_TIME_ASSERT +#if !defined(COMPILE_TIME_ASSERT) && !defined(NUTTX_NO_EXTENSIONS) # define COMPILE_TIME_ASSERT(x) static_assert(x, "compile time assert failed") #endif @@ -140,7 +170,9 @@ * aren't permitted). */ +#ifndef NUTTX_NO_EXTENSIONS #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) +#endif /**************************************************************************** * Public Data diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index fc6350fbe54..d1a152d8bfb 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -1620,10 +1620,12 @@ * keep some non-standard names free for its own use. Then the headers do * not define ERROR and OK (sys/types.h), set_errno() and get_errno() * (errno.h), zalloc() (stdlib.h), O_TEXT and O_BINARY (fcntl.h), utimens() - * and lutimens() (sys/stat.h) and the helper macros of this file below, - * such as memory_barrier() and UNUSED(). The headers that a program - * includes do not use these names. A definition that the program made - * before is restored (saved at the start of this file). + * and lutimens() (sys/stat.h), PANIC(), PANIC_WITH_REGS(), ASSERT(), + * VERIFY(), COMPILE_TIME_ASSERT() and BUILD_BUG_ON_ZERO() (assert.h) and + * the helper macros of this file below, such as memory_barrier() and + * UNUSED(). The headers that a program includes do not use these names. + * A definition that the program made before is restored (saved at the + * start of this file). */ #ifdef NUTTX_NO_EXTENSIONS
