Commit graph

4753 commits

Author SHA1 Message Date
Andrew Kelley
8e10c80c5f std: fix i386-openbsd failing to build from source
closes #9705
2022-02-07 12:24:19 -07:00
Evan Haas
a8bd36c3d2 std: Allow mem.zeroes to work at comptime with extern union
Fixes #10797
2022-02-07 12:23:56 -07:00
boofexxx
2e95bb0e29 std: fix doc comment typo in os.zig 2022-02-07 12:23:11 -07:00
Andrew Kelley
cee0f082df Merge pull request #10743 from m-radomski/master
std: correct rounding in parse_hex_float.zig
2022-02-02 22:07:56 -07:00
John Schmidt
23d148e5c7 debug: fix edge cases in macOS debug symbol lookup
This commit fixes two related things:

1. If the loop goes all the way through the slice without a match, on
   the last iteration `mid == symbols.len - 1` which causes
   `&symbols[mid + 1]` to be out of bounds. End one step before that
   instead.

2. If the address we're looking for is greater than the address of the
   last symbol in the slice, we now match it to that symbol. Previously,
   we would miss this case since we only matched if the address was _in
   between_ the address of two symbols.
2022-02-02 22:06:32 -07:00
Jakub Konka
ac3ac255a2 Merge pull request #10404 from ominitay/iterator
std: Fix using `fs.Dir.Iterator` twice
2022-02-02 22:04:36 -07:00
Jean Dao
69f46cab55 fix argsAlloc buffer size
The buffer `buf` contains N (= `slice_sizes.len`) slices followed by the
N null-terminated arguments. The N null-terminated arguments are stored
in the `contents` array list. Thus, `buf` size should be:
    @sizeOf([]u8) * slice_sizes.len + contents_slice.len

Instead of:
    @sizeOf([]u8) * slice_sizes.len + contents_slice.len + slice_sizes.len

This bug was found thanks to the gpa allocator which checks if freed
size matches allocated sizes for large allocations.
2022-02-02 22:04:02 -07:00
Jonathan S
a24f4d8da4 Fix overflow in std.math.isNormal when applied to -Inf or a negative NaN 2022-02-02 22:03:47 -07:00
John Schmidt
5762b6d218 std.fmt: fix out-of-bounds array write in float printing
This commit fixes an out of bounds write that can occur when
formatting certain float values. The write messes up the stack and
causes incorrect results, segfaults, or nothing at all, depending on the
optimization mode used.

The `errol` function writes the digits of the float into `buffer`
starting from index 1, leaving index 0 untouched, and returns `buffer[1..]`
and the exponent. This is because `roundToPrecision` relies on index 0 being
unused in case the rounding adds a digit (e.g rounding 999.99
to 1000.00). When this happens, pointer arithmetic is used
[here](0e6d2184ca/lib/std/fmt/errol.zig (L61-L65))
to access index 0 and put the ones digit in the right place.

However, `errol3u` contains two special cases: `errolInt` and `errolFixed`,
which return from the function early. For these two special cases
index 0 was never reserved, and the return value contains `buffer`
instead of `buffer[1..]`. This causes the pointer arithmetic in
`roundToPrecision` to write out of bounds, which in the case of
`std.fmt.formatFloatDecimal` messes up the stack and causes undefined behavior.

The fix is to move the slicing of `buffer` to `buffer[1..]` from `errol3u`
to `errol` so that both the default and the special cases operate on the sliced
buffer.
2022-02-02 22:01:47 -07:00
John Schmidt
8b5e4af78e fmt: handle doc comments on struct members
Closes https://github.com/ziglang/zig/issues/10443.
2022-02-02 22:01:38 -07:00
Andrew Kelley
e2f36c292e std: break up some long lines
This makes packaging Zig for Debian slightly easier since it will no
longer trigger a Lintian warning for long lines.
2022-02-02 22:00:55 -07:00
Vesim
d7feeaaa2c fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-02-02 22:00:06 -07:00
vnc5
8f89056dc2 fix startup procedure for async WinMain 2022-02-02 21:59:47 -07:00
Josh Hannaford
340bb8198f Update the documentation for std.mem.sliceTo for readability 2022-02-02 21:48:48 -07:00
Meghan
8ed432fe3c std.crypto.random: Randoms are no longer passed by reference 2022-02-02 21:46:22 -07:00
Sizhe Zhao
b713ce0249 Avoid duplicate TLS startup symbols 2022-02-02 21:25:40 -07:00
Pablo Santiago Blum de Aguiar
4d5a598599 readUntilDelimiter*: read only if buffer not full
Ref.: #9594
2022-02-02 21:25:03 -07:00
fifty-six
aa8112c847 std/fs: Support XDG_DATA_HOME
This is generally used for user-specific data on linux, with the
default being ~/.local/share
2022-02-02 21:24:40 -07:00
joachimschmidt557
3d52a322ab std: Add some missing termios types to c/linux.zig and os.zig 2022-02-02 21:23:34 -07:00
Andrew Kelley
18fabd99cc Merge pull request #10475 from lithdew/master
lld: allow for entrypoint symbol name to be set
2022-02-02 21:19:18 -07:00
John Schmidt
afd1f7ed47 Implement segfault handler for macOS x86_64 2022-02-02 21:18:45 -07:00
johnLate
bb9399cc5d Fix os.rusage when linking with c library on Linux
Fixes ziglang#10543 on Linux.
2022-02-02 21:17:15 -07:00
Jakub Konka
1e6de105c8 Merge branch 'Jarred-Sumner-patch-1' 2022-02-02 21:14:59 -07:00
Jakub Konka
385b7e4808 Merge pull request #10576 from schmee/macos-resolve-ip
Use libc if_nametoindex for macOS when parsing IPs
2022-02-02 21:12:24 -07:00
Jakub Konka
dafbc6eb25 Merge branch 'Luukdegram-linker-eport-symbols' 2022-01-12 12:01:32 -07:00
afranchuk
511990c83b Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538)
* Fix FUTEX usage in std.Thread.Condition - It was using an old name.
2022-01-12 11:59:09 -07:00
Andrew Kelley
9fa55ae777 Merge pull request #10566 from fifty-six/master
std.os.uefi improvements/fixes
2022-01-12 11:59:02 -07:00
djg
9b97edb012 std: hash_map: optimize isFree/isTombstone (#10562)
- Add an `Metadata.isFree` helper method.
- Implement `Metadata.isTombstone` and `Metadata.isFree` with `@bitCast` then comparing to a constant. I assume `@bitCast`-then-compare is faster than the old method because it only involves one comparison, and doesn't require bitmasking.
- Summary of benchmarked changes (`gotta-go-fast`, run locally, compared to master):
  - 3/4 of the hash map benchmarks used ~10% fewer cycles
  - The last one (project Euler) shows 4% fewer cycles.
2022-01-12 11:58:24 -07:00
Meghan Denny
73cbc13a97 std: fix zig.Ast being called Tree internally 2022-01-12 11:56:45 -07:00
Ryan Liptak
2304dbaba4 Add CANNOT_DELETE as a possible error in os.windows.DeleteFile
Can happen when e.g. trying to delete a file with the Read Only flag set
2022-01-12 11:54:31 -07:00
Vincent Rischmann
4d38f456ea io_uring: improve IO_Uring.copy_cqe
copy_cqes() is not guaranteed to return as many CQEs as provided in the
`wait_nr` argument, meaning the assert in `copy_cqe` can trigger.

Instead, loop until we do get at least one CQE returned.

This mimics the behaviour of liburing's _io_uring_get_cqe.
2022-01-12 11:53:42 -07:00
Jimmi Holst Christensen
1676729c66 fmt: Refactor parsing of placeholders into its own function
This saves on comptime format string parsing, as the compiler caches
comptime calls. The catch here, is that parsePlaceHolder cannot take the
placeholder string as a slice. It must take it as an array by value for
the caching to occure.

There is also some logic in here that ensures that the specifier_arg is
always them same slice when the items they contain are the same. This
makes the compiler stamp out less copies of formatType.
2022-01-12 11:53:07 -07:00
Vincent Rischmann
eee395287f io_uring: fix version check in tests
For renameat, unlinkat, mkdirat, symlinkat and linkat the error code
differs between kernel 5.4 which returns EBADF and kernel 5.10 which returns EINVAL.

Fixes #10466
2022-01-12 11:52:11 -07:00
r00ster
419499b252 std.fmt: improve @compileError message 2022-01-12 11:51:26 -07:00
Tom Manner
64a2b14f26 Fixed typo in deprecation error for E format specifier where it would instead complain about a specifier of X. 2021-12-31 14:23:59 -07:00
Ali Chraghi
b86aadfa38 std: Skip comptime struct fields in mem.zeroes() (#10406)
closes #9934
2021-12-31 14:22:38 -07:00
Dante Catalfamo
4d9377923d Add BSD Authentication constants (#10376) 2021-12-31 14:21:22 -07:00
Stephen Lumenta
cfc00e743e fix expectStringEndsWith error output.
before it started outputting the actual starting, not ending characters.
2021-12-31 14:20:09 -07:00
Jonathan S
f5cb3fc688 Only check the file's length once in pdb.Msf.init 2021-12-31 14:20:02 -07:00
ominitay
acdb859644 Fix dead link 2021-12-31 14:19:36 -07:00
Kenta Iwasaki
5c7f2ab011 stage1: deal with BPF not supporting @returnAddress()
Make `@returnAddress()` return for the BPF target, as the BPF target for
the time being does not support probing for the return address. Stack
traces for the general purpose allocator for the BPF target is also set
to not be captured.
2021-12-19 23:22:05 -08:00
Lee Cannon
16b7535497
Allocator: allocBytes and reallocBytes (#10352)
Closes #10348
2021-12-19 01:58:13 -05:00
Andrew Kelley
07c03f85a8 zig test: fix test runner detection of tty
Before, `std.Progress` was printing unwanted stuff to stderr. Now, the
test runner's logic to detect whether we should print each test as a
separate line to stderr is properly activated.
2021-12-18 23:45:32 -07:00
Isaac Freund
9f9f215305
stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
Jakub Konka
a08137330c macho: handle -install_name option for dylibs/MachO
The status quo for the `build.zig` build system is preserved in
the sense that, if the user does not explicitly override
`dylib.setInstallName(...);` in their build script, the default
of `@rpath/libname.dylib` applies. However, should they want to
override the default behaviour, they can either:

1) unset it with

```dylib.setIntallName(null);```

2) set it to an explicit string with

```dylib.setInstallName("somename.dylib");```

When it comes to the command line however, the default is not to
use `@rpath` for the install name when creating a dylib. The user
will now be required to explicitly specify the `@rpath` as part
of the desired install name should they choose so like so:

1) with `build-lib`

```
zig build-lib -dynamic foo.zig -install_name @rpath/libfoo.dylib
```

2) with `cc`

```
zig cc -shared foo.c -o libfoo.dylib -Wl,"-install_name=@rpath/libfoo.dylib"
```
2021-12-18 17:55:53 -08:00
Andrew Kelley
6adecdc58a init-exe template: build.zig: setTarget on the tests 2021-12-18 17:29:46 -07:00
fubark
88ea2cb757 Make Builder.spawnChildEnvMap public 2021-12-18 15:25:09 -08:00
Jens Goldberg
5b29b4ffa6 Fix MIPS inline assembly clobbers 2021-12-18 14:42:01 -08:00
Andrew Kelley
6d04de706a Revert "std: optimize hash_map probe loop condition"
This reverts commit 11803a3a56.

Observations from the performance dashboard:
 * strictly worse in terms of CPU instructions
 * slightly worse wall time (but this can be noisy)
 * sometimes better, sometimes worse for branch predictions

Given that the commit was introducing complexity for optimization's
sake, these performance changes do not seem worth it.
2021-12-17 16:56:43 -07:00
sentientwaffle
11803a3a56 std: optimize hash_map probe loop condition
See https://github.com/ziglang/zig/pull/10337 for context.

In #10337 the `available` tracking fix necessitated an additional condition on the probe loop in both `getOrPut` and `getIndex` to prevent an infinite loop. Previously, this condition was implicit thanks to the guaranteed presence of a free slot.

The new condition hurts the `HashMap` benchmarks (https://github.com/ziglang/zig/pull/10337#issuecomment-996432758).

This commit removes that extra condition on the loop. Instead, when probing, first check whether the "home" slot is the target key — if so, return it. Otherwise, save the home slot's metadata to the stack and temporarily "free" the slot (but don't touch its value). Then continue with the original loop. Once again, the loop will be implicitly broken by the new "free" slot. The original metadata is restored before the function returns.

`getOrPut` has one additional gotcha — if the home slot is a tombstone and `getOrPut` misses, then the home slot is is written with the new key; that is, its original metadata (the tombstone) is not restored.

Other changes:

- Test hash map misses.
- Test using `getOrPutAssumeCapacity` to get keys at the end (along with `get`).
2021-12-17 15:21:41 -08:00