ReviewOS

also looking at this

zig-utils/zig-regex

Port to latest zig-master

#2
Closed armagidon-exception wants to merge main into main
53 files +1149 -1017
src/thread_safety.zigmodified+7-5
Changes to src/thread_safety.zig
@@ -43,7 +43,7 @@ const std = @import("std");
4343/// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
4444/// const allocator = gpa.allocator();
4545///
46/// const regex = try Regex.compile(allocator, "\\d+");
46/// const regex = try Regex.compile(allocator, init.io, "\\d+");
4747/// defer regex.deinit();
4848///
4949/// // Thread 1
@@ -115,12 +115,12 @@ pub fn SharedRegex(comptime Regex: type) type {
115115 allocator: std.mem.Allocator,
116116
117117 /// Initialize a shared regex pattern
118 pub fn init(allocator: std.mem.Allocator, pattern: []const u8) !*Self {
118 pub fn init(allocator: std.mem.Allocator, io: std.Io, pattern: []const u8) !*Self {
119119 const self = try allocator.create(Self);
120120 errdefer allocator.destroy(self);
121121
122122 self.* = .{
123 .regex = try Regex.compile(allocator, pattern),
123 .regex = try Regex.compile(allocator, io, pattern),
124124 .ref_count = std.atomic.Value(usize).init(1),
125125 .allocator = allocator,
126126 };
@@ -198,11 +198,13 @@ pub fn RegexCache(comptime Regex: type) type {
198198 };
199199
200200 cache: std.StringHashMap(Regex),
201 io: std.Io,
201202 allocator: std.mem.Allocator,
202203 initialized: bool = false,
203204
204 pub fn init(allocator: std.mem.Allocator) Self {
205 pub fn init(allocator: std.mem.Allocator, io: std.Io) Self {
205206 return .{
207 .io = io,
206208 .cache = std.StringHashMap(Regex).init(allocator),
207209 .allocator = allocator,
208210 .initialized = true,
@@ -229,7 +231,7 @@ pub fn RegexCache(comptime Regex: type) type {
229231 }
230232
231233 // Not in cache, compile and store
232 const regex = try Regex.compile(self.allocator, pattern);
234 const regex = try Regex.compile(self.allocator,self.io, pattern);
233235 errdefer {
234236 var mut_regex = regex;
235237 mut_regex.deinit();