From 6d7deff11ea63a789875ae2714fe42df51764bfc Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 16 Aug 2019 08:01:17 -0700 Subject: [PATCH] Removing shared scratch, passing in scratch on all system calls --- 4coder_default_hooks.cpp | 8 ++- 4coder_log_parser.cpp | 5 +- 4ed_api_implementation.cpp | 8 +-- 4ed_cli.cpp | 2 +- 4ed_edit.cpp | 2 +- 4ed_file.cpp | 2 +- 4ed_system.h | 10 ++-- 4ed_working_set.cpp | 7 ++- platform_all/4ed_shared_init_logic.cpp | 26 ++++----- platform_all/4ed_shared_library_constants.h | 14 ++--- platform_all/4ed_system_shared.cpp | 5 +- platform_all/4ed_system_shared.h | 3 +- platform_unix/unix_4ed_functions.cpp | 7 --- platform_win32/win32_4ed.cpp | 65 +++++++++++---------- platform_win32/win32_4ed_functions.cpp | 53 ++++++----------- platform_win32/win32_error_box.cpp | 22 ------- platform_win32/win32_library_wrapper.h | 7 +-- 17 files changed, 103 insertions(+), 143 deletions(-) delete mode 100644 platform_win32/win32_error_box.cpp diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index fd89e675..314dea52 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -849,9 +849,11 @@ default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view, } } else{ - // TODO(allen): this doesn't actually work we aren't supposed to - // assume that a function pointer is 64-bits I don't think. How - // should we attach a user named hook to a scope easily? + // TODO(allen): This doesn't actually work. + // We aren't supposed to assume that a function + // pointer is 64-bits I don't think. How + // should we attach a user named hook to a scope + // easily? View_Render_Hook *hook = (View_Render_Hook*)render_hook_value; hook(app, view, frame_info, inner); } diff --git a/4coder_log_parser.cpp b/4coder_log_parser.cpp index 9b522ac8..893d8c1b 100644 --- a/4coder_log_parser.cpp +++ b/4coder_log_parser.cpp @@ -399,9 +399,9 @@ CUSTOM_DOC("Tests the log parser") case LogTagKind_String: { - String_Const_u8 value = log_parse__get_string(&parse, node->value.value); + String_Const_u8 string_value = log_parse__get_string(&parse, node->value.value); string_list_pushf(scratch, &line, " [%.*s:%.*s]", - string_expand(tag_name), string_expand(value)); + string_expand(tag_name), string_expand(string_value)); }break; } } @@ -413,5 +413,6 @@ CUSTOM_DOC("Tests the log parser") } } + // BOTTOM diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 7bc4af2c..e1cd450d 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -1091,15 +1091,15 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl { Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; + Arena *arena = &models->mem.arena; Editing_File *file = imp_get_file(models, buffer_id); Buffer_Reopen_Result result = BufferReopenResult_Failed; if (api_check_buffer(file)){ if (file->canon.name_size > 0){ Plat_Handle handle = {}; - if (system->load_handle((char*)file->canon.name_space, &handle)){ + if (system->load_handle(arena, (char*)file->canon.name_space, &handle)){ File_Attributes attributes = system->load_attributes(handle); - Arena *arena = &models->mem.arena; Temp_Memory temp = begin_temp(arena); char *file_memory = push_array(arena, char, (i32)attributes.size); @@ -1176,8 +1176,8 @@ API_EXPORT File_Attributes Get_File_Attributes(Application_Links *app, String_Const_u8 file_name) { Models *models = (Models*)app->cmd_context; - File_Attributes attributes = models->system->quick_file_attributes(file_name); - return(attributes); + Arena *arena = &models->mem.arena; + return(models->system->quick_file_attributes(arena, file_name)); } internal View* diff --git a/4ed_cli.cpp b/4ed_cli.cpp index 2b634c20..cabdc467 100644 --- a/4ed_cli.cpp +++ b/4ed_cli.cpp @@ -98,7 +98,7 @@ child_process_call(Models *models, System_Functions *system, String_Const_u8 pat String_Const_u8 path_n = push_string_copy(scratch, path); String_Const_u8 command_n = push_string_copy(scratch, command); CLI_Handles cli_handles = {}; - if (system->cli_call((char*)path_n.str, (char*)command_n.str, &cli_handles)){ + if (system->cli_call(scratch, (char*)path_n.str, (char*)command_n.str, &cli_handles)){ Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes); *id_out = new_process.id; new_process.process->cli = cli_handles; diff --git a/4ed_edit.cpp b/4ed_edit.cpp index cdfda5bb..66244905 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -549,7 +549,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) do_empty_buffer = true; } else{ - if (!system->load_handle((char*)canon.name_space, &handle)){ + if (!system->load_handle(scratch, (char*)canon.name_space, &handle)){ do_empty_buffer = true; } } diff --git a/4ed_file.cpp b/4ed_file.cpp index 8b5fa1de..555c88b4 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -189,7 +189,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, } } - File_Attributes new_attributes = system->save_file((char*)file_name, data, size); + File_Attributes new_attributes = system->save_file(scratch, (char*)file_name, data, size); if (new_attributes.last_write_time > 0){ if (using_actual_file_name){ file->state.ignore_behind_os = 1; diff --git a/4ed_system.h b/4ed_system.h index 309ca113..404201e1 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -27,10 +27,10 @@ typedef Sys_Get_Canonical_Sig(System_Get_Canonical); typedef Sys_Get_File_List_Sig(System_Get_File_List); // file load/save -#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String_Const_u8 file_name) +#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(Arena *scratch, String_Const_u8 file_name) typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes); -#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out) +#define Sys_Load_Handle_Sig(name) b32 name(Arena *scratch, char *filename, Plat_Handle *handle_out) typedef Sys_Load_Handle_Sig(System_Load_Handle); #define Sys_Load_Attributes_Sig(name) File_Attributes name(Plat_Handle handle) @@ -42,7 +42,7 @@ typedef Sys_Load_File_Sig(System_Load_File); #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) typedef Sys_Load_Close_Sig(System_Load_Close); -#define Sys_Save_File_Sig(name) File_Attributes name(char *filename, char *buffer, u32 size) +#define Sys_Save_File_Sig(name) File_Attributes name(Arena *scratch, char *filename, char *buffer, u32 size) typedef Sys_Save_File_Sig(System_Save_File); // time @@ -82,8 +82,8 @@ struct CLI_Handles{ i32 exit; }; -#define Sys_CLI_Call_Sig(n, path, script, cli_out) b32 n(char *path, char *script, CLI_Handles *cli_out) -typedef Sys_CLI_Call_Sig(System_CLI_Call, path, script, cli_out); +#define Sys_CLI_Call_Sig(n, scratch, path, script, cli_out) b32 n(Arena *scratch, char *path, char *script, CLI_Handles *cli_out) +typedef Sys_CLI_Call_Sig(System_CLI_Call, scratch, path, script, cli_out); #define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli) typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update); diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index c82a346d..ed471bc1 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -20,10 +20,10 @@ working_set_file_default_settings(Working_Set *working_set, Editing_File *file){ //////////////////////////////// internal void -file_change_notification_check(System_Functions *system, Working_Set *working_set, Editing_File *file){ +file_change_notification_check(System_Functions *system, Arena *scratch, Working_Set *working_set, Editing_File *file){ if (file->canon.name_size > 0 && !file->settings.unimportant){ String_Const_u8 name = SCu8(file->canon.name_space, file->canon.name_size); - File_Attributes attributes = system->quick_file_attributes(name); + File_Attributes attributes = system->quick_file_attributes(scratch, name); if (attributes.last_write_time > file->attributes.last_write_time){ file_add_dirty_flag(file, DirtyState_UnloadedChanges); if (file->external_mod_node.next == 0){ @@ -41,6 +41,7 @@ internal void file_change_notification_thread_main(void *ptr){ Models *models = (Models*)ptr; System_Functions *system = models->system; + Arena arena = make_arena_system(system); Working_Set *working_set = &models->working_set; for (;;){ system->sleep(Thousand(250)); @@ -59,7 +60,7 @@ file_change_notification_thread_main(void *ptr){ if (node == used){ node = node->next; } - file_change_notification_check(system, working_set, file); + file_change_notification_check(system, &arena, working_set, file); } working_set->sync_check_iterator = node; } diff --git a/platform_all/4ed_shared_init_logic.cpp b/platform_all/4ed_shared_init_logic.cpp index 959c993e..98a8d466 100644 --- a/platform_all/4ed_shared_init_logic.cpp +++ b/platform_all/4ed_shared_init_logic.cpp @@ -10,7 +10,7 @@ // TOP internal void -memory_init(){ +memory_init(Arena *scratch){ #if defined(FRED_INTERNAL) # if ARCH_64BIT void *bases[] = { (void*)TB(1), (void*)TB(2), }; @@ -40,22 +40,20 @@ memory_init(){ if (!alloc_success){ char msg[] = "Could not allocate sufficient memory. Please make sure you have atleast 512Mb of RAM free. (This requirement will be relaxed in the future)."; - system_error_box(msg); + system_error_box(scratch, msg); } } internal void -load_app_code(void){ - //LOG("Loading 4coder core..."); - +load_app_code(Arena *scratch){ App_Get_Functions *get_funcs = 0; - if (system_load_library(&shared_vars.scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){ + if (system_load_library(scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){ get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions"); } else{ char msg[] = "Could not load '4ed_app." DLL "'. This file should be in the same directory as the main '4ed' executable."; - system_error_box(msg); + system_error_box(scratch, msg); } if (get_funcs != 0){ @@ -63,7 +61,7 @@ load_app_code(void){ } else{ char msg[] = "Failed to get application code from '4ed_app." DLL "'."; - system_error_box(msg); + system_error_box(scratch, msg); } } @@ -72,7 +70,7 @@ global char custom_fail_version_msg[] = "Failed to load custom code due to missi global char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper."; internal void -load_custom_code(){ +load_custom_code(Arena *scratch){ local_persist char *default_file = "custom_4coder"; local_persist Load_Library_Location locations[] = { LoadLibrary_CurrentDirectory, @@ -95,7 +93,7 @@ load_custom_code(){ for (u32 i = 0; custom_files[i] != 0 && !has_library; ++i){ char *file = custom_files[i]; for (u32 j = 0; j < ArrayCount(locations) && !has_library; ++j){ - if (system_load_library(&shared_vars.scratch, &libraries.custom, file, locations[j], success_file, sizeof(success_file))){ + if (system_load_library(scratch, &libraries.custom, file, locations[j], success_file, sizeof(success_file))){ has_library = true; success_file[sizeof(success_file) - 1] = 0; } @@ -103,21 +101,21 @@ load_custom_code(){ } if (!has_library){ - system_error_box("Did not find a library for the custom layer."); + system_error_box(scratch, "Did not find a library for the custom layer."); } custom_api.get_alpha_4coder_version = (_Get_Version_Function*) system_get_proc(&libraries.custom, "get_alpha_4coder_version"); if (custom_api.get_alpha_4coder_version == 0 || custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - system_error_box(custom_fail_version_msg); + system_error_box(scratch, custom_fail_version_msg); } custom_api.get_bindings = (Get_Binding_Data_Function*) system_get_proc(&libraries.custom, "get_bindings"); if (custom_api.get_bindings == 0){ - system_error_box(custom_fail_missing_get_bindings_msg); + system_error_box(scratch, custom_fail_missing_get_bindings_msg); } //LOGF("Loaded custom file: %s\n", success_file); @@ -132,7 +130,7 @@ read_command_line(Arena *scratch, i32 argc, char **argv){ char **files = 0; i32 *file_count = 0; app.read_command_line(&sysfunc, &memory_vars, curdir, &plat_settings, &files, &file_count, argc, argv); - sysshared_filter_real_files(files, file_count); + sysshared_filter_real_files(scratch, files, file_count); end_temp(temp); } diff --git a/platform_all/4ed_shared_library_constants.h b/platform_all/4ed_shared_library_constants.h index d236f9d7..3d1abe78 100644 --- a/platform_all/4ed_shared_library_constants.h +++ b/platform_all/4ed_shared_library_constants.h @@ -16,7 +16,7 @@ union Library; internal b32 -system_load_library_direct(Library *library, char *name); +system_load_library_direct(Arena *scratch, Library *library, char *name); internal void* system_get_proc(Library *library, char *name); @@ -69,12 +69,12 @@ system_load_library(Arena *scratch, Library *library, char *name_cstr, Load_Libr else{ path = push_u8_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name)); } - success = system_load_library_direct(library, (char*)path.str); - if (success && full_file_out != 0 && full_file_out > 0){ - u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1)); - block_copy(full_file_out, path.str, fill_size); - full_file_out[fill_size] = 0; - } + success = system_load_library_direct(scratch, library, (char*)path.str); + } + if (success && full_file_out != 0 && full_file_out > 0){ + u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1)); + block_copy(full_file_out, path.str, fill_size); + full_file_out[fill_size] = 0; } end_temp(temp); diff --git a/platform_all/4ed_system_shared.cpp b/platform_all/4ed_system_shared.cpp index 12cfdd98..36bd8910 100644 --- a/platform_all/4ed_system_shared.cpp +++ b/platform_all/4ed_system_shared.cpp @@ -18,7 +18,6 @@ internal void init_shared_vars(){ - shared_vars.scratch = make_arena_system(&sysfunc); shared_vars.font_scratch = make_arena_system(&sysfunc); shared_vars.pixel_scratch = make_arena_system(&sysfunc); } @@ -28,11 +27,11 @@ init_shared_vars(){ // internal void -sysshared_filter_real_files(char **files, i32 *file_count){ +sysshared_filter_real_files(Arena *scratch, char **files, i32 *file_count){ i32 end = *file_count; i32 i = 0, j = 0; for (; i < end; ++i){ - if (system_file_can_be_made((u8*)files[i])){ + if (system_file_can_be_made(scratch, (u8*)files[i])){ files[j] = files[i]; ++j; } diff --git a/platform_all/4ed_system_shared.h b/platform_all/4ed_system_shared.h index 1e4286a7..acc64717 100644 --- a/platform_all/4ed_system_shared.h +++ b/platform_all/4ed_system_shared.h @@ -24,11 +24,10 @@ struct File_Data{ }; global File_Data null_file_data = {}; -#define Sys_File_Can_Be_Made_Sig(name) b32 name(u8 *filename) +#define Sys_File_Can_Be_Made_Sig(name) b32 name(Arena *scratch, u8 *filename) internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); struct Shared_Vars{ - Arena scratch; Arena font_scratch; Arena pixel_scratch; }; diff --git a/platform_unix/unix_4ed_functions.cpp b/platform_unix/unix_4ed_functions.cpp index 641eccba..5341b3d4 100644 --- a/platform_unix/unix_4ed_functions.cpp +++ b/platform_unix/unix_4ed_functions.cpp @@ -392,12 +392,5 @@ Sys_File_Exists_Sig(system_file_exists){ return(result); } -internal b32 -system_directory_exists(char *path){ - struct stat st; - b32 result = (stat(path, &st) == 0 && S_ISDIR(st.st_mode)); - return(result); -} - // BOTTOM diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 99090a60..efeea656 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -63,7 +63,7 @@ enum{ }; internal void -win32_output_error_string(i32 error_string_type); +win32_output_error_string(Arena *scratch, i32 error_string_type); ////////////////////////////// @@ -153,6 +153,8 @@ struct Win32_Object{ }; struct Win32_Vars{ + Arena arena; + Win32_Input_Chunk input_chunk; b8 lctrl_lalt_is_altgr; b8 got_useful_event; @@ -212,25 +214,28 @@ global Custom_API custom_api; //////////////////////////////// -#include "win32_error_box.cpp" +internal void +system_error_box(Arena *scratch, char *msg, b32 shutdown = true){ + //LOGF("error box: %s\n", msg); + MessageBox_utf8(scratch, 0, (u8*)msg, (u8*)"Error", 0); + if (shutdown){ + exit(1); + } +} //////////////////////////////// internal void -win32_output_error_string(b32 use_error_box){ +win32_output_error_string(Arena *scratch, b32 use_error_box){ DWORD error = GetLastError(); char *str = 0; char *str_ptr = (char*)&str; if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, error, 0, str_ptr, 0, 0)){ - //LOGF("win32 error:\n%s\n", str); if (use_error_box){ - system_error_box(str, false); + system_error_box(scratch, str, false); } } - else{ - //LOGF("win32 error raw: %d\n", error); - } } //////////////////////////////// @@ -334,10 +339,10 @@ Sys_Is_Fullscreen_Sig(system_is_fullscreen){ // internal void -win32_post_clipboard(char *text, i32 len){ +win32_post_clipboard(Arena *scratch, char *text, i32 len){ if (OpenClipboard(win32vars.window_handle)){ if (!EmptyClipboard()){ - win32_output_error_string(ErrorString_UseLog); + win32_output_error_string(scratch, ErrorString_UseLog); } HANDLE memory_handle = GlobalAlloc(GMEM_MOVEABLE, len + 1); if (memory_handle){ @@ -373,8 +378,7 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } internal b32 -win32_read_clipboard_contents(void){ - Arena *scratch = &shared_vars.scratch; +win32_read_clipboard_contents(Arena *scratch){ Temp_Memory temp = begin_temp(scratch); b32 result = false; @@ -456,14 +460,12 @@ win32_read_clipboard_contents(void){ // internal -Sys_CLI_Call_Sig(system_cli_call, path, script_name, cli_out){ +Sys_CLI_Call_Sig(system_cli_call, scratch, path, script_name, cli_out){ Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); char cmd[] = "c:\\windows\\system32\\cmd.exe"; char *env_variables = 0; - Arena *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp(scratch); String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script_name); @@ -495,7 +497,7 @@ Sys_CLI_Call_Sig(system_cli_call, path, script_name, cli_out){ startup.wShowWindow = SW_HIDE; PROCESS_INFORMATION info = {}; - if (CreateProcess_utf8(&shared_vars.scratch, (u8*)cmd, s.str, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){ + if (CreateProcess_utf8(scratch, (u8*)cmd, s.str, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){ success = true; CloseHandle(info.hThread); *(HANDLE*)&cli_out->proc = info.hProcess; @@ -1026,6 +1028,7 @@ Sys_Condition_Variable_Free_Sig(system_condition_variable_free){ internal LRESULT win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ LRESULT result = 0; + Arena *scratch = &win32vars.arena; switch (uMsg){ case WM_MENUCHAR:break; @@ -1249,7 +1252,7 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_CLIPBOARDUPDATE: { win32vars.got_useful_event = true; - LogEventLit(win32vars.log_string(M), &shared_vars.scratch, 0, 0, system_thread_get_id(), + LogEventLit(win32vars.log_string(M), scratch, 0, 0, system_thread_get_id(), "new clipboard contents"); }break; @@ -1537,6 +1540,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Memory init // + win32vars.arena = make_arena_system(&sysfunc); + memset(&win32vars, 0, sizeof(win32vars)); memset(&target, 0, sizeof(target)); memset(&memory_vars, 0, sizeof(memory_vars)); @@ -1546,7 +1551,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS memset(&app, 0, sizeof(app)); memset(&custom_api, 0, sizeof(custom_api)); - memory_init(); + memory_init(&win32vars.arena); win32vars.cursor_show = MouseCursorShow_Always; win32vars.prev_cursor_show = MouseCursorShow_Always; @@ -1564,16 +1569,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS init_shared_vars(); - load_app_code(); + load_app_code(&win32vars.arena); win32vars.log_string = app.get_logger(&sysfunc); - read_command_line(&shared_vars.scratch, argc, argv); + read_command_line(&win32vars.arena, argc, argv); // // Load Custom Code // #if defined(FRED_SUPER) - load_custom_code(); + load_custom_code(&win32vars.arena); #else custom_api.get_bindings = get_bindings; #endif @@ -1614,7 +1619,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // if (!AddClipboardFormatListener(win32vars.window_handle)){ - win32_output_error_string(ErrorString_UseLog); + win32_output_error_string(&win32vars.arena, ErrorString_UseLog); } win32vars.clip_max = KB(16); @@ -1622,7 +1627,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.clipboard_sequence = GetClipboardSequenceNumber(); if (win32vars.clipboard_sequence == 0){ - win32_post_clipboard("", 0); + win32_post_clipboard(&win32vars.arena, "", 0); win32vars.clipboard_sequence = GetClipboardSequenceNumber(); win32vars.next_clipboard_is_self = 0; @@ -1632,7 +1637,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } } else{ - win32_read_clipboard_contents(); + win32_read_clipboard_contents(&win32vars.arena); } win32_keycode_init(); @@ -1657,8 +1662,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // { - Temp_Memory temp = begin_temp(&shared_vars.scratch); - String_Const_u8 curdir = sysfunc.get_current_path(&shared_vars.scratch); + Temp_Memory temp = begin_temp(&win32vars.arena); + String_Const_u8 curdir = sysfunc.get_current_path(&win32vars.arena); curdir = string_mod_replace_character(curdir, '\\', '/'); app.init(&sysfunc, &target, &memory_vars, win32vars.clipboard_contents, curdir, custom_api); end_temp(temp); @@ -1837,7 +1842,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } // NOTE(allen): Frame Clipboard Input - memset(&win32vars.clipboard_contents, 0, sizeof(win32vars.clipboard_contents)); + block_zero_struct(&win32vars.clipboard_contents); input.clipboard_changed = false; if (win32vars.clipboard_sequence != 0){ DWORD new_number = GetClipboardSequenceNumber(); @@ -1847,7 +1852,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } else{ for (i32 R = 0; R < 4; ++R){ - if (win32_read_clipboard_contents()){ + if (win32_read_clipboard_contents(&win32vars.arena)){ input.clipboard_changed = true; break; } @@ -1877,12 +1882,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // NOTE(allen): Post New Clipboard Content if (win32vars.clip_post.size > 0){ - win32_post_clipboard((char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); + win32_post_clipboard(&win32vars.arena, (char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); } // NOTE(allen): Switch to New Title if (result.has_new_title){ - SetWindowText_utf8(&shared_vars.scratch, win32vars.window_handle, (u8*)result.title_string); + SetWindowText_utf8(&win32vars.arena, win32vars.window_handle, (u8*)result.title_string); } // NOTE(allen): Switch to New Cursor diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index 686f2336..b8f72cfd 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -15,7 +15,7 @@ internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ - HANDLE file = CreateFile_utf8(&shared_vars.scratch, filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile_utf8(scratch, filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); b32 result = false; if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); @@ -71,9 +71,9 @@ Sys_Memory_Free_Sig(system_memory_free){ internal Sys_Get_Current_Path_Sig(system_get_current_path){ - DWORD size = GetCurrentDirectory_utf8(&shared_vars.scratch, 0, 0); + DWORD size = GetCurrentDirectory_utf8(arena, 0, 0); u8 *out = push_array(arena, u8, size); - GetCurrentDirectory_utf8(&shared_vars.scratch, size, out); + GetCurrentDirectory_utf8(arena, size, out); return(SCu8(out, size - 1)); } @@ -84,7 +84,7 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){ has_stashed_4ed_path = true; local_const i32 binary_path_capacity = KB(32); u8 *memory = (u8*)system_memory_allocate(binary_path_capacity); - i32 size = GetModuleFileName_utf8(&shared_vars.scratch, 0, memory, binary_path_capacity); + i32 size = GetModuleFileName_utf8(arena, 0, memory, binary_path_capacity); Assert(size <= binary_path_capacity - 1); win32vars.binary_path = SCu8(memory, size); win32vars.binary_path = string_remove_last_folder(win32vars.binary_path); @@ -121,22 +121,20 @@ win32_remove_unc_prefix_characters(String_Const_u8 path){ internal Sys_Get_Canonical_Sig(system_get_canonical){ String_Const_u8 result = {}; - Arena *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp(scratch); if ((character_is_alpha(string_get_character(name, 0)) && string_get_character(name, 1) == ':') || string_match(string_prefix(name, 2), string_u8_litexpr("\\\\"))){ - u8 *c_name = push_array(scratch, u8, name.size + 1); + u8 *c_name = push_array(arena, u8, name.size + 1); block_copy(c_name, name.str, name.size); c_name[name.size] = 0; - HANDLE file = CreateFile_utf8(scratch, c_name, GENERIC_READ, 0, 0, OPEN_EXISTING, + HANDLE file = CreateFile_utf8(arena, c_name, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD capacity = GetFinalPathNameByHandle_utf8(scratch, file, 0, 0, 0); + DWORD capacity = GetFinalPathNameByHandle_utf8(arena, file, 0, 0, 0); u8 *buffer = push_array(arena, u8, capacity); - DWORD length = GetFinalPathNameByHandle_utf8(scratch, file, buffer, capacity, 0); + DWORD length = GetFinalPathNameByHandle_utf8(arena, file, buffer, capacity, 0); if (length > 0 && buffer[length - 1] == 0){ length -= 1; } @@ -148,19 +146,19 @@ Sys_Get_Canonical_Sig(system_get_canonical){ String_Const_u8 path = string_remove_front_of_path(name); String_Const_u8 front = string_front_of_path(name); - u8 *c_path = push_array(scratch, u8, path.size + 1); + u8 *c_path = push_array(arena, u8, path.size + 1); block_copy(c_path, path.str, path.size); c_path[path.size] = 0; - HANDLE dir = CreateFile_utf8(scratch, c_path, FILE_LIST_DIRECTORY, + HANDLE dir = CreateFile_utf8(arena, c_path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD capacity = GetFinalPathNameByHandle_utf8(scratch, dir, 0, 0, 0); + DWORD capacity = GetFinalPathNameByHandle_utf8(arena, dir, 0, 0, 0); u8 *buffer = push_array(arena, u8, capacity + front.size + 1); - DWORD length = GetFinalPathNameByHandle_utf8(scratch, dir, buffer, capacity, 0); + DWORD length = GetFinalPathNameByHandle_utf8(arena, dir, buffer, capacity, 0); if (length > 0 && buffer[length - 1] == 0){ length -= 1; } @@ -174,7 +172,6 @@ Sys_Get_Canonical_Sig(system_get_canonical){ } } } - end_temp(temp); return(result); } @@ -209,18 +206,16 @@ win32_file_attributes_from_HANDLE(HANDLE file){ internal Sys_Get_File_List_Sig(system_get_file_list){ File_List result = {}; - Arena *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp(scratch); String_Const_u8 search_pattern = {}; if (character_is_slash(string_get_character(directory, directory.size - 1))){ - search_pattern = push_u8_stringf(scratch, "%.*s*", string_expand(directory)); + search_pattern = push_u8_stringf(arena, "%.*s*", string_expand(directory)); } else{ - search_pattern = push_u8_stringf(scratch, "%.*s\\*", string_expand(directory)); + search_pattern = push_u8_stringf(arena, "%.*s\\*", string_expand(directory)); } WIN32_FIND_DATA find_data = {}; - HANDLE search = FindFirstFile_utf8(&shared_vars.scratch, search_pattern.str, &find_data); + HANDLE search = FindFirstFile_utf8(arena, search_pattern.str, &find_data); if (search != INVALID_HANDLE_VALUE){ File_Info *first = 0; File_Info *last = 0; @@ -260,7 +255,6 @@ Sys_Get_File_List_Sig(system_get_file_list){ } } - end_temp(temp); return(result); } @@ -268,7 +262,7 @@ internal Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){ WIN32_FILE_ATTRIBUTE_DATA info = {}; File_Attributes result = {}; - if (GetFileAttributesEx_utf8String(&shared_vars.scratch, file_name, GetFileExInfoStandard, &info)){ + if (GetFileAttributesEx_utf8String(scratch, file_name, GetFileExInfoStandard, &info)){ result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow); result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime); result.flags = win32_convert_file_attribute_flags(info.dwFileAttributes); @@ -279,7 +273,7 @@ Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){ internal Sys_Load_Handle_Sig(system_load_handle){ b32 result = false; - HANDLE file = CreateFile_utf8(&shared_vars.scratch, (u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ *(HANDLE*)handle_out = file; result = true; @@ -319,7 +313,8 @@ Sys_Load_Close_Sig(system_load_close){ internal Sys_Save_File_Sig(system_save_file){ File_Attributes result = {}; - HANDLE file = CreateFile_utf8(&shared_vars.scratch, (u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + + HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ DWORD written_total = 0; @@ -344,16 +339,6 @@ Sys_Save_File_Sig(system_save_file){ return(result); } -// -// File System -// - -internal b32 -system_directory_exists(char *path){ - DWORD attrib = GetFileAttributes_utf8(&shared_vars.scratch, (u8*)path); - return(attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); -} - // // Color picker // diff --git a/platform_win32/win32_error_box.cpp b/platform_win32/win32_error_box.cpp deleted file mode 100644 index ad6771ec..00000000 --- a/platform_win32/win32_error_box.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 18.07.2017 - * - * Windows fatal error message box. - * - */ - -// TOP - -internal void -system_error_box(char *msg, b32 shutdown = true){ - //LOGF("error box: %s\n", msg); - MessageBox_utf8(&shared_vars.scratch, 0, (u8*)msg, (u8*)"Error", 0); - if (shutdown){ - exit(1); - } -} - -// BOTTOM - diff --git a/platform_win32/win32_library_wrapper.h b/platform_win32/win32_library_wrapper.h index 3f4a1b59..a647a4bb 100644 --- a/platform_win32/win32_library_wrapper.h +++ b/platform_win32/win32_library_wrapper.h @@ -15,20 +15,19 @@ union Library{ }; internal b32 -system_load_library_direct(Library *library, char *name){ +system_load_library_direct(Arena *scratch, Library *library, char *name){ AssertLibrarySizes(); library->lib = LoadLibraryA(name); b32 success = (library->lib != 0); if (!success){ - win32_output_error_string(ErrorString_UseLog); + win32_output_error_string(scratch, ErrorString_UseLog); } return(success); } internal void* system_get_proc(Library *library, char *name){ - void *result = GetProcAddress(library->lib, name); - return(result); + return(GetProcAddress(library->lib, name)); } internal void