zig master updates: allocator changes (#60)
This commit is contained in:
parent
844c9370bc
commit
cf8a34d11f
4
clap.zig
4
clap.zig
|
@ -337,7 +337,7 @@ pub const ParseOptions = struct {
|
|||
/// `parse`, `parseEx` does not wrap the allocator so the heap allocator can be
|
||||
/// quite expensive. (TODO: Can we pick a better default? For `parse`, this allocator
|
||||
/// is fine, as it wraps it in an arena)
|
||||
allocator: *mem.Allocator = heap.page_allocator,
|
||||
allocator: mem.Allocator = heap.page_allocator,
|
||||
diagnostic: ?*Diagnostic = null,
|
||||
};
|
||||
|
||||
|
@ -350,7 +350,7 @@ pub fn parse(
|
|||
var iter = try args.OsIterator.init(opt.allocator);
|
||||
const clap = try parseEx(Id, params, &iter, .{
|
||||
// Let's reuse the arena from the `OSIterator` since we already have it.
|
||||
.allocator = &iter.arena.allocator,
|
||||
.allocator = iter.arena.allocator(),
|
||||
.diagnostic = opt.diagnostic,
|
||||
});
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ pub const OsIterator = struct {
|
|||
/// return an error when we have no exe.
|
||||
exe_arg: ?[:0]const u8,
|
||||
|
||||
pub fn init(allocator: *mem.Allocator) Error!OsIterator {
|
||||
pub fn init(allocator: mem.Allocator) Error!OsIterator {
|
||||
var res = OsIterator{
|
||||
.arena = heap.ArenaAllocator.init(allocator),
|
||||
.args = process.args(),
|
||||
|
@ -73,7 +73,7 @@ pub const OsIterator = struct {
|
|||
|
||||
pub fn next(iter: *OsIterator) Error!?[:0]const u8 {
|
||||
if (builtin.os.tag == .windows) {
|
||||
return try iter.args.next(&iter.arena.allocator) orelse return null;
|
||||
return try iter.args.next(iter.arena.allocator()) orelse return null;
|
||||
} else {
|
||||
return iter.args.nextPosix();
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ pub const ShellIterator = struct {
|
|||
arena: heap.ArenaAllocator,
|
||||
str: []const u8,
|
||||
|
||||
pub fn init(allocator: *mem.Allocator, str: []const u8) ShellIterator {
|
||||
pub fn init(allocator: mem.Allocator, str: []const u8) ShellIterator {
|
||||
return .{
|
||||
.arena = heap.ArenaAllocator.init(allocator),
|
||||
.str = str,
|
||||
|
@ -106,7 +106,7 @@ pub const ShellIterator = struct {
|
|||
// Whenever possible, this iterator will return slices into `str` instead of
|
||||
// allocating. Sometimes this is not possible, for example, escaped characters
|
||||
// have be be unescape, so we need to allocate in this case.
|
||||
var list = std.ArrayList(u8).init(&iter.arena.allocator);
|
||||
var list = std.ArrayList(u8).init(iter.arena.allocator());
|
||||
var start: usize = 0;
|
||||
var state: enum {
|
||||
skip_whitespace,
|
||||
|
@ -274,7 +274,7 @@ pub const ShellIterator = struct {
|
|||
|
||||
fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) !void {
|
||||
var allocator = testing.FailingAllocator.init(testing.allocator, allocations);
|
||||
var it = ShellIterator.init(&allocator.allocator, str);
|
||||
var it = ShellIterator.init(allocator.allocator(), str);
|
||||
defer it.deinit();
|
||||
|
||||
for (expect) |e| {
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn ComptimeClap(
|
|||
single_options_is_set: std.PackedIntArray(u1, single_options),
|
||||
flags: std.PackedIntArray(u1, flags),
|
||||
pos: []const []const u8,
|
||||
allocator: *mem.Allocator,
|
||||
allocator: mem.Allocator,
|
||||
|
||||
pub fn parse(iter: anytype, opt: clap.ParseOptions) !@This() {
|
||||
const allocator = opt.allocator;
|
||||
|
|
Loading…
Reference in New Issue
Block a user