summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar lch3612025-03-25 00:29:52 +0300
committerGravatar Sam Atman2025-04-29 12:30:55 -0400
commit2f44fdebca57d9eabb682e05d04189d0600b8664 (patch)
tree617e7d4be89c1a965848dbc7f9b5f2a273faa9d7
parentBump copyright year, isolate iterator tests (diff)
downloadzg-2f44fdebca57d9eabb682e05d04189d0600b8664.tar.gz
zg-2f44fdebca57d9eabb682e05d04189d0600b8664.tar.xz
zg-2f44fdebca57d9eabb682e05d04189d0600b8664.zip
All the std.mem.Allocators that were stored just for init and deinit
methods were removed, mem.Allocators were added to deinit as arguments.
-rw-r--r--src/CanonData.zig22
-rw-r--r--src/CaseData.zig10
-rw-r--r--src/CombiningData.zig9
-rw-r--r--src/CompatData.zig10
-rw-r--r--src/FoldData.zig13
-rw-r--r--src/GenCatData.zig11
-rw-r--r--src/GraphemeData.zig11
-rw-r--r--src/HangulData.zig9
-rw-r--r--src/NormData.zig20
-rw-r--r--src/NormPropsData.zig9
-rw-r--r--src/Normalize.zig10
-rw-r--r--src/PropsData.zig17
-rw-r--r--src/ScriptsData.zig13
-rw-r--r--src/WidthData.zig12
-rw-r--r--src/unicode_tests.zig12
15 files changed, 86 insertions, 102 deletions
diff --git a/src/CanonData.zig b/src/CanonData.zig
index 05b9017..794748c 100644
--- a/src/CanonData.zig
+++ b/src/CanonData.zig
@@ -3,8 +3,7 @@ const builtin = @import("builtin");
3const compress = std.compress; 3const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5 5
6allocator: mem.Allocator, 6nfc: std.AutoHashMapUnmanaged([2]u21, u21),
7nfc: std.AutoHashMap([2]u21, u21),
8nfd: [][]u21 = undefined, 7nfd: [][]u21 = undefined,
9 8
10const Self = @This(); 9const Self = @This();
@@ -18,16 +17,15 @@ pub fn init(allocator: mem.Allocator) !Self {
18 17
19 const endian = builtin.cpu.arch.endian(); 18 const endian = builtin.cpu.arch.endian();
20 var self = Self{ 19 var self = Self{
21 .allocator = allocator, 20 .nfc = .{},
22 .nfc = std.AutoHashMap([2]u21, u21).init(allocator),
23 .nfd = try allocator.alloc([]u21, 0x110000), 21 .nfd = try allocator.alloc([]u21, 0x110000),
24 }; 22 };
25 23
26 var slices: usize = 0; 24 var slices: usize = 0;
27 errdefer { 25 errdefer {
28 self.nfc.deinit(); 26 self.nfc.deinit(allocator);
29 for (self.nfd[0..slices]) |slice| self.allocator.free(slice); 27 for (self.nfd[0..slices]) |slice| allocator.free(slice);
30 self.allocator.free(self.nfd); 28 allocator.free(self.nfd);
31 } 29 }
32 30
33 @memset(self.nfd, &.{}); 31 @memset(self.nfd, &.{});
@@ -42,17 +40,17 @@ pub fn init(allocator: mem.Allocator) !Self {
42 self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); 40 self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian));
43 } 41 }
44 if (len == 3) { 42 if (len == 3) {
45 try self.nfc.put(self.nfd[cp][0..2].*, @intCast(cp)); 43 try self.nfc.put(allocator, self.nfd[cp][0..2].*, @intCast(cp));
46 } 44 }
47 } 45 }
48 46
49 return self; 47 return self;
50} 48}
51 49
52pub fn deinit(self: *Self) void { 50pub fn deinit(self: *Self, allocator: mem.Allocator) void {
53 self.nfc.deinit(); 51 self.nfc.deinit(allocator);
54 for (self.nfd) |slice| self.allocator.free(slice); 52 for (self.nfd) |slice| allocator.free(slice);
55 self.allocator.free(self.nfd); 53 allocator.free(self.nfd);
56} 54}
57 55
58/// Returns canonical decomposition for `cp`. 56/// Returns canonical decomposition for `cp`.
diff --git a/src/CaseData.zig b/src/CaseData.zig
index 3a35fdd..f05ac26 100644
--- a/src/CaseData.zig
+++ b/src/CaseData.zig
@@ -7,7 +7,6 @@ const unicode = std.unicode;
7 7
8const CodePointIterator = @import("code_point").Iterator; 8const CodePointIterator = @import("code_point").Iterator;
9 9
10allocator: mem.Allocator,
11case_map: [][2]u21, 10case_map: [][2]u21,
12prop_s1: []u16 = undefined, 11prop_s1: []u16 = undefined,
13prop_s2: []u8 = undefined, 12prop_s2: []u8 = undefined,
@@ -19,7 +18,6 @@ pub fn init(allocator: mem.Allocator) !Self {
19 const endian = builtin.cpu.arch.endian(); 18 const endian = builtin.cpu.arch.endian();
20 19
21 var self = Self{ 20 var self = Self{
22 .allocator = allocator,
23 .case_map = try allocator.alloc([2]u21, 0x110000), 21 .case_map = try allocator.alloc([2]u21, 0x110000),
24 }; 22 };
25 errdefer allocator.free(self.case_map); 23 errdefer allocator.free(self.case_map);
@@ -74,10 +72,10 @@ pub fn init(allocator: mem.Allocator) !Self {
74 return self; 72 return self;
75} 73}
76 74
77pub fn deinit(self: *const Self) void { 75pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
78 self.allocator.free(self.case_map); 76 allocator.free(self.case_map);
79 self.allocator.free(self.prop_s1); 77 allocator.free(self.prop_s1);
80 self.allocator.free(self.prop_s2); 78 allocator.free(self.prop_s2);
81} 79}
82 80
83// Returns true if `cp` is either upper, lower, or title case. 81// Returns true if `cp` is either upper, lower, or title case.
diff --git a/src/CombiningData.zig b/src/CombiningData.zig
index 44140f8..b5e227a 100644
--- a/src/CombiningData.zig
+++ b/src/CombiningData.zig
@@ -3,7 +3,6 @@ const builtin = @import("builtin");
3const compress = std.compress; 3const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5 5
6allocator: mem.Allocator,
7s1: []u16 = undefined, 6s1: []u16 = undefined,
8s2: []u8 = undefined, 7s2: []u8 = undefined,
9 8
@@ -18,7 +17,7 @@ pub fn init(allocator: mem.Allocator) !Self {
18 17
19 const endian = builtin.cpu.arch.endian(); 18 const endian = builtin.cpu.arch.endian();
20 19
21 var self = Self{ .allocator = allocator }; 20 var self = Self{};
22 21
23 const stage_1_len: u16 = try reader.readInt(u16, endian); 22 const stage_1_len: u16 = try reader.readInt(u16, endian);
24 self.s1 = try allocator.alloc(u16, stage_1_len); 23 self.s1 = try allocator.alloc(u16, stage_1_len);
@@ -33,9 +32,9 @@ pub fn init(allocator: mem.Allocator) !Self {
33 return self; 32 return self;
34} 33}
35 34
36pub fn deinit(self: *const Self) void { 35pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
37 self.allocator.free(self.s1); 36 allocator.free(self.s1);
38 self.allocator.free(self.s2); 37 allocator.free(self.s2);
39} 38}
40 39
41/// Returns the canonical combining class for a code point. 40/// Returns the canonical combining class for a code point.
diff --git a/src/CompatData.zig b/src/CompatData.zig
index cf184a1..ac08048 100644
--- a/src/CompatData.zig
+++ b/src/CompatData.zig
@@ -3,7 +3,6 @@ const builtin = @import("builtin");
3const compress = std.compress; 3const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5 5
6allocator: mem.Allocator,
7nfkd: [][]u21 = undefined, 6nfkd: [][]u21 = undefined,
8 7
9const Self = @This(); 8const Self = @This();
@@ -17,10 +16,9 @@ pub fn init(allocator: mem.Allocator) !Self {
17 16
18 const endian = builtin.cpu.arch.endian(); 17 const endian = builtin.cpu.arch.endian();
19 var self = Self{ 18 var self = Self{
20 .allocator = allocator,
21 .nfkd = try allocator.alloc([]u21, 0x110000), 19 .nfkd = try allocator.alloc([]u21, 0x110000),
22 }; 20 };
23 errdefer self.deinit(); 21 errdefer self.deinit(allocator);
24 22
25 @memset(self.nfkd, &.{}); 23 @memset(self.nfkd, &.{});
26 24
@@ -37,11 +35,11 @@ pub fn init(allocator: mem.Allocator) !Self {
37 return self; 35 return self;
38} 36}
39 37
40pub fn deinit(self: *const Self) void { 38pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
41 for (self.nfkd) |slice| { 39 for (self.nfkd) |slice| {
42 if (slice.len != 0) self.allocator.free(slice); 40 if (slice.len != 0) allocator.free(slice);
43 } 41 }
44 self.allocator.free(self.nfkd); 42 allocator.free(self.nfkd);
45} 43}
46 44
47/// Returns compatibility decomposition for `cp`. 45/// Returns compatibility decomposition for `cp`.
diff --git a/src/FoldData.zig b/src/FoldData.zig
index a3d47af..e44e714 100644
--- a/src/FoldData.zig
+++ b/src/FoldData.zig
@@ -3,7 +3,6 @@ const builtin = @import("builtin");
3const compress = std.compress; 3const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5 5
6allocator: mem.Allocator,
7cutoff: u21 = undefined, 6cutoff: u21 = undefined,
8cwcf_exceptions_min: u21 = undefined, 7cwcf_exceptions_min: u21 = undefined,
9cwcf_exceptions_max: u21 = undefined, 8cwcf_exceptions_max: u21 = undefined,
@@ -24,7 +23,7 @@ pub fn init(allocator: mem.Allocator) !Self {
24 23
25 const endian = builtin.cpu.arch.endian(); 24 const endian = builtin.cpu.arch.endian();
26 25
27 var self = Self{ .allocator = allocator }; 26 var self = Self{};
28 self.cutoff = @intCast(try reader.readInt(u24, endian)); 27 self.cutoff = @intCast(try reader.readInt(u24, endian));
29 self.multiple_start = @intCast(try reader.readInt(u24, endian)); 28 self.multiple_start = @intCast(try reader.readInt(u24, endian));
30 29
@@ -53,11 +52,11 @@ pub fn init(allocator: mem.Allocator) !Self {
53 return self; 52 return self;
54} 53}
55 54
56pub fn deinit(self: *const Self) void { 55pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
57 self.allocator.free(self.stage1); 56 allocator.free(self.stage1);
58 self.allocator.free(self.stage2); 57 allocator.free(self.stage2);
59 self.allocator.free(self.stage3); 58 allocator.free(self.stage3);
60 self.allocator.free(self.cwcf_exceptions); 59 allocator.free(self.cwcf_exceptions);
61} 60}
62 61
63/// Returns the case fold for `cp`. 62/// Returns the case fold for `cp`.
diff --git a/src/GenCatData.zig b/src/GenCatData.zig
index 5ce9fb6..a69f7a2 100644
--- a/src/GenCatData.zig
+++ b/src/GenCatData.zig
@@ -37,7 +37,6 @@ pub const Gc = enum {
37 Zs, // Separator, Space 37 Zs, // Separator, Space
38}; 38};
39 39
40allocator: mem.Allocator,
41s1: []u16 = undefined, 40s1: []u16 = undefined,
42s2: []u5 = undefined, 41s2: []u5 = undefined,
43s3: []u5 = undefined, 42s3: []u5 = undefined,
@@ -53,7 +52,7 @@ pub fn init(allocator: mem.Allocator) !Self {
53 52
54 const endian = builtin.cpu.arch.endian(); 53 const endian = builtin.cpu.arch.endian();
55 54
56 var self = Self{ .allocator = allocator }; 55 var self = Self{};
57 56
58 const s1_len: u16 = try reader.readInt(u16, endian); 57 const s1_len: u16 = try reader.readInt(u16, endian);
59 self.s1 = try allocator.alloc(u16, s1_len); 58 self.s1 = try allocator.alloc(u16, s1_len);
@@ -73,10 +72,10 @@ pub fn init(allocator: mem.Allocator) !Self {
73 return self; 72 return self;
74} 73}
75 74
76pub fn deinit(self: *const Self) void { 75pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
77 self.allocator.free(self.s1); 76 allocator.free(self.s1);
78 self.allocator.free(self.s2); 77 allocator.free(self.s2);
79 self.allocator.free(self.s3); 78 allocator.free(self.s3);
80} 79}
81 80
82/// Lookup the General Category for `cp`. 81/// Lookup the General Category for `cp`.
diff --git a/src/GraphemeData.zig b/src/GraphemeData.zig
index de98bde..6d3174d 100644
--- a/src/GraphemeData.zig
+++ b/src/GraphemeData.zig
@@ -30,7 +30,6 @@ pub const Gbp = enum {
30 ZWJ, 30 ZWJ,
31}; 31};
32 32
33allocator: mem.Allocator,
34s1: []u16 = undefined, 33s1: []u16 = undefined,
35s2: []u16 = undefined, 34s2: []u16 = undefined,
36s3: []u8 = undefined, 35s3: []u8 = undefined,
@@ -46,7 +45,7 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
46 45
47 const endian = builtin.cpu.arch.endian(); 46 const endian = builtin.cpu.arch.endian();
48 47
49 var self = Self{ .allocator = allocator }; 48 var self = Self{};
50 49
51 const s1_len: u16 = reader.readInt(u16, endian) catch unreachable; 50 const s1_len: u16 = reader.readInt(u16, endian) catch unreachable;
52 self.s1 = try allocator.alloc(u16, s1_len); 51 self.s1 = try allocator.alloc(u16, s1_len);
@@ -66,10 +65,10 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
66 return self; 65 return self;
67} 66}
68 67
69pub fn deinit(self: *const Self) void { 68pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
70 self.allocator.free(self.s1); 69 allocator.free(self.s1);
71 self.allocator.free(self.s2); 70 allocator.free(self.s2);
72 self.allocator.free(self.s3); 71 allocator.free(self.s3);
73} 72}
74 73
75/// Lookup the grapheme break property for a code point. 74/// Lookup the grapheme break property for a code point.
diff --git a/src/HangulData.zig b/src/HangulData.zig
index 048841d..4bccbe6 100644
--- a/src/HangulData.zig
+++ b/src/HangulData.zig
@@ -13,7 +13,6 @@ pub const Syllable = enum {
13 T, 13 T,
14}; 14};
15 15
16allocator: mem.Allocator,
17s1: []u16 = undefined, 16s1: []u16 = undefined,
18s2: []u3 = undefined, 17s2: []u3 = undefined,
19 18
@@ -27,7 +26,7 @@ pub fn init(allocator: mem.Allocator) !Self {
27 var reader = in_decomp.reader(); 26 var reader = in_decomp.reader();
28 27
29 const endian = builtin.cpu.arch.endian(); 28 const endian = builtin.cpu.arch.endian();
30 var self = Self{ .allocator = allocator }; 29 var self = Self{};
31 30
32 const stage_1_len: u16 = try reader.readInt(u16, endian); 31 const stage_1_len: u16 = try reader.readInt(u16, endian);
33 self.s1 = try allocator.alloc(u16, stage_1_len); 32 self.s1 = try allocator.alloc(u16, stage_1_len);
@@ -42,9 +41,9 @@ pub fn init(allocator: mem.Allocator) !Self {
42 return self; 41 return self;
43} 42}
44 43
45pub fn deinit(self: *const Self) void { 44pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
46 self.allocator.free(self.s1); 45 allocator.free(self.s1);
47 self.allocator.free(self.s2); 46 allocator.free(self.s2);
48} 47}
49 48
50/// Returns the Hangul syllable type for `cp`. 49/// Returns the Hangul syllable type for `cp`.
diff --git a/src/NormData.zig b/src/NormData.zig
index 15cc401..a123860 100644
--- a/src/NormData.zig
+++ b/src/NormData.zig
@@ -18,20 +18,20 @@ const Self = @This();
18 18
19pub fn init(self: *Self, allocator: std.mem.Allocator) !void { 19pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
20 self.canon_data = try CanonData.init(allocator); 20 self.canon_data = try CanonData.init(allocator);
21 errdefer self.canon_data.deinit(); 21 errdefer self.canon_data.deinit(allocator);
22 self.ccc_data = try CccData.init(allocator); 22 self.ccc_data = try CccData.init(allocator);
23 errdefer self.ccc_data.deinit(); 23 errdefer self.ccc_data.deinit(allocator);
24 self.compat_data = try CompatData.init(allocator); 24 self.compat_data = try CompatData.init(allocator);
25 errdefer self.compat_data.deinit(); 25 errdefer self.compat_data.deinit(allocator);
26 self.hangul_data = try HangulData.init(allocator); 26 self.hangul_data = try HangulData.init(allocator);
27 errdefer self.hangul_data.deinit(); 27 errdefer self.hangul_data.deinit(allocator);
28 self.normp_data = try NormPropsData.init(allocator); 28 self.normp_data = try NormPropsData.init(allocator);
29} 29}
30 30
31pub fn deinit(self: *Self) void { 31pub fn deinit(self: *Self, allocator: mem.Allocator) void {
32 self.canon_data.deinit(); 32 self.canon_data.deinit(allocator);
33 self.ccc_data.deinit(); 33 self.ccc_data.deinit(allocator);
34 self.compat_data.deinit(); 34 self.compat_data.deinit(allocator);
35 self.hangul_data.deinit(); 35 self.hangul_data.deinit(allocator);
36 self.normp_data.deinit(); 36 self.normp_data.deinit(allocator);
37} 37}
diff --git a/src/NormPropsData.zig b/src/NormPropsData.zig
index 5861860..e79ae91 100644
--- a/src/NormPropsData.zig
+++ b/src/NormPropsData.zig
@@ -4,7 +4,6 @@ const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5const testing = std.testing; 5const testing = std.testing;
6 6
7allocator: mem.Allocator,
8s1: []u16 = undefined, 7s1: []u16 = undefined,
9s2: []u4 = undefined, 8s2: []u4 = undefined,
10 9
@@ -18,7 +17,7 @@ pub fn init(allocator: mem.Allocator) !Self {
18 var reader = in_decomp.reader(); 17 var reader = in_decomp.reader();
19 18
20 const endian = builtin.cpu.arch.endian(); 19 const endian = builtin.cpu.arch.endian();
21 var self = Self{ .allocator = allocator }; 20 var self = Self{};
22 21
23 const stage_1_len: u16 = try reader.readInt(u16, endian); 22 const stage_1_len: u16 = try reader.readInt(u16, endian);
24 self.s1 = try allocator.alloc(u16, stage_1_len); 23 self.s1 = try allocator.alloc(u16, stage_1_len);
@@ -33,9 +32,9 @@ pub fn init(allocator: mem.Allocator) !Self {
33 return self; 32 return self;
34} 33}
35 34
36pub fn deinit(self: *const Self) void { 35pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
37 self.allocator.free(self.s1); 36 allocator.free(self.s1);
38 self.allocator.free(self.s2); 37 allocator.free(self.s2);
39} 38}
40 39
41/// Returns true if `cp` is already in NFD form. 40/// Returns true if `cp` is already in NFD form.
diff --git a/src/Normalize.zig b/src/Normalize.zig
index 1e9878b..7b87406 100644
--- a/src/Normalize.zig
+++ b/src/Normalize.zig
@@ -221,11 +221,11 @@ test "decompose" {
221 221
222/// Returned from various functions in this namespace. Remember to call `deinit` to free any allocated memory. 222/// Returned from various functions in this namespace. Remember to call `deinit` to free any allocated memory.
223pub const Result = struct { 223pub const Result = struct {
224 allocator: ?mem.Allocator = null, 224 allocated: bool = false,
225 slice: []const u8, 225 slice: []const u8,
226 226
227 pub fn deinit(self: *const Result) void { 227 pub fn deinit(self: *const Result, allocator: mem.Allocator) void {
228 if (self.allocator) |allocator| allocator.free(self.slice); 228 if (self.allocated) allocator.free(self.slice);
229 } 229 }
230}; 230};
231 231
@@ -291,7 +291,7 @@ fn nfxd(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) mem.A
291 try dstr_list.appendSlice(buf[0..len]); 291 try dstr_list.appendSlice(buf[0..len]);
292 } 292 }
293 293
294 return Result{ .allocator = allocator, .slice = try dstr_list.toOwnedSlice() }; 294 return Result{ .allocated = true, .slice = try dstr_list.toOwnedSlice() };
295} 295}
296 296
297test "nfd ASCII / no-alloc" { 297test "nfd ASCII / no-alloc" {
@@ -528,7 +528,7 @@ fn nfxc(self: Self, allocator: mem.Allocator, str: []const u8, form: Form) mem.A
528 try cstr_list.appendSlice(buf[0..len]); 528 try cstr_list.appendSlice(buf[0..len]);
529 } 529 }
530 530
531 return Result{ .allocator = allocator, .slice = try cstr_list.toOwnedSlice() }; 531 return Result{ .allocated = true, .slice = try cstr_list.toOwnedSlice() };
532 } 532 }
533 } 533 }
534} 534}
diff --git a/src/PropsData.zig b/src/PropsData.zig
index b77bf30..09c69c7 100644
--- a/src/PropsData.zig
+++ b/src/PropsData.zig
@@ -4,7 +4,6 @@ const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5const testing = std.testing; 5const testing = std.testing;
6 6
7allocator: mem.Allocator,
8core_s1: []u16 = undefined, 7core_s1: []u16 = undefined,
9core_s2: []u8 = undefined, 8core_s2: []u8 = undefined,
10props_s1: []u16 = undefined, 9props_s1: []u16 = undefined,
@@ -24,7 +23,7 @@ pub fn init(allocator: mem.Allocator) !Self {
24 var core_decomp = decompressor(.raw, core_fbs.reader()); 23 var core_decomp = decompressor(.raw, core_fbs.reader());
25 var core_reader = core_decomp.reader(); 24 var core_reader = core_decomp.reader();
26 25
27 var self = Self{ .allocator = allocator }; 26 var self = Self{};
28 27
29 const core_stage_1_len: u16 = try core_reader.readInt(u16, endian); 28 const core_stage_1_len: u16 = try core_reader.readInt(u16, endian);
30 self.core_s1 = try allocator.alloc(u16, core_stage_1_len); 29 self.core_s1 = try allocator.alloc(u16, core_stage_1_len);
@@ -71,13 +70,13 @@ pub fn init(allocator: mem.Allocator) !Self {
71 return self; 70 return self;
72} 71}
73 72
74pub fn deinit(self: *const Self) void { 73pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
75 self.allocator.free(self.core_s1); 74 allocator.free(self.core_s1);
76 self.allocator.free(self.core_s2); 75 allocator.free(self.core_s2);
77 self.allocator.free(self.props_s1); 76 allocator.free(self.props_s1);
78 self.allocator.free(self.props_s2); 77 allocator.free(self.props_s2);
79 self.allocator.free(self.num_s1); 78 allocator.free(self.num_s1);
80 self.allocator.free(self.num_s2); 79 allocator.free(self.num_s2);
81} 80}
82 81
83/// True if `cp` is a mathematical symbol. 82/// True if `cp` is a mathematical symbol.
diff --git a/src/ScriptsData.zig b/src/ScriptsData.zig
index 415ce2d..4ad8549 100644
--- a/src/ScriptsData.zig
+++ b/src/ScriptsData.zig
@@ -172,7 +172,6 @@ pub const Script = enum {
172 Zanabazar_Square, 172 Zanabazar_Square,
173}; 173};
174 174
175allocator: mem.Allocator,
176s1: []u16 = undefined, 175s1: []u16 = undefined,
177s2: []u8 = undefined, 176s2: []u8 = undefined,
178s3: []u8 = undefined, 177s3: []u8 = undefined,
@@ -188,7 +187,7 @@ pub fn init(allocator: mem.Allocator) !Self {
188 187
189 const endian = builtin.cpu.arch.endian(); 188 const endian = builtin.cpu.arch.endian();
190 189
191 var self = Self{ .allocator = allocator }; 190 var self = Self{};
192 191
193 const s1_len: u16 = try reader.readInt(u16, endian); 192 const s1_len: u16 = try reader.readInt(u16, endian);
194 self.s1 = try allocator.alloc(u16, s1_len); 193 self.s1 = try allocator.alloc(u16, s1_len);
@@ -208,10 +207,10 @@ pub fn init(allocator: mem.Allocator) !Self {
208 return self; 207 return self;
209} 208}
210 209
211pub fn deinit(self: *const Self) void { 210pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
212 self.allocator.free(self.s1); 211 allocator.free(self.s1);
213 self.allocator.free(self.s2); 212 allocator.free(self.s2);
214 self.allocator.free(self.s3); 213 allocator.free(self.s3);
215} 214}
216 215
217/// Lookup the Script type for `cp`. 216/// Lookup the Script type for `cp`.
@@ -223,6 +222,6 @@ pub fn script(self: Self, cp: u21) ?Script {
223 222
224test "script" { 223test "script" {
225 const self = try init(std.testing.allocator); 224 const self = try init(std.testing.allocator);
226 defer self.deinit(); 225 defer self.deinit(std.testing.allocator);
227 try testing.expectEqual(Script.Latin, self.script('A').?); 226 try testing.expectEqual(Script.Latin, self.script('A').?);
228} 227}
diff --git a/src/WidthData.zig b/src/WidthData.zig
index d77879e..4a49c80 100644
--- a/src/WidthData.zig
+++ b/src/WidthData.zig
@@ -6,7 +6,6 @@ const testing = std.testing;
6 6
7const GraphemeData = @import("GraphemeData"); 7const GraphemeData = @import("GraphemeData");
8 8
9allocator: mem.Allocator,
10g_data: GraphemeData, 9g_data: GraphemeData,
11s1: []u16 = undefined, 10s1: []u16 = undefined,
12s2: []i4 = undefined, 11s2: []i4 = undefined,
@@ -23,10 +22,9 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
23 const endian = builtin.cpu.arch.endian(); 22 const endian = builtin.cpu.arch.endian();
24 23
25 var self = Self{ 24 var self = Self{
26 .allocator = allocator,
27 .g_data = try GraphemeData.init(allocator), 25 .g_data = try GraphemeData.init(allocator),
28 }; 26 };
29 errdefer self.g_data.deinit(); 27 errdefer self.g_data.deinit(allocator);
30 28
31 const stage_1_len: u16 = reader.readInt(u16, endian) catch unreachable; 29 const stage_1_len: u16 = reader.readInt(u16, endian) catch unreachable;
32 self.s1 = try allocator.alloc(u16, stage_1_len); 30 self.s1 = try allocator.alloc(u16, stage_1_len);
@@ -41,10 +39,10 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
41 return self; 39 return self;
42} 40}
43 41
44pub fn deinit(self: *const Self) void { 42pub fn deinit(self: *const Self, allocator: mem.Allocator) void {
45 self.allocator.free(self.s1); 43 allocator.free(self.s1);
46 self.allocator.free(self.s2); 44 allocator.free(self.s2);
47 self.g_data.deinit(); 45 self.g_data.deinit(allocator);
48} 46}
49 47
50/// codePointWidth returns the number of cells `cp` requires when rendered 48/// codePointWidth returns the number of cells `cp` requires when rendered
diff --git a/src/unicode_tests.zig b/src/unicode_tests.zig
index 245c03f..7236ff6 100644
--- a/src/unicode_tests.zig
+++ b/src/unicode_tests.zig
@@ -19,7 +19,7 @@ comptime {
19test "Iterator.peek" { 19test "Iterator.peek" {
20 const peek_seq = "aΔ👨🏻‍🌾→"; 20 const peek_seq = "aΔ👨🏻‍🌾→";
21 const data = try GraphemeData.init(std.testing.allocator); 21 const data = try GraphemeData.init(std.testing.allocator);
22 defer data.deinit(); 22 defer data.deinit(std.testing.allocator);
23 23
24 var iter = grapheme.Iterator.init(peek_seq, &data); 24 var iter = grapheme.Iterator.init(peek_seq, &data);
25 const peek_a = iter.peek().?; 25 const peek_a = iter.peek().?;
@@ -94,7 +94,7 @@ test "Unicode normalization tests" {
94 94
95 const want = w_buf.items; 95 const want = w_buf.items;
96 var got = try n.nfc(allocator, input); 96 var got = try n.nfc(allocator, input);
97 defer got.deinit(); 97 defer got.deinit(allocator);
98 98
99 try testing.expectEqualStrings(want, got.slice); 99 try testing.expectEqualStrings(want, got.slice);
100 } else if (field_index == 2) { 100 } else if (field_index == 2) {
@@ -111,7 +111,7 @@ test "Unicode normalization tests" {
111 111
112 const want = w_buf.items; 112 const want = w_buf.items;
113 var got = try n.nfd(allocator, input); 113 var got = try n.nfd(allocator, input);
114 defer got.deinit(); 114 defer got.deinit(allocator);
115 115
116 try testing.expectEqualStrings(want, got.slice); 116 try testing.expectEqualStrings(want, got.slice);
117 } else if (field_index == 3) { 117 } else if (field_index == 3) {
@@ -128,7 +128,7 @@ test "Unicode normalization tests" {
128 128
129 const want = w_buf.items; 129 const want = w_buf.items;
130 var got = try n.nfkc(allocator, input); 130 var got = try n.nfkc(allocator, input);
131 defer got.deinit(); 131 defer got.deinit(allocator);
132 132
133 try testing.expectEqualStrings(want, got.slice); 133 try testing.expectEqualStrings(want, got.slice);
134 } else if (field_index == 4) { 134 } else if (field_index == 4) {
@@ -145,7 +145,7 @@ test "Unicode normalization tests" {
145 145
146 const want = w_buf.items; 146 const want = w_buf.items;
147 const got = try n.nfkd(allocator, input); 147 const got = try n.nfkd(allocator, input);
148 defer got.deinit(); 148 defer got.deinit(allocator);
149 149
150 try testing.expectEqualStrings(want, got.slice); 150 try testing.expectEqualStrings(want, got.slice);
151 } else { 151 } else {
@@ -163,7 +163,7 @@ test "Segmentation GraphemeIterator" {
163 var input_stream = buf_reader.reader(); 163 var input_stream = buf_reader.reader();
164 164
165 const data = try GraphemeData.init(allocator); 165 const data = try GraphemeData.init(allocator);
166 defer data.deinit(); 166 defer data.deinit(allocator);
167 167
168 var buf: [4096]u8 = undefined; 168 var buf: [4096]u8 = undefined;
169 var line_no: usize = 1; 169 var line_no: usize = 1;