From 435c8ad703503e4dcc102b0907b45459d2693822 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Oct 2020 16:06:14 -0700 Subject: [PATCH] non-hacky workaround for the empty file bug See #3328 --- src/stage1.zig | 2 ++ src/stage1/analyze.cpp | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/stage1.zig b/src/stage1.zig index d07a1c199c..2dabea91ad 100644 --- a/src/stage1.zig +++ b/src/stage1.zig @@ -428,5 +428,7 @@ export fn stage2_fetch_file( const max_file_size = std.math.maxInt(u32); const contents = comp.stage1_cache_manifest.addFilePostFetch(file_path, max_file_size) catch return null; result_len.* = contents.len; + // TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475 + if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1); return contents.ptr; } diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 24530307a2..fd0de8e907 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -8052,13 +8052,10 @@ not_integer: } Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) { - size_t len = 0xAA; + size_t len; const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len); - if (len == 0) { - // File exists but is empty (otherwise it would be 0xAA) - } else if (contents == nullptr) { + if (contents == nullptr) return ErrorFileNotFound; - } buf_init_from_mem(contents_buf, contents, len); return ErrorNone; }