4579 Commits

Author SHA1 Message Date
Meghan
c84147f90d
std: add writer methods on all crypto.hash types (#10168) 2021-11-20 01:37:17 -08:00
Dante Catalfamo
54bcd1cd51
Add OpenBSD termios constants to std.c.openbsd (#10178) 2021-11-20 01:34:53 -08:00
Rohlem
a83fb9289f std.bounded_array: fix self parameter type in constSlice
Because `.buffer` is an inline array field, we actually require `self` to be passed as a pointer.
If the compiler decided to pass the object by copying, we would return a pointer to to-be-destroyed stack memory.
2021-11-20 02:35:36 -05:00
Andrew Kelley
e24dcd2707 std.builtin.StackTrace: format() workaround on freestanding
This whole thing needs to be reworked but for now at least don't cause a
compile error when building for a target that doesn't have stderr or
detectTTYConfig.
2021-11-19 19:15:14 -07:00
Kenta Iwasaki
00966b7258 compiler_rt: disable spinlocks for atomic instrinsics for bpf
The BPF target does not support mutable global variables. Mark the BPF
target as a target that does not support atomic variables in order to
avoid including the global spinlock table provided in compiler_rt.
2021-11-18 13:16:35 -05:00
Felix "xq" Queißner
2fefd4ea8e Fixes invalid errno definition for ***-linux-android 2021-11-18 12:58:28 -05:00
Vincent Rischmann
3d528161c8 io_uring: implement register_files_update 2021-11-16 19:54:19 -05:00
Jonathan Marler
9c1c1d478d add print field to RunStep
A new print field is added to RunStep that will control whether it prints the cmd before running it.  By default it will be set to builder.verbose which means it will print only if builder.verbose is true.
2021-11-16 16:35:12 -05:00
Marc Tiehuis
dcd88ae568 std/json: use bit-stack for nesting instead of large LLVM integer type
The stack has been adjusted so that instead of pushing to index 0 in the
integer we push to the current end/index of the underlying integer. This
means we don't require a shift for every limb after each push/pop and
instead only require a mask/or and add/sub on a single element of the array.

Fixes #5959.
2021-11-16 16:33:56 -05:00
Andrew Kelley
c587be78d7
Merge pull request #10016 from courajs/array-build-options
Various build options (OptionsStep) fixes
2021-11-16 16:31:46 -05:00
Ominitay
796687f156 Add chmod and chown 2021-11-15 20:04:55 -05:00
Lewis Gaul
dfd604834b Fix copy-paste error that results in incorrect results from exp64() 2021-11-15 19:40:03 -05:00
Chris Heyes
5d2a77cd9a
Json Stringify option to not write out null optional fields (#8979) 2021-11-15 18:56:51 -05:00
lucky
590880158a
update docs (#10150)
add fast kdf test
fix inconsistent kdf error
refactor

Co-authored-by: lucky <>
2021-11-15 20:48:24 +01:00
Gregory Anders
b26b72f540 BoundedArray: add appendAssumeCapacity 2021-11-14 22:52:01 -05:00
Andrew Kelley
46af3a320c
Merge pull request #10081 from hnakamur/lib_std_os_linux_io_uring_cancel
std.os.linux: Add cancel and io_uring_prep_cancel
2021-11-14 22:51:11 -05:00
lucky
c61fbe77c8
add argon2 kdf (#9756) 2021-11-15 04:47:57 +01:00
Kenta Iwasaki
09c17acf02 io_uring: add poll_update
Add method from liburing to queue (but not submit) a SQE to update the
user data of an existing poll operation.
2021-11-14 13:56:41 -05:00
Hiroaki Nakamura
77d1d5839a Use io_uring_prep_rw in io_uring_prep_cancel
follow liburing's API as closely as possible.

Signed-off-by: Hiroaki Nakamura <hnakamur@gmail.com>
2021-11-12 10:51:49 +09:00
Hiroaki Nakamura
2a54c2ff19 std.os.linux: Add cancel and io_uring_prep_cancel
Signed-off-by: Hiroaki Nakamura <hnakamur@gmail.com>
2021-11-12 10:51:49 +09:00
Jakub Konka
19e5663869
Merge pull request #9935 from g-w1/plan9-std
add plan9 support to std
2021-11-11 10:45:00 -08:00
Andrew Kelley
e5bc092408
Merge pull request #10058 from marler8997/builderPathJoin
add pathJoin to builder
2021-11-10 12:40:15 -05:00
Andrew Kelley
b521510cd4
Merge pull request #9853 from koachan/sparc64-unittests
SPARCv9: make more tests pass
2021-11-10 11:32:10 -05:00
Andrew Kelley
008b0ec5e5 std.Thread.Mutex: change API to lock() and unlock()
This is a breaking change. Before, usage looked like this:

```zig
const held = mutex.acquire();
defer held.release();
```

Now it looks like this:

```zig
mutex.lock();
defer mutex.unlock();
```

The `Held` type was an idea to make mutexes slightly safer by making it
more difficult to forget to release an aquired lock. However, this
ultimately caused more problems than it solved, when any data structures
needed to store a held mutex. Simplify everything by reducing the API
down to the primitives: lock() and unlock().

Closes #8051
Closes #8246
Closes #10105
2021-11-09 18:31:03 -07:00
Andrew Kelley
65e518e8e8 io_uring: skip statx test failure on older kernels 2021-11-09 18:31:03 -07:00
Andrew Kelley
d2cdfb9490 stage2: add 4 new linker flags for WebAssembly
--import-memory          import memory from the environment
--initial-memory=[bytes] initial size of the linear memory
--max-memory=[bytes]     maximum size of the linear memory
--global-base=[addr]     where to start to place global data

See #8633
2021-11-09 14:29:20 -07:00
Jonathan Marler
c13166ee85 Omit array type for pathJoin calls 2021-11-09 14:20:28 -07:00
Jonathan Marler
cebac8c662 add pathJoin to builder 2021-11-09 14:20:28 -07:00
Silver
9bb7ff68cc std: Publicize Allocator.reallocBytes
This is useful when dealing with runtime-known alignments, eg. interfacing
with C code that accepts custom allocation callbacks.

Closes #9394
2021-11-09 13:41:38 -05:00
Gregory Anders
3534f8a3ed std: ppoll: cast number of fds to nfds_t
On some systems, the type of the length of a slice is different from the
nfds_t type, so cast the slice length to nfds_t. This is already done in
poll, so just copy that implementation for ppoll.
2021-11-09 13:36:36 -05:00
Vincent Rischmann
082072bd4f os/linux/io_uring: implement statx 2021-11-09 13:35:17 -05:00
Jacob G-W
73be14027d plan9: more syscalls 2021-11-09 07:08:27 -05:00
Jacob G-W
fe314e60bb fix outputs in inline assembly 2021-11-09 07:08:27 -05:00
Jacob G-W
09992f8acc add initial plan9 support to std 2021-11-09 07:08:23 -05:00
Frank Denis
bd8b94bd0e crypto/edwards25519: correctly flip the Y sign in the H2C operation
No security implications, but the current hash-to-curve standard
defines the sign of the Y coordinate to be negative if `gx1`
is a square, positive otherwise.

We were doing it the other way round.
2021-11-08 14:55:27 +01:00
LemonBoy
2551946a51 std: Fix path resolution on Windows
GetCurrentDirectory returns a path with a trailing slash iff the cwd is
a root directory, making the code in `resolveWindows` return an invalid
path with two consecutive slashes.

Closes #10093
2021-11-04 21:05:14 -04:00
Ryan Liptak
e97feb96e4 Replace ArrayList.init/ensureTotalCapacity pairs with initCapacity
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
2021-11-04 14:54:25 -04:00
LemonBoy
d03e9d0b83 compiler-rt: Fix f16 API declarations to be consistent
LLVM and compiler-rt must agree on how the parameters are passed, it
turns out that in LLVM13 something changed and broke the test case for
AArch64 systems.

It has nothing to do with fma at all.

Closes #9900
2021-11-04 14:30:35 -04:00
Andrew Kelley
a78e61acf9 std: expose rusage constants under rusage namespace 2021-11-01 15:55:22 -07:00
Andrew Kelley
63f4778827 std: add Linux perf syscall bits
Example usage:

```zig
const std = @import("std");
const PERF = std.os.linux.PERF;
const assert = std.debug.assert;

test "perf" {
    var attr: std.os.linux.perf_event_attr = .{
        .type = PERF.TYPE.HARDWARE,
        .config = @enumToInt(PERF.COUNT.HW.INSTRUCTIONS),
        .flags = .{
            .disabled = true,
            .exclude_kernel = true,
            .exclude_hv = true,
        },
    };
    const fd = try std.os.perf_event_open(&attr, 0, -1, -1, PERF.FLAG.FD_CLOEXEC);
    defer std.os.close(fd);

    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.RESET, 0);
    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.ENABLE, 0);

    long();

    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.DISABLE, 0);

    var result: usize = 0;
    assert((try std.os.read(fd, std.mem.asBytes(&result))) == @sizeOf(usize));

    std.debug.print("instruction count: {d}\n", .{result});
}

fn long() void {
    var i: usize = 0;
    while (i < 100000) : (i += 1) {}
}
```
2021-11-01 14:45:05 -07:00
Ryan Liptak
a343758141 Update ensureTotalCapacity to ensureTotalCapacityPrecise where it makes sense
These calls are all late-initialization of ArrayList's that were initialized outside the current scope. This allows us to still get the potential memory-saving benefits of the 'precision' of initCapacity.
2021-11-01 00:57:33 -07:00
Ryan Liptak
f49d42729a std.ArrayList: add ensureTotalCapacityPrecise and update doc comments
initCapacity did and still does use the ensureTotalCapacityPrecise logic because the initial capacity of an ArrayList is not important in terms of how it grows, so allocating a more exact slice up-front allows for saving memory when the array list never exceeds that initial allocation size. There are use cases where this precise capacity is useful outside of the `init` function, though, like in instances where the user does not call the `init` function themselves but otherwise knows that an ArrayList is empty so calling `ensureTotalCapacityPrecise` can give the same memory savings that `initCapacity` would have.

Closes #9775
2021-11-01 00:57:24 -07:00
pfg
1de6f9a267
std: add missing termios def to std/c/linux.zig
Fixes #9707
2021-10-30 18:32:26 +02:00
Andrew Kelley
d6067db062 stage2: implement @popCount for non-vectors 2021-10-29 17:49:02 -07:00
Matthew Borkowski
5ff01bd820 gpa: fix memory limit accounting for large allocations 2021-10-29 19:22:24 -04:00
ominitay
544d7d9982 Add argument for fillFn to Random.init
As suggested by @leecannon, this provides more flexibility to the
`Random` interface. For exmaple, this allows for an implementation to
provide multiple different fill functions.
2021-10-29 19:20:31 -04:00
Kenta Iwasaki
2cdffc97f0 zig: expose linker options and include '-z notext'
Add an option to allow the '-z notext' option to be passed to the linker
via. the compiler frontend, which is a flag that tells the linker that
relocations in read-only sections are permitted. Certain targets such as
Solana BPF rely on this flag.

Expose all linker options i.e. '-z nodelete', '-z now', '-z relro' in
the compiler frontend. Usage documentation has been updated accordingly.

Expose the '-z notext' flag in the standard library build runner.
2021-10-29 19:18:44 -04:00
InKryption
83a4bb6e69 Make std.meta.trait.isContainer true for opaques
Makes `std.meta.trait.hasFn` work as expected for opaque types with function declarations. Alternative is to add clause directly to `std.meta.trait.hasFn` to account for opaque types.
2021-10-29 20:02:25 +00:00
InKryption
eeb8629bea Use debug.assert instead of testing.expect.
`testing.expect` and friends are intended to be used only in tests; this change reflects that intention.
2021-10-29 20:01:59 +00:00
InKryption
ee038df7e2
Make pointer variables in ( init-lib | init-exe )/build.zig const. (#10057)
* Make `main_tests` variable constant
* Apply same change in init-exe.zig
2021-10-29 13:37:17 -04:00