Skip to content

Commit

Permalink
shotgun fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apache-hb committed Apr 15, 2024
1 parent e7d4187 commit 297e854
Show file tree
Hide file tree
Showing 70 changed files with 475 additions and 360 deletions.
4 changes: 2 additions & 2 deletions data/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ PREDEFINED = OS_RESULT(X)=X \
IN_READS()= \
OUT_WRITES()= \
OUT_PTR_INVALID= \
RET_RANGE()= \
RET_DOMAIN()= \
RET_NOTNULL= \
RET_STRING= \
RET_INSPECT= \
Expand All @@ -2140,7 +2140,7 @@ PREDEFINED = OS_RESULT(X)=X \
FIELD_RANGE()= \
IN_NOTNULL= \
IN_STRING= \
IN_RANGE()= \
IN_DOMAIN()= \
CT_PRINTF()= \
CONSTFN= \
PUREFN= \
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if default_library == 'both'
error('cthulhu does not support building both static and shared libraries in a single build')
endif

opt_asserts = get_option('asserts').disable_auto_if(is_release)
opt_paranoid = get_option('paranoid').disable_auto_if(is_release)
opt_analyze = get_option('analyze').disable_auto_if(meson.is_subproject())
trace_time = get_option('trace_time').disable_auto_if(meson.is_subproject())
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ option('trace_memory', type : 'feature',
value : 'auto'
)

option('asserts', type : 'feature',
description : 'enable assertions, enabled by default in debug builds',
value : 'auto'
)

option('paranoid', type : 'feature',
description : 'enable paranoid assertions',
value : 'auto'
Expand Down
28 changes: 14 additions & 14 deletions src/common/arena/include/arena/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef struct arena_t
/// @param size the size of the allocation
CT_ARENA_API void arena_free(
OUT_PTR_INVALID void *ptr,
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @brief allocate memory from a custom allocator
Expand All @@ -128,7 +128,7 @@ CT_ARENA_API void arena_free(
CT_NODISCARD CT_ALLOC(arena_free) CT_ALLOC_SIZE(1)
RET_NOTNULL
CT_ARENA_API void *arena_malloc(
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @brief allocate memory from a custom allocator
Expand All @@ -145,7 +145,7 @@ CT_ARENA_API void *arena_malloc(
CT_NODISCARD CT_ALLOC(arena_free) CT_ALLOC_SIZE(1)
RET_NOTNULL
CT_ARENA_API void *arena_malloc_info(
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
const char *name,
const void *parent,
IN_NOTNULL arena_t *arena);
Expand All @@ -166,8 +166,8 @@ CT_NODISCARD CT_ALLOC(arena_free) CT_ALLOC_SIZE(2)
RET_NOTNULL
CT_ARENA_API void *arena_realloc(
OUT_PTR_INVALID void *ptr,
IN_RANGE(!=, 0) size_t new_size,
IN_RANGE(!=, 0) size_t old_size,
IN_DOMAIN(!=, 0) size_t new_size,
IN_DOMAIN(!=, 0) size_t old_size,
IN_NOTNULL arena_t *arena);

/// @brief allocate a copy of a string from a custom allocator
Expand Down Expand Up @@ -197,7 +197,7 @@ CT_NODISCARD CT_ALLOC(arena_free)
RET_NOTNULL
CT_ARENA_API char *arena_strndup(
IN_READS(len) const char *str,
IN_RANGE(>, 0) size_t len,
IN_DOMAIN(>, 0) size_t len,
IN_NOTNULL arena_t *arena);

/// @brief duplicate a memory region from a custom allocator
Expand All @@ -215,7 +215,7 @@ CT_NODISCARD CT_ALLOC(arena_free) CT_ALLOC_SIZE(2)
RET_NOTNULL
CT_ARENA_API void *arena_memdup(
IN_READS(size) const void *ptr,
IN_RANGE(>, 0) size_t size,
IN_DOMAIN(>, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @defgroup memory_opt Failable arena allocation
Expand All @@ -233,7 +233,7 @@ CT_ARENA_API void *arena_memdup(
/// @param size the size of the allocation
CT_ARENA_API void arena_opt_free(
OUT_PTR_INVALID void *ptr,
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @brief allocate memory from a custom allocator
Expand All @@ -245,7 +245,7 @@ CT_ARENA_API void arena_opt_free(
/// @return the allocated pointer
CT_NODISCARD CT_ALLOC(arena_opt_free) CT_ALLOC_SIZE(1)
CT_ARENA_API void *arena_opt_malloc(
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @brief allocate memory from a custom allocator
Expand All @@ -260,7 +260,7 @@ CT_ARENA_API void *arena_opt_malloc(
/// @return the allocated pointer
CT_NODISCARD CT_ALLOC(arena_opt_free) CT_ALLOC_SIZE(1)
CT_ARENA_API void *arena_opt_malloc_info(
IN_RANGE(!=, 0) size_t size,
IN_DOMAIN(!=, 0) size_t size,
const char *name,
const void *parent,
IN_NOTNULL arena_t *arena);
Expand All @@ -277,8 +277,8 @@ CT_ARENA_API void *arena_opt_malloc_info(
CT_NODISCARD CT_ALLOC(arena_opt_free)
CT_ARENA_API void *arena_opt_realloc(
OUT_PTR_INVALID void *ptr,
IN_RANGE(!=, 0) size_t new_size,
IN_RANGE(!=, 0) size_t old_size,
IN_DOMAIN(!=, 0) size_t new_size,
IN_DOMAIN(!=, 0) size_t old_size,
IN_NOTNULL arena_t *arena);

/// @brief allocate a copy of a string from a custom allocator
Expand Down Expand Up @@ -306,7 +306,7 @@ CT_ARENA_API char *arena_opt_strdup(
CT_NODISCARD CT_ALLOC(arena_free)
CT_ARENA_API char *arena_opt_strndup(
IN_READS(len) const char *str,
IN_RANGE(>, 0) size_t len,
IN_DOMAIN(>, 0) size_t len,
IN_NOTNULL arena_t *arena);

/// @brief duplicate a memory region from a custom allocator
Expand All @@ -322,7 +322,7 @@ CT_ARENA_API char *arena_opt_strndup(
CT_NODISCARD CT_ALLOC(arena_free) CT_ALLOC_SIZE(2)
CT_ARENA_API void *arena_opt_memdup(
IN_READS(size) const void *ptr,
IN_RANGE(>, 0) size_t size,
IN_DOMAIN(>, 0) size_t size,
IN_NOTNULL arena_t *arena);

/// @}
Expand Down
2 changes: 1 addition & 1 deletion src/common/backtrace/include/backtrace/backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct bt_symbol_t
{
/// @brief the line number
/// @brief when @a eResolveLine is not set this is initialized to @a CT_LINE_UNKNOWN
source_line_t line;
source_ctu_line_t line;

/// @brief a buffer to hold the name
text_t name;
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/include/base/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CT_BEGIN_API
typedef struct bitset_t
{
/// @brief the number of bytes in @a data
FIELD_RANGE(>, 0) size_t words;
FIELD_RANGE(0, SIZE_MAX) size_t words;

/// @brief the data for the bitset
FIELD_SIZE(words) void *data;
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/include/base/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CT_NORETURN CT_BASE_API ctu_vpanic(source_info_t location, CT_FMT_STRING const c
/// @param expr the condition to assert
/// @param ... the format string and optional arguments to format

#if CTU_DEBUG
#if CTU_ASSERTS
# define CTASSERTF(expr, ...) CTASSERTF_ALWAYS(expr, __VA_ARGS__)
#else
# define CTASSERTF(expr, ...) CT_ASSUME(expr)
Expand Down
12 changes: 12 additions & 0 deletions src/common/base/include/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ CT_BASE_API char *ctu_strcpy(OUT_WRITES(size) char *dst, IN_STRING const char *s
CT_NODISCARD CT_PUREFN
CT_BASE_API size_t ctu_strlen(IN_STRING const char *str);

/// @brief check if a string is empty
/// equivalent to strlen(str) == 0
///
/// @pre @p str must not be null
///
/// @param str the string
///
/// @retval true if the string is empty
/// @retval false otherwise
CT_NODISCARD CT_PUREFN
CT_BASE_API bool ctu_string_empty(IN_STRING const char *str);

/// @brief compare two strings
/// equivalent to strncmp but with safety checks
///
Expand Down
8 changes: 8 additions & 0 deletions src/common/base/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ size_t ctu_strlen(const char *str)
return strlen(str);
}

USE_DECL
bool ctu_string_empty(const char *str)
{
CTASSERT(str != NULL);

return *str == '\0';
}

USE_DECL
int ctu_strncmp(const char *lhs, const char *rhs, size_t length)
{
Expand Down
20 changes: 9 additions & 11 deletions src/common/config/include/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ typedef struct cfg_arg_t
// long args are discarded on windows
// dos args are discarded on unix

#define ARG_SHORT(name) { .style = eArgShort, .arg = (name) }
#define ARG_LONG(name) { .style = eArgLong, .arg = (name) }
#define ARG_DOS(name) { .style = eArgDOS, .arg = (name) }
#define CT_ARG_SHORT(name) { .style = eArgShort, .arg = (name) }
#define CT_ARG_LONG(name) { .style = eArgLong, .arg = (name) }
#define CT_ARG_DOS(name) { .style = eArgDOS, .arg = (name) }
#define CT_ARGS(it) { .args = (it), .count = sizeof(it) / sizeof(cfg_arg_t) }

typedef struct cfg_arg_array_t
Expand Down Expand Up @@ -80,17 +80,15 @@ typedef struct cfg_info_t
typedef struct cfg_int_t
{
/// @brief default value
FIELD_RANGE(>, min)
FIELD_RANGE(<, max)
int initial;
FIELD_RANGE(min, max) int initial;

/// @brief minimum value
/// @note if min == INT_MIN, there is no minimum
FIELD_RANGE(<, max) int min;
FIELD_RANGE(INT_MIN, max) int min;

/// @brief maximum value
/// @note if max == INT_MAX, there is no maximum
FIELD_RANGE(>, min) int max;
FIELD_RANGE(min, INT_MAX) int max;
} cfg_int_t;

/// @brief a choice in a set of options
Expand Down Expand Up @@ -291,23 +289,23 @@ CT_CONFIG_API const cfg_flags_t *cfg_flags_info(IN_NOTNULL const cfg_field_t *fi
///
/// @return the name of @p type
CT_CONSTFN RET_NOTNULL
CT_CONFIG_API const char *cfg_type_string(IN_RANGE(<, eConfigCount) cfg_type_t type);
CT_CONFIG_API const char *cfg_type_string(IN_DOMAIN(<, eConfigCount) cfg_type_t type);

/// @brief get the name of an argument style
///
/// @param style the style to get the name of
///
/// @return the name of @p style
CT_CONSTFN RET_NOTNULL
CT_CONFIG_API const char *cfg_arg_string(IN_RANGE(<, eArgCount) arg_style_t style);
CT_CONFIG_API const char *cfg_arg_string(IN_DOMAIN(<, eArgCount) arg_style_t style);

/// @brief get the prefix for an argument style
///
/// @param style the style to get the prefix for
///
/// @return the prefix for @p style
CT_CONSTFN RET_NOTNULL
CT_CONFIG_API const char *cfg_arg_prefix(IN_RANGE(<, eArgCount) arg_style_t style);
CT_CONFIG_API const char *cfg_arg_prefix(IN_DOMAIN(<, eArgCount) arg_style_t style);

/// @brief get all subgroups in a configuration group
///
Expand Down
Loading

0 comments on commit 297e854

Please sign in to comment.