commit d060be880460598dcf89cb3d59bfcdf5059a923d (tree)
parent 6b4863416611253c68539136ae9e4b83359efe74
Author: Noam Preil <pleasantatk@gmail.com>
Date: Wed, 8 Jul 2020 14:10:11 -0400
CBE: Don't expose openCFile, always close file after an update
Diffstat:
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig
@@ -86,7 +86,7 @@ pub fn writeFilePath(
return result;
}
-pub fn openCFile(allocator: *Allocator, file: fs.File, options: Options) !File.C {
+fn openCFile(allocator: *Allocator, file: fs.File, options: Options) !File.C {
return File.C{
.allocator = allocator,
.file = file,
@@ -282,6 +282,8 @@ pub const File = struct {
}
}
try writer.writeAll(self.main.items);
+ self.file.?.close();
+ self.file = null;
}
};
diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig
@@ -480,9 +480,8 @@ pub const TestContext = struct {
switch (update.case) {
.Transformation => |expected_output| {
if (case.cbe) {
- var cfile: *link.File.C = module.bin_file.cast(link.File.C).?;
- cfile.file.?.close();
- cfile.file = null;
+ // The C file is always closed after an update, because we don't support
+ // incremental updates
var file = try tmp.dir.openFile(bin_name, .{ .read = true });
defer file.close();
var out = file.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!");