Commit graph

7846 commits

Author SHA1 Message Date
Jacob Young
6e0de1d116 InternPool: port most of value tags 2023-06-10 20:47:54 -07:00
Andrew Kelley
1b64eed107 remove the kludges from std.builtin
I added these in an earlier commit in this branch. This commit removes
them before the branch is merged.
2023-06-10 20:47:54 -07:00
Andrew Kelley
17882162b3 stage2: move function types to InternPool 2023-06-10 20:47:53 -07:00
Andrew Kelley
88dbd62bcb stage2: move enum tag values into the InternPool
I'm seeing a new assertion trip: the call to `enumTagFieldIndex` in the
implementation of `@Type` is attempting to query the field index of an
union's enum tag, but the type of the enum tag value provided is not the
same as the union's tag type. Most likely this is a problem with type
coercion, since values are now typed.

Another problem is that I added some hacks in std.builtin because I
didn't see any convenient way to access them from Sema. That should
definitely be cleaned up before merging this branch.
2023-06-10 20:46:17 -07:00
Andrew Kelley
1c7095cb7d add std.hash.uint32
This is handy if you have a u32 and want a u32 and don't want to take a
detour through many layers of abstraction elsewhere in the std.hash
namespace.
Copied from https://nullprogram.com/blog/2018/07/31/
2023-06-10 20:42:30 -07:00
Andrew Kelley
70a4b76aca std.builtin.AddressSpace: allocate one more bit to this enum 2023-06-10 20:42:28 -07:00
Andrew Kelley
75cf06c187 std.mem.alignForwardGeneric: manually inline the assertions
This matches more directly the documentation comments, and makes it more
obvious what went wrong when an assertion fails.
2023-06-10 20:42:28 -07:00
Andrew Kelley
cac60a05a7 std.builtin: give some enums integer types 2023-06-10 20:40:03 -07:00
Jacob G-W
c842deea75 os/plan9: fix order of register setting in syscall1
We need to set rbp last because the arguments are stored on the
stack. If we clobber rbp first, then we will get a segfault when
trying to access the function arguments.

I believe I had already done this with the other syscall* functions,
but not with syscall1, so this allows single argument syscalls like
close to work.
2023-06-10 11:36:32 +03:00
Veikka Tuominen
2094d98694
Merge pull request #15980 from squeek502/walker-fixes
A few `IterableDir.Walker`/`Iterator` fixes
2023-06-10 05:09:34 +03:00
sentientwaffle
f04e65bc09 std.hash_map: fetchRemove increment available
To avoid leaking slots, `fetchRemove` must increment `available` (when the "fetch" succeeds).

Without the `available += 1`, the added test `"std.hash_map repeat fetchRemove"` fails with

    run test std-x86-linux-none-Debug: error: thread 432734 panic: integer overflow
    .../zig/lib/std/hash_map.zig:1365:28: 0x6471d5 in getOrPutAssumeCapacityAdapted__anon_47495 (test)
            self.available -= 1;
                           ^
    .../zig/lib/std/hash_map.zig:1308:62: 0x616950 in getOrPutAssumeCapacityContext (test)
            const result = self.getOrPutAssumeCapacityAdapted(key, ctx);
                                                             ^

Alternatively, `fetchRemove` could call `removeByIndex`, though that would entail calling `header()` twice instead of once.
2023-06-10 02:24:35 +03:00
Loris Cro
99fe2a23c0
Merge pull request #15950 from der-teufel-programming/autodoc-quickfixes
autodoc: Fix rendering of some values in main.js
2023-06-09 09:35:45 -07:00
Ryan Liptak
af835111fa Allow recovering from Walker.next errors without continually hitting the same error
Before this commit, if Walker.next errored with e.g. `error.AccessDenied` and the caller did something like `while (true) { walker.next() catch continue; }`, then the directory that errored with AccessDenied would be continually iterated in each `next` call and error every time with AccessDenied.

After this commit, the directory that errored will be popped off the stack before the error is returned, meaning that in the subsequent `next` call, it won't be retried and the Walker will continue with whatever directories remain on its stack.

For a real example, before this commit, walking `/proc/` on my system would infinitely loop due to repeated AccessDenied errors on the same directory. After this commit, I am able to walk `/proc/` on my system fully (skipping over any directories that are unable to be iterated).
2023-06-08 02:16:15 -07:00
Ryan Liptak
7555085e63 Directory iteration: handle EACCES returned from getdents64
This can occur for directories that the user does not have the necessary permissions to be able to iterate.
2023-06-08 02:16:15 -07:00
Ryan Liptak
2f188290e2 Use iterateAssumeFirstIteration in Walker.next to avoid unnecessary lseek calls
Since we are opening each directory for iteration, we know that we don't need to reset the cursor's directory before iterating. Using `iterateAssumeFirstIteration` skips the cursor resetting which eliminates an `lseek` syscall for every directory opened on non-Windows platforms.

This doesn't seem to actually matter much for performance (1.01 ± 0.02 times faster when walking /home/ on my system) but avoiding unnecessary syscalls is always nice anyway.
2023-06-08 02:16:15 -07:00
Marc Tiehuis
00ff653576
reimplement wyhash v4.1 (#15969) 2023-06-07 19:27:17 -07:00
Josh Wolfe
cb7040154e
std: fix parseInt for single-digit signed minInt (#15966) 2023-06-07 10:34:25 -04:00
Frank Denis
9ee0a706da
crypto.bcrypt: allow very large passwords to be pre-hashed (#15955)
crypto.bcrypt: allow very large passwords to be pre-hashed

bcrypt has a slightly annoying limitation: passwords are limited
to 72 characters. In the original implementation, additional characters
are silently ignored.

When they care, applications adopt different strategies to work around
this, in incompatible ways.

Ideally, large passwords should be pre-hashed using a hash function that
hinders GPU attackers, and the hashed function should not be deterministic
in order to defeat shucking attacks.

This change improves the developer experience by adding a very explicit
`silently_truncate_password` option, that can be set to `false` in
order to do that automatically, and consistently across Zig applications.

By default, passwords are still truncated, so this is not a breaking
change.

Add some inline documentation for our beloved autodoc by the way.
2023-06-06 09:08:57 +02:00
Jakub Konka
7e0a02ee25 macos+libc: add zlib.h,sys/paths.h,netinet/{ip.h,udp.h} 2023-06-04 16:37:53 +02:00
Krzysztof Wolicki
ad6e106f52 autodoc: Fix rendering of some values in main.js 2023-06-04 11:05:53 +00:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
dweiller
3add9d8257 std.c: fix return type of recv/recvfrom on windows
Windows defines `recv` and `recvfrom` to return a value of type `int`,
rather than a pointer-sized signed integer, and so should use `c_int`
rather than `isize` for their return types.
2023-06-03 13:45:52 -07:00
xEgoist
ff57a264ad
Build: fix producesPdbFile logic (#15756)
Fixes bug causing ReleaseSmall to fail on Windows.

Due to the change in default behavior of ReleaseSmall, debug info are
stripped by default. However because `Compile.create` still defaults to
null, `producesPdbFile` will report true for
`lib/std/Build/Step/InstallArtifact.zig` causing it to fail on copying a
file that does not exist. This commit change the default of strip
depending on `optimize`.
2023-06-03 16:45:08 -04:00
Eric Joldasov
5c6f111379 std.io.reader.Reader: add streamUntilDelimiter
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-03 13:38:23 -07:00
Andrew Kelley
77b40d6ecb
Merge pull request #15927 from truemedian/http-bugs
std.http: fix infinite read loop, deduplicate connection code, add TlsAlert errors
2023-06-03 13:36:07 -07:00
Frank Denis
879f0b9cee
Fix std.hash benchmarks (#15917) 2023-06-02 20:08:28 +02:00
Nameless
23ccff9cce
std.http.Server: collapse BufferedConnection into Connection 2023-06-01 13:44:00 -05:00
Nameless
0e5e6cb10c
std.http: add TlsAlert descriptions so that they can at least be viewed in err return traces 2023-06-01 13:43:55 -05:00
Nameless
8136123aa7
std.http.Client: collapse BufferedConnection into Connection 2023-06-01 13:43:23 -05:00
Evin Yulo
6c2f374556 Use the word 'base' consistently instead of 'radix' 2023-06-01 00:02:16 +03:00
Jakub Konka
76aa1fffb7
Merge pull request #15905 from jacobly0/x86_64-hotfix
x86_64: hotfix for crash during in-memory coercion of large type
2023-05-30 13:22:13 +02:00
Frank Denis
1ab008d89d
RSA: remove usage of allocators (#15901)
Individual max buffer sizes are well known, now that arithmetic doesn't
require allocations any more.

Also bump `main_cert_pub_key_buf`, so that e.g. `nodejs.org` public
keys can fit.
2023-05-30 10:06:44 +00:00
kcbanner
9244e4fe2d cache: handle 0-length prefix paths in findPrefixResolved 2023-05-30 01:21:01 -07:00
Andrew Kelley
22b0457dd4
Merge pull request #15891 from mlugg/fix/dont-emit-fn-called-at-comptime
Prevent analysis of functions only referenced at comptime
2023-05-29 23:41:40 -07:00
Jacob Young
28df1d09dc Revert "Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths""
This reverts commit b5fad3a40a.

The latent x86_64 backend bug has been fixed.
2023-05-29 22:09:13 -04:00
Andrew Kelley
706bdf6512 std.debug: disable sporadically failing test
This was observed to fail on aarch64-windows as well.

See tracking issue #13963
2023-05-29 16:29:19 -07:00
mlugg
4976b58ab1
Prevent analysis of functions only referenced at comptime
The idea here is that there are two ways we can reference a function at runtime:

* Through a direct call, i.e. where the function is comptime-known
* Through a function pointer

This means we can easily perform a form of rudimentary escape analysis
on functions. If we ever see a `decl_ref` or `ref` of a function, we
have a function pointer, which could "leak" into runtime code, so we
emit the function; but for a plain `decl_val`, there's no need to.

This change means that `comptime { _ = f; }` no longer forces a function
to be emitted, which was used for some things (mainly tests). These use
sites have been replaced with `_ = &f;`, which still triggers analysis
of the function body, since you're taking a pointer to the function.

Resolves: #6256
Resolves: #15353
2023-05-29 23:06:08 +01:00
Andrew Kelley
b5fad3a40a Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths"
This reverts commit 1697d44809.

Master branch started failing after this commit landed.
2023-05-29 15:01:24 -07:00
David CARLIER
138f1253de std.os: fix uname usage.
close #15839.
2023-05-29 22:08:43 +03:00
mlugg
46e724ab28 std.dwarf: handle DWARF 5 compile unit DW_AT_ranges correctly
This data changed quite significantly between DWARF 4 and 5. Some
systems are shipping DWARF 5 libraries (Void Linux on musl libc seems to
use it for crt1 etc), which meant when printing stack traces, a random
compile unit might be incorrectly identified as containing an address,
resulting in incorrect location information.

I was consistently experiencing this issue with compiler stack traces,
and this change fixed it.
2023-05-29 11:28:39 -07:00
Ryan Liptak
1697d44809 Windows: Support UNC, rooted, drive relative, and namespaced/device paths
There are many different types of Windows paths, and there are a few different possible namespaces on top of that. Before this commit, NT namespaced paths were somewhat supported, and for Win32 paths (those without a namespace prefix), only relative and drive absolute paths were supported. After this commit, all of the following are supported:

- Device namespaced paths (`\\.\`)
- Verbatim paths (`\\?\`)
- NT-namespaced paths (`\??\`)
- Relative paths (`foo`)
- Drive-absolute paths (`C:\foo`)
- Drive-relative paths (`C:foo`)
- Rooted paths (`\foo`)
- UNC absolute paths (`\\server\share\foo`)
- Root local device paths (`\\.` or `\\?` exactly)

Plus:

- Any of the path types and namespace types can be mixed and matched together as appropriate.
- All of the `std.os.windows.*ToPrefixedFileW` functions will accept any path type, prefixed or not, and do the appropriate thing to convert them to an NT-prefixed path if necessary.

This is achieved by making the `std.os.windows.*ToPrefixedFileW` functions behave like `ntdll.RtlDosPathNameToNtPathName_U`, but with a few differences:

- Does not allocate on the heap (this is why we can't use `ntdll.RtlDosPathNameToNtPathName_U` directly, it does internal heap allocation).
- Relative paths are kept as relative unless they contain too many .. components, in which case they are treated as 'drive relative' and resolved against the CWD (this is how it behaved before this commit as well).
- Special case device names like COM1, NUL, etc are not handled specially (TODO)
- `.` and space are not stripped from the end of relative paths (potential TODO)

Most of the non-trivial conversion of non-relative paths is done via `ntdll.RtlGetFullPathName_U`, which AFAIK is used internally by `ntdll.RtlDosPathNameToNtPathName_U`.

Some relevant reading on Windows paths:

- https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
- https://chrisdenton.github.io/omnipath/Overview.html

Closes #8205
Might close (untested) #12729

Note:
- This removes checking for illegal characters in `std.os.windows.sliceToPrefixedFileW`, since the previous solution (iterate the whole string and error if any illegal characters were found) was naive and won't work for all path types. This is further complicated by things like file streams (where `:` is used as a delimiter, e.g. `file.ext:stream_name:$DATA`) and things in the device namespace (where a path like `\\.\GLOBALROOT\??\UNC\localhost\C$\foo` is valid despite the `?`s in the path and is effectively equivalent to `C:\foo`). Truly validating paths is complicated and would need to be tailored to each path type. The illegal character checking being removed may open up users to more instances of hitting `OBJECT_NAME_INVALID => unreachable` when using `fs` APIs.
  + This is related to https://github.com/ziglang/zig/issues/15607
2023-05-29 13:08:51 +03:00
Mizuochi Keita
ec58b475b7 std.math.big.int: Fix typo
- `bytes` -> `buffer`
- Correct naming consistency between
  1. fn argument and doc comment of `(read|write)PackedTwosComplement`
  2. fn arguments of `(read|write)PackedTwosComplement` and `(read|write)TwosComplement`
2023-05-29 13:04:55 +03:00
Mizuochi Keita
4422af8be9 std.math.big.int: Add Sqrt
Implemented with reference to Modern Computer Arithmetic, Algorithm 1.13.
https://members.loria.fr/PZimmermann/mca/pub226.html

The below optimization ideas are derived from Go's big package.

* Minimize initial loop value
* Reuse loop values

math/big/int.go: https://cs.opensource.google/go/go/+/refs/tags/go1.20.4:src/math/big/int.go;l=1286
2023-05-29 13:04:32 +03:00
Cortex
6e6a61a384
std.io.Writer: add support for non-power-of-two int sizes 2023-05-29 13:01:54 +03:00
Frank Denis
ab37ab33ce
poly1305: properly cast the mask from u1 to u64 (#15869)
Fixes #15855
2023-05-27 08:50:57 +00:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Veikka Tuominen
8f5f8090c5
Merge pull request #15803 from linusg/std-snek-case-enums
std: Snake-case some public facing enums
2023-05-27 02:40:38 +03:00
David CARLIER
41502c6aa5
std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
Linus Groh
ba35eeb417 std.fs.file: Rename File.Lock enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00