1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 22:43:50 +01:00

Merge pull request #17268 from maribu/core/BUILD_BUG_ON

core/kernel_defines: drop BUILD_BUG_ON()
This commit is contained in:
Alexandre Abadie 2022-01-05 17:27:18 +01:00 committed by GitHub
commit d72ff50777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 27 deletions

View File

@ -132,18 +132,6 @@ extern "C" {
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#endif
/**
* @def BUILD_BUG_ON(condition)
* @brief Forces a compilation error if condition is true.
* This trick is only needed if the condition can't be evaluated
* before compile time (i.e. sizeof(sometype_t) < 42 )
* For more details on this see for example:
* https://git.kernel.org/pub/scm/linux/kernel/git/stable/
* linux-stable.git/tree/include/linux/bug.h
* @param[in] condition A condition that will be evaluated at compile time
*/
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
/**
* @def IS_ACTIVE(macro)
* @brief Allows to verify a macro definition outside the preprocessor.

View File

@ -104,7 +104,7 @@ static inline void _cpy_add_crc(uint8_t *data, size_t len, uint8_t *crcd_data)
* @return true if all CRCs are valid
* @return false if at least one CRC is invalid
*/
static inline bool _cpy_check_crc(uint8_t *data, size_t len, uint8_t *crcd_data)
static inline bool _cpy_check_crc(uint8_t *data, size_t len, const uint8_t *crcd_data)
{
for (size_t elem = 0; elem < len / 2; elem++) {
int idx = (elem << 1);
@ -223,7 +223,8 @@ int sps30_read_measurement(const sps30_t *dev, sps30_data_t *data)
{
/* This compile time check is needed to ensure the below method used for
endianness conversion will work as expected */
BUILD_BUG_ON(sizeof(sps30_data_t) != (sizeof(float) * 10));
static_assert(sizeof(sps30_data_t) == (sizeof(float) * 10),
"sps30_data_t must be sized 10 floats");
assert(dev && data);
/* The target buffer is also used for storing the raw data temporarily */

View File

@ -18,6 +18,7 @@
* @}
*/
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <inttypes.h>
@ -26,7 +27,6 @@
#include "fs/fatfs.h"
#include "kernel_defines.h" /* needed for BUILD_BUG_ON */
#include "time.h"
#define ENABLE_DEBUG 0
@ -50,8 +50,10 @@ static int _mount(vfs_mount_t *mountp)
{
/* if one of the lines below fail to compile you probably need to adjust
vfs buffer sizes ;) */
BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(DIR));
BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(fatfs_file_desc_t));
static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(DIR),
"DIR must fit into VFS_DIR_BUFFER_SIZE");
static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(fatfs_file_desc_t),
"fatfs_file_desc_t must fit into VFS_FILE_BUFFER_SIZE");
fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data;

View File

@ -18,6 +18,7 @@
* @}
*/
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <inttypes.h>
@ -25,8 +26,6 @@
#include "fs/littlefs_fs.h"
#include "kernel_defines.h"
#define ENABLE_DEBUG 0
#include <debug.h>
@ -170,8 +169,10 @@ static int _mount(vfs_mount_t *mountp)
{
/* if one of the lines below fail to compile you probably need to adjust
vfs buffer sizes ;) */
BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(lfs_dir_t));
BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(lfs_file_t));
static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(lfs_dir_t),
"lfs_dir_t must fit in VFS_DIR_BUFFER_SIZE");
static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(lfs_file_t),
"lfs_file_t must fit in VFS_FILE_BUFFER_SIZE");
littlefs_desc_t *fs = mountp->private_data;

View File

@ -18,6 +18,7 @@
* @}
*/
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <inttypes.h>
@ -25,8 +26,6 @@
#include "fs/littlefs2_fs.h"
#include "kernel_defines.h"
#define ENABLE_DEBUG 0
#include <debug.h>
@ -176,8 +175,10 @@ static int _mount(vfs_mount_t *mountp)
{
/* if one of the lines below fail to compile you probably need to adjust
vfs buffer sizes ;) */
BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(lfs_dir_t));
BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(lfs_file_t));
static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(lfs_dir_t),
"lfs_dir_t must fit in VFS_DIR_BUFFER_SIZE");
static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(lfs_file_t),
"lfs_file_t must fit in VFS_FILE_BUFFER_SIZE");
littlefs2_desc_t *fs = mountp->private_data;

View File

@ -66,8 +66,10 @@ SPISettings::SPISettings(uint32_t clock_hz, uint8_t bitOrder, uint8_t dataMode)
SPIClass::SPIClass(spi_t spi_dev)
{
/* Check if default SPI interface is valid */
BUILD_BUG_ON(ARDUINO_SPI_INTERFACE >= SPI_NUMOF);
/* Check if default SPI interface is valid. Casting to int to avoid
* bogus type-limits warning here. */
static_assert((int)ARDUINO_SPI_INTERFACE <= (int)SPI_NUMOF,
"spi_dev out of bounds");
this->spi_dev = spi_dev;
this->settings = SPISettings();
this->is_transaction = false;