| author | |
| committer | |
| log | a870228ab467906ecc663bf89ecd042b49e116f5 |
| tree | 9a584d415178434c7eecc38f7b1b3161774d351f |
| parent | cc4552733351390aecab9ae900beb822237d6041 |
2 files changed, 12 insertions(+), 2 deletions(-)
src-self-hosted/compilation.zig+8-2| ... | ... | @@ -30,6 +30,9 @@ const Package = @import("package.zig").Package; |
| 30 | 30 | const link = @import("link.zig").link; |
| 31 | 31 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 32 | 32 | const CInt = @import("c_int.zig").CInt; |
| 33 | const fs = event.fs; | |
| 34 | ||
| 35 | const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB | |
| 33 | 36 | |
| 34 | 37 | /// Data that is local to the event loop. |
| 35 | 38 | pub const EventLoopLocal = struct { |
| ... | ... | @@ -757,8 +760,11 @@ pub const Compilation = struct { |
| 757 | 760 | const root_scope = blk: { |
| 758 | 761 | errdefer self.gpa().free(root_src_real_path); |
| 759 | 762 | |
| 760 | // TODO async/await readFileAlloc() | |
| 761 | const source_code = io.readFileAlloc(self.gpa(), root_src_real_path) catch |err| { | |
| 763 | const source_code = (await (async fs.readFile( | |
| 764 | self.loop, | |
| 765 | root_src_real_path, | |
| 766 | max_src_size, | |
| 767 | ) catch unreachable)) catch |err| { | |
| 762 | 768 | try printError("unable to open '{}': {}", root_src_real_path, err); |
| 763 | 769 | return err; |
| 764 | 770 | }; |
std/event/fs.zig+4| ... | ... | @@ -273,6 +273,7 @@ pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []cons |
| 273 | 273 | |
| 274 | 274 | /// The promise resumes when the last data has been confirmed written, but before the file handle |
| 275 | 275 | /// is closed. |
| 276 | /// Caller owns returned memory. | |
| 276 | 277 | pub async fn readFile(loop: *event.Loop, file_path: []const u8, max_size: usize) ![]u8 { |
| 277 | 278 | var close_op = try CloseOperation.create(loop); |
| 278 | 279 | defer close_op.deinit(); |
| ... | ... | @@ -292,6 +293,9 @@ pub async fn readFile(loop: *event.Loop, file_path: []const u8, max_size: usize) |
| 292 | 293 | const buf_array = [][]u8{buf}; |
| 293 | 294 | const amt = try await (async preadv(loop, fd, list.len, buf_array) catch unreachable); |
| 294 | 295 | list.len += amt; |
| 296 | if (list.len > max_size) { | |
| 297 | return error.FileTooBig; | |
| 298 | } | |
| 295 | 299 | if (amt < buf.len) { |
| 296 | 300 | return list.toOwnedSlice(); |
| 297 | 301 | } |