diff --git a/src/common/base/include/base/bitset.h b/src/common/base/include/base/bitset.h index cd393db0..4170817a 100644 --- a/src/common/base/include/base/bitset.h +++ b/src/common/base/include/base/bitset.h @@ -48,7 +48,7 @@ CT_BASE_API bitset_t bitset_of(IN_READS(words) void *data, size_t words); /// /// @return the index of the next free bit, or SIZE_MAX if none are free CT_NODISCARD -CT_BASE_API size_t bitset_set_first(IN_NOTNULL bitset_t set, size_t start); +CT_BASE_API size_t bitset_set_first(bitset_t set, size_t start); /// @brief test if any bits in a given mask are set /// @@ -56,7 +56,7 @@ CT_BASE_API size_t bitset_set_first(IN_NOTNULL bitset_t set, size_t start); /// @param mask the mask to test /// /// @return true if any bits in the mask are set -CT_BASE_API bool bitset_any(IN_NOTNULL const bitset_t set, IN_NOTNULL const bitset_t mask); +CT_BASE_API bool bitset_any(bitset_t set, bitset_t mask); /// @brief test if all bits in a given mask are set /// @@ -64,7 +64,7 @@ CT_BASE_API bool bitset_any(IN_NOTNULL const bitset_t set, IN_NOTNULL const bits /// @param mask the mask to test /// /// @return true if all bits in the mask are set -CT_BASE_API bool bitset_all(IN_NOTNULL const bitset_t set, IN_NOTNULL const bitset_t mask); +CT_BASE_API bool bitset_all(bitset_t set, bitset_t mask); /// @brief test if a bit is set /// @@ -72,31 +72,31 @@ CT_BASE_API bool bitset_all(IN_NOTNULL const bitset_t set, IN_NOTNULL const bits /// @param index the index of the bit to test /// /// @return true if the bit is set -CT_BASE_API bool bitset_test(IN_NOTNULL const bitset_t set, size_t index); +CT_BASE_API bool bitset_test(bitset_t set, size_t index); /// @brief set a bit /// /// @param set the bitset to modify /// @param index the index of the bit to set -CT_BASE_API void bitset_set(IN_NOTNULL bitset_t set, size_t index); +CT_BASE_API void bitset_set(bitset_t set, size_t index); /// @brief clear a bit /// /// @param set the bitset to modify /// @param index the index of the bit to clear -CT_BASE_API void bitset_clear(IN_NOTNULL bitset_t set, size_t index); +CT_BASE_API void bitset_clear(bitset_t set, size_t index); /// @brief reset all bits in a bitset /// /// @param set the bitset to reset -CT_BASE_API void bitset_reset(IN_NOTNULL bitset_t set); +CT_BASE_API void bitset_reset(bitset_t set); /// @brief get the number of bits in a bitset /// /// @param set the bitset to get the length of /// /// @return the number of bits in the bitset -CT_BASE_API size_t bitset_len(IN_NOTNULL const bitset_t set); +CT_BASE_API size_t bitset_len(bitset_t set); /// @} diff --git a/src/common/base/include/base/util.h b/src/common/base/include/base/util.h index 9f75cb94..93eb2e31 100644 --- a/src/common/base/include/base/util.h +++ b/src/common/base/include/base/util.h @@ -16,6 +16,12 @@ CT_BEGIN_API /// @ingroup base /// @{ +/// @brief check if a path is special +/// special paths are paths such as "." and ".." that are not valid for most operations +/// +/// @param path the path to check +/// +/// @retval true if the path is special CT_NODISCARD CT_CONSTFN CT_BASE_API bool is_path_special(IN_STRING const char *path); @@ -25,7 +31,7 @@ CT_BASE_API bool is_path_special(IN_STRING const char *path); /// /// @return the hash of the pointer CT_NODISCARD CT_CONSTFN -CT_BASE_API size_t ptrhash(const void *ptr); +CT_BASE_API size_t ctu_ptrhash(const void *ptr); /// @brief hash a string /// diff --git a/src/common/base/src/bitset.c b/src/common/base/src/bitset.c index e2a26993..b5735420 100644 --- a/src/common/base/src/bitset.c +++ b/src/common/base/src/bitset.c @@ -25,14 +25,14 @@ static size_t word_offset(size_t bit) return bit % WORD_SIZE; } -static bitset_word_t *bitset_start(const bitset_t set) +static bitset_word_t *bitset_start(bitset_t set) { CTASSERT(set.data != NULL); return (bitset_word_t*)set.data; } -static bitset_word_t *word_at(const bitset_t set, size_t index) +static bitset_word_t *word_at(bitset_t set, size_t index) { return bitset_start(set) + index; } @@ -80,7 +80,7 @@ size_t bitset_set_first(bitset_t set, size_t start) } USE_DECL -bool bitset_any(const bitset_t set, const bitset_t mask) +bool bitset_any(bitset_t set, bitset_t mask) { size_t words = CT_MIN(set.words, mask.words); @@ -99,7 +99,7 @@ bool bitset_any(const bitset_t set, const bitset_t mask) } USE_DECL -bool bitset_all(const bitset_t set, const bitset_t mask) +bool bitset_all(bitset_t set, bitset_t mask) { size_t words = CT_MIN(set.words, mask.words); @@ -118,7 +118,7 @@ bool bitset_all(const bitset_t set, const bitset_t mask) } USE_DECL -bool bitset_test(const bitset_t set, size_t index) +bool bitset_test(bitset_t set, size_t index) { CTASSERTF(bitset_len(set) > index, "index %zu is out of range %zu", index, bitset_len(set)); @@ -158,7 +158,7 @@ void bitset_reset(bitset_t set) } USE_DECL -size_t bitset_len(const bitset_t set) +size_t bitset_len(bitset_t set) { CTASSERT(set.data != NULL); diff --git a/src/common/base/src/util.c b/src/common/base/src/util.c index a859c0e7..6ff444cb 100644 --- a/src/common/base/src/util.c +++ b/src/common/base/src/util.c @@ -13,7 +13,7 @@ bool is_path_special(const char *path) } USE_DECL -size_t ptrhash(const void *ptr) +size_t ctu_ptrhash(const void *ptr) { uintptr_t key = (uintptr_t)ptr; key = (~key) + (key << 18); diff --git a/src/common/core/include/core/compiler.h b/src/common/core/include/core/compiler.h index 6ced5784..651f79a9 100644 --- a/src/common/core/include/core/compiler.h +++ b/src/common/core/include/core/compiler.h @@ -199,13 +199,4 @@ # define CT_ENUM_FLAGS(X, T) #endif -/// @brief the container length type -/// seperately defined as some compilers have support -/// for unsigned types with undefined overflow behaviour. -/// we can use these to get more effective ubsan checks. -/// @note i think it can also help with optimization but i'm not sure -typedef size_t ctu_length_t; - -typedef size_t ctu_hash_t; - /// @} diff --git a/src/common/core/include/core/size.h b/src/common/core/include/core/size.h new file mode 100644 index 00000000..b258de21 --- /dev/null +++ b/src/common/core/include/core/size.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +/// @ingroup core +/// @{ + +/// @brief the container length type +/// seperately defined as some compilers have support +/// for unsigned types with undefined overflow behaviour. +/// we can use these to get more effective ubsan checks. +/// @note i think it can also help with optimization but i'm not sure +typedef size_t ctu_length_t; +#define CTU_LENGTH_MAX SIZE_MAX + +typedef size_t ctu_hash_t; +#define CTU_HASH_MAX SIZE_MAX + +typedef unsigned char ctu_byte_t; +#define CTU_BYTE_MAX UCHAR_MAX + +/// @} diff --git a/src/common/io/include/io/impl.h b/src/common/io/include/io/impl.h index f2bbd131..fa4d68b9 100644 --- a/src/common/io/include/io/impl.h +++ b/src/common/io/include/io/impl.h @@ -44,7 +44,7 @@ typedef size_t (*io_write_t)(io_t *self, const void *src, size_t size); /// @param args the format arguments /// /// @return the total number of bytes copied into the io object -typedef size_t (*io_write_format_t)(io_t *self, const char *fmt, va_list args); +typedef size_t (*io_fwrite_t)(io_t *self, const char *fmt, va_list args); /// @brief io size callback /// get the total size of an io objects backing data @@ -92,7 +92,7 @@ typedef struct io_callbacks_t /// @brief write format callback /// may be NULL on non-writable objects /// @note if this is NULL, @a fn_write will be used instead - io_write_format_t fn_fwrite; + io_fwrite_t fn_fwrite; /// @brief total size callback /// must always be provided diff --git a/src/common/os/include/os/core.h b/src/common/os/include/os/core.h index 9ff2e5b7..49c59f62 100644 --- a/src/common/os/include/os/core.h +++ b/src/common/os/include/os/core.h @@ -36,6 +36,8 @@ typedef enum os_access_t { #define OS_ACCESS(ID, STR, BIT) ID = (BIT), #include "os.inc" + + eOsAccessMask = eOsAccessRead | eOsAccessWrite | eOsAccessTruncate, } os_access_t; /// @brief file mapping memory protection @@ -43,6 +45,8 @@ typedef enum os_protect_t { #define OS_PROTECT(ID, STR, BIT) ID = (BIT), #include "os.inc" + + eOsProtectMask = eOsProtectRead | eOsProtectWrite | eOsProtectExecute, } os_protect_t; /// @brief directory entry type diff --git a/src/common/os/include/os/os.h b/src/common/os/include/os/os.h index d2279f3c..c6485644 100644 --- a/src/common/os/include/os/os.h +++ b/src/common/os/include/os/os.h @@ -104,6 +104,31 @@ CT_OS_API os_error_t os_library_symbol( CT_NODISCARD CT_OS_API const char *os_library_name(IN_NOTNULL const os_library_t *library); +/// console api + +/// @brief write to the default output stream +/// stdout or equivalent +/// +/// @param text the text to write +/// +/// @return an error if the text could not be written +CT_OS_API os_error_t os_console_write(IN_STRING const char *text); + +/// @brief write to the default error stream +/// stderr or equivalent +/// +/// @param text the text to write +/// +/// @return an error if the text could not be written +CT_OS_API os_error_t os_console_error(IN_STRING const char *text); + +/// @brief write to the debug stream +/// +/// @param text the text to write +/// +/// @return an error if the text could not be written +CT_OS_API os_error_t os_console_debug(IN_STRING const char *text); + /// filesytem api /// @brief copy a file from one location to another @@ -234,6 +259,7 @@ CT_OS_API os_error_t os_tmpfile_open(OUT_NOTNULL os_file_t *file); /// @brief close a file /// /// @param file the file to close +RET_INSPECT CT_OS_API os_error_t os_file_close(OUT_PTR_INVALID os_file_t *file); /// @brief read from a file diff --git a/src/common/os/src/os_common.c b/src/common/os/src/os_common.c index 426ce5bd..80c9f04c 100644 --- a/src/common/os/src/os_common.c +++ b/src/common/os/src/os_common.c @@ -17,58 +17,38 @@ const char *os_dirent_string(os_dirent_t type) return kDirentNames[type]; } +static const char *const kAccessNames[] = { + [eOsAccessNone] = "none", + [eOsAccessRead] = "read", + [eOsAccessWrite] = "write", + [eOsAccessRead | eOsAccessWrite] = "read/write", + [eOsAccessTruncate] = "truncate", + [eOsAccessRead | eOsAccessTruncate] = "read (truncate)", + [eOsAccessWrite | eOsAccessTruncate] = "write (truncate)", + [eOsAccessRead | eOsAccessWrite | eOsAccessTruncate] = "read/write (truncate)", +}; + USE_DECL const char *os_access_string(os_access_t access) { - switch (access) - { - case (eOsAccessRead | eOsAccessWrite | eOsAccessTruncate): - return "read/write (truncate)"; - case (eOsAccessWrite | eOsAccessTruncate): - return "write (truncate)"; - case (eOsAccessRead | eOsAccessTruncate): - return "read (truncate)"; - - case (eOsAccessRead | eOsAccessWrite): - return "read/write"; - case eOsAccessRead: - return "read"; - case eOsAccessWrite: - return "write"; - - case eOsAccessNone: - return "none"; - - default: - CT_NEVER("invalid access flags 0x%x", access); - } + CTASSERTF(!(access & ~eOsAccessMask), "invalid access flags 0x%x", access); + return kAccessNames[access]; } +static const char *const kProtectNames[] = { + [eOsProtectNone] = "none", + [eOsProtectRead] = "read", + [eOsProtectWrite] = "write", + [eOsProtectExecute] = "execute", + [eOsProtectRead | eOsProtectWrite] = "read/write", + [eOsProtectRead | eOsProtectExecute] = "read/execute", + [eOsProtectWrite | eOsProtectExecute] = "write/execute", + [eOsProtectRead | eOsProtectWrite | eOsProtectExecute] = "read/write/execute", +}; + USE_DECL const char *os_protect_string(os_protect_t protect) { - switch (protect) - { - case (eOsProtectRead | eOsProtectWrite | eOsProtectExecute): - return "read/write/execute"; - case (eOsProtectRead | eOsProtectExecute): - return "read/execute"; - case (eOsProtectWrite | eOsProtectExecute): - return "write/execute"; - case (eOsProtectRead | eOsProtectWrite): - return "read/write"; - - case eOsProtectRead: - return "read"; - case eOsProtectWrite: - return "write"; - case eOsProtectExecute: - return "execute"; - - case eOsProtectNone: - return "none"; - - default: - CT_NEVER("invalid protect flags 0x%x", protect); - } + CTASSERTF(!(protect & ~eOsProtectMask), "invalid protect flags 0x%x", protect); + return kProtectNames[protect]; } diff --git a/src/common/scan/include/scan/scan.h b/src/common/scan/include/scan/scan.h index 361b1389..6deb3dc4 100644 --- a/src/common/scan/include/scan/scan.h +++ b/src/common/scan/include/scan/scan.h @@ -33,7 +33,7 @@ typedef struct scan_t arena_t *nodes; /// @brief the name of the language this file contains - const char *language; + FIELD_STRING const char *language; /// @brief the path to this file FIELD_STRING const char *path; diff --git a/src/common/std/src/typeinfo.c b/src/common/std/src/typeinfo.c index 3685d7c5..ad6ad20b 100644 --- a/src/common/std/src/typeinfo.c +++ b/src/common/std/src/typeinfo.c @@ -5,7 +5,7 @@ #include "std/typeinfo.h" #include "base/util.h" -size_t info_ptr_hash(const void *key) { return ptrhash(key); } +size_t info_ptr_hash(const void *key) { return ctu_ptrhash(key); } bool info_ptr_equal(const void *lhs, const void *rhs) { return lhs == rhs; } size_t info_str_hash(const void *key) { return str_hash(key); } diff --git a/src/frontend/gui/imgui/imgui_draw.cpp b/src/frontend/gui/imgui/imgui_draw.cpp index c3251478..cce13581 100644 --- a/src/frontend/gui/imgui/imgui_draw.cpp +++ b/src/frontend/gui/imgui/imgui_draw.cpp @@ -2884,7 +2884,7 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) // Convert our ranges in the format stb_truetype wants ImFontConfig& cfg = atlas->ConfigData[src_i]; src_tmp.PackRange.font_size = cfg.SizePixels * cfg.RasterizerDensity; - src_tmp.PackRange.first_unicode_codepoint_IN_DOMAIN = 0; + src_tmp.PackRange.first_unicode_codepoint_in_range = 0; src_tmp.PackRange.array_of_unicode_codepoints = src_tmp.GlyphsList.Data; src_tmp.PackRange.num_chars = src_tmp.GlyphsList.Size; src_tmp.PackRange.chardata_for_range = src_tmp.PackedChars; diff --git a/src/frontend/gui/imgui/imstb_truetype.h b/src/frontend/gui/imgui/imstb_truetype.h index 11f47928..684a1d3d 100644 --- a/src/frontend/gui/imgui/imstb_truetype.h +++ b/src/frontend/gui/imgui/imstb_truetype.h @@ -607,10 +607,10 @@ STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc); #define STBTT_POINT_SIZE(x) (-(x)) STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_char_IN_DOMAIN, int num_chars_IN_DOMAIN, stbtt_packedchar *chardata_for_range); + int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range); // Creates character bitmaps from the font_index'th font found in fontdata (use -// font_index=0 if you don't know what that is). It creates num_chars_IN_DOMAIN -// bitmaps for characters with unicode values starting at first_unicode_char_IN_DOMAIN +// font_index=0 if you don't know what that is). It creates num_chars_in_range +// bitmaps for characters with unicode values starting at first_unicode_char_in_range // and increasing. Data for how to render them is stored in chardata_for_range; // pass these to stbtt_GetPackedQuad to get back renderable quads. // @@ -624,7 +624,7 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char typedef struct { float font_size; - int first_unicode_codepoint_IN_DOMAIN; // if non-zero, then the chars are continuous, and this is the first codepoint + int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints int num_chars; stbtt_packedchar *chardata_for_range; // output @@ -4167,7 +4167,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb ranges[i].v_oversample = (unsigned char) spc->v_oversample; for (j=0; j < ranges[i].num_chars; ++j) { int x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_IN_DOMAIN + j : ranges[i].array_of_unicode_codepoints[j]; + int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; int glyph = stbtt_FindGlyphIndex(info, codepoint); if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) { rects[k].w = rects[k].h = 0; @@ -4237,7 +4237,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const if (r->was_packed && r->w != 0 && r->h != 0) { stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; int advance, lsb, x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_IN_DOMAIN + j : ranges[i].array_of_unicode_codepoints[j]; + int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; int glyph = stbtt_FindGlyphIndex(info, codepoint); stbrp_coord pad = (stbrp_coord) spc->padding; @@ -4344,12 +4344,12 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char } STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_codepoint_IN_DOMAIN, int num_chars_IN_DOMAIN, stbtt_packedchar *chardata_for_range) + int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) { stbtt_pack_range range; - range.first_unicode_codepoint_IN_DOMAIN = first_unicode_codepoint_IN_DOMAIN; + range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range; range.array_of_unicode_codepoints = NULL; - range.num_chars = num_chars_IN_DOMAIN; + range.num_chars = num_chars_in_range; range.chardata_for_range = chardata_for_range; range.font_size = font_size; return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1); diff --git a/src/support/setup/src/setup.c b/src/support/setup/src/setup.c index 59adc2b3..e44ec7b6 100644 --- a/src/support/setup/src/setup.c +++ b/src/support/setup/src/setup.c @@ -165,7 +165,6 @@ static void pretty_panic_handler(source_info_t location, const char *fmt, va_lis io_printf(io, "[panic][%s:%" CT_PRI_LINE "] => %s: %s\n", location.file, location.line, location.function, msg); print_backtrace(backtrace_config, report); - os_abort(); os_exit(CT_EXIT_INTERNAL); } diff --git a/tests/unit/cases/util/bitset.c b/tests/unit/cases/util/bitset.c index 136fa5c7..ed1dc7e6 100644 --- a/tests/unit/cases/util/bitset.c +++ b/tests/unit/cases/util/bitset.c @@ -48,4 +48,3 @@ int main(void) return test_suite_finish(&suite); } -