mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Writer: Delete writePreserve/writeAllPreserve
This is one way of partially addressing https://github.com/ziglang/zig/issues/24767
- These functions are unused
- These functions are untested
- These functions are broken
+ The same dangling pointer bug from 6219c015d8 exists in `writePreserve`
+ The order of the bytes preserved in relation to the `bytes` being written can differ depending on unused buffer capacity at the time of the call and the drain implementation.
If there ends up being a need for these functions, they can be fixed and added back.
This commit is contained in:
parent
b9a6dae2ae
commit
3280fc98f3
1 changed files with 0 additions and 31 deletions
|
|
@ -498,25 +498,6 @@ pub fn write(w: *Writer, bytes: []const u8) Error!usize {
|
||||||
return w.vtable.drain(w, &.{bytes}, 1);
|
return w.vtable.drain(w, &.{bytes}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts `buffer` capacity exceeds `preserve_len`.
|
|
||||||
pub fn writePreserve(w: *Writer, preserve_len: usize, bytes: []const u8) Error!usize {
|
|
||||||
assert(preserve_len <= w.buffer.len);
|
|
||||||
if (w.end + bytes.len <= w.buffer.len) {
|
|
||||||
@branchHint(.likely);
|
|
||||||
@memcpy(w.buffer[w.end..][0..bytes.len], bytes);
|
|
||||||
w.end += bytes.len;
|
|
||||||
return bytes.len;
|
|
||||||
}
|
|
||||||
const temp_end = w.end -| preserve_len;
|
|
||||||
const preserved = w.buffer[temp_end..w.end];
|
|
||||||
w.end = temp_end;
|
|
||||||
defer w.end += preserved.len;
|
|
||||||
const n = try w.vtable.drain(w, &.{bytes}, 1);
|
|
||||||
assert(w.end <= temp_end + preserved.len);
|
|
||||||
@memmove(w.buffer[w.end..][0..preserved.len], preserved);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calls `drain` as many times as necessary such that all of `bytes` are
|
/// Calls `drain` as many times as necessary such that all of `bytes` are
|
||||||
/// transferred.
|
/// transferred.
|
||||||
pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
|
pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
|
||||||
|
|
@ -524,18 +505,6 @@ pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
|
||||||
while (index < bytes.len) index += try w.write(bytes[index..]);
|
while (index < bytes.len) index += try w.write(bytes[index..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls `drain` as many times as necessary such that all of `bytes` are
|
|
||||||
/// transferred.
|
|
||||||
///
|
|
||||||
/// When draining the buffer, ensures that at least `preserve_len` bytes
|
|
||||||
/// remain buffered.
|
|
||||||
///
|
|
||||||
/// Asserts `buffer` capacity exceeds `preserve_len`.
|
|
||||||
pub fn writeAllPreserve(w: *Writer, preserve_len: usize, bytes: []const u8) Error!void {
|
|
||||||
var index: usize = 0;
|
|
||||||
while (index < bytes.len) index += try w.writePreserve(preserve_len, bytes[index..]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Renders fmt string with args, calling `writer` with slices of bytes.
|
/// Renders fmt string with args, calling `writer` with slices of bytes.
|
||||||
/// If `writer` returns an error, the error is returned from `format` and
|
/// If `writer` returns an error, the error is returned from `format` and
|
||||||
/// `writer` is not called again.
|
/// `writer` is not called again.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue