Skip to content

Commit bb8fa93

Browse files
committed
Merge branch 'change/rename_va_narg' into 'master'
fix(system): rename __VA_NARG__ macro Closes IDF-11367 See merge request espressif/esp-idf!34068
2 parents f0bd096 + 64e0fc7 commit bb8fa93

File tree

7 files changed

+43
-28
lines changed

7 files changed

+43
-28
lines changed

components/esp_common/include/esp_macros.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ extern "C" {
5050
/* Count number of arguments of __VA_ARGS__
5151
* - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
5252
* - __GET_NTH_ARG__() takes args >= N (64) but only expand to Nth one (64th)
53-
* - __RSEQ_N__() is reverse sequential to N to add padding to have Nth
53+
* - ESP_RSEQ_N() is reverse sequential to N to add padding to have Nth
5454
* position is the same as the number of arguments
5555
* - ##__VA_ARGS__ is used to deal with 0 parameter (swallows comma)
5656
*/
57-
#ifndef __VA_NARG__
58-
# define __VA_NARG__(...) __NARG__(_0, ##__VA_ARGS__, __RSEQ_N__())
57+
#ifndef ESP_VA_NARG
58+
# define ESP_VA_NARG(...) ESP_NARG(_0, ##__VA_ARGS__, ESP_RSEQ_N())
5959

60-
# define __NARG__(...) __GET_NTH_ARG__(__VA_ARGS__)
61-
# define __GET_NTH_ARG__( \
60+
# define ESP_NARG(...) ESP_GET_NTH_ARG(__VA_ARGS__)
61+
# define ESP_GET_NTH_ARG( \
6262
_01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
6363
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
6464
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
6565
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
6666
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
6767
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
6868
_61,_62,_63,N,...) N
69-
# define __RSEQ_N__() \
69+
# define ESP_RSEQ_N() \
7070
62,61,60, \
7171
59,58,57,56,55,54,53,52,51,50, \
7272
49,48,47,46,45,44,43,42,41,40, \
@@ -80,25 +80,6 @@ extern "C" {
8080
#define ESP_UNUSED(x) ((void)(x))
8181
#endif
8282

83-
/* test macros */
84-
#define foo_args(...) 1
85-
#define foo_no_args() 2
86-
#if defined(__cplusplus) && (__cplusplus > 201703L)
87-
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args __VA_OPT__(,) __VA_ARGS__)(__VA_ARGS__)
88-
#else
89-
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args, ##__VA_ARGS__)(__VA_ARGS__)
90-
#endif
91-
92-
ESP_STATIC_ASSERT(foo() == 2, "CHOOSE_MACRO_VA_ARG() result does not match for 0 arguments");
93-
ESP_STATIC_ASSERT(foo(42) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for 1 argument");
94-
#if defined(__cplusplus) && (__cplusplus > 201703L)
95-
ESP_STATIC_ASSERT(foo(42, 87) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for n arguments");
96-
#endif
97-
98-
#undef foo
99-
#undef foo_args
100-
#undef foo_no_args
101-
10283
#define ESP_INFINITE_LOOP() \
10384
do { \
10485
ESP_COMPILER_DIAGNOSTIC_PUSH_IGNORE("-Wanalyzer-infinite-loop") \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
idf_component_register(SRCS "test_app_main.c" "test_attr.c"
1+
idf_component_register(SRCS "test_app_main.c" "test_attr.c" "test_esp_macro.c"
22
INCLUDE_DIRS "."
33
PRIV_REQUIRES unity esp_mm esp_psram
44
WHOLE_ARCHIVE)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5+
*/
6+
#include "esp_macros.h"
7+
8+
/* test macros */
9+
#define foo_args(...) 1
10+
#define foo_no_args() 2
11+
#if defined(__cplusplus) && (__cplusplus > 201703L)
12+
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args __VA_OPT__(,) __VA_ARGS__)(__VA_ARGS__)
13+
#else
14+
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args, ##__VA_ARGS__)(__VA_ARGS__)
15+
#endif
16+
17+
ESP_STATIC_ASSERT(foo() == 2, "CHOOSE_MACRO_VA_ARG() result does not match for 0 arguments");
18+
ESP_STATIC_ASSERT(foo(42) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for 1 argument");
19+
#if defined(__cplusplus) && (__cplusplus > 201703L)
20+
ESP_STATIC_ASSERT(foo(42, 87) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for n arguments");
21+
#endif

components/esp_hw_support/include/esp_private/esp_regdma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ void *regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint3
396396
*/
397397
void *regdma_find_next_module_link_head(void *link, void *tail, int entry, uint32_t module);
398398

399-
#define regdma_link_init_safe(pcfg, branch, module, ...) regdma_link_init((pcfg), (branch), (module), __VA_NARG__(__VA_ARGS__), ##__VA_ARGS__)
399+
#define regdma_link_init_safe(pcfg, branch, module, ...) regdma_link_init((pcfg), (branch), (module), ESP_VA_NARG(__VA_ARGS__), ##__VA_ARGS__)
400400

401-
#define regdma_link_update_next_safe(link, ...) regdma_link_update_next((link), __VA_NARG__(__VA_ARGS__), ##__VA_ARGS__)
401+
#define regdma_link_update_next_safe(link, ...) regdma_link_update_next((link), ESP_VA_NARG(__VA_ARGS__), ##__VA_ARGS__)
402402

403403
#endif // SOC_PAU_SUPPORTED
404404

docs/en/migration-guides/release-5.x/5.4/system.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ System
33

44
:link_to_translation:`zh_CN:[中文]`
55

6+
ESP-Common
7+
----------
8+
9+
``__VA_NARG__`` and its related macros have been re-named to avoid naming collisions, use the new name with ``ESP`` pre-fix, e.g. ``ESP_VA_NARG`` instead.
10+
611
Log
712
---
813

docs/zh_CN/migration-guides/release-5.x/5.4/system.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
:link_to_translation:`en:[English]`
55

6+
ESP-Common
7+
----------
8+
9+
``__VA_NARG__`` 及其相关宏已被重新命名以避免命名冲突,请使用带有 ESP 前缀的新名称,例如 ``ESP_VA_NARG``。
10+
611
日志
712
------
813

tools/idf_py_actions/hints.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,6 @@
447447
-
448448
re: "(error: Total discarded sections size is \\d+ bytes)|(region [`'.\\w]+ overflowed by \\d+ bytes)"
449449
hint: "The binary size has exceeded the limit. To resolve the issue consider reducing the binary size.\nYou can explore size optimization techniques in the documentation by running 'idf.py docs -sp api-guides/performance/size.html#reducing-overall-size'.\nNote that the linker performed the dead code elimination."
450+
451+
re: "implicit declaration of function '__VA_NARG__'"
452+
hint: "__VA_NARG_ has been renamed. Please use ESP_VA_NARG instead"

0 commit comments

Comments
 (0)