56 Commits

Author SHA1 Message Date
Andrew Kelley
0c1fbc4ea6 std: remove loop from growCapacity
I measured this against master branch and found no statistical
difference. Since this code is simpler and logically superior due to
always leaving sufficient unused capacity when growing, it is preferred
over status quo.
2025-09-20 14:34:18 -07:00
Andrew Kelley
eac2bbfec9 std.Io.Writer.writeSliceEndian: add compile error
check when an auto-layout struct is attempted to be memory reinterpreted
and written out. it would be writing undefined memory
2025-09-08 18:18:27 -07:00
Andrew Kelley
1d764c1fdf Revert "Merge pull request #24905 from gooncreeper/file-reader-buffered"
This reverts commit ac42eaaadd0650ffc281f9a1ed1a642fde8984b7, reversing
changes made to 9fa2394f8c00d060931d69fb6f342f7f2e3d826e.

I would like a chance to review this, please. I already spotted some
issues.
2025-09-05 11:26:38 -07:00
Kendall Condon
d26b532647 sendFileAll: use stream instead of sendFileReading
This is a simpler implementation and allows file_reader to do more
optimal streaming.
2025-09-04 17:26:52 -04:00
Kendall Condon
58dda3b10b fix sendFile implementations bypassing interface buffer
Also removes `File.Reader.read` since it is otherwise unused and is a
footgun.
2025-09-04 17:26:49 -04:00
Travis Staloch
1ec8a7ab4c Io.Writer.Allocating: test new *Aligned methods
* added initAligned()
* added missing @alignCast in toArrayListAligned()
2025-08-31 19:29:02 -07:00
Andrew Kelley
fadd268a60 upgrade more old API uses 2025-08-30 00:48:50 -07:00
Andrew Kelley
9a0970a12b rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to:
* std.fs.Dir.readFileAlloc
* std.fs.Dir.readFileAllocOptions
2025-08-30 00:48:50 -07:00
Andrew Kelley
cc931660eb link.MachO: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
2dc6ddd7e8 std.Io.Writer: add toArrayList/fromArrayList 2025-08-28 18:30:57 -07:00
TemariVirus
51a2c0feaf std.Io.Writer: fix upper case hex float formatting 2025-08-19 11:20:30 -07:00
Isaac Freund
551e009da7 Build.Step.Run: fix missing stdin buffer and flush
Writer.sendFileAll() asserts non-zero buffer capacity in the case that
the fallback is hit. It also requires the caller to flush. The buffer
may be bypassed as an optimization but this is not a guarantee.

Also improve the Writer documentation and add an earlier assert on
buffer capacity in sendFileAll().
2025-08-16 15:43:48 -07:00
Josh Wolfe
4fcdb08390 [std] fix compile error in std.Io.Writer.failing 2025-08-16 00:23:47 -07:00
Andrew Kelley
30b41dc510 std.compress.zstd.Decompress fixes
* std.Io.Reader: appendRemaining no longer supports alignment and has
  different rules about how exceeding limit. Fixed bug where it would
  return success instead of error.StreamTooLong like it was supposed to.

* std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited
  to be implemented based on std.Io.Writer.Allocating

* std.Io.Writer: introduce unreachableRebase

* std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe
  that flexibility could have been handy, but let's see if anyone
  actually needs it. The field is redundant with the superlinear growth
  of ArrayList capacity.

* std.Io.Writer: growingRebase also ensures total capacity on the
  preserve parameter, making it no longer necessary to do
  ensureTotalCapacity at the usage site of decompression streams.

* std.compress.flate.Decompress: fix rebase not taking into account seek

* std.compress.zstd.Decompress: split into "direct" and "indirect" usage
  patterns depending on whether a buffer is provided to init, matching
  how flate works. Remove some overzealous asserts that prevented buffer
  expansion from within rebase implementation.

* std.zig: fix readSourceFileToAlloc returning an overaligned slice
  which was difficult to free correctly.

fixes #24608
2025-08-15 10:44:35 -07:00
Andrew Kelley
af7e142485 std.Io.Writer: introduce rebase to the vtable
fixes #24814
2025-08-14 12:56:37 -07:00
Kendall Condon
4f639ff880 http: fix handling of limit in chunkedSendFile
`limit` in chunkedSendFile applies only to the file, not the entire
chunk. `limit` in sendFileHeader does not include the header.

Additionally adds a comment to clarify what `limit` applies to in
sendFileHeader and fixed a small bug in it (`drain` is able to return
less then `header.len`).
2025-08-13 13:14:01 -07:00
Isaac Freund
b8124d9c0b std.io.Writer.Allocating: rename getWritten() to written()
This "get" is useless noise and was copied from FixedBufferWriter.
Since this API has not yet landed in a release, now is a good time
to make the breaking change to fix this.
2025-08-13 01:43:52 -07:00
Jacob Young
60f8584927 Dwarf: port to new Writer API 2025-08-11 12:00:50 -07:00
Ryan Liptak
3280fc98f3 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 6219c015d8e8c958d96e5caa5ef0dbab9c414996 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.
2025-08-10 19:49:02 -07:00
Andrew Kelley
df46ee61c4 std.Io.Writer.Allocating: configurable bump amount 2025-08-08 19:22:08 -07:00
Andrew Kelley
3d25a9c1e0 std.Io.Writer.Allocating.sendFile: use logicalPos
fixes #24754

tested with `zig build test-std -Dskip-release`
2025-08-08 14:21:57 -07:00
Igor Anić
6219c015d8 Io.Writer fix dangling pointer
While underlying writer is Allocating writer buffer can grow in
vtable.drain call. We should not hold pointer to the buffer before that
call and use it after.
This remembers positions instead of holding reference.
2025-08-08 12:56:26 -07:00
Andrew Kelley
9a538e0d54 link.Dwarf: minimal changes to remove CountingWriter 2025-08-07 22:26:42 -07:00
Andrew Kelley
e2d81bf6c0 http fixes 2025-08-07 10:04:29 -07:00
Andrew Kelley
eb17d4562a std.Io.Writer.Hashed: fix bad assert 2025-07-31 22:36:52 -07:00
Ian Johnson
d91744401f fetch: More Git fixes 2025-07-31 22:10:11 -07:00
Andrew Kelley
64814dc986 std.compress.flate.Decompress: respect stream limit 2025-07-31 22:10:11 -07:00
Andrew Kelley
6caa100f0d std.Io.Writer: fix wrong return value from fixedDrain 2025-07-31 22:10:11 -07:00
Andrew Kelley
c49c90a42a fetch: update API usage 2025-07-31 22:10:11 -07:00
Andrew Kelley
cf7a28febb std.Io.Reader: introduce readVec back into the VTable
simplifies and fixes things

addresses a subset of #24608
2025-07-30 09:26:34 -07:00
Andrew Kelley
66e49d93b7
Merge pull request #24559 from ziglang/zstd
std: rework zstd for new I/O API
2025-07-25 20:02:53 -07:00
Andrew Kelley
9e11727c7c
Merge pull request #23340 from castholm/pass-null-to-b-dependency
Add support for passing null, string literals, enum lists and more to `b.dependency()`
2025-07-25 18:00:46 -07:00
Andrew Kelley
7f1c04423e std.Io: add "preserve" variants to Reader/Writer 2025-07-25 14:15:33 -07:00
Jacob Young
5060ab99c9 aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
Andrew Kelley
9abc3232a8 std.fs.File.Reader: fix missed advance writer positions 2025-07-21 13:08:43 +02:00
Carl Åstholm
e7604bba3e Serialize float options using the hexadecimal format
This ensures no information is lost when the value is round-tripped.
2025-07-20 18:28:36 +02:00
Andrew Kelley
8373788c4c
Merge pull request #24488 from ziglang/more
std.zig: finish updating to new I/O API
2025-07-20 11:24:41 +02:00
Marc Tiehuis
4780cc50cf std.Io.Writer: support alignment for {t} specifier 2025-07-20 10:30:17 +02:00
Andrew Kelley
c40fb96ca3 std.Io.Writer: fix writeSliceSwap
tried to be too clever, wrote bad code
2025-07-19 22:12:37 -07:00
Andrew Kelley
8489bab1f4 std.Io.Writer: add missing writeSliceSwap 2025-07-19 19:57:37 -07:00
John Benediktsson
e62e42f0d9
std.io.Writer: remove requirement of a 2-byte buffer for extern unions (#24489)
closes #24486
2025-07-17 16:42:53 +00:00
Andrew Kelley
73cfba4d0d std.Io.Writer: fix writeStruct 2025-07-16 17:20:03 -07:00
Andrew Kelley
c4776d66af update compiler 2025-07-16 17:20:02 -07:00
Andrew Kelley
2d5d2ba4f5 std.zig.Render: update it and references 2025-07-16 17:20:02 -07:00
Silver
d772c06272 fix splatBytesAll and writeSplatAll 2025-07-16 20:37:38 +02:00
Andrew Kelley
6d39c29564 std.Io.Writer.Allocating: fix sendFile EndOfStream 2025-07-15 11:43:55 -07:00
Andrew Kelley
c7f332a260 std.Io.Writer.Discarding: fix sendFile EndOfStream 2025-07-15 11:32:40 -07:00
Andrew Kelley
a5dbb656b1
Merge pull request #24454 from ziglang/packed-struct-streams
std.Io: handle packed structs better
2025-07-15 13:43:08 +02:00
Travis Staloch
294db62d92 memory safety fix for Io.Writer.Allocating.toOwnedSlice*()
don't forget to save the list.  this allows a
`testing.checkAllAllocationFailures()` test to pass in one of my
projects which newly failed since #24329 was merged.
2025-07-15 08:49:54 +02:00
Andrew Kelley
deb9f3e88f std.Io: handle packed structs better
Rather than having the endian-suffixed functions be the preferred ones
the unsuffixed ones are the preferred ones and the tricky functions get
a special suffix.

Makes packed structs read and written the same as integers.

closes #12960
2025-07-14 18:43:56 -07:00