So im currently implementing the first steps in a play c compiler. Im using process.run() to perform a gcc command on a c file that i want to generate an assembly and preprocessed file for. What im confused about is when i use gpa.free() on result.stderr and result.stdout it works fine but when i try and use it in result.term it causes a comp error. Now i know and understand that term is a Union type but in the Allocator.free() documentation it states that:
" Free an array allocated with alloc . If memory has length 0, free is a no-op. To free a single item, see destroy"
with the function signature as: anytype
pub fn free(self: Allocator, memory: anytype) void
Looking at the source code for it confuses me why cant it delete a type union if the memory in the signature for free is anytype??
const result = try std.process.run(gpa, io, .{ .argv = gcc_cmd });
if (result.term.exited != 0) {
print("failed with: {s}", .{result.stderr});
}
defer {
gpa.free(result.stderr);
gpa.free(result.stdout);
// this is what causes a comp error
// gpa.free(result.term);
}
This is the error that i get:
error: access of union field 'pointer' while field 'union' is active
const slice_info = @typeInfo(@TypeOf(memory)).pointer;
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/usr/local/Cellar/zig/0.16.0/lib/zig/std/builtin.zig:550:18: note: union declared here
pub const Type = union(enum) {
^~~~~
referenced by:
Any help understanding this would be helpful thanj you.