From cff67f93caeb3f98261860904dd232f6b551299e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 28 Feb 2019 00:02:41 +0100 Subject: fix crashes --- src/parser.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index da85292..bb7c8d3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5,6 +5,7 @@ #include "../include/std/file.h" #include "../include/std/mem.h" #include "../include/std/log.h" +#include "../include/std/alloc.h" #include #include #include @@ -220,8 +221,8 @@ int parser_parse_buffer(Parser *self, BufferView code_buffer, BufferView buffer_ int parser_parse_file(Parser *self, BufferView filepath) { int result; - int mapped_file_deinit_result; - MappedFile mapped_file; + char *file_data; + usize file_size; char *filepath_tmp; amal_log_debug("Parsing %.*s", (int)filepath.size, filepath.data); @@ -232,11 +233,12 @@ int parser_parse_file(Parser *self, BufferView filepath) { filepath_tmp = malloc(filepath.size + 1); am_memcpy(filepath_tmp, filepath.data, filepath.size); filepath_tmp[filepath.size] = '\0'; - result = mapped_file_init(&mapped_file, filepath_tmp, MAPPED_FILE_READ); + result = read_whole_file(filepath_tmp, &file_data, &file_size); if(result != 0) return result; - result = parser_parse_buffer(self, create_buffer_view(mapped_file.file_data, mapped_file.file_size), filepath); - mapped_file_deinit_result = mapped_file_deinit(&mapped_file); - return result != 0 ? result : mapped_file_deinit_result; + result = parser_parse_buffer(self, create_buffer_view(file_data, file_size), create_buffer_view(filepath_tmp, filepath.size)); + /* TODO: Somehow free this.. causes issue where filepath becomes corrupt */ + /*am_free(file_data);*/ + return result; } /* -- cgit v1.2.3