From bc8d525a3e419fed3943d9dfa7c523b7881dd89e Mon Sep 17 00:00:00 2001 From: ktkk Date: Thu, 16 Jul 2026 08:34:33 +0000 Subject: [PATCH] Don't store allocator --- src/Class.zig | 37 +++++++++++++++++-------------------- src/main.zig | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/Class.zig b/src/Class.zig index e0d0244..09a3846 100644 --- a/src/Class.zig +++ b/src/Class.zig @@ -7,8 +7,6 @@ pub const MethodInfo = @import("Class/MethodInfo.zig"); pub const AttributeInfo = @import("Class/AttributeInfo.zig").AttributeInfo; pub const ConstantPool = @import("Class/ConstantPool.zig"); -allocator: std.mem.Allocator, - magic: u32, minor_version: u16, major_version: u16, @@ -90,7 +88,6 @@ pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) (ParseError || } return .{ - .allocator = allocator, .magic = magic, .minor_version = minor_version, .major_version = major_version, @@ -153,37 +150,37 @@ pub fn parseAttributes(input: *std.Io.Reader, constant_pool: ConstantPool, alloc return attributes; } -pub fn deinit(self: *Self) void { - self.constant_pool.deinit(self.allocator); - self.freeInterfaces(); - self.freeFields(); - self.freeMethods(); - self.freeAttributes(); +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { + self.constant_pool.deinit(allocator); + self.freeInterfaces(allocator); + self.freeFields(allocator); + self.freeMethods(allocator); + self.freeAttributes(allocator); } -fn freeInterfaces(self: *Self) void { - self.allocator.free(self.interfaces); +fn freeInterfaces(self: *Self, allocator: std.mem.Allocator) void { + allocator.free(self.interfaces); } -fn freeFields(self: *Self) void { +fn freeFields(self: *Self, allocator: std.mem.Allocator) void { for (self.fields) |*field_info| { - field_info.deinit(self.allocator); + field_info.deinit(allocator); } - self.allocator.free(self.fields); + allocator.free(self.fields); } -fn freeMethods(self: *Self) void { +fn freeMethods(self: *Self, allocator: std.mem.Allocator) void { for (self.methods) |*method_info| { - method_info.deinit(self.allocator); + method_info.deinit(allocator); } - self.allocator.free(self.methods); + allocator.free(self.methods); } -fn freeAttributes(self: *Self) void { +fn freeAttributes(self: *Self, allocator: std.mem.Allocator) void { for (self.attributes) |*attr| { - attr.deinit(self.allocator); + attr.deinit(allocator); } - self.allocator.free(self.attributes); + allocator.free(self.attributes); } pub fn jsonStringify(self: *const Self, jws: *std.json.Stringify) !void { diff --git a/src/main.zig b/src/main.zig index 8c4831e..bf3f1f1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -50,7 +50,7 @@ pub fn main(init: std.process.Init) !void { }, else => return err, }; - defer class.deinit(); + defer class.deinit(allocator); try stdout.print("{f}", .{ class });