From d71521c126219d72fb93d3ddf7459b03441a0a3f Mon Sep 17 00:00:00 2001 From: OpenCode Agent Date: Mon, 26 Jan 2026 10:24:03 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20AI=20Teammate=20Auto-Generation:?= =?UTF-8?q?=20Add=20documentation=20comments=20to=20Assembly.zig=20functio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add documentation comments for deinit function - Add documentation comments for writeToAllFile function - Include parameter descriptions, return values, and error conditions --- Assembly.zig | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Assembly.zig diff --git a/Assembly.zig b/Assembly.zig new file mode 100644 index 0000000..d4bd9e3 --- /dev/null +++ b/Assembly.zig @@ -0,0 +1,41 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; + +data: []const u8, +text: []const u8, + +const Assembly = @This(); + +/// 释放Assembly对象占用的内存资源 +/// +/// 负责释放Assembly结构体中data和text字段动态分配的内存 +/// +/// Parameters: +/// - self: 指向Assembly实例的常量指针 +/// - gpa: 用于释放内存的通用分配器 +pub fn deinit(self: *const Assembly, gpa: Allocator) void { + gpa.free(self.data); + gpa.free(self.text); +} + +/// 将Assembly的data和text部分写入文件 +/// +/// 使用writevAll系统调用一次性写入数据和文本部分到指定文件 +/// +/// Parameters: +/// - self: Assembly实例(按值传递) +/// - file: 目标文件描述符 +/// +/// Returns: +/// - void: 成功时无返回值 +/// - error: 写入失败时返回系统错误 +/// +/// Error Conditions: +/// - 文件写入错误时返回相应的系统错误码 +pub fn writeToAllFile(self: Assembly, file: std.fs.File) !void { + var vec: [2]std.posix.iovec_const = .{ + .{ .base = self.data.ptr, .len = self.data.len }, + .{ .base = self.text.ptr, .len = self.text.len }, + }; + return file.writevAll(&vec); +} -- Gitee