Fix really stupid bug in Array's array_reserve
This commit is contained in:
parent
5c18e6f4da
commit
046d86423a
@ -16,3 +16,9 @@ void internal_free (void* memory) {
|
||||
allocator.proc(Allocator_Mode::DEALLOCATE, 0, 0, memory, allocator.data);
|
||||
}
|
||||
|
||||
void print_context_allocator () {
|
||||
Assert(thread_context()->allocator.proc);
|
||||
|
||||
char* result = (char*)thread_context()->allocator.proc(Allocator_Mode::DETAILS, 0, 0, nullptr, thread_context()->allocator.data);
|
||||
log_none("Current allocator details: %s", result);
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ enum class Allocator_Mode: s32 {
|
||||
RESIZE = 1,
|
||||
DEALLOCATE = 2,
|
||||
// IS_THIS_YOURS = 3,
|
||||
// DETAILS = 4,
|
||||
DETAILS = 4, // #who_am_i
|
||||
};
|
||||
|
||||
typedef void* (*Allocator_Proc)(Allocator_Mode mode, s64 requested_size, s64 old_size, void* old_memory, void* allocator_data);
|
||||
@ -119,3 +119,7 @@ template <typename T> T* copy_struct (T* src) {
|
||||
T* dst = New<T>(false);
|
||||
memcpy(dst, src, sizeof(T));
|
||||
}
|
||||
|
||||
// #TODO: Turn this into a macro that also provides the
|
||||
// file, line number to the print.
|
||||
void print_context_allocator ();
|
||||
@ -22,9 +22,15 @@ void* arena_allocator_proc (Allocator_Mode mode, s64 requested_size, s64 old_siz
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
case Allocator_Mode::DEALLOCATE:
|
||||
case Allocator_Mode::DEALLOCATE: {
|
||||
return nullptr; // unused
|
||||
break;
|
||||
} break;
|
||||
case Allocator_Mode::DETAILS: {
|
||||
if (allocator_data == nullptr) {
|
||||
return "arena_allocator_proc: data pointer is null!";
|
||||
}
|
||||
return "arena_allocator_proc";
|
||||
} break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
@ -122,7 +122,6 @@ template <typename T>
|
||||
void array_reserve (Array<T>& src, s64 desired_items) {
|
||||
if (desired_items <= src.allocated) return;
|
||||
|
||||
src.data = nullptr;
|
||||
if (src.allocator.proc == nullptr) {
|
||||
src.allocator = context_allocator();
|
||||
}
|
||||
@ -133,7 +132,7 @@ void array_reserve (Array<T>& src, s64 desired_items) {
|
||||
|
||||
Assert(src.data != nullptr);
|
||||
|
||||
src.allocated = desired_items;
|
||||
src.allocated = desired_items;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@ -51,3 +51,4 @@ struct Push_Allocator {
|
||||
context->allocator = old_allocator;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -213,7 +213,7 @@ void push_errors_to_parent_thread (Thread_Context* tctx) {
|
||||
}
|
||||
|
||||
ArrayView<Error*> get_all_errors (Thread_Context* tctx) {
|
||||
Array<Error*> error_array;
|
||||
Array<Error*> error_array = {};
|
||||
// call with temp() recommended.
|
||||
Error* current_error = tctx->first_error;
|
||||
while (current_error) {
|
||||
|
||||
@ -28,9 +28,21 @@ void* expandable_arena_allocator_proc (Allocator_Mode mode, s64 requested_size,
|
||||
memcpy(new_memory, old_memory, old_size);
|
||||
return new_memory;
|
||||
} break;
|
||||
case Allocator_Mode::DEALLOCATE:
|
||||
case Allocator_Mode::DEALLOCATE: {
|
||||
return nullptr;
|
||||
break;
|
||||
} break;
|
||||
case Allocator_Mode::DETAILS: {
|
||||
if (allocator_data == nullptr) {
|
||||
return "expandable_arena_allocator_proc: data pointer is null!";
|
||||
}
|
||||
if (thread_context()->temp == allocator_data) {
|
||||
return "expandable_arena_allocator_proc: temp arena";
|
||||
}
|
||||
if (thread_context()->arena == allocator_data) {
|
||||
return "expandable_arena_allocator_proc: main arena";
|
||||
}
|
||||
return "expandable_arena_allocator_proc: other arena";
|
||||
} break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
@ -158,9 +158,13 @@ void* GPAllocator_Proc (Allocator_Mode mode, s64 requested_size, s64 old_size, v
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
case Allocator_Mode::DEALLOCATE:
|
||||
case Allocator_Mode::DEALLOCATE: {
|
||||
GPAllocator_Delete(old_memory); // unused
|
||||
break;
|
||||
} break;
|
||||
case Allocator_Mode::DETAILS: {
|
||||
Assert(allocator_data == nullptr);
|
||||
return "GPAllocator";
|
||||
} break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
@ -165,7 +165,7 @@ File_System Win32_filesystem_from_string (string s) {
|
||||
Assert(false);
|
||||
return File_System::Unknown;
|
||||
}
|
||||
struct Dense_FS; // #Temp forward declare!
|
||||
struct Dense_FS; // #hack forward declare!
|
||||
struct Win32_Drive {
|
||||
string label;
|
||||
string volume_name;
|
||||
|
||||
@ -205,6 +205,10 @@ Error* NTFS_MFT_read_raw (OS_Drive* drive) {
|
||||
|
||||
Assert(data_attribute != nullptr);
|
||||
|
||||
// #dense_fs_alloc
|
||||
Dense_FS* dfs = New<Dense_FS>();
|
||||
initialize(dfs, drive);
|
||||
|
||||
NTFS_RunHeader* dataRun = (NTFS_RunHeader*)((u8*)data_attribute + data_attribute->dataRunsOffset);
|
||||
u64 cluster_number = 0, records_processed = 0;
|
||||
|
||||
@ -273,6 +277,7 @@ Error* NTFS_MFT_read_raw (OS_Drive* drive) {
|
||||
// We need to get size from the data attribute
|
||||
|
||||
// #TODO: #continue from here!
|
||||
// See Dense_FS drive->data
|
||||
mft->file_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,10 +182,11 @@ void Ex1_Control_Panel () { using namespace ImGui;
|
||||
for_each(t, ex1_ntfs.threads_in_flight) {
|
||||
if (thread_is_done(ex1_ntfs.threads_in_flight[t])) {
|
||||
push_allocator(GPAllocator());
|
||||
|
||||
Thread* thread = ex1_ntfs.threads_in_flight[t];
|
||||
auto task = thread_task(NTFS_Enumeration_Task);
|
||||
array_free(task->drives);
|
||||
// internal_free(
|
||||
|
||||
// make sure to retreive any data you need to from here!
|
||||
release_arena(task->pool);
|
||||
|
||||
@ -200,6 +201,7 @@ void Ex1_Control_Panel () { using namespace ImGui;
|
||||
|
||||
void ImGui_Debug_Panel () { using namespace ImGui;
|
||||
push_allocator(temp());
|
||||
|
||||
Begin("Debug Panel");
|
||||
SeparatorText("ex1_ntfs");
|
||||
Text("Threads in flight count: %d", ex1_ntfs.threads_in_flight.count);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user