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


The following commit(s) were added to refs/heads/master by this push:
     new da047a1af79 include/nuttx/compiler.h: Hide object_size() with 
NUTTX_NO_EXTENSIONS.
da047a1af79 is described below

commit da047a1af79eb21f04dc7e266198b9c48f4c68be
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 1 19:44:57 2026 +0100

    include/nuttx/compiler.h: Hide object_size() with NUTTX_NO_EXTENSIONS.
    
    nuttx/compiler.h reaches every program, and it defines the generic name
    object_size() as a macro with two arguments.  A program that has its
    own object_size() with another number of arguments does not compile, for
    example a C++ class with a member function object_size().
    
    With NUTTX_NO_EXTENSIONS, remove object_size() at the end of the file
    and restore the program's own definition, as for the other helper
    macros.  NOTE_PRINTF_OBJECT_SIZE() in nuttx/sched_note.h, which syslog()
    of a program can expand, uses __builtin_object_size() now.  The _Generic
    and statement expressions there need GCC or clang, which have the
    builtin.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 include/nuttx/compiler.h   | 10 +++++++---
 include/nuttx/sched_note.h |  8 ++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index a4b1c31d279..ee8e9e87206 100644
--- a/include/nuttx/compiler.h
+++ b/include/nuttx/compiler.h
@@ -109,6 +109,8 @@
 #  undef is_constexpr
 #  pragma push_macro("used_data")
 #  undef used_data
+#  pragma push_macro("object_size")
+#  undef object_size
 #endif
 
 /****************************************************************************
@@ -1649,9 +1651,9 @@
  * (unistd.h), the types unchar and s_char (sys/types.h),
  * builtin_function() and builtin_original() (above: string.h then declares
  * the plain functions) 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).
+ * memory_barrier(), UNUSED() and object_size().  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
@@ -1689,6 +1691,7 @@
 #  undef predict_true
 #  undef is_constexpr
 #  undef used_data
+#  undef object_size
 #  pragma pop_macro("weak_alias")
 #  pragma pop_macro("visibility_hidden")
 #  pragma pop_macro("visibility_default")
@@ -1723,6 +1726,7 @@
 #  pragma pop_macro("predict_true")
 #  pragma pop_macro("is_constexpr")
 #  pragma pop_macro("used_data")
+#  pragma pop_macro("object_size")
 #endif
 
 /****************************************************************************
diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h
index f509047a603..8cea95495d0 100644
--- a/include/nuttx/sched_note.h
+++ b/include/nuttx/sched_note.h
@@ -148,9 +148,13 @@
 #define NOTE_PRINTF_INT_TYPE(arg) (sizeof((arg) + 0) <= sizeof(uint32_t) ? \
                                    NOTE_PRINTF_UINT32 : NOTE_PRINTF_UINT64)
 
-/* Use object_size to mark strings of known size */
+/* Use the object size to mark strings of known size.  This is the builtin:
+ * a program can expand this macro, and NUTTX_NO_EXTENSIONS removes
+ * object_size().
+ */
 
-#define NOTE_PRINTF_OBJECT_SIZE(arg) object_size((FAR void *)(uintptr_t)(arg), 
2)
+#define NOTE_PRINTF_OBJECT_SIZE(arg) \
+        __builtin_object_size((FAR void *)(uintptr_t)(arg), 2)
 
 /* Use _Generic to determine the type of the parameter */
 

Reply via email to