Allocgate/Zig 0.9.1

This commit is contained in:
Cat /dev/Nulo 2022-07-18 16:22:31 -03:00
parent fadda3c05f
commit c12e89a3e5
2 changed files with 9 additions and 9 deletions

View File

@ -4,7 +4,7 @@ const aaronsw = @import("main.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator;
const allocator = gpa.allocator();
const str = try std.io.getStdIn().reader().readAllAlloc(allocator, 10241024);
defer allocator.free(str);

View File

@ -37,20 +37,20 @@ const Document = struct {
};
const Paragraph = struct {
text: []u8,
pub fn deinit(self: *Paragraph, allocator: *std.mem.Allocator) void {
pub fn deinit(self: *Paragraph, allocator: std.mem.Allocator) void {
allocator.free(self.text);
}
};
const Heading = struct {
level: u8,
text: []u8,
pub fn deinit(self: *Heading, allocator: *std.mem.Allocator) void {
pub fn deinit(self: *Heading, allocator: std.mem.Allocator) void {
allocator.free(self.text);
}
};
const BlockQuote = struct {
children: Children,
pub fn deinit(self: *BlockQuote, _: *std.mem.Allocator) void {
pub fn deinit(self: *BlockQuote, _: std.mem.Allocator) void {
deinitChildren(&self.children);
}
};
@ -61,13 +61,13 @@ const List = struct {
kind: Kind,
tight: bool,
children: Children,
pub fn deinit(self: *List, _: *std.mem.Allocator) void {
pub fn deinit(self: *List, _: std.mem.Allocator) void {
deinitChildren(&self.children);
}
};
const ListItem = struct {
children: Children,
pub fn deinit(self: *ListItem, _: *std.mem.Allocator) void {
pub fn deinit(self: *ListItem, _: std.mem.Allocator) void {
deinitChildren(&self.children);
}
};
@ -79,7 +79,7 @@ fn arrayListAppend(comptime T: type, list: *std.ArrayList(T), item: T) !*T {
}
fn reallocAppend(
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
alloc_str: []u8,
append_str: []const u8,
) ![]u8 {
@ -139,7 +139,7 @@ fn getHeadingLevel(line: []const u8) u8 {
}
return level;
}
fn checkIfBlockStarts(allocator: *std.mem.Allocator, line: *[]const u8) !?Block {
fn checkIfBlockStarts(allocator: std.mem.Allocator, line: *[]const u8) !?Block {
if (std.mem.startsWith(u8, line.*, ">")) {
line.* = line.*[1..];
const indent = detectIndent(line.*);
@ -193,7 +193,7 @@ fn verifyStack(stack: Stack) void {
}
}
pub fn parse(allocator: *std.mem.Allocator, str: []const u8) !Document {
pub fn parse(allocator: std.mem.Allocator, str: []const u8) !Document {
var doc_block = Block{ .document = Document{ .children = Children.init(allocator) } };
errdefer doc_block.document.deinit();