aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-08 16:53:41 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-10-08 16:54:31 -0700
commitf48ec4b8ee30f8bd42326e5b8df631a8d9234518 (patch)
tree555f43639f0d35f8cd86662ec1390414ffced5fc /src/Compilation.zig
parent1ad33f53fea4109160ccfceec94efa2013f3b3b3 (diff)
downloadzig-f48ec4b8ee30f8bd42326e5b8df631a8d9234518.tar.gz
zig-f48ec4b8ee30f8bd42326e5b8df631a8d9234518.zip
use long-lived arena for `@cImport`-generated Module
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 29689ce6b9..c2ce5f16f5 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -41,8 +41,9 @@ const resinator = @import("resinator.zig");
/// General-purpose allocator. Used for both temporary and long-term storage.
gpa: Allocator,
-/// Arena-allocated memory used during initialization. Should be untouched until deinit.
-arena_state: std.heap.ArenaAllocator.State,
+/// Arena-allocated memory, mostly used during initialization. However, it can be used
+/// for other things requiring the same lifetime as the `Compilation`.
+arena: std.heap.ArenaAllocator,
bin_file: *link.File,
c_object_table: std.AutoArrayHashMapUnmanaged(*CObject, void) = .{},
win32_resource_table: if (build_options.only_core_functionality) void else std.AutoArrayHashMapUnmanaged(*Win32Resource, void) =
@@ -124,7 +125,7 @@ cache_parent: *Cache,
/// Path to own executable for invoking `zig clang`.
self_exe_path: ?[]const u8,
/// null means -fno-emit-bin.
-/// This is mutable memory allocated into the Compilation-lifetime arena (`arena_state`)
+/// This is mutable memory allocated into the Compilation-lifetime arena (`arena`)
/// of exactly the correct size for "o/[digest]/[basename]".
/// The basename is of the outputted binary file in case we don't know the directory yet.
whole_bin_sub_path: ?[]u8,
@@ -1661,7 +1662,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
errdefer bin_file.destroy();
comp.* = .{
.gpa = gpa,
- .arena_state = arena_allocator.state,
+ .arena = arena_allocator,
.zig_lib_directory = options.zig_lib_directory,
.local_cache_directory = options.local_cache_directory,
.global_cache_directory = options.global_cache_directory,
@@ -1979,7 +1980,8 @@ pub fn destroy(self: *Compilation) void {
if (self.owned_link_dir) |*dir| dir.close();
// This destroys `self`.
- self.arena_state.promote(gpa).deinit();
+ var arena_instance = self.arena;
+ arena_instance.deinit();
}
pub fn clearMiscFailures(comp: *Compilation) void {
@@ -3899,17 +3901,12 @@ pub fn obtainWin32ResourceCacheManifest(comp: *const Compilation) Cache.Manifest
return man;
}
-test "cImport" {
- _ = cImport;
-}
-
pub const CImportResult = struct {
out_zig_path: []u8,
cache_hit: bool,
errors: std.zig.ErrorBundle,
pub fn deinit(result: *CImportResult, gpa: std.mem.Allocator) void {
- gpa.free(result.out_zig_path);
result.errors.deinit(gpa);
}
};
@@ -4054,7 +4051,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
};
}
- const out_zig_path = try comp.local_cache_directory.join(comp.gpa, &[_][]const u8{
+ const out_zig_path = try comp.local_cache_directory.join(comp.arena.allocator(), &.{
"o", &digest, cimport_zig_basename,
});
if (comp.verbose_cimport) {