From 482027b4071d069d43199b4232284bd67ce84c6b Mon Sep 17 00:00:00 2001 From: Travis Staloch <1562827+travisstaloch@users.noreply.github.com> Date: Sun, 26 Nov 2023 10:05:00 -0800 Subject: [PATCH] update to zig version 0.12.0-dev.1717+54f4abae2 fix 'var never mutated' errors --- src/protobuf-types.zig | 6 +++--- src/protobuf.zig | 10 +++++----- src/test-common.zig | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/protobuf-types.zig b/src/protobuf-types.zig index 39786a7..ca629cd 100644 --- a/src/protobuf-types.zig +++ b/src/protobuf-types.zig @@ -32,7 +32,7 @@ fn InitBytes(comptime T: type) MessageInit { return struct { pub fn initBytes(bytes: [*]u8, len: usize) void { assert(len == @sizeOf(T)); - var ptr = ptrAlignCast(*T, bytes); + const ptr = ptrAlignCast(*T, bytes); ptr.* = T.init(); } }.initBytes; @@ -784,7 +784,7 @@ pub const Message = extern struct { } else { const size = pb.protobuf.repeatedEleSize(field.type); const L = ListMutScalar(u8); - var list = ptrAlignCast(*L, bytes + field.offset); + const list = ptrAlignCast(*L, bytes + field.offset); if (list.len != 0) { log.debug( "deinit {s}.{s} repeated field {s} len {} size {} bytelen {}", @@ -833,7 +833,7 @@ pub const Message = extern struct { "deinit {s}.{s} single message field", .{ desc.name, field.name }, ); - var subm = ptrAlignCast(**Message, bytes + field.offset); + const subm = ptrAlignCast(**Message, bytes + field.offset); deinitImpl(subm.*, allocator, .only_pointer_fields); const subbytes = @as([*]align(@alignOf(*Message)) u8, @ptrCast(subm.*)); const subdesc = subm.*.descriptor orelse diff --git a/src/protobuf.zig b/src/protobuf.zig index 9453f3a..8162eb7 100644 --- a/src/protobuf.zig +++ b/src/protobuf.zig @@ -461,7 +461,7 @@ fn parseRepeatedMember( message: *Message, ctx: *Ctx, ) !void { - var field = scanned_member.field orelse unreachable; + const field = scanned_member.field orelse unreachable; log.debug( "parseRepeatedMember() field name='{s}' offset=0x{x}/{}", .{ field.name, field.offset, field.offset }, @@ -575,7 +575,7 @@ fn parseRequiredMember( if (field.label == .LABEL_REPEATED) { listAppend(member, ListMut(String), String.init(bytes)); } else { - var s = ptrAlignCast(*String, member); + const s = ptrAlignCast(*String, member); s.* = String.init(bytes); } log.info("{s}: '{s}'", .{ field.name, bytes }); @@ -662,7 +662,7 @@ fn parseMember( "parseMember() '{s}' .{s} .{s} ", .{ field.name, @tagName(field.label), @tagName(field.type) }, ); - var member = @as([*]u8, @ptrCast(message)) + field.offset; + const member = @as([*]u8, @ptrCast(message)) + field.offset; return switch (field.label) { .LABEL_REQUIRED => parseRequiredMember(scanned_member, member, message, ctx, true), .LABEL_OPTIONAL, .LABEL_NONE => if (flagsContain(field.flags, FieldFlag.FLAG_ONEOF)) @@ -705,7 +705,7 @@ fn deserializeErr(comptime fmt: []const u8, args: anytype, err: Error) Error { /// create a new Message and deserialize a protobuf wire format message from /// ctx.data into its fields. uses ctx.allocator for allocations. pub fn deserialize(desc: *const MessageDescriptor, ctx: *Ctx) Error!*Message { - var buf = try ctx.allocator.alignedAlloc( + const buf = try ctx.allocator.alignedAlloc( u8, common.ptrAlign(*Message), desc.sizeof_message, @@ -900,7 +900,7 @@ pub fn deserialize(desc: *const MessageDescriptor, ctx: *Ctx) Error!*Message { .{ field.name, size * list.len, size, list.len }, ); // TODO CLEAR_REMAINING_N_PTRS? - var bytes = switch (field.type) { + const bytes = switch (field.type) { .TYPE_DOUBLE, .TYPE_INT64, .TYPE_UINT64, diff --git a/src/test-common.zig b/src/test-common.zig index 5cf8ada..054431e 100644 --- a/src/test-common.zig +++ b/src/test-common.zig @@ -38,7 +38,7 @@ pub fn deserializeBytesHelper(comptime T: type, bytes: []const u8, alloc: mem.Al return try message.as(T); } pub fn deserializeHexBytesHelper(comptime T: type, hexbytes: []const u8, alloc: mem.Allocator) !*T { - var out = try alloc.alloc(u8, hexbytes.len / 2); + const out = try alloc.alloc(u8, hexbytes.len / 2); defer alloc.free(out); const bytes = try std.fmt.hexToBytes(out, hexbytes); return deserializeBytesHelper(T, bytes, alloc);