JorgeGzm opened a new pull request, #20015:
URL: https://github.com/apache/nuttx/pull/20015

   
   ## Summary
   
   `FOREACH_ARG()` hands the action the position of the argument as an
   expression (`count - N`), which cannot be pasted into an identifier. This
   adds a companion that passes it as a two digit literal (`00`, `01`, ...),
   so the position can become part of a symbol name and, through
   `SORT_BY_NAME()`, part of the order the linker gives to the objects a
   subsystem registers with the link time iterable sections.
   
   The dispatch uses `CONCATENATE()` and `GET_ARG_COUNT()`, each arity emits
   its own literal, and the list is reversed first with `REVERSE_ARG()`, so
   no increment tables are needed. An empty list expands to nothing.
   
   Using `REVERSE_ARG()` required fixing it first:
   
   `REVERSE_ARG()` expanded to `REVERSE_ARG_(##__VA_ARGS__)`. The token
   before the `##` is an opening parenthesis, not a comma, so the GNU
   extension that swallows an empty variable argument list does not apply:
   the preprocessor pastes `(` with the first argument and the build fails
   with
   
   ```
   error: pasting "(" and "x" does not give a valid preprocessing token
   ```
   
   The macro therefore only ever worked with an empty argument list, which
   is why the problem went unnoticed since the file was added in
   3271142b87. Dropping the `##` makes the arguments expand; the empty case
   is unaffected.
   
   **And fix `REVERSE_ARG()`, which it needs**
   
   ## Impact
   
   **Nothing existing is affected.** `FOREACH_IDX_ARG()` is entirely new, and
   `REVERSE_ARG()` has no user in either repository: with arguments it did
   not compile, so no code could depend on it, and with an empty list it
   expands exactly as before. No macro already in the header changes
   behaviour.
   
   The documentation of the iterable sections already said that an instance
   may encode its order in its name but not how; it now points at the new
   macro (four lines in
   `Documentation/components/iterable_sections.rst`).
   
   The first user of the new macro is the zbus port
   (apache/nuttx-apps#3743), which names one object per channel/observer
   pair after the position of the observer in the channel definition.
   
   ## Testing
   
   Host: Ubuntu 24.04.4 x86_64, arm-none-eabi-gcc 13.2.1.
   
   Expansion checked for 0, 1, 3, 8 and 32 arguments with
   
   ```c
   #define SHOW(p, x, i) [p:x:i]
   FOREACH_IDX_ARG(SHOW, P, a, b, c)   /* [P:c:02] [P:b:01] [P:a:00] */
   FOREACH_IDX_ARG(SHOW, P)            /* expands to nothing */
   ```
   
   and the 32 argument case yields `[a1:00] ... [d8:31]`. Without the
   `REVERSE_ARG()` fix the same expansions fail with the pasting error
   quoted above.
   
   Built and run on linum-stm32h753bi together with apache/nuttx-apps#3743:
   the observations of every channel come out of the linker grouped per
   channel and ordered by the position in the definition, and the zbus test
   suite passes 17/17 twice in the same boot, including a test that asserts
   the notification order.
   
   `tools/checkpatch.sh -c -u -m -g` on the commit: all checks pass, and
   `sphinx-build -W` builds the documentation clean.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to