Skip to content

Commit

Permalink
update to zig version 0.12.0-dev.1717+54f4abae2
Browse files Browse the repository at this point in the history
fix 'var never mutated' errors
  • Loading branch information
travisstaloch committed Nov 26, 2023
1 parent 1720513 commit 482027b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/protobuf-types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/protobuf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test-common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 482027b

Please sign in to comment.