std.io.BufferedReader: get rid of the @constCast

but it's pushed out to various callsites
This commit is contained in:
Andrew Kelley
2025-04-18 18:23:06 -07:00
parent f333267782
commit 00afaa4b18
5 changed files with 11 additions and 9 deletions
+1 -1
View File
@@ -2236,7 +2236,7 @@ pub const ElfModule = struct {
const section_bytes = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
sections[section_index.?] = if ((shdr.sh_flags & elf.SHF_COMPRESSED) > 0) blk: {
var section_reader: std.io.BufferedReader = undefined;
section_reader.initFixed(section_bytes);
section_reader.initFixed(@constCast(section_bytes));
const chdr = section_reader.takeStruct(elf.Chdr) catch continue;
if (chdr.ch_type != .ZLIB) continue;
const ch_size = chdr.ch_size;
+2 -2
View File
@@ -262,7 +262,7 @@ pub fn StackMachine(comptime options: Options) type {
) Error!?Value {
if (initial_value) |i| try self.stack.append(allocator, .{ .generic = i });
var reader: std.io.BufferedReader = undefined;
reader.initFixed(expression);
reader.initFixed(@constCast(expression));
while (try self.step(&reader, allocator, context)) {}
if (self.stack.items.len == 0) return null;
return self.stack.items[self.stack.items.len - 1];
@@ -721,7 +721,7 @@ pub fn StackMachine(comptime options: Options) type {
if (context.thread_context == null) return error.IncompleteExpressionContext;
var block_reader: std.io.BufferedReader = undefined;
block_reader.initFixed(block);
block_reader.initFixed(@constCast(block));
const register = (try readOperand(&block_reader, block[0], context)).?.register;
const value = mem.readInt(usize, (try abi.regBytes(context.thread_context.?, register, context.reg_context))[0..@sizeOf(usize)], native_endian);
try self.stack.append(allocator, .{ .generic = value });
+1 -1
View File
@@ -53,7 +53,7 @@ pub fn readIntChecked(
pub fn readLeb128(fbr: *FixedBufferReader, comptime T: type) Error!T {
var br: std.io.BufferedReader = undefined;
br.initFixed(fbr.buf);
br.initFixed(@constCast(fbr.buf));
br.seek = fbr.pos;
const result = br.takeLeb128(T);
fbr.pos = br.seek;
+2 -2
View File
@@ -2026,8 +2026,8 @@ pub const VirtualMachine = struct {
if (pc < fde.pc_begin or pc >= fde.pc_begin + fde.pc_range) return error.AddressOutOfRange;
var readers: [2]std.io.BufferedReader = undefined;
readers[0].initFixed(cie.initial_instructions);
readers[1].initFixed(fde.instructions);
readers[0].initFixed(@constCast(cie.initial_instructions));
readers[1].initFixed(@constCast(fde.instructions));
var prev_row: Row = self.current_row;
for (&readers, [2]bool{ true, false }) |*reader, is_initial| {