Commit graph

165 commits

Author SHA1 Message Date
Motiejus Jakštys
d41111d7ef mem: rename align*Generic to mem.align*
Anecdote 1: The generic version is way more popular than the non-generic
one in Zig codebase:

     git grep -w alignForward | wc -l
    56
     git grep -w alignForwardGeneric | wc -l
    149

     git grep -w alignBackward | wc -l
    6
     git grep -w alignBackwardGeneric | wc -l
    15

Anecdote 2: In my project (turbonss) that does much arithmetic and
alignment I exclusively use the Generic functions.

Anecdote 3: we used only the Generic versions in the Macho Man's linker
workshop.
2023-06-17 12:49:13 -07:00
Linus Groh
94e30a756e std: fix a bunch of typos
The majority of these are in comments, some in doc comments which might
affect the generated documentation, and a few in parameter names -
nothing that should be breaking, however.
2023-04-30 18:16:04 -07:00
Borja Clemente
bd801dc489
std: GPA deinit return an enum instead of a bool 2023-04-22 14:09:44 +03:00
Andrew Kelley
658de75500 add std.heap.ThreadSafeAllocator
This wraps any allocator and makes it thread-safe by using a mutex.
2023-03-15 10:48:12 -07:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
8d64e5283a
Merge pull request #12586 from MasterQ32/std_memory_pool
Adds std.heap.MemoryPool
2023-01-03 14:53:54 -05:00
Andrew Kelley
4b5fc5239c std.heap.raw_c_allocator: fix illegal alignment cast
See the comment added in this commit for more details.

closes #14090
2022-12-29 20:25:40 -07:00
Veikka Tuominen
622311fb9a update uses of overflow arithmetic builtins 2022-12-27 15:13:14 +02:00
Felix "xq" Queißner
108b3c5673 Improves the comment formatting. 2022-12-15 10:16:28 +01:00
Felix "xq" Queißner
e28f4a1d85 Implements std.heap.MemoryPool and friends. 2022-12-15 09:27:23 +01:00
Andrew Kelley
823d1e7087 add std.heap.wasm_allocator 2022-12-06 12:27:28 -07:00
Andrew Kelley
e2e60f5ff9 std.heap.WasmAllocator: redo
The previous version had a fatal flaw: it did ensureCapacity(1) on the
freelist when allocating, but I neglected to consider that you could
free() twice in a row. Silly!

This strategy allocates an intrusive freelist node with every
allocation, big or small. It also does not have the problems with resize
because in this case we can push the upper areas of freed stuff into the
corresponding freelist.
2022-11-29 23:46:02 -07:00
Andrew Kelley
9f8c19210b std.heap: extract PageAllocator, WasmPageAllocator 2022-11-29 23:46:02 -07:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Jakub Konka
648579b330 libstd: skip problematic tests on aarch64-windows 2022-11-30 00:26:40 +01:00
notcancername
f98aac9db4 document std.heap.StackFallbackAllocator 2022-11-28 14:31:57 +02:00
delitako
c8a5ad6d9d
Improve doc comments for two functions (#13456)
* std.heap: fix function name in doc comment

* std.mem: document return value of `replace`
2022-11-05 22:55:50 +01:00
Andrew Kelley
d02242661e std.heap: make wasm32 PageAllocator handle large allocation
When a number of bytes to be allocated is so great that alignForward()
is not possible, return `error.OutOfMemory`.

Companion commit to 3f3003097c.
2022-10-30 19:28:26 -07:00
Andrew Kelley
3f3003097c std.heap.PageAllocator: add check for large allocation
Instead of making the memory alignment functions more complicated, I
added more API documentation for their existing semantics.

closes #12118
closes #12135
2022-10-30 16:10:20 -07:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Veikka Tuominen
6d44c0a16c std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
Andrew Kelley
b6798c26ef stage2: fix pointer arithmetic result type
This makes it so the result of doing pointer arithmetic creates a new
pointer type that has adjusted alignment.
2022-05-17 23:50:38 -07:00
r00ster
f65ca80bbe std.heap: Fix typo 2022-05-01 14:41:12 -04:00
Isaac Freund
6f4343b61a std: replace usage of std.meta.bitCount() with @bitSizeOf() 2022-04-27 11:10:52 +02: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
Lee Cannon
066eaa5e9c
allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
Lee Cannon
f68cda738a
allocgate: split free out from resize 2021-11-30 23:32:48 +00:00
Lee Cannon
9377f32c08
allocgate: utilize a *const vtable field 2021-11-30 23:32:48 +00:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
47bc13bc59
allocgate: dont use a dummy temporary for stateless allocators 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
361217bda2 stage2: fix inline assembly with expression output
Thanks @g-w1 for the print_air.zig implementation for inline assembly. I
copied it and slightly modified it from your open pull request.
2021-10-20 15:34:10 -07:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Lee Cannon
629e2e7844
Add a logging allocator that uses std.log (#8511) 2021-06-09 21:42:07 +03:00
LemonBoy
0c091f8b09 std: Add helpers to safely align pointers
Add two helpers to ensure people won't ignore some edge cases such as
pointers overflowing the address space.

Also fix #8924 to some degree, the amount of unchecked alignForward is
still scary.
2021-06-06 18:04:16 -07:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Andrew Kelley
c60d8f017e std: remove redundant comptime keyword
@g-w1's fancy new compile error in action
2021-04-28 22:58:12 -07:00
Andrew Kelley
429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Isaac Freund
7ed499ec45 std/heap: fix documentation of raw_c_allocator
This is not in fact safe to use with GeneralPurposeAllocator as GPA
requires align(page_size) but raw_c_allocator provides only
@alignOf(std.c.max_align_t).
2020-12-28 16:15:04 +02:00
Luuk de Gram
d73f46b57c Fix StackFallbackAllocator 2020-12-17 19:09:29 +02:00
Andrew Kelley
13cccdd92c add std.heap.raw_c_allocator
This API does what `std.heap.c_allocator` previously did. See the new
doc comments for more details.
2020-11-18 22:09:34 -07:00
Andrew Kelley
02a4e5a4bf
Merge pull request #6385 from LemonBoy/callocator
std: Make C allocator respect the required alignment
2020-11-18 20:16:57 -08:00
xackus
5c8f7f81cd change debug.assert to testing.expect in tests 2020-11-06 22:48:54 +01:00