this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

completed translation and fixed a few things

authored by

ItsMeSamey and committed by
Tim Culverhouse
c9b9cdf7 4320ec29

+62 -22
+6
build.zig
··· 3 3 pub fn build(b: *std.Build) void { 4 4 const target = b.standardTargetOptions(.{}); 5 5 const optimize = b.standardOptimizeOption(.{}); 6 + const use_llvm = b.option(bool, "llvm", "Use the LLVM backend for compile steps") orelse true; 6 7 const root_source_file = b.path("src/main.zig"); 7 8 8 9 // Dependencies ··· 69 70 const example = b.addExecutable(.{ 70 71 .name = b.fmt("example-{t}", .{example_option}), 71 72 .root_module = examples.get(example_option) orelse unreachable, 73 + .use_llvm = use_llvm, 72 74 }); 73 75 74 76 b.getInstallStep().dependOn(&example.step); ··· 80 82 const bench_step = b.step("bench", "Run benchmarks"); 81 83 const bench = b.addExecutable(.{ 82 84 .name = "bench", 85 + .use_llvm = use_llvm, 83 86 .root_module = b.createModule(.{ 84 87 .root_source_file = b.path("bench/bench.zig"), 85 88 .target = target, ··· 99 102 const tests_step = b.step("test", "Run tests"); 100 103 101 104 const tests = b.addTest(.{ 105 + .use_llvm = use_llvm, 102 106 .root_module = b.createModule(.{ 103 107 .root_source_file = b.path("src/main.zig"), 104 108 .target = target, ··· 115 119 var it = examples.iterator(); 116 120 while (it.next()) |v| { 117 121 const e = b.addTest(.{ 122 + .use_llvm = use_llvm, 118 123 .root_module = v.value.*, 119 124 }); 120 125 const r = b.addRunArtifact(e); ··· 129 134 const docs_step = b.step("docs", "Build the vaxis library docs"); 130 135 const docs_obj = b.addObject(.{ 131 136 .name = "vaxis", 137 + .use_llvm = use_llvm, 132 138 .root_module = b.createModule(.{ 133 139 .root_source_file = root_source_file, 134 140 .target = target,
+1 -3
examples/image.zig
··· 32 32 33 33 const imgs = [_]vaxis.Image{ 34 34 try vx.transmitImage(alloc, tty.writer(), &img1, .rgba), 35 - // var img1 = try vaxis.zigimg.Image.fromFilePath(alloc, "examples/zig.png"); 36 - // try vx.loadImage(alloc, tty.writer(), .{ .path = "examples/zig.png" }), 37 35 try vx.loadImage(alloc, tty.writer(), .{ .path = "examples/vaxis.png" }), 38 36 }; 39 37 defer vx.freeImage(tty.writer(), imgs[0].id); ··· 44 42 var clip_y: u16 = 0; 45 43 46 44 while (true) { 47 - const event = loop.nextEvent(); 45 + const event = try loop.nextEvent(); 48 46 switch (event) { 49 47 .key_press => |key| { 50 48 if (key.matches('c', .{ .ctrl = true })) {
+1 -1
src/Vaxis.zig
··· 1088 1088 1089 1089 var read_buffer: [1024 * 1024]u8 = undefined; // 1MB buffer 1090 1090 var img = switch (src) { 1091 - .path => |path| try zigimg.Image.fromFilePath(alloc, path, &read_buffer), 1091 + .path => |path| try zigimg.Image.fromFilePath(alloc, self.io, path, &read_buffer), 1092 1092 .mem => |bytes| try zigimg.Image.fromMemory(alloc, bytes), 1093 1093 }; 1094 1094 defer img.deinit(alloc);
+2 -2
src/queue.zig
··· 71 71 72 72 /// Poll the queue. This call blocks until events are in the queue 73 73 pub fn poll(self: *Self) !void { 74 - self.mutex.lock(self.io); 74 + try self.mutex.lock(self.io); 75 75 defer self.mutex.unlock(self.io); 76 76 while (self.isEmptyLH()) { 77 - self.not_empty.wait(&self.mutex); 77 + try self.not_empty.wait(self.io, &self.mutex); 78 78 } 79 79 std.debug.assert(!self.isEmptyLH()); 80 80 }
+1 -1
src/tty.zig
··· 722 722 return .{ 723 723 .fd = fds[0], 724 724 .pipe_read = fds[0], 725 - .pipe_write = fds[0], 725 + .pipe_write = fds[1], 726 726 .tty_writer = list, 727 727 }; 728 728 }
+51 -15
src/widgets/terminal/Command.zig
··· 22 22 pub fn spawn(self: *Command, io: std.Io, allocator: std.mem.Allocator) !void { 23 23 var arena_allocator = std.heap.ArenaAllocator.init(allocator); 24 24 defer arena_allocator.deinit(); 25 + const arena = arena_allocator.allocator(); 26 + 27 + // Keep fork->exec child path allocation-free, following std/Io/Threaded.zig:posixExecv 28 + const argv_block = try arena.allocSentinel(?[*:0]const u8, self.argv.len, null); 29 + for (self.argv, 0..) |arg, i| argv_block[i] = (try arena.dupeZ(u8, arg)).ptr; 30 + const env_block = try self.env_map.createPosixBlock(arena, .{}); 31 + const path = self.env_map.get("PATH") orelse std.Io.Threaded.default_PATH; 25 32 26 33 const pid = pid: { 27 34 const rc = linux.fork(); ··· 63 70 self.pty.tty.close(io); 64 71 if (self.pty.pty.handle > 2) self.pty.pty.close(io); 65 72 66 - // if (self.working_directory) |wd| { 67 - // try std.posix.chdir(wd); 68 - // } 73 + if (self.working_directory) |wd| { 74 + const wd_z = try posix.toPosixPath(wd); 75 + if (linux.errno(linux.chdir(&wd_z)) != .SUCCESS) return error.ChdirFailed; 76 + } 69 77 70 78 // exec 71 - std.process.replace(io, .{ 72 - .argv = self.argv, 73 - .environ_map = self.env_map, 74 - }) catch {}; 79 + execvpeLinux(argv_block.ptr, env_block, self.argv[0], path) catch {}; 80 + linux.exit(127); 75 81 } 76 82 77 83 // we are the parent ··· 110 116 111 117 pub fn kill(self: *Command) void { 112 118 if (self.pid) |pid| { 113 - std.posix.kill(pid, std.posix.SIG.TERM) catch {}; 119 + posix.kill(pid, posix.SIG.TERM) catch {}; 114 120 self.pid = null; 115 121 } 116 122 } 117 123 118 - /// Creates a null-deliminated environment variable block in the format expected by POSIX, from a 119 - /// hash map plus options. 120 - fn createEnvironFromMap( 121 - arena: std.mem.Allocator, 122 - map: *const std.process.Environ.Map, 123 - ) ![:null]?[*:0]u8 { 124 - return try map.createPosixBlock(arena, .{}); 124 + // Keep fork->exec child path allocation-free, following std/Io/Threaded.zig:posixExecv 125 + fn execvpeLinux( 126 + argv: [*:null]const ?[*:0]const u8, 127 + env_block: std.process.Environ.PosixBlock, 128 + arg0: []const u8, 129 + path: []const u8, 130 + ) !noreturn { 131 + // This implementation is largely copied from std/Io/Threaded.zig 132 + // (`spawnPosix` + `posixExecv`/`posixExecvPath`) and adapted for this PTY fork path. 133 + if (std.mem.indexOfScalar(u8, arg0, '/') != null) { 134 + const path_z = try posix.toPosixPath(arg0); 135 + return std.Io.Threaded.posixExecvPath(&path_z, argv, env_block); 136 + } 137 + 138 + var it = std.mem.tokenizeScalar(u8, path, std.fs.path.delimiter); 139 + var path_buf: [posix.PATH_MAX]u8 = undefined; 140 + var err: std.process.ReplaceError = error.FileNotFound; 141 + var seen_eacces = false; 142 + 143 + while (it.next()) |dir| { 144 + const path_len = dir.len + arg0.len + 1; 145 + if (path_buf.len < path_len + 1) return error.NameTooLong; 146 + @memcpy(path_buf[0..dir.len], dir); 147 + path_buf[dir.len] = '/'; 148 + @memcpy(path_buf[dir.len + 1 ..][0..arg0.len], arg0); 149 + path_buf[path_len] = 0; 150 + const full_path = path_buf[0..path_len :0].ptr; 151 + err = std.Io.Threaded.posixExecvPath(full_path, argv, env_block); 152 + switch (err) { 153 + error.AccessDenied => seen_eacces = true, 154 + error.FileNotFound, error.NotDir => {}, 155 + else => |e| return e, 156 + } 157 + } 158 + 159 + if (seen_eacces) return error.AccessDenied; 160 + return err; 125 161 }