authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 20:22:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 20:22:15-04:00
log3fccc0747903f0726d6cc8ee73832cb62f1304bb
treea54ec000a8bb83ebe6691dc73a3f418483fef063
parentf68d8060ec2c65e3062007348c0e331ffbe86f37
signaturelock-open Commit is signed but in an unrecognized format.

self-hosted translate-c: fix bad memory arena references


1 files changed, 14 insertions(+), 14 deletions(-)

src-self-hosted/translate_c.zig+14-14
......@@ -151,10 +151,21 @@ pub fn translate(
151151
152152 var tree_arena = std.heap.ArenaAllocator.init(backing_allocator);
153153 errdefer tree_arena.deinit();
154 var arena = &tree_arena.allocator;
155154
156 const root_node = try arena.create(ast.Node.Root);
157 root_node.* = ast.Node.Root{
155 const tree = try tree_arena.allocator.create(ast.Tree);
156 tree.* = ast.Tree{
157 .source = undefined, // need to use Buffer.toOwnedSlice later
158 .root_node = undefined,
159 .arena_allocator = tree_arena,
160 .tokens = undefined, // can't reference the allocator yet
161 .errors = undefined, // can't reference the allocator yet
162 };
163 const arena = &tree.arena_allocator.allocator; // now we can reference the allocator
164 tree.tokens = ast.Tree.TokenList.init(arena);
165 tree.errors = ast.Tree.ErrorList.init(arena);
166
167 tree.root_node = try arena.create(ast.Node.Root);
168 tree.root_node.* = ast.Node.Root{
158169 .base = ast.Node{ .id = ast.Node.Id.Root },
159170 .decls = ast.Node.Root.DeclList.init(arena),
160171 .doc_comments = null,
......@@ -162,17 +173,6 @@ pub fn translate(
162173 .eof_token = undefined,
163174 };
164175
165 const tree = try arena.create(ast.Tree);
166 tree.* = ast.Tree{
167 .source = undefined, // need to use Buffer.toOwnedSlice later
168 .root_node = root_node,
169 .arena_allocator = undefined,
170 .tokens = ast.Tree.TokenList.init(arena),
171 .errors = ast.Tree.ErrorList.init(arena),
172 };
173 tree.arena_allocator = tree_arena;
174 arena = &tree.arena_allocator.allocator;
175
176176 var source_buffer = try std.Buffer.initSize(arena, 0);
177177
178178 var context = Context{