96 Commits

Author SHA1 Message Date
Vexu
1df0f3ac24
update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
Cléo Rebert
fc001110b4 Added edge case test to mem.count
Some implementations break on this edge case. Thought relevant to add it.
2020-08-27 04:12:28 -04:00
Sobeston
7d0bb0774e std.mem.count 2020-08-26 17:37:05 -04:00
Frank Denis
ad18078d53 forceEval() -> doNotOptimizeAway() 2020-08-26 10:50:34 +02:00
Frank Denis
0bd53dd203 Rename blackBox, move it to std.mem.forceEval() 2020-08-26 10:50:34 +02:00
Andrew Kelley
9cfcd0c296
Merge pull request #6103 from Vexu/extern
Disallow extern variables with initializers.
2020-08-20 18:35:31 -04: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
Vexu
adc5bce5e8
translate-c: correct translation of global variables
* externs with intializers are translated as exports
* non extern without explicit initialization are zero initalized
2020-08-20 10:08:27 +03:00
Dmitry Atamanov
a9590f3bf8
Support tuples in mem.len and trait.isIndexable (#5897) 2020-08-14 01:14:32 +03: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
Andrew Kelley
d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
meme
f050150ffa Add memory replacement routines
* Added `replace` for simple pre-allocated search-and-replace
* Added `replacementSize` for calculating ahead-of-time buffer sizes for
performing a safe search-and-replace
* Added `replaceOwned` for automatically allocating and performing
replacement
2020-07-26 05:42:38 +00:00
Vexu
a1e78d0b06
add is_tuple field to struct typeinfo
part of #4335
2020-07-17 00:15:34 +03:00
Vexu
06c08e5219
std.mem.zeroes use std.mem.set instead of @memset
stage1 comptime is not smart enough to remeber the size of the casted
item which leads to out of bounds errors.
2020-07-16 17:05:14 +03:00
Vexu
8fe076daaf
std.mem.zeroInit support initiating with tuples 2020-07-16 16:00:42 +03:00
Isaac Freund
ef17af1270 std: add mem.joinZ
currently the only options are doing a second allocation and copying or
implementing this yourself.
2020-07-12 22:17:40 +00:00
xackus
5b570bceb5 document a few functions in std.mem 2020-07-12 21:55:49 +00:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Alexandros Naskos
30ae7f7573 Corrected default value field initialization in std.zeroInit 2020-07-01 23:09:08 +00:00
Jonathan Marler
c2eead9629 Fix issue 5741, use after free 2020-06-28 18:05:18 -04:00
Jonathan Marler
a728436992 new allocator interface after Andrew Kelley review 2020-06-27 08:57:35 -06:00
Jonathan Marler
dc9648f868 new allocator interface 2020-06-26 13:34:48 -06:00
Andrew Kelley
109c0b9d96 rename std.mem.defaultInit to std.mem.zeroInit 2020-06-01 14:47:18 -04:00
Alexis Brodeur
c0e5eca6f2 Add initialization helper
When using C libraries, C99 designator list initialization is often
times used to initialize data structure.

While `std.mem.zeroes` and manually assigning to each field can
achieve the same result, it is much more verbose then the equivalent
C code:

```zig
usingnamespace @cImport({
    @cInclude("sokol_app.h");
});

// Using `std.mem.zeroes` and manual assignment.
var app_desc = std.mem.zeroes(sapp_desc);
app_desc.init_cb = init;
app_desc.frame_cb = frame;
app_desc.cleanup_cb = cleanup;
app_desc.width = 400;
app_desc.height = 300;
app_desc.window_name = "no default init";

// Using `std.mem.defaultInit`.
var app_desc = std.mem.defaultInit(sapp_desc, .{
    .init_cb = init,
    .frame_cb = frame,
    .cleanup_cb = cleanup,
    .width = 400,
    .height = 300,
    .window_name = "default init"
});
```

The `std.mem.defaultInit` aims to solve this problem by zero
initializing all fields of the given struct to their zero, or default
value if any.  Each field mentionned in the `init` variable is then
assigned to the corresponding field in the struct.

If a field is a struct, and an initializer for it is present, it is
recursively initialized.
2020-06-01 14:45:35 -04:00
data-man
49dd2cbd9a Support vectors in mem.len 2020-05-27 00:00:19 +05:00
data-man
db0c30446a Supports vectors in mem.zeroes 2020-05-24 20:48:29 -04:00
Andrew Kelley
dd05f2be80 run zig fmt on std lib 2020-05-24 10:04:09 -04:00
Andrew Kelley
69a5f0d797 Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation 2020-05-16 01:26:18 -04:00
Andrew Kelley
81a01bd481 fix codegen of sentinel-terminated arrays and .got alignment
we now have an exit(0) program working
2020-05-14 16:34:04 -04:00
Andrew Kelley
080022f6c6 self-hosted: fix compile errors, except for codegen.zig 2020-05-13 20:06:01 -04:00
Vexu
453df1cc1e
Merge pull request #4892 from Sobeston/patch-4
mem.zeroes - add sentinel terminated array support
2020-05-08 22:37:27 +03:00
Vexu
336ddb5b76
std: add test for mem.zeroes on sentinel terminated arrays 2020-05-08 19:03:27 +03:00
Jonathan Marler
0a76e11617 add failAllocator to enable some regression tests 2020-05-06 23:56:48 -06:00
Jonathan Marler
0c7397b49f fix copy/paste error in AllocWithOptionaPayload 2020-05-06 23:08:08 -06:00
Vexu
e72f45475d
Merge pull request #4683 from LakeByTheWoods/parser_test
Add visible newlines to parser_test output when there's a failure.
2020-04-30 12:04:23 +03:00
Vexu
2d06e731ec
rename diffIndex to indexOfDiff 2020-04-30 10:33:50 +03:00
Tadeo Kondrak
350b2adacd
std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00
Andrew Kelley
9ebf25d145 link: change default executable mode to 0o777
Jonathan S writes:

On common systems with a 022 umask, this will still result in a
file created with 755 permissions, but it works appropriately if the
system is configured more leniently. (As another data point, C's fopen
seems to open files with the 666 mode.)
2020-04-24 15:36:08 -04:00
Andrew Kelley
a3dfe36ca1 zir-to-elf skeleton 2020-04-22 23:42:58 -04:00
Andrew Kelley
22e7ca5613 ir: analysis of fn instruction 2020-04-21 16:06:15 -04:00
Andrew Kelley
cc1c2bd568 simplify ZIR spec; separate parsing/rendering from analysis 2020-04-20 19:21:03 -04:00
Vexu
b6fe839248
update std lib to decls being disallowed between fields 2020-04-18 23:56:05 +03:00
Lachlan Easton
daff072af2 Add visible newlines to parser_test output when there's a failure.
Also print first line that differs between expected and result.
2020-04-10 10:38:36 +10:00
Benjamin Feng
cb98984ae6 Generate clearer size mismatch error message 2020-04-05 18:38:19 -04:00
xackus
cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Sebastian
92a423739d mem.zeroes - add sentinel terminated array support 2020-04-01 10:08:29 +01:00
daurnimator
b1eb831aba
std: fix mem.span* when an optional pointer is passed 2020-04-01 01:44:55 +11:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Sebastian
ef419dd72d mem.zeroes .Array improvements
Before (when given an array with many elements):
```
zig\std\mem.zig:345:13: error: evaluation exceeded 1000
backwards branches
            for (array) |*element| {
            ^
```
related to https://github.com/ziglang/zig/issues/4847#issuecomment-605721461
2020-03-30 11:16:25 -04:00