Skip to content

Commit

Permalink
uhhh
Browse files Browse the repository at this point in the history
  • Loading branch information
apache-hb committed Apr 15, 2024
1 parent 297e854 commit 55ba7f5
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 87 deletions.
16 changes: 8 additions & 8 deletions src/common/base/include/base/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,55 @@ 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
///
/// @param set the bitset to test
/// @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
///
/// @param set the bitset to test
/// @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
///
/// @param set the bitset to test
/// @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);

/// @}

Expand Down
8 changes: 7 additions & 1 deletion src/common/base/include/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
///
Expand Down
12 changes: 6 additions & 6 deletions src/common/base/src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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));

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/common/base/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions src/common/core/include/core/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// @}
22 changes: 22 additions & 0 deletions src/common/core/include/core/size.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <stddef.h>

/// @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

/// @}
4 changes: 2 additions & 2 deletions src/common/io/include/io/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/common/os/include/os/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ 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
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
Expand Down
26 changes: 26 additions & 0 deletions src/common/os/include/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
72 changes: 26 additions & 46 deletions src/common/os/src/os_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
2 changes: 1 addition & 1 deletion src/common/scan/include/scan/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/common/std/src/typeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/gui/imgui/imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 55ba7f5

Please sign in to comment.