~leon_plickat/nfm

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] update to zig 0.10.0

Details
Message ID
<20221101174241.8183-1-andrea@andreafeletto.com>
DKIM signature
missing
Download raw message
Patch: +51 -41
---
 src/Config.zig        |  4 ++--
 src/Dir.zig           | 18 ++++++++++--------
 src/DirMap.zig        | 12 +++++-------
 src/File.zig          | 13 ++++++++-----
 src/UserInterface.zig |  2 +-
 src/ini.zig           | 35 +++++++++++++++++++++--------------
 src/nfm.zig           |  8 ++++----
 7 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/src/Config.zig b/src/Config.zig
index 9b39da4..f51e919 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -157,7 +157,7 @@ pub const KeyOperationPayload = union {

pub const KeyOperation = struct {
    payload: KeyOperationPayload = .{ .fmt = null },
    impl: fn (self: *const KeyOperation) anyerror!void = undefined,
    impl: *const fn (self: *const KeyOperation) anyerror!void = undefined,
};

pub const PermissionFormat = enum { none, text, octal };
@@ -550,7 +550,7 @@ fn isOperationWithArg(comptime prefix: []const u8, value: []const u8, path: []co
/// Add a keybind, but only if there is not already an operation bound to the
/// event. Only intended to be called during config init for default keybinds.
/// Asserts that the input description is correct.
fn addBindIfUndefined(self: *Self, comptime description: []const u8, fun: fn (self: *const KeyOperation) anyerror!void, payload: KeyOperationPayloadTagged) !void {
fn addBindIfUndefined(self: *Self, comptime description: []const u8, fun: *const fn (self: *const KeyOperation) anyerror!void, payload: KeyOperationPayloadTagged) !void {
    const ev = comptime spoon.Input.fromDescription(description) catch @compileError("Bad input description for default keybind!");
    const alloc = self.arena.allocator();
    const res = try self.keybinds.getOrPut(alloc, ev);
diff --git a/src/Dir.zig b/src/Dir.zig
index efd8b38..6f698ed 100644
--- a/src/Dir.zig
+++ b/src/Dir.zig
@@ -37,7 +37,7 @@ visible: bool = false,
last_selected_id: usize,
last_scroll_offset: usize = 0,

pub fn init(self: *Self, map: *DirMap, alloc: mem.Allocator, dir: fs.Dir, name: []const u8) !void {
pub fn init(self: *Self, map: *DirMap, alloc: mem.Allocator, dir: fs.IterableDir, name: []const u8) !void {
    self.* = .{
        .name = name,
        .last_selected_id = math.maxInt(usize),
@@ -47,12 +47,14 @@ pub fn init(self: *Self, map: *DirMap, alloc: mem.Allocator, dir: fs.Dir, name:
    var it = dir.iterate();
    while (try it.next()) |entry| {
        const file = try self.files.addOne(alloc);
        file.dir = self;
        file.name = try alloc.dupeZ(u8, entry.name);
        file.kind = entry.kind;
        file.mark = false;
        file.text = null;
        file.id = map.genId();
        file.* = .{
            .dir = self,
            .name = try alloc.dupeZ(u8, entry.name),
            .kind = entry.kind,
            .mark = false,
            .text = null,
            .id = map.genId(),
        };
        try file.updateStats();
    }

@@ -70,7 +72,7 @@ pub fn deinit(self: *Self) void {
    debug.assert(!self.visible);
    const alloc = context.gpa.allocator();
    alloc.free(self.*.name);
    for (self.files.items) |file| file.deinit();
    for (self.files.items) |*file| file.deinit();
    self.files.deinit(alloc);
    if (self.*.wd) |wd| {
        os.inotify_rm_watch(context.dirmap.inotify_fd, wd);
diff --git a/src/DirMap.zig b/src/DirMap.zig
index 719b870..5ed6667 100644
--- a/src/DirMap.zig
+++ b/src/DirMap.zig
@@ -337,11 +337,11 @@ pub fn setCwd(self: *Self, _relpath: []const u8) !void {
pub fn setCwdRaw(self: *Self, relpath: []const u8) !void {
    const alloc = context.gpa.allocator();

    var _dir = try fs.cwd().openDir(relpath, .{ .iterate = true });
    var _dir = try fs.cwd().openIterableDir(relpath, .{});
    defer _dir.close();
    try _dir.setAsCwd();
    try _dir.dir.setAsCwd();

    const dir_path = try _dir.realpathAlloc(alloc, ".");
    const dir_path = try _dir.dir.realpathAlloc(alloc, ".");
    errdefer alloc.free(dir_path);

    var mapentry = try self.dirs.getOrPut(alloc, dir_path);
@@ -487,9 +487,7 @@ fn addNewFileToDir(self: *Self, dir: *Dir, name: []const u8) !void {
        .mark = false,
        .text = null,
        .id = self.genId(),
        .stat = undefined,
        .kind = .Unknown,
        .link_target = undefined,
    };
    try f.updateStats();
    try dir.files.append(alloc, f);
@@ -514,7 +512,7 @@ fn deleteFileFromDir(self: *Self, dir: *Dir, name: []const u8) !void {
}

fn deleteFileFromDirByIndex(self: *Self, dir: *Dir, i: usize) !void {
    const file = dir.files.items[i];
    const file = &dir.files.items[i];

    var restore_cursor: ?usize = null;
    var dv: *DirView = undefined;
@@ -558,7 +556,7 @@ pub fn handleInotifyEvent(self: *Self) !void {
        @alignOf(os.linux.inotify_event),
        ptr + @sizeOf(os.linux.inotify_event) + ev.len,
    )) {
        ev = @ptrCast(*const os.linux.inotify_event, ptr);
        ev = @ptrCast(*const os.linux.inotify_event, @alignCast(@alignOf(os.linux.inotify_event), ptr));

        // See inotify(7)
        if (ev.mask & os.linux.IN.MODIFY > 0 or
diff --git a/src/File.zig b/src/File.zig
index e9edce0..3f62a50 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -31,12 +31,12 @@ const context = &@import("nfm.zig").context;

dir: *Dir,
name: [:0]const u8,
kind: fs.Dir.Entry.Kind,
kind: fs.IterableDir.Entry.Kind,
mark: bool,
text: ?bool,
id: usize,
stat: os.system.Stat,

stat: os.system.Stat = mem.zeroes(os.system.Stat),
link_target: ?[]const u8 = null,

pub fn updateStats(self: *Self) !void {
@@ -72,7 +72,7 @@ pub fn updateStats(self: *Self) !void {
    }
}

fn fileKindFromStatMode(mode: u32) fs.Dir.Entry.Kind {
fn fileKindFromStatMode(mode: u32) fs.IterableDir.Entry.Kind {
    // TODO likely only works on linux.
    return switch (mode & os.S.IFMT) {
        os.S.IFBLK => .BlockDevice,
@@ -86,10 +86,13 @@ fn fileKindFromStatMode(mode: u32) fs.Dir.Entry.Kind {
    };
}

pub fn deinit(self: *const Self) void {
pub fn deinit(self: *Self) void {
    const alloc = context.gpa.allocator();
    alloc.free(self.name);
    if (self.link_target) |t| alloc.free(t);
    if (self.link_target) |t| {
        alloc.free(t);
        self.link_target = null;
    }
}

pub fn rename(self: *Self, new_name: []const u8) !void {
diff --git a/src/UserInterface.zig b/src/UserInterface.zig
index 1c15fac..455b47d 100644
--- a/src/UserInterface.zig
+++ b/src/UserInterface.zig
@@ -50,7 +50,7 @@ pub fn init(self: *Self) !void {

    // Someone honestly thought that the best way to make terminal programs
    // aware of a size change is a signal...
    os.sigaction(os.SIG.WINCH, &os.Sigaction{
    try os.sigaction(os.SIG.WINCH, &os.Sigaction{
        .handler = .{ .handler = handleSigWinch },
        .mask = os.empty_sigset,
        .flags = 0,
diff --git a/src/ini.zig b/src/ini.zig
index 678194b..bcb9144 100644
--- a/src/ini.zig
+++ b/src/ini.zig
@@ -116,7 +116,7 @@ pub fn tokenize(reader: anytype) IniTok(@TypeOf(reader)) {
}

test "ini tokenizer good input" {
    const reader = io.fixedBufferStream(
    var fbs = io.fixedBufferStream(
        \\[header] # I am a comment
        \\a = b;
        \\
@@ -131,7 +131,8 @@ test "ini tokenizer good input" {
        \\hello = this one; is weird;
        \\hello = test=test;
        \\
    ).reader();
    );
    const reader = fbs.reader();

    var it = tokenize(reader);
    var line: usize = 0;
@@ -219,60 +220,66 @@ test "ini tokenizer good input" {

test "ini tokenizer bad input" {
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\[section
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
        try std.testing.expect(line == 1);
    }
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\section]
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
        try std.testing.expect(line == 1);
    }
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\[]
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
        try std.testing.expect(line == 1);
    }
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\ =B;
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
        try std.testing.expect(line == 1);
    }
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\a =
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
        try std.testing.expect(line == 1);
    }
    {
        const reader = io.fixedBufferStream(
        var fbs = io.fixedBufferStream(
            \\a =  ;
            \\
        ).reader();
        );
        const reader = fbs.reader();
        var it = tokenize(reader);
        var line: usize = 0;
        try std.testing.expectError(error.InvalidLine, it.next(&line));
diff --git a/src/nfm.zig b/src/nfm.zig
index 91a4941..13d8497 100644
--- a/src/nfm.zig
+++ b/src/nfm.zig
@@ -411,10 +411,10 @@ pub var runtime_log_level: std.log.Level = .info;

/// Custom panic handler, so that we can try to cook the terminal on a crash,
/// as otherwise all messages will be mangled.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
    @setCold(true);
    context.ui.stop() catch {};
    std.builtin.default_panic(msg, error_return_trace);
    std.builtin.default_panic(msg, error_return_trace, ret_addr);
}

pub fn main() !u8 {
@@ -436,12 +436,12 @@ pub fn main() !u8 {
    };
    defer context.config.deinit();

    os.sigaction(os.SIG.TERM, &os.Sigaction{
    try os.sigaction(os.SIG.TERM, &os.Sigaction{
        .handler = .{ .handler = handleSigTerm },
        .mask = os.empty_sigset,
        .flags = 0,
    }, null);
    os.sigaction(os.SIG.INT, &os.Sigaction{
    try os.sigaction(os.SIG.INT, &os.Sigaction{
        .handler = .{ .handler = handleSigTerm },
        .mask = os.empty_sigset,
        .flags = 0,
-- 
2.38.1
Details
Message ID
<COKUOB6TAT5T.11OV8EIKTLW89@kasten>
In-Reply-To
<20221101174241.8183-1-andrea@andreafeletto.com> (view parent)
DKIM signature
missing
Download raw message
Thanks!


Friendly greetings,
Leon Henrik Plickat
Reply to thread Export thread (mbox)