Commit d060be8804

Noam Preil <pleasantatk@gmail.com>
2020-07-08 20:10:11
CBE: Don't expose openCFile, always close file after an update
1 parent 6b48634
Changed files (2)
src-self-hosted
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;
         }
     };
 
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!");