more fixes

This commit is contained in:
2025-02-09 00:37:35 -05:00
parent d82af845bc
commit 83ce4d1bb2
17 changed files with 1348 additions and 1324 deletions
+5 -5
View File
@@ -12,22 +12,22 @@
//- rjf: arena creation/destruction
Arena*
arena_alloc_(ArenaParams* params)
arena__alloc(ArenaParams params)
{
SPTR const header_size = align_pow2(size_of(Arena), MD_DEFAULT_MEMORY_ALIGNMENT);
// TODO(Ed): Do we need to be slapping the arena onto the memory now?
// (its technically not needed a its no longer always backed by vmem)
void* base = alloc(params->backing, params->block_size);
void* base = alloc(params.backing, params.block_size);
// rjf: extract arena header & fill
Arena* arena = (Arena*) base;
arena->prev = nullptr;
arena->current = arena;
arena->backing = params->backing;
arena->backing = params.backing;
arena->base_pos = 0;
arena->pos = header_size;
arena->block_size = params->block_size;
arena->flags = params->flags;
arena->block_size = params.block_size;
arena->flags = params.flags;
asan_unpoison_memory_region(base, sizeof(Arena));
return arena;
}
+2 -2
View File
@@ -171,7 +171,7 @@ cmd_line_from_string_list(Arena* arena, String8List command_line)
}
U8 splits[] = { ',' };
String8List args_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
String8List args_in_this_string = str8_split(arena, string, splits, array_count(splits), 0);
for (String8Node* sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) {
str8_list_push(arena, &arguments, sub_arg->string);
}
@@ -273,7 +273,7 @@ cmd_line_from_string_list_alloc(AllocatorInfo ainfo, String8List command_line)
}
U8 splits[] = { ',' };
String8List args_in_this_string = str8_split_alloc(ainfo, string, splits, ArrayCount(splits), 0);
String8List args_in_this_string = str8_split_alloc(ainfo, string, splits, array_count(splits), 0);
for (String8Node* sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) {
str8_list_alloc(ainfo, &arguments, sub_arg->string);
}
+3 -3
View File
@@ -14,9 +14,9 @@
#ifndef trap
# if COMPILER_MSVC
# if _MSC_VER < 1300
# define MD_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
# define trap() __asm int 3 /* Trap to debugger! */
# else
# define MD_DEBUG_TRAP() __debugbreak()
# define trap() __debugbreak()
# endif
# elif COMPILER_CLANG || COMPILER_GCC
# define trap() __builtin_trap()
@@ -31,7 +31,7 @@
if ( ! ( cond ) ) \
{ \
assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \
MD_DEBUG_TRAP(); \
trap(); \
} \
} while ( 0 )
+1 -1
View File
@@ -17,7 +17,7 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char**
tmSetMaxThreadCount(256);
tmInitialize(sizeof(tm_data), (char *)tm_data);
#endif
ThreadNameF("[main thread]");
thread_namef("[main thread]");
// TODO(Ed): Review?
TempArena scratch = scratch_begin(0, 0);
+1
View File
@@ -2,6 +2,7 @@
# pragma once
# include "linkage.h"
# include "strings.h"
# include "thread_context.h"
#endif
// Copyright (c) 2024 Epic Games Tools
+2 -2
View File
@@ -370,10 +370,10 @@ struct Rng1S64Array
#endif
#ifndef clamp_top
#define clamp_top(A, X) Min(A, X)
#define clamp_top(A, X) md_min(A, X)
#endif
#ifndef clamp_bot
#define clamp_bot(X, B) Max(X, B)
#define clamp_bot(X, B) md_max(X, B)
#endif
#define clamp(A, X, B) (((X) < (A)) ? (A) : ((X) > (B)) ? (B) : (X))
+5 -5
View File
@@ -202,7 +202,7 @@ void* mem_move( void* destination, void const* source, SSIZE byte_count )
if ( dest_ptr < src_ptr )
{
if ( to_uptr(src_ptr) % size_of( SSIZE ) == to_uptr(dest_ptr) % size_of( SSIZE ) )
if ( scast(UPTR, src_ptr) % size_of( SSIZE ) == scast(UPTR, dest_ptr) % size_of( SSIZE ) )
{
while ( pcast( UPTR, dest_ptr) % size_of( SSIZE ) )
{
@@ -224,9 +224,9 @@ void* mem_move( void* destination, void const* source, SSIZE byte_count )
}
else
{
if ( ( to_uptr(src_ptr) % size_of( SSIZE ) ) == ( to_uptr(dest_ptr) % size_of( SSIZE ) ) )
if ( ( scast(UPTR, src_ptr) % size_of( SSIZE ) ) == ( scast(UPTR, dest_ptr) % size_of( SSIZE ) ) )
{
while ( to_uptr( dest_ptr + byte_count ) % size_of( SSIZE ) )
while ( scast(UPTR, dest_ptr + byte_count ) % size_of( SSIZE ) )
{
if ( ! byte_count-- )
return destination;
@@ -274,7 +274,7 @@ void* mem_set( void* destination, U8 fill_byte, SSIZE byte_count )
if ( byte_count < 9 )
return destination;
align_offset = -to_sptr( dest_ptr ) & 3;
align_offset = -scast(SPTR, dest_ptr ) & 3;
dest_ptr += align_offset;
byte_count -= align_offset;
byte_count &= -4;
@@ -300,7 +300,7 @@ void* mem_set( void* destination, U8 fill_byte, SSIZE byte_count )
* rcast( U32*, dest_ptr + byte_count - 20 ) = fill_word;
* rcast( U32*, dest_ptr + byte_count - 16 ) = fill_word;
align_offset = 24 + to_uptr( dest_ptr ) & 4;
align_offset = 24 + scast(UPTR, dest_ptr ) & 4;
dest_ptr += align_offset;
byte_count -= align_offset;
+32 -1
View File
@@ -4,6 +4,37 @@
# include "../os/os.h"
#endif
void*
default_resize_align( AllocatorInfo a, void* old_memory, SSIZE old_size, SSIZE new_size, SSIZE alignment )
{
if ( ! old_memory )
return alloc_align( a, new_size, alignment );
if ( new_size == 0 )
{
alloc_free( a, old_memory );
return nullptr;
}
if ( new_size < old_size )
new_size = old_size;
if ( old_size == new_size )
{
return old_memory;
}
else
{
void* new_memory = alloc_align( a, new_size, alignment );
if ( ! new_memory )
return nullptr;
mem_move( new_memory, old_memory, md_min( new_size, old_size ) );
alloc_free( a, old_memory );
return new_memory;
}
}
#ifdef MD_HEAP_ANALYSIS
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
@@ -96,7 +127,7 @@ heap_allocator_proc( void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE
{
ptr = _aligned_malloc( size, alignment );
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
zero_size( ptr, size );
memory_zero( ptr, size );
}
break;
-31
View File
@@ -287,34 +287,3 @@ resize_align( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE new_size, SSIZE
}
return a.proc( a.data, AllocatorMode_Resize, new_size, alignment, ptr, old_size, MD_DEFAULT_ALLOCATOR_FLAGS );
}
inline void*
default_resize_align( AllocatorInfo a, void* old_memory, SSIZE old_size, SSIZE new_size, SSIZE alignment )
{
if ( ! old_memory )
return alloc_align( a, new_size, alignment );
if ( new_size == 0 )
{
allocator_free( a, old_memory );
return nullptr;
}
if ( new_size < old_size )
new_size = old_size;
if ( old_size == new_size )
{
return old_memory;
}
else
{
void* new_memory = alloc_align( a, new_size, alignment );
if ( ! new_memory )
return nullptr;
mem_move( new_memory, old_memory, min( new_size, old_size ) );
allocator_free( a, old_memory );
return new_memory;
}
}
+2 -2
View File
@@ -2093,7 +2093,7 @@ fuzzy_match_range_list_copy_alloc(AllocatorInfo ainfo, FuzzyMatchRangeList* src)
U64
str8_serial_push_align(Arena* arena, String8List* srl, U64 align) {
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
Assert(is_pow2(align));
assert(is_pow2(align));
U64 pos = srl->total_size;
U64 new_pos = align_pow2(pos, align);
U64 size = (new_pos - pos);
@@ -2178,7 +2178,7 @@ str8_serial_push_u32(Arena* arena, String8List* srl, U32 x) {
U64
str8_serial_alloc_align(AllocatorInfo ainfo, String8List* srl, U64 align) {
Assert(is_pow2(align));
assert(is_pow2(align));
U64 pos = srl->total_size;
U64 new_pos = align_pow2(pos, align);
U64 size = (new_pos - pos);
+2 -2
View File
@@ -38,7 +38,7 @@ msg_list_push(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, String8 str
sll_queue_push(msgs->first, msgs->last, msg);
msgs->count += 1;
msgs->worst_message_kind = Max(kind, msgs->worst_message_kind);
msgs->worst_message_kind = md_max(kind, msgs->worst_message_kind);
}
void
@@ -912,7 +912,7 @@ parse_from_text_tokens(Arena* arena, String8 filename, String8 text, TokenArray
Node* error = push_node(arena, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
String8 error_string = push_str8f(arena, "More than two newlines following \"%S\", which has implicitly-delimited children, resulting in an empty list of children.", node->string);
msg_list_push(arena, &msgs, error, MsgKind_Warning, error_string);
MD_ParseWorkPop();
parse_work_pop();
}
else
{
+1
View File
@@ -19,6 +19,7 @@ MD_NS_BEGIN
#include "base/strings.c"
#include "base/text.c"
#include "base/thread_context.c"
#include "base/markup.c"
#include "base/command_line.c"
#include "base/logger.c"
#include "base/entry_point.c"
+1 -1
View File
@@ -536,7 +536,7 @@ mg_node_grid_make_from_node(Arena *arena, Node *root)
for each_node(row, root->first)
{
U64 cell_count_this_row = child_count_from_node(row);
column_count = Max(column_count, cell_count_this_row);
column_count = md_max(column_count, cell_count_this_row);
}
// rjf: fill grid
+3 -3
View File
@@ -950,10 +950,10 @@ os_safe_call(OS_ThreadFunctionType* func, OS_ThreadFunctionType* fail_handler, v
int signals_to_handle[] = {
SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP,
};
struct sigaction og_act[ArrayCount(signals_to_handle)] = {0};
struct sigaction og_act[array_count(signals_to_handle)] = {0};
// rjf: attach handler info for all signals
for(U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) {
for(U32 i = 0; i < array_count(signals_to_handle); i += 1) {
sigaction(signals_to_handle[i], &new_act, &og_act[i]);
}
@@ -961,7 +961,7 @@ os_safe_call(OS_ThreadFunctionType* func, OS_ThreadFunctionType* fail_handler, v
func(ptr);
// rjf: reset handler info for all signals
for (U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) {
for (U32 i = 0; i < array_count(signals_to_handle); i += 1) {
sigaction(signals_to_handle[i], &og_act[i], 0);
}
}
+15 -15
View File
@@ -859,7 +859,7 @@ os_thread_launch(OS_ThreadFunctionType* func, void* ptr, void* params) {
entity->thread.func = func;
entity->thread.ptr = ptr;
entity->thread.handle = CreateThread(0, 0, os_w32_thread_entry_point, entity, 0, &entity->thread.tid);
OS_Handle result = {IntFromPtr(entity)};
OS_Handle result = {int_from_ptr(entity)};
return result;
}
@@ -891,7 +891,7 @@ OS_Handle
os_mutex_alloc(void) {
OS_W32_Entity* entity = os_w32_entity_alloc(OS_W32_EntityKind_Mutex);
InitializeCriticalSection(&entity->mutex);
OS_Handle result = {IntFromPtr(entity)};
OS_Handle result = {int_from_ptr(entity)};
return result;
}
@@ -920,7 +920,7 @@ OS_Handle
os_rw_mutex_alloc(void) {
OS_W32_Entity* entity = os_w32_entity_alloc(OS_W32_EntityKind_RWMutex);
InitializeSRWLock(&entity->rw_mutex);
OS_Handle result = {IntFromPtr(entity)};
OS_Handle result = {int_from_ptr(entity)};
return result;
}
@@ -960,7 +960,7 @@ OS_Handle
os_condition_variable_alloc(void) {
OS_W32_Entity* entity = os_w32_entity_alloc(OS_W32_EntityKind_ConditionVariable);
InitializeConditionVariable(&entity->cv);
OS_Handle result = {IntFromPtr(entity)};
OS_Handle result = {int_from_ptr(entity)};
return result;
}
@@ -1178,7 +1178,7 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
int buflen = 0;
DWORD exception_code = exception_ptrs->ExceptionRecord->ExceptionCode;
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"A fatal exception (code 0x%x) occurred. The process is terminating.\n", exception_code);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"A fatal exception (code 0x%x) occurred. The process is terminating.\n", exception_code);
// load dbghelp dynamically just in case if it is missing
HMODULE dbghelp = LoadLibraryA("dbghelp.dll");
@@ -1267,7 +1267,7 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
const U32 max_frames = 32;
if(idx == max_frames)
{
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"...");
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"...");
break;
}
@@ -1285,16 +1285,16 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
if(idx==0)
{
#if BUILD_CONSOLE_INTERFACE
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"\nCreate a new issue with this report at %S.\n\n", BUILD_ISSUES_LINK_STRING_LITERAL);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"\nCreate a new issue with this report at %S.\n\n", BUILD_ISSUES_LINK_STRING_LITERAL);
#else
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen,
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen,
L"\nPress Ctrl+C to copy this text to clipboard, then create a new issue at\n"
L"<a href=\"%S\">%S</a>\n\n", BUILD_ISSUES_LINK_STRING_LITERAL, BUILD_ISSUES_LINK_STRING_LITERAL);
#endif
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"Call stack:\n");
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"Call stack:\n");
}
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"%u. [0x%I64x]", idx + 1, address);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"%u. [0x%I64x]", idx + 1, address);
struct
{
@@ -1308,7 +1308,7 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
DWORD64 displacement = 0;
if (dbg_SymFromAddrW(process, address, &displacement, &symbol.info))
{
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L" %s +%u", symbol.info.Name, (DWORD)displacement);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L" %s +%u", symbol.info.Name, (DWORD)displacement);
IMAGEHLP_LINEW64
line = {0};
@@ -1316,7 +1316,7 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
DWORD line_displacement = 0;
if(dbg_SymGetLineFromAddrW64(process, address, &line_displacement, &line)) {
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L", %s line %u", PathFindFileNameW(line.FileName), line.LineNumber);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L", %s line %u", PathFindFileNameW(line.FileName), line.LineNumber);
}
}
else
@@ -1325,18 +1325,18 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs)
module = {0};
module.SizeOfStruct = sizeof(module);
if (dbg_SymGetModuleInfoW64(process, address, &module)) {
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L" %s", module.ModuleName);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L" %s", module.ModuleName);
}
}
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"\n");
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"\n");
}
}
}
}
}
buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"\nVersion: %S%S", BUILD_VERSION_STRING_LITERAL, BUILD_GIT_HASH_STRING_LITERAL_APPEND);
buflen += wnsprintfW(buffer + buflen, array_count(buffer) - buflen, L"\nVersion: %S%S", BUILD_VERSION_STRING_LITERAL, BUILD_GIT_HASH_STRING_LITERAL_APPEND);
#if BUILD_CONSOLE_INTERFACE
fwprintf(stderr, L"\n--- Fatal Exception ---\n");
+8 -8
View File
@@ -1016,14 +1016,14 @@ namespace MsgKind, MD_MsgKind
word Msg, MD_Msg
word MsgList, MD_MsgList
word TokenFlags, MD_MsgFlags
namespace TokenFlag_, MD_TokenFlag_
word TokenFlagGroups, MD_TokenFlagGroups
namespace TokenFlagGroup_, MD_TokenFlagGroup_
word Token, MD_Token
word TokenChunkNode, MD_TokenChunkNode
word TokenChunkList, MD_TokenChunkList
word TokenArray, MD_TokenArray
word TokenFlags, MD_MsgFlags
namespace TokenFlag_, MD_TokenFlag_
word TokenFlagGroups, MD_TokenFlagGroups
namespace TokenFlagGroup_, MD_TokenFlagGroup_
word Token, MD_Token
word TokenChunkNode, MD_TokenChunkNode
word TokenChunkList, MD_TokenChunkList
word TokenArray, MD_TokenArray
namespace NodeKind, MD_NodeKind
word Node, MD_Node
+1265 -1243
View File
File diff suppressed because it is too large Load Diff