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
daurnimator
3be720a729
std: mem span functions can take an optional pointer
2020-03-30 11:04:58 -04:00
Andrew Kelley
28a6c136e9
revert std.mem.span to prefer len over sentinel; add spanZ
2020-03-19 19:30:09 -04:00
Andrew Kelley
f614d94faa
update std lib to take advantage of slicing with comptime indexes
2020-03-19 14:48:47 -04:00
Andrew Kelley
7fa88cc0a6
std lib fixups for new semantics
...
std lib tests are passing now
2020-03-19 09:53:55 -04:00
Andrew Kelley
8ea0a00f40
improve std lib code for the new semantics
2020-03-19 09:53:54 -04:00
Andrew Kelley
8d0ac6dc4d
@ptrCast
supports casting a slice to pointer
2020-03-19 09:53:54 -04:00
Andrew Kelley
0707be8de8
fixes in semantic analysis needed to support this feature
2020-03-19 09:53:54 -04:00
Andrew Kelley
a27a8561e9
adjust renameatW to always supply dest root dir
...
this fixes tests for wine
2020-03-15 17:26:29 -04:00
Andrew Kelley
7e45a3ef6a
fix typo in new mem.len test
2020-03-15 15:57:51 -04:00
Andrew Kelley
6c2b23593b
fix std.mem.span handling of sentinel-terminated arrays
...
previously this function would use the array length, but now it scans
the array looking for the first sentinel that occurs.
2020-03-15 15:46:56 -04:00
Andrew Kelley
51c6bb92b1
Merge pull request #4709 from LemonBoy/implement-2096
...
Stricter shift left/right safety checks
2020-03-11 14:22:40 -04:00
LemonBoy
2f1052a313
std: Fix broken tests
2020-03-10 23:50:04 +01:00
Jonathan Marler
90c232bbe8
add allocSentinel function
2020-03-10 15:03:59 -04:00
Michaël Larouche
f5954dad83
Fix crash when freeing empty string as null-terminated sentinel
2020-03-05 17:08:12 -05:00
xackus
00be934569
short std.builtin enum literals in std lib
2020-03-01 13:57:41 -05:00
Andrew Kelley
ef3d761da5
breaking: std.mem.len no longer takes a type argument
...
also update fmt code to use std.mem.span.
2020-03-01 13:21:39 -05:00
Andrew Kelley
5b26128bac
add new functions to std.mem and deprecate others
...
add std.mem.Span
add std.mem.span
add std.mem.length
add std.mem.indexOfSentinel
deprecate std.mem.len
deprecate std.mem.toSlice
deprecate std.mem.toSliceConst
2020-03-01 13:07:55 -05:00
Andrew Kelley
4505857e30
revert changes outside std.fmt
2020-03-01 13:07:31 -05:00
daurnimator
0b0de22fd1
std: format contents of sentinel terminated many pointers
...
std: add std.meta.Sentinel to get sentinel of a type
2020-03-01 13:04:29 -05:00
Andrew Kelley
5503f3f7c4
Merge pull request #4544 from BarabasGitHub/zeroes-for-non-extern-types
...
implement zeroes for non extern structs and native types
2020-02-24 22:01:56 -05:00