@@ -41,8 +41,9 @@ const resinator = @import("resinator.zig");
41
41
42
42
/// General-purpose allocator. Used for both temporary and long-term storage.
43
43
gpa : Allocator ,
44
- /// Arena-allocated memory used during initialization. Should be untouched until deinit.
45
- arena_state : std.heap.ArenaAllocator.State ,
44
+ /// Arena-allocated memory, mostly used during initialization. However, it can be used
45
+ /// for other things requiring the same lifetime as the `Compilation`.
46
+ arena : std.heap.ArenaAllocator ,
46
47
bin_file : * link.File ,
47
48
c_object_table : std .AutoArrayHashMapUnmanaged (* CObject , void ) = .{},
48
49
win32_resource_table : if (build_options .only_core_functionality ) void else std .AutoArrayHashMapUnmanaged (* Win32Resource , void ) =
@@ -124,7 +125,7 @@ cache_parent: *Cache,
124
125
/// Path to own executable for invoking `zig clang`.
125
126
self_exe_path : ? []const u8 ,
126
127
/// null means -fno-emit-bin.
127
- /// This is mutable memory allocated into the Compilation-lifetime arena (`arena_state `)
128
+ /// This is mutable memory allocated into the Compilation-lifetime arena (`arena `)
128
129
/// of exactly the correct size for "o/[digest]/[basename]".
129
130
/// The basename is of the outputted binary file in case we don't know the directory yet.
130
131
whole_bin_sub_path : ? []u8 ,
@@ -1661,7 +1662,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1661
1662
errdefer bin_file .destroy ();
1662
1663
comp .* = .{
1663
1664
.gpa = gpa ,
1664
- .arena_state = arena_allocator . state ,
1665
+ .arena = arena_allocator ,
1665
1666
.zig_lib_directory = options .zig_lib_directory ,
1666
1667
.local_cache_directory = options .local_cache_directory ,
1667
1668
.global_cache_directory = options .global_cache_directory ,
@@ -1979,7 +1980,8 @@ pub fn destroy(self: *Compilation) void {
1979
1980
if (self .owned_link_dir ) | * dir | dir .close ();
1980
1981
1981
1982
// This destroys `self`.
1982
- self .arena_state .promote (gpa ).deinit ();
1983
+ var arena_instance = self .arena ;
1984
+ arena_instance .deinit ();
1983
1985
}
1984
1986
1985
1987
pub fn clearMiscFailures (comp : * Compilation ) void {
@@ -3899,17 +3901,12 @@ pub fn obtainWin32ResourceCacheManifest(comp: *const Compilation) Cache.Manifest
3899
3901
return man ;
3900
3902
}
3901
3903
3902
- test "cImport" {
3903
- _ = cImport ;
3904
- }
3905
-
3906
3904
pub const CImportResult = struct {
3907
3905
out_zig_path : []u8 ,
3908
3906
cache_hit : bool ,
3909
3907
errors : std.zig.ErrorBundle ,
3910
3908
3911
3909
pub fn deinit (result : * CImportResult , gpa : std.mem.Allocator ) void {
3912
- gpa .free (result .out_zig_path );
3913
3910
result .errors .deinit (gpa );
3914
3911
}
3915
3912
};
@@ -4054,7 +4051,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
4054
4051
};
4055
4052
}
4056
4053
4057
- const out_zig_path = try comp .local_cache_directory .join (comp .gpa , &[ _ ][] const u8 {
4054
+ const out_zig_path = try comp .local_cache_directory .join (comp .arena . allocator () , &. {
4058
4055
"o" , & digest , cimport_zig_basename ,
4059
4056
});
4060
4057
if (comp .verbose_cimport ) {
0 commit comments