4838 Commits

Author SHA1 Message Date
naeu
bdd1a9e48c std: add test for Thread.Semaphore 2022-01-29 20:30:53 +00:00
naeu
4efd951801 std: add test for Thread.Condition 2022-01-29 20:30:53 +00:00
Meghan
5e60ee4127
std: define static error set for fs.Dir.copyFile 2022-01-29 20:48:36 +02:00
Jean Dao
fedff06079 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-01-29 20:46:06 +02:00
Jonathan S
aca665cebd
Fix overflow in std.math.isNormal when applied to -Inf or a negative NaN 2022-01-29 18:11:49 +02:00
Jonathan Marler
ba445013c4
improve comptime windows GUID.parse performance
I found that after switching from my custom Guid parser to the one in std that it increased zigwin32 build times substantially (from 40 seconds to over 10 minutes).  More information can be found in the benchmark PR I created here: https://github.com/ziglang/gotta-go-fast/pull/21 .  This PR ports my GUID parser to std so all projects can leverage the faster comptime performance.
2022-01-29 18:10:22 +02:00
Veikka Tuominen
8d0c17f5e4 std: remove superfluous .read = true from deflate tests 2022-01-29 16:57:10 +02:00
Sage Hane
e288148f60
fs: Use OpenMode enum instead of read/write flags. 2022-01-29 15:52:08 +02:00
Veikka Tuominen
88edde4edc
Merge pull request #9915 from zzyxyzz/indexOfMinMax
std.mem: add indexOfMin and indexOfMax
2022-01-29 15:49:47 +02:00
ominitay
8ca9452a82 Remove deprecation warnings and enable test
Also fixes previously broken code uncovered by this
2022-01-29 15:49:00 +02:00
John Schmidt
adea9a1765
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-01-29 12:25:25 +01:00
John Schmidt
e51a44b342 fmt: handle doc comments on struct members
Closes https://github.com/ziglang/zig/issues/10443.
2022-01-29 12:19:31 +01:00
Andrew Kelley
225910f934
Merge pull request #10639 from Vexu/f80
Add f80
2022-01-29 03:45:15 -05:00
John Schmidt
63ee6e6625 Rename mem.bswapAllFields to byteSwapAllFields
To match the renaming of `@bswap` to `@byteSwap` in
1fdb24827f.
2022-01-28 21:03:21 -05:00
Andrew Kelley
68fc26cd08 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-01-28 16:23:47 -07:00
Veikka Tuominen
67d04a988a std: add f80 bits 2022-01-28 11:45:04 -07:00
Mikhail Popov
100b8a244c Add std.mem.minMax() and std.mem.IndexOfMinMax()
For finding the minimum and maximum values (and indices)
in a slice in a single pass.
2022-01-27 21:22:00 +02:00
Vesim
8c90b05add fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-01-27 20:27:16 +02:00
Mikhail Popov
dddbd2f511 std.mem: Add functions to find the index of the mimimum/maximum value in a slice. 2022-01-27 19:58:27 +02:00
vnc5
1adb6440db fix startup procedure for async WinMain 2022-01-27 19:49:12 +02:00
David John
80ac022c46 add std.debug.todo 2022-01-27 19:42:40 +02:00
John Schmidt
997600ac6f Preserve alignment when cloning 2022-01-27 19:35:08 +02:00
John Schmidt
f04007028f Implement clone with initCapacity and appendSliceAssumeCapacity
`ArrayList.ensureTotalCapacityPrecise` uses `Allocator.reallocAtLeast` under
the hood, which can return more than `new_capacity` bytes if `alignment
!= @alignOf(T)`. This implementation of `clone` assures that
the case of `ensureTotalCapacityPrecise` is handled correctly.

Thanks @Vexu and @squeek502 for pointing this out.
2022-01-27 19:35:08 +02:00
John Schmidt
d86b8663fc Use expectEqualSlices instead of loop 2022-01-27 19:35:08 +02:00
John Schmidt
da8e8b89e0 Set len on copied items array
Also fix the argument order for `expectEquals`.
2022-01-27 19:35:08 +02:00
John Schmidt
554734f9f8 Add ArrayList.clone
This is a common operation and matches the API on other stdlib
collections like HashMap and MultiArrayList.
2022-01-27 19:35:08 +02:00
Andrew Kelley
db55f469c1 std.mem.Allocator: upgrade to new function pointer semantics 2022-01-26 20:02:01 -07:00
Andrew Kelley
50accb757f stage2: fix crash on file-level struct field source locations 2022-01-26 20:02:01 -07:00
Josh Hannaford
178cd60a5e Update the documentation for std.mem.sliceTo for readability 2022-01-26 00:49:17 -05:00
John Schmidt
9ee67b967b stage2: avoid inferred struct in os_version_check.zig
Before this commit, compiling an empty main with Stage 2 on macOS x86_64 results in

```
../stage2/bin/zig build-exe -ODebug -fLLVM empty_main.zig
error: sub-compilation of compiler_rt failed
    [...]/zig/stage2/lib/zig/std/special/compiler_rt/os_version_check.zig:26:10: error: TODO: Sema.zirStructInit for runtime-known struct values
```

By assigning the value to a variable we can sidestep the issue for now.
2022-01-26 00:48:05 -05:00
Andrew Kelley
0c1df96b17
Merge pull request #10552 from hdorio/deflate
compress: add a deflate compressor
2022-01-26 00:43:13 -05:00
Meghan
f1b79c9a44 std.crypto.random: Randoms are no longer passed by reference 2022-01-25 13:00:39 -05:00
Andrew Kelley
b34f994c0b stage2: type system treats fn ptr and body separately
This commit updates stage2 to enforce the property that the syntax
`fn()void` is a function *body* not a *pointer*. To get a pointer, the
syntax `*const fn()void` is required.

ZIR puts function alignment into the func instruction rather than the
decl because this way it makes it into function types. LLVM backend
respects function alignments.

Struct and Union have methods `fieldSrcLoc` to help look up source
locations of their fields. These trigger full loading, tokenization, and
parsing of source files, so should only be called once it is confirmed
that an error message needs to be printed.

There are some nice new error hints for explaining why a type is
required to be comptime, particularly for structs that contain function
body types.

`Type.requiresComptime` is now moved into Sema because it can fail and
might need to trigger field type resolution. Comptime pointer loading
takes into account types that do not have a well-defined memory layout
and does not try to compute a byte offset for them.

`fn()void` syntax no longer secretly makes a pointer. You get a function
body type, which requires comptime. However a pointer to a function body
can be runtime known (obviously).

Compile errors that report "expected pointer, found ..." are factored
out into convenience functions `checkPtrOperand` and `checkPtrType` and
have a note about function pointers.

Implemented `Value.hash` for functions, enum literals, and undefined values.

stage1 is not updated to this (yet?), so some workarounds and disabled
tests are needed to keep everything working. Should we update stage1 to
these new type semantics? Yes probably because I don't want to add too
much conditional compilation logic in the std lib for the different
backends.
2022-01-24 21:47:53 -07:00
Andrew Kelley
913d61ebb9 Revert "MultiArrayList: Fix error when struct is 0 sized"
This reverts commit 1f10cf4edf2b645e63dedc42f5d7475914bf2311.

Re-opens #10618

I want to solve this a different way. `align(S)` where S is a 0-byte
type should work in this context.

This also caused issues such as
https://github.com/Vexu/arocc/issues/221
2022-01-24 21:29:04 -07:00
Frank Denis
4e5495e443 std.crypto.25519.scalar: implement edwards25519 scalar field inversion
This operation is extremely useful for multiplicative blinding.
2022-01-24 23:09:45 +01:00
John Schmidt
40b3c9a592 Handle FormatOptions in fmtDuration/fmtDurationSigned 2022-01-24 20:30:36 +02:00
riverbl
a0732117d0 HashMap: add removeByPtr 2022-01-24 20:29:05 +02:00
Sizhe Zhao
15ef251a15 Avoid duplicate TLS startup symbols 2022-01-24 20:26:29 +02:00
Jonathan Marler
3f341bdc26
Normalize some build function names
An attempt to normalize some of the function names in build.zig.  Normalize add*Dir to add*Path.  Also use "Library" instead of the "Lib" abbreviation.

The PR does not remove the old names, only adds the new normalized ones to faciliate a transition period.
2022-01-24 20:15:32 +02:00
Pablo Santiago Blum de Aguiar
5ba4385971 readUntilDelimiter*: read only if buffer not full
Ref.: #9594
2022-01-24 17:44:26 +02:00
Jonathan Marler
2fc2d88fc6 use explicit integer bit widths for windows GUID
The size of a GUID is not platform-dependent, it's always a fixed number of bits.  So I've updated guid to use fixed bit integer types rather than platform-dependent C integer types.
2022-01-24 17:35:15 +02:00
fifty-six
da8d4d9225 std/fs: Support XDG_DATA_HOME
This is generally used for user-specific data on linux, with the
default being ~/.local/share
2022-01-24 17:33:38 +02:00
riverbl
1f10cf4edf
MultiArrayList: Fix error when struct is 0 sized
Also fixes error with ArrayHashMap when both key and value are 0 sized
2022-01-24 17:31:27 +02:00
Lee Cannon
c54a7ca4b2 allow expected_exit_code to be null 2022-01-24 17:29:19 +02:00
Andrew Kelley
12c2de6ee2
Merge pull request #10662 from ziglang/doc-comments-zir
Doc comments zir
2022-01-23 18:31:55 -05:00
Andrew Kelley
8a69726209 AstGen: doc comment fixups
* AstGen: use Ast.zig helper methods to avoid copy pasting token counting logic
   - take advantage of the `first_doc_comment` field we already have for
     param AST nodes
 * Add missing ZIR docs
2022-01-23 16:24:46 -07:00
Jimmi Holst Christensen
7287c7482a Stop using LinearFifo in BufferedWriter
Looking at the BufferedWriter assembly generated, one can see that is
has to do a lot of work, just to copy over some bytes and increase an
offset. This is because the LinearFifo is a much more general construct
than what BufferedWriter needs and the optimizer cannot prove that we
don't need to do this extra work.
2022-01-23 14:41:15 -05:00
Hadrien Dorio
490f067de8
compress: add a deflate compressor
Replaces the inflate API from `inflateStream(reader: anytype, window_slice: []u8)` to
`decompressor(allocator: mem.Allocator, reader: anytype, dictionary: ?[]const u8)` and
`compressor(allocator: mem.Allocator, writer: anytype, options: CompressorOptions)`
2022-01-23 19:30:06 +01:00
Hadrien Dorio
dba04a272a
compress: remove sha256 checks from tests
Read bytes to check expected values instead of reading and hashing them.
Hashing is a waste of time when we can just read and compare.
This also removes a dependency on std.crypto.hash.sha2.Sha256 for tests.
2022-01-23 19:29:57 +01:00
joachimschmidt557
fa84625aeb std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00