Apply new .clang-format

This commit is contained in:
Tilen Majerle 2023-05-28 12:04:53 +02:00
parent d5a595e03c
commit 6f4d286f47
3 changed files with 20 additions and 20 deletions

View File

@ -16,14 +16,14 @@ AlignConsecutiveBitFields:
AlignConsecutiveDeclarations: None AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right AlignEscapedNewlines: Right
AlignOperands: Align AlignOperands: Align
SortIncludes: false SortIncludes: true
InsertBraces: true # Control statements must have curly brackets InsertBraces: true # Control statements must have curly brackets
AlignTrailingComments: true AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Empty AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never AllowShortIfStatementsOnASingleLine: Never

View File

@ -35,8 +35,8 @@
#define LWMEM_HDR_H #define LWMEM_HDR_H
#include <limits.h> #include <limits.h>
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include "lwmem/lwmem_opt.h" #include "lwmem/lwmem_opt.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -124,13 +124,13 @@
* *
* Default size is size of meta block * Default size is size of meta block
*/ */
#define LWMEM_BLOCK_MIN_SIZE (LWMEM_BLOCK_META_SIZE) #define LWMEM_BLOCK_MIN_SIZE (LWMEM_BLOCK_META_SIZE)
/** /**
* \brief Get LwMEM instance based on user input * \brief Get LwMEM instance based on user input
* \param[in] in_lwobj: LwMEM instance. Set to `NULL` for default instance * \param[in] in_lwobj: LwMEM instance. Set to `NULL` for default instance
*/ */
#define LWMEM_GET_LWOBJ(in_lwobj) ((in_lwobj) != NULL ? (in_lwobj) : (&lwmem_default)) #define LWMEM_GET_LWOBJ(in_lwobj) ((in_lwobj) != NULL ? (in_lwobj) : (&lwmem_default))
/** /**
* \brief Gets block before input block (marked as prev) and its previous free block * \brief Gets block before input block (marked as prev) and its previous free block
@ -139,9 +139,9 @@
* \param[in] in_pp: Previous previous of input block * \param[in] in_pp: Previous previous of input block
* \param[in] in_p: Previous of input block * \param[in] in_p: Previous of input block
*/ */
#define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lwobj, in_b, in_pp, in_p) \ #define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lwobj, in_b, in_pp, in_p) \
do { \ do { \
for ((in_pp) = NULL, (in_p) = &((in_lwobj)->start_block); (in_p) != NULL && (in_p)->next < (in_b); \ for ((in_pp) = NULL, (in_p) = &((in_lwobj)->start_block); (in_p) != NULL && (in_p)->next < (in_b); \
(in_pp) = (in_p), (in_p) = (in_p)->next) {} \ (in_pp) = (in_p), (in_p) = (in_p)->next) {} \
} while (0) } while (0)
@ -156,10 +156,10 @@
/* Statistics part */ /* Statistics part */
#if LWMEM_CFG_ENABLE_STATS #if LWMEM_CFG_ENABLE_STATS
#define LWMEM_INC_STATS(field) (++(field)) #define LWMEM_INC_STATS(field) (++(field))
#define LWMEM_UPDATE_MIN_FREE(lwobj) \ #define LWMEM_UPDATE_MIN_FREE(lwobj) \
do { \ do { \
if ((lwobj)->mem_available_bytes < (lwobj)->stats.minimum_ever_mem_available_bytes) { \ if ((lwobj)->mem_available_bytes < (lwobj)->stats.minimum_ever_mem_available_bytes) { \
(lwobj)->stats.minimum_ever_mem_available_bytes = (lwobj)->mem_available_bytes; \ (lwobj)->stats.minimum_ever_mem_available_bytes = (lwobj)->mem_available_bytes; \
} \ } \
} while (0) } while (0)
#else #else
@ -369,7 +369,7 @@ prv_alloc(lwmem_t* const lwobj, const lwmem_region_t* region, const size_t size)
/* Set default values */ /* Set default values */
prev = &(lwobj->start_block); /* Use pointer from custom lwmem block */ prev = &(lwobj->start_block); /* Use pointer from custom lwmem block */
curr = prev->next; /* Curr represents first actual free block */ curr = prev->next; /* Curr represents first actual free block */
/* /*
* If region is not set to NULL, * If region is not set to NULL,
@ -431,7 +431,7 @@ prv_alloc(lwmem_t* const lwobj, const lwmem_region_t* region, const size_t size)
lwobj->mem_available_bytes -= curr->size; /* Decrease available bytes by allocated block size */ lwobj->mem_available_bytes -= curr->size; /* Decrease available bytes by allocated block size */
prv_split_too_big_block(lwobj, curr, final_size); /* Split block if it is too big */ prv_split_too_big_block(lwobj, curr, final_size); /* Split block if it is too big */
LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */
LWMEM_UPDATE_MIN_FREE(lwobj); LWMEM_UPDATE_MIN_FREE(lwobj);
LWMEM_INC_STATS(lwobj->stats.nr_alloc); LWMEM_INC_STATS(lwobj->stats.nr_alloc);
@ -592,8 +592,8 @@ prv_realloc(lwmem_t* const lwobj, const lwmem_region_t* region, void* const ptr,
prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */
prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */
LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */
return ptr; /* Return existing pointer */ return ptr; /* Return existing pointer */
} }
/* /*
@ -625,8 +625,8 @@ prv_realloc(lwmem_t* const lwobj, const lwmem_region_t* region, void* const ptr,
block = prev; /* Move block pointer to previous one */ block = prev; /* Move block pointer to previous one */
prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */
LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */
return new_data_ptr; /* Return new data ptr */ return new_data_ptr; /* Return new data ptr */
} }
/* /*
@ -669,8 +669,8 @@ prv_realloc(lwmem_t* const lwobj, const lwmem_region_t* region, void* const ptr,
block = prev; /* Previous block is now current */ block = prev; /* Previous block is now current */
prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */
LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */
return new_data_ptr; /* Return new data ptr */ return new_data_ptr; /* Return new data ptr */
} }
} else { } else {
/* Hard error. Input pointer is not NULL and block is not considered allocated */ /* Hard error. Input pointer is not NULL and block is not considered allocated */
@ -691,7 +691,7 @@ prv_realloc(lwmem_t* const lwobj, const lwmem_region_t* region, void* const ptr,
block_size = block_size =
(block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; /* Get application size from input pointer */ (block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; /* Get application size from input pointer */
LWMEM_MEMCPY(retval, ptr, size > block_size ? block_size : size); /* Copy content to new allocated block */ LWMEM_MEMCPY(retval, ptr, size > block_size ? block_size : size); /* Copy content to new allocated block */
prv_free(lwobj, ptr); /* Free input pointer */ prv_free(lwobj, ptr); /* Free input pointer */
} }
return retval; return retval;
} }
@ -760,7 +760,7 @@ lwmem_assignmem_ex(lwmem_t* lwobj, const lwmem_region_t* regions) {
#if LWMEM_CFG_OS #if LWMEM_CFG_OS
|| lwmem_sys_mutex_isvalid(&(lwobj->mutex)) /* Check if mutex valid already = must not be */ || lwmem_sys_mutex_isvalid(&(lwobj->mutex)) /* Check if mutex valid already = must not be */
|| !lwmem_sys_mutex_create(&(lwobj->mutex)) /* Final step = try to create mutex for new instance */ || !lwmem_sys_mutex_create(&(lwobj->mutex)) /* Final step = try to create mutex for new instance */
#endif /* LWMEM_CFG_OS */ #endif /* LWMEM_CFG_OS */
) { ) {
return 0; return 0;
} }