Skip to content

Commit 95b934b

Browse files
committed
baselibc: Update static asserts definition
Static asserts are part of C11. There is C language keyword _Static_assert and convenience macro static_assert. For C++ there is no _Static_assert while static_assert is defined. This adds missing macro to assert.h that is defined when compiled by C compiler. header files are updated so they could be used by C++. C files are updated just to make it consistent.
1 parent 037d0a1 commit 95b934b

File tree

17 files changed

+31
-24
lines changed

17 files changed

+31
-24
lines changed

hw/bsp/black_vet6/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const uint32_t stm32_flash_sectors[] = {
6969
};
7070

7171
#define SZ ARRAY_SIZE(stm32_flash_sectors)
72-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
72+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
7373
"STM32_FLASH_NUM_AREAS does not match flash sectors");
7474

7575
#if MYNEWT_VAL(TRNG)

hw/bsp/nucleo-f401re/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const uint32_t stm32_flash_sectors[] = {
5151
};
5252

5353
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
54-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
54+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
5555
"STM32_FLASH_NUM_AREAS does not match flash sectors");
5656

5757
#if MYNEWT_VAL(UART_0)

hw/bsp/nucleo-f413zh/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const uint32_t stm32_flash_sectors[] = {
6060
};
6161

6262
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
63-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
63+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
6464
"STM32_FLASH_NUM_AREAS does not match flash sectors");
6565

6666
#if MYNEWT_VAL(UART_0)

hw/bsp/nucleo-f439zi/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const uint32_t stm32_flash_sectors[] = {
8181
};
8282

8383
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
84-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
84+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
8585
"STM32_FLASH_NUM_AREAS does not match flash sectors");
8686

8787
#if MYNEWT_VAL(TRNG)

hw/bsp/nucleo-f746zg/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const uint32_t stm32_flash_sectors[] = {
9595
};
9696

9797
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
98-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
98+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
9999
"STM32_FLASH_NUM_AREAS does not match flash sectors");
100100

101101
#if MYNEWT_VAL(TRNG)

hw/bsp/nucleo-f767zi/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const uint32_t stm32_flash_sectors[] = {
100100
};
101101

102102
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
103-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
103+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
104104
"STM32_FLASH_NUM_AREAS does not match flash sectors");
105105

106106
#if MYNEWT_VAL(TRNG)

hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const uint32_t stm32_flash_sectors[] = {
6868
};
6969

7070
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
71-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
71+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
7272
"STM32_FLASH_NUM_AREAS does not match flash sectors");
7373

7474
#if MYNEWT_VAL(TRNG)

hw/bsp/stm32f429discovery/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const uint32_t stm32_flash_sectors[] = {
6868
};
6969

7070
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
71-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
71+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
7272
"STM32_FLASH_NUM_AREAS does not match flash sectors");
7373

7474
#if MYNEWT_VAL(UART_0)

hw/bsp/stm32f4discovery/src/hal_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const uint32_t stm32_flash_sectors[] = {
5757
};
5858

5959
#define SZ (sizeof(stm32_flash_sectors) / sizeof(stm32_flash_sectors[0]))
60-
_Static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
60+
static_assert(MYNEWT_VAL(STM32_FLASH_NUM_AREAS) == SZ,
6161
"STM32_FLASH_NUM_AREAS does not match flash sectors");
6262

6363
#if MYNEWT_VAL(UART_0)

hw/drivers/flash/spiflash/src/spiflash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <string.h>
21+
#include <assert.h>
2122

2223
#include "os/mynewt.h"
2324
#include <bsp/bsp.h>
@@ -1337,7 +1338,7 @@ spiflash_identify(struct spiflash_dev *dev)
13371338
/* List of supported spi flash chips can be found in:
13381339
* hw/drivers/flash/spiflash/chips/sysconfig.yml
13391340
*/
1340-
_Static_assert((sizeof(supported_chips) / sizeof(supported_chips[0])) > 1,
1341+
static_assert((sizeof(supported_chips) / sizeof(supported_chips[0])) > 1,
13411342
"At lease one spiflash chip must be specified in sysconfig with SPIFLASH_<chipid>:1");
13421343

13431344
spiflash_lock(dev);

hw/mcu/stm/stm32l0xx/src/hal_flash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <string.h>
21+
#include <assert.h>
2122
#include <syscfg/syscfg.h>
2223
#include <mcu/stm32_hal.h>
2324
#include "hal/hal_flash_int.h"
@@ -38,7 +39,7 @@
3839
* intentionally alerts the user that this code needs to be updated
3940
* as well.
4041
*/
41-
_Static_assert(_FLASH_SECTOR_SIZE == (_REAL_SECTOR_SIZE * _PAGES_PER_SECTOR),
42+
static_assert(_FLASH_SECTOR_SIZE == (_REAL_SECTOR_SIZE * _PAGES_PER_SECTOR),
4243
"STM32_FLASH_SECTOR_SIZE was changed; the erase function needs updating!");
4344

4445
int

kernel/os/src/os_mempool.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ STAILQ_HEAD(, os_mempool) g_os_mempool_list;
4141
#if MYNEWT_VAL(OS_MEMPOOL_POISON)
4242
static uint32_t os_mem_poison = 0xde7ec7ed;
4343

44-
_Static_assert(sizeof(struct os_memblock) % 4 == 0, "sizeof(struct os_memblock) shall be aligned to 4");
45-
_Static_assert(sizeof(os_mem_poison) == 4, "sizeof(os_mem_poison) shall be 4");
44+
static_assert(sizeof(struct os_memblock) % 4 == 0, "sizeof(struct os_memblock) shall be aligned to 4");
45+
static_assert(sizeof(os_mem_poison) == 4, "sizeof(os_mem_poison) shall be 4");
4646

4747
static void
4848
os_mempool_poison(const struct os_mempool *mp, void *start)
@@ -305,8 +305,8 @@ os_memblock_from(const struct os_mempool *mp, const void *block_addr)
305305
uint32_t baddr32;
306306
uint32_t end;
307307

308-
_Static_assert(sizeof block_addr == sizeof baddr32,
309-
"Pointer to void must be 32-bits.");
308+
static_assert(sizeof block_addr == sizeof baddr32,
309+
"Pointer to void must be 32-bits.");
310310

311311
baddr32 = (uint32_t)block_addr;
312312
true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp);

kernel/os/src/os_time.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ os_time_ms_to_ticks(uint32_t ms, os_time_t *out_ticks)
333333
return 0;
334334
#endif
335335

336-
_Static_assert(OS_TICKS_PER_SEC <= UINT32_MAX,
337-
"OS_TICKS_PER_SEC must be <= UINT32_MAX");
336+
static_assert(OS_TICKS_PER_SEC <= UINT32_MAX,
337+
"OS_TICKS_PER_SEC must be <= UINT32_MAX");
338338

339339
ticks = ((uint64_t)ms * OS_TICKS_PER_SEC) / 1000;
340340
if (ticks > UINT32_MAX) {

libc/baselibc/include/assert.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ extern "C" {
2727

2828
#endif
2929

30+
#if __STDC_VERSION__ >= 201112L && !defined __cplusplus
31+
#define static_assert _Static_assert
32+
#endif
33+
3034
#ifdef __cplusplus
3135
}
3236
#endif

sys/stats/full/include/stats/stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int stats_persist_init(struct stats_hdr *hdr, uint8_t size,
306306
#else /* MYNEWT_VAL(STATS_PERSIST) */
307307

308308
#define STATS_PERSISTED_SECT_START(__name) \
309-
_Static_assert(0, "You must enable STATS_PERSIST to use persistent stats");
309+
static_assert(0, "You must enable STATS_PERSIST to use persistent stats");
310310

311311
#define STATS_PERSIST_SCHED(hdrp_)
312312

sys/sysdown/src/sysdown.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

20+
#include <assert.h>
2021
#include "os/mynewt.h"
2122

2223
/**
@@ -44,8 +45,8 @@ sysdown(int reason)
4445
#define SYSDOWN_TIMEOUT_TICKS \
4546
(MYNEWT_VAL(SYSDOWN_TIMEOUT_MS) * OS_TICKS_PER_SEC / 1000)
4647

47-
_Static_assert(SYSDOWN_TIMEOUT_TICKS >= 0 && SYSDOWN_TIMEOUT_TICKS < INT32_MAX,
48-
"SYSDOWN_TIMEOUT_MS value not in valid range");
48+
static_assert(SYSDOWN_TIMEOUT_TICKS >= 0 && SYSDOWN_TIMEOUT_TICKS < INT32_MAX,
49+
"SYSDOWN_TIMEOUT_MS value not in valid range");
4950

5051
static volatile int sysdown_num_in_progress;
5152
bool sysdown_active;

test/testutil/include/testutil/testutil.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ TEST_SUITE_##suite_name(void); \
259259
#else
260260

261261
#define TEST_CASE_SELF(case_name) \
262-
_Static_assert(0, "Test `"#case_name"` is a self test. " \
263-
"It can only be run from `newt test`"); \
262+
static_assert(0, "Test `"#case_name"` is a self test. " \
263+
"It can only be run from `newt test`"); \
264264
/* Emit case definition anyway to prevent syntax errors. */ \
265265
TEST_CASE_SELF_EMIT_(case_name)
266266

267267
#define TEST_CASE_TASK(case_name) \
268-
_Static_assert(0, "Test `"#case_name"` is a self test. " \
269-
"It can only be run from `newt test`"); \
268+
static_assert(0, "Test `"#case_name"` is a self test. " \
269+
"It can only be run from `newt test`"); \
270270
/* Emit case definition anyway to prevent syntax errors. */ \
271271
TEST_CASE_TASK_EMIT_(case_name)
272272

0 commit comments

Comments
 (0)