Commit Graph

12897 Commits

Author SHA1 Message Date
Andrew Kelley f4140f6e8b std.Io.Threaded: fix batchWait impl 2026-01-30 12:10:01 -08:00
Andrew Kelley afd91234a1 std.Io.Threaded: fix error set 2026-01-30 12:10:01 -08:00
Andrew Kelley d67c8f5d23 compiler: update for std.Io.File.MultiReader API 2026-01-30 12:10:01 -08:00
Andrew Kelley d579375a7a std.Io.operate: fix bogus catch
this used to have a different error set. just goes to show you how
useful switching on error set is even when there is only 1 prong
2026-01-30 12:10:01 -08:00
Andrew Kelley 5a2cab21e1 std.Io.File.MultiReader: implementation fixes 2026-01-30 12:10:01 -08:00
Andrew Kelley 0cca18e43c std: update rest of build runner to new File.MultiReader API 2026-01-30 12:10:01 -08:00
Andrew Kelley 1a168f08b5 std.Io.File: introduce MultiReader
Concurrently read from multiple file streams, eliminating risk of
deadlocking.
2026-01-30 12:10:01 -08:00
Andrew Kelley a1b3d9e447 std.Io.Threaded: delete dead code 2026-01-30 12:10:01 -08:00
Andrew Kelley 50db074bdf Build.WebServer: update concurrency API usage 2026-01-30 12:10:01 -08:00
Jacob Young dea653fdb9 Io: add ring to Batch API 2026-01-30 12:10:01 -08:00
Andrew Kelley 5456f953fa std.Io.Threaded: super broken Windows impl of batch
this is a cry for help
2026-01-30 12:10:01 -08:00
Andrew Kelley 72894900ec std.process.Child.collectOutput: change back to other impl
this one avoids calling poll() more than necessary
2026-01-30 12:10:01 -08:00
Andrew Kelley 45bc4b4e36 std.Io: exploring a different batch API proposal 2026-01-30 12:10:01 -08:00
Andrew Kelley d1d39cb3fe Revert "std.process.Child: rewrite using concurrent"
This reverts commit 76e1ba8f490812c6e2ebf6f6becd89a71275d21e.
2026-01-30 12:10:01 -08:00
Andrew Kelley 3998fa3c3b std.process.Child: rewrite using concurrent
I plan to immediately revert this, but here's a commit for posterity
2026-01-30 12:10:01 -08:00
Andrew Kelley 13ef792cc6 fix error set 2026-01-30 12:10:01 -08:00
Andrew Kelley 3ef1266582 std.Io.Threaded: set poll_buffer_len to 32
reasoning is that polling with large amount of operations will be rarely
done with std.Io.Threaded. However this still provides the opportunity
to provide concurrency for any real world use cases that need it.
2026-01-30 12:10:01 -08:00
Andrew Kelley 24b3c4cec1 std.Io.Threaded.operate: handle poll buffer exceeded 2026-01-30 12:10:01 -08:00
Andrew Kelley ae2d71b65e std.Io.Threaded.operate: handle cancelation and poll errors 2026-01-30 12:10:01 -08:00
Andrew Kelley f391adc3af std.Io: simplify operate function
- no timeout
- no n_wait
- infallible
2026-01-30 12:10:01 -08:00
Andrew Kelley 6d22f7b4d7 std.Io: proof-of-concept "operations" API
This commit shows a proof-of-concept direction for std.Io.VTable to go,
which is to have general support for batching, timeouts, and
non-blocking.

I'm not sure if this is a good idea or not so I'm putting it up for
scrutiny.

This commit introduces `std.Io.operate`, `std.Io.Operation`, and
implements it experimentally for `FileReadStreaming`.

In `std.Io.Threaded`, the implementation is based on poll().

This commit shows how it can be used in `std.process.run` to collect
both stdout and stderr in a single-threaded program using
`std.Threaded.Io`.

It also demonstrates how to upgrade code that was previously using
`std.Io.poll` (*not* integrated with the interface!) using concurrency.
This may not be ideal since it makes the build runner no longer support
single-threaded mode. There is still a needed abstraction for
conveniently reading multiple File streams concurrently without
io.concurrent, but this commit demonstrates that such an API can be
built on top of the new `std.Io.operate` functionality.
2026-01-30 12:10:01 -08:00
Andrew Kelley def22c2b63 std.Io: delete the poll API 2026-01-30 12:10:01 -08:00
Jacob Young b5174455f8 Io.Threaded: fix UAF-induced crashes during asynchronous operations
When `NtReadFile` returns `SUCCESS`, the APC routine still runs when
next alertable, which was previously clobbering an out of scope `done`.
Instead of adding an extra syscall to the success path, avoid all APC
side effects, allowing instant completions to return immediately.
2026-01-30 12:10:01 -08:00
Andrew Kelley 29f44952c1 std.Io.Threaded: fix NtDelayExecution delay interval 2026-01-30 12:10:01 -08:00
Andrew Kelley 9240881806 std.Io.Threaded: handle some more error codes from NtReadFile 2026-01-30 12:10:01 -08:00
Andrew Kelley b470800265 std.Io.Threaded: avoid extra fields of Thread
As mlugg pointed out those race when a thread finishes an operation just
after it is canceled and then that thread to picks up another task,
resulting in these fields being potentially overwritten.

This updates fileReadStreaming on Windows to handle being alerted, and
then manage its own cancelation of the file I/O.
2026-01-30 12:10:01 -08:00
Andrew Kelley 84303546ba std.Io.Threaded: don't pass null to NtDelayExecution
Windows returns ACCESS_VIOLATION if you do that.
2026-01-30 12:10:01 -08:00
Andrew Kelley 36940c3953 std.Io.Threaded: implement APC cancelation
specifically the call to NtCancelIoFileEx
2026-01-30 12:10:01 -08:00
Andrew Kelley 0553525fe6 std.Io.Threaded: introduce Thread.InterruptMethod
implements APC cancelation except for the actual call to NtCancelIoFileEx
2026-01-30 12:10:01 -08:00
Andrew Kelley 1b157499ef std.Io.Threaded: add some temporary, choice panics 2026-01-30 12:10:01 -08:00
Andrew Kelley 4f948bb13e std: back out the flags field of Io.File
For now, let us refrain from putting the sync mode into the Io.File
struct, and document that to do concurrent batch operations, any Windows
file handles must be in asynchronous mode. The consequences for
violating this requirement is neither illegal behavior, nor an error,
but that concurrency is lost. In other words, deadlock might occur. This
prevents the addition of flags field.

partial revert of 2faf14200f58ee72ec3a13e894d765f59e6483a9
2026-01-30 12:10:00 -08:00
Andrew Kelley 59ebd82ebf std.Io: give File a nonblocking bit on Windows
This tracks whether it is a file opened in synchronous mode, or
something that supports APC.

This will be needed in order to know whether concurrent batch operations
on the file should return error.ConcurrencyUnavailable, or use APC to
complete the batch.

This patch also switches to using NtCreateFile directly in
std.Io.Threaded for dirCreateFile, as well as NtReadFile for
fileReadStreaming, making it handle files opened in synchronous mode as
well as files opened in asynchronous mode.
2026-01-30 12:10:00 -08:00
mercenary fa988e88ed zstd.Decompress: smarter rebase when discarding (#30891)
The call to `rebase` in `discardIndirect` and `discardDirect` was inappropriate. As `rebase` expects the `capacity` parameter to exclude the sliding window, this call was asking for ANOTHER `d.window_len` bytes. This was impossible to fulfill with a buffer smaller than 2*`d.window_len`, and caused [#25764](https://github.com/ziglang/zig/issues/25764).

This PR adds a basic test to do a discard (which does trigger [#25764](https://github.com/ziglang/zig/issues/25764)), and rebases only as much as is required to make the discard succeed ([or no rebase at all](https://github.com/ziglang/zig/issues/25764#issuecomment-3484716253)). That means: ideally rebase to fit `limit`, or if the buffer is too small, as much as possible.

I must say, `discardDirect` does not make much sense to me, but I replaced it anyway. `rebaseForDiscard` works fine with `d.reader.buffer.len == 0`. Let me know if anything should be changed.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30891
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: mercenary <mercenary@noreply.codeberg.org>
Co-committed-by: mercenary <mercenary@noreply.codeberg.org>
2026-01-30 20:19:19 +01:00
Andrew Kelley 6a3226c43c std.Io: add net.Socket.createPair
and remove the following from std.posix:
- socketpair
- fcntl
2026-01-30 02:07:26 -08:00
Andrew Kelley 0c67d9ebde std.posix: goodbye gettimeofday 2026-01-30 01:58:49 -08:00
Andrew Kelley 36eb8dec98 std.posix: goodbye to some functions
- fstat
- inotify_init1
- inotify_add_watch, inotify_add_watchZ
- inotify_rm_watch
- sysctlbynameZ
2026-01-30 01:58:49 -08:00
Andrew Kelley e7e168727e std.posix: goodbye connect, eventfd 2026-01-30 01:58:49 -08:00
rpkak b9819fce69 Io.Threaded: limit copy_file_range len to prevent EOVERFLOW 2026-01-30 08:19:50 +01:00
Andrew Kelley 377bb8f237 Merge pull request 'std: migrate getcwd to Io' (#31047) from getcwd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31047
2026-01-30 06:38:08 +01:00
lzm-build ccd82ae7cc Add f16, f80 and f128 support for atan 2026-01-30 06:20:14 +01:00
Pablo Alessandro Santos Hugen ad0458f582 std.Build: Fix wrong error enum
Signed-off-by: Pablo Alessandro Santos Hugen <phugen@redhat.com>
2026-01-30 06:19:49 +01:00
Brandon Black ecb9ddf267 Threaded.sleepPosix: fix libc error handling
Confusingly, the POSIX spec for clock_nanosleep() says it returns
*positive* error values directly and does not touch `errno`. Not
detecting EINTR properly here was breaking the cancellation of
threads blocked in this call when linking libc.
2026-01-30 06:19:31 +01:00
Andrew Kelley b1d1806fef std.process: currentDir -> currentPath
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
2026-01-29 18:47:58 -08:00
Andrew Kelley 0a37ad2ec4 std.Io.File: handle DISK_FULL on windows 2026-01-29 18:40:56 -08:00
Andrew Kelley 3cc5dda756 fix RtlGetCurrentDirectory_U parameter
it's the byte length not number of wchars
2026-01-29 18:40:56 -08:00
Andrew Kelley 649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
Andrew Kelley 9b415761dd std.os.windows: delete unused APIs
Intention is to go through std.Io for these things.
2026-01-30 03:39:46 +01:00
Andrew Kelley 18c6abc0ba std: finish moving os.windows.ReadLink logic to Io.Threaded
- remove error.SharingViolation from all error sets since it has the
  same meaning as FileBusy
- add error.FileBusy to CreateFileAtomicError and ReadLinkError
- update dirReadLinkWindows to use NtCreateFile and NtFsControlFile and
  integrate with cancelation properly.
- move windows CTL_CODE constants to the proper namespace
- delete os.windows.ReadLink
2026-01-28 17:02:17 -08:00
Andrew Kelley 5774248041 std.os.windows: delete unused CreateSymbolicLink 2026-01-28 15:33:04 -08:00
lzm-build 757ec185f0 Add f16, f80 and f128 support for acos and asin (#30997)
The software impl of `acos` and `asin` depends on the `sqrt` op. Since support for `sqrt` in `f16`, `f80`, and `f128` has been added, the impl of `acos` and `asin` for `f16`, `f80`, and `f128` is now being supplemented.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30997
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: lzm-build <3575188313@qq.com>
Co-committed-by: lzm-build <3575188313@qq.com>
2026-01-28 23:33:35 +01:00