Commit Graph

69 Commits

Author SHA1 Message Date
Lee Cannon f68cda738a allocgate: split free out from resize 2021-11-30 23:32:48 +00:00
Lee Cannon 02e5e0ba1f allocgate: apply missed changes 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 85de022c56 allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley 902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -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
Coleman Broaddus e14fcd60cb FIX resize() for non u8 element types. (#9806) 2021-09-22 12:09:16 +03: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
LemonBoy 53cc63f0c9 std: Clear old memory on free
Re-enable the clear-on-free step, it was previously disabled due to
translate-c using freed memory.
2021-02-25 22:20:30 +02:00
Frank Denis 6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley d8fa8b5455 use Allocator.allocSentinel now that the stage1 bug is fixed
Thanks @LemonBoy!
2020-09-29 12:06:35 -07:00
Andrew Kelley 32a77a6047 Merge pull request #6239 from pfgithub/patch-1
Support allocating 0 bit types
2020-09-06 01:16:33 -04:00
Vexu 1df0f3ac24 update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
pfg bf1d83482b "Support" allocating 0 bit types 2020-09-02 22:28:37 -07:00
Andrew Kelley 4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley 3ccfd58bb6 std.mem.Allocator: fix not passing return_address
This makes collected stack traces omit less useful frames. For user
applications which only store a fixed number of stack frames this can
make a big difference.
2020-08-11 14:04:08 -07:00
Andrew Kelley cd6cdd0a75 std.mem.Allocator: add return_address to the interface
The high level Allocator interface API functions will now do a
`@returnAddress()` so that stack traces captured by allocator
implementations have a return address that does not include the
Allocator overhead functions. This makes `4` a more reasonable default
for how many stack frames to capture.
2020-08-08 00:34:13 -07:00
Andrew Kelley cc17f84ccc std: introduce GeneralPurposeAllocator
`std.GeneralPurposeAllocator` is now available. It is a function that
takes a configuration struct (with default field values) and returns an
allocator. There is a detailed description of this allocator in the
doc comments at the top of the new file.

The main feature of this allocator is that it is *safe*. It
prevents double-free, use-after-free, and detects leaks.

Some deprecation compile errors are removed.

The Allocator interface gains `old_align` as a new parameter to
`resizeFn`. This is useful to quickly look up allocations.

`std.heap.page_allocator` is improved to use mmap address hints to avoid
obtaining the same virtual address pages when unmapping and mapping
pages. The new general purpose allocator uses the page allocator as its
backing allocator by default.

`std.testing.allocator` is replaced with usage of this new allocator,
which does leak checking, and so the LeakCheckAllocator is retired.

stage1 is improved so that the `@typeInfo` of a pointer has a lazy value
for the alignment of the child type, to avoid false dependency loops
when dealing with pointers to async function frames.

The `std.mem.Allocator` interface is refactored to be in its own file.

`std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`.

This allocator is great for debug mode, however it needs some work to
have better performance in release modes. The next step will be setting
up a series of tests in ziglang/gotta-go-fast and then making
improvements to the implementation.
2020-08-07 22:45:45 -07:00