aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-28 00:02:41 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitcff67f93caeb3f98261860904dd232f6b551299e (patch)
tree94715ee98cc0ea62ea60da96b8b2d3a595b5276e /src/parser.c
parent0ed62b9337c64a91481afd91f9e5706a36eca7b5 (diff)
fix crashes
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c14
1 files changed, 8 insertions, 6 deletions
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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -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;
}
/*