Commit Graph

1888 Commits (68cc068a3aa5df8bd1995d10a9133af1fa1ea1d3)

Author SHA1 Message Date
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
Sebastian 937dcad0b3 fixed timestamp() 2020-06-01 14:43:13 -04:00
Alexandros Naskos 215a0d61ab Fix evented builds on windows with runtime safety on 2020-06-01 14:22:45 -04:00
Veikka Tuominen 078e4afdaf
Merge pull request #5500 from Vexu/fix
Fix std.zig rejecting literal tabs in comments
2020-06-01 17:24:30 +03:00
Veikka Tuominen eb687810cf
Merge pull request #4976 from xackus/std-lib-docs
std lib docs: fix null and int values
2020-06-01 14:50:05 +03:00
Veikka Tuominen 8c5c860b00
Merge pull request #5443 from data-man/mem_len_vectors
Support vectors in mem.len
2020-06-01 14:44:38 +03:00
Vexu a47257d9b0
fix std.zig rejecting literal tabs in comments 2020-06-01 14:37:36 +03:00
Jonathan Marler 0d32f4acf7 enable dns test on windows 2020-05-31 11:58:50 -06:00
Jonathan Marler 58fb5b29b6 more windows network fixes
* support posix SOCK_NONBLOCK and SOCK_CLOEXEC flags on windows
* fix bugs in os.socket and os.connect to return at the correct place
2020-05-31 10:07:51 -06:00
Veikka Tuominen 899d79f8f0
Merge pull request #5478 from vrischmann/fix-iouring
linux: fix IOSQE_BIT decl and io_uring_sqe flags
2020-05-31 16:59:04 +03:00
Veikka Tuominen 30b2bc86b9
Merge pull request #5477 from alexnask/patch-1
Fix WSARecvFrom signature
2020-05-31 16:49:08 +03:00
Veikka Tuominen 21544267ee
Merge pull request #5481 from kubkon/typo-packedintarray
Fix typo in PackedIntArray tests
2020-05-31 16:48:19 +03:00
Jakub Konka 13c405127d Fix typo in PackedIntArray tests
Both `PackedIntArray` and `PackedIntSlice` tests defined `max_bits`
but didn't use it in the predicate in the inline while loop.
2020-05-30 23:17:55 +02:00
Vexu 010c58e303
fix zig fmt out of bounds on empty file 2020-05-30 23:07:51 +03:00
Jonathan Marler 2bae91e769 convert getaddrinfo rc to enum before switching on it 2020-05-30 09:56:52 -06:00
Vincent Rischmann 636d3ba780
linux: fix IOSQE_BIT decl and io_uring_sqe flags 2020-05-30 16:05:46 +02:00
Alexandros Naskos dbdacb0938
Fix WSARecvFrom signature
The lpFromLen should be a pointer.
2020-05-30 16:46:32 +03:00
Jonathan Marler 2eaab1e65e more windows network support, including dns 2020-05-29 22:38:48 -06:00
Andrew Kelley 89a97a7a27 cleanups 2020-05-29 18:30:09 -04:00
Jonathan S c209da1589 Document the failure to improve selfExe{,Dir}PathAlloc 2020-05-29 18:27:39 -04:00
Jonathan S 0674b51453 In getCwdAlloc, geometrically allocate larger buffers to find an appropriate size. 2020-05-29 18:27:39 -04:00
Jonathan S ab3931fa95 Prefer Files to paths in std.debug. Additionally [breaking] add a flags parameter to openSelfExe and stop exporting openElfDebugInfo.
This should save a call to readlink in openSelfDebugInfo and support executables in overlong paths on Linux.
2020-05-29 18:27:39 -04:00
Jonathan S 631633b252 Document and reduce usage of MAX_PATH_BYTES, lifting arbitrary buffer size requirements 2020-05-29 18:23:06 -04:00
Andrew Kelley 65c3833ec2
Merge pull request #5388 from kubkon/wasi-args-iter
Add ArgIteratorWasi and integrate it with ArgIterator
2020-05-29 15:55:14 -04:00
Noam Preil e9f344dcd4 Add include dirs to translate-c (close #5098) 2020-05-29 13:39:16 -04:00
Jakub Konka 6e347e6180 Fix args iterator test 2020-05-29 17:12:19 +02:00
Jakub Konka 6f48842ddb Make ArgIterator.init() a compile error in WASI
Given that the previous design would require the use of a default
allocator to have `ArgIterator.init()` work in WASI, and since in
Zig we're trying to avoid default allocators, I've changed the design
slightly in that now `init()` is a compile error in WASI, and instead
in its message it points to `initWithAllocator(*mem.Allocator)`.
The latter by virtue of requiring an allocator as an argument can
safely be used in WASI as well as on other OSes (where the allocator
argument is simply unused). When using `initWithAllocator` it is then
natural to remember to call `deinit()` after being done with the
iterator. Also, to make use of this, I've also added `argsWithAllocator`
function which is equivalent to `args` minus the requirement of supplying
an allocator and being fallible.

Finally, I've also modified the WASI only test `process.ArgWasiIterator`
to test all OSes.
2020-05-29 10:48:03 +02:00
Jakub Konka f1a4e1a70f Add ArgIteratorWasi and integrate it with ArgIterator
This commit pulls WASI specific implementation of args extraction
from the runtime from `process.argsAlloc` and `process.argsFree`
into a new iterator struct `process.ArgIteratorWasi`. It also
integrates the struct with platform-independent `process.ArgIterator`.
2020-05-29 10:48:03 +02:00
data-man dc4fea983d Use tuples in multiTrait 2020-05-28 23:10:44 -04:00
Dmitry Atamanov 0328537ca6
Support stringify for vectors (#5441)
* use array's pointer
2020-05-28 23:10:16 -04:00
Walter Mays 8630ae7523 Remove reliance on hashing algorithm for iterator reset test. 2020-05-28 23:09:21 -04:00
Andrew Kelley 1e0de896b8
Merge pull request #5452 from squeek502/comptime-string-map
Add std.ComptimeStringMap based on the tokenizer optimization in #5442
2020-05-28 23:06:40 -04:00
Jakub Konka 4f24ab9cfc Fix skipping condition (skip when wasm32) 2020-05-29 00:06:26 +02:00
Jakub Konka 3dbe376c77 Link issue to the failing test case targeting wasm 2020-05-28 23:32:17 +02:00
data-man c91786caf3 zig fmt 2020-05-28 16:41:15 +05:00
data-man f9bdf325d3 Added tests with tuple 2020-05-28 16:39:00 +05:00
Ryan Liptak 3cac0a5614 Not sure how a tab snuck in there 2020-05-26 23:26:19 -07:00
Ryan Liptak b683498ae8 Use ComptimeStringMap in std.meta.stringToEnum when feasible 2020-05-26 23:10:13 -07:00
Ryan Liptak dfafafac7b std.ComptimeStringMap: Add support for void value type (i.e. a set) 2020-05-26 23:10:12 -07:00
Ryan Liptak 62cfc68d2f Use std.ComptimeStringMap in the C tokenizer 2020-05-26 23:10:08 -07:00
Ryan Liptak a9dd79d293 Use std.ComptimeStringMap in zig's tokenizer
Should have no performance change, the implementation was just made generic/re-usable
2020-05-26 21:36:58 -07:00
Ryan Liptak 0865e5d360 Add std.ComptimeStringMap 2020-05-26 21:34:55 -07:00
Jakub Konka e61e8c94be Reenable zig parser tests disabled targeting Wasm
I'm not sure why I disabled them when landing extended Wasm/WASI
support, but they pass the parser tests just fine now, so I'm gonna
go ahead and re-enable them.
2020-05-26 21:01:54 -04:00
data-man 78a1f6976d Add more traits 2020-05-27 04:00:38 +05:00
Andrew Kelley ba41a9d5d7 different strategy for tokenizing keywords
throughput: 279 MiB/s => 347 MiB/s
2020-05-26 18:59:49 -04:00
Walter Mays e1186c88ea Remove unimplemented `init` call from ArrayListUnmanaged. 2020-05-26 15:59:56 -04:00
data-man 49dd2cbd9a Support vectors in mem.len 2020-05-27 00:00:19 +05:00
Dmitry Atamanov dd62f63c04
fmt padding correction (#5403)
* Make .Left as default
2020-05-26 20:53:51 +03:00
Walter Mays 19a04d8ebd
Add `writeToSlice` method to SegmentedList. (#5405) 2020-05-26 13:04:25 -04:00
Andrew Kelley 62fefe8648 std.fmt: non-exhaustive enums: avoid the loop when it's not necessary 2020-05-26 12:15:08 -04:00
daurnimator 5cdeac3b0e std: in fmt, use tag names of non-exhaustive enums when available 2020-05-26 12:00:33 -04:00
daurnimator 292d515e91 std: allow specifiying enums to be formatted as numbers 2020-05-26 12:00:33 -04:00
data-man d10e407977 More vector support in std.meta 2020-05-26 10:56:29 -04:00
Veikka Tuominen 4b8077ea8e
Merge pull request #5383 from Vexu/fix
Fix missing compile error on while/for missing block
2020-05-26 11:13:09 +03:00
Andrew Kelley 7c8d0cc678 fix pwrite on 32-bit linux 2020-05-25 19:59:39 -04:00
Andrew Kelley a83aab5209 fix std lib tests for WASI 2020-05-25 19:46:28 -04:00
Andrew Kelley cda102be02 improvements to self-hosted cache hash system
* change miscellaneous things to more idiomatic zig style
 * change the digest length to 24 bytes instead of 48. This is
   still 70  more bits than UUIDs. For an analysis of probability of
   collisions, see:
   https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions
 * fix the API having the possibility of mismatched allocators
 * fix some error paths to behave properly
 * modify the guarantees about when file contents are loaded for input files
 * pwrite instead of seek + write
 * implement isProblematicTimestamp
 * fix tests with regards to a working isProblematicTimestamp function.
   this requires sleeping until the current timestamp becomes
   unproblematic.
 * introduce std.fs.File.INode, a cross platform type abstraction
   so that cache hash implementation does not need to reach into std.os.
2020-05-25 19:29:03 -04:00
Vexu e07b467c7c
fix missing compile error on while/for missing block 2020-05-25 23:25:06 +03:00
Andrew Kelley 69ff89fd12 stage2 parser: heuristics to pre-allocate token arrays
throughput: 72.2 MiB/s => 75.3 MiB/s

I also tried the idea from the deleted comment in this commit and it
made the throughput worse.
2020-05-25 15:12:23 -04:00
Andrew Kelley 6d5ec184ab stage2 parser: heuristics to pre-allocate token arrays
throughput: 72.2 MiB/s => 75.3 MiB/s
2020-05-25 15:02:02 -04:00
LeRoyce Pearson 72716ecc3a Fix improper initialization of CacheHashFiles 2020-05-25 13:48:43 -04:00
LeRoyce Pearson c3c332c9ec Add max_file_size argument 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 5a1c6a3627 Set manifest's maximum size to Andrew's recommendation 2020-05-25 13:48:43 -04:00
LeRoyce Pearson be69e8e871 Remove non-null assertion in `CacheHash.release()`
People using the API as intended would never trigger this assertion
anyway, but if someone has a non standard use case, I see no reason
to make the program panic.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson e6a37ed941 Change null pointer test to `addFilePost` test 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 42007307be Make if statement more idiomatic 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 2c59f95e87 Don't use `iterate` when opening manifest directory 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 1ffff1bb18 Add test case for fix in previous commit 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 0fa89dc51d Fix read from null pointer in CacheHash.hit
It occured when the manifest file was manually edited to include an extra
file. Now it will simply copy the file name in the manifest file
2020-05-25 13:48:43 -04:00
LeRoyce Pearson f13c67bcfe Return an index from `CacheHash.addFile`
This makes it possible for the user to retrieve the contents of the
file without running into data races.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 4d62d97076 Update code using deprecated ArrayList APIs 2020-05-25 13:48:43 -04:00
LeRoyce Pearson b429f4607c Make `addFilePost*` functions' documentation more clear 2020-05-25 13:48:43 -04:00
LeRoyce Pearson e7657f2938 Make `CacheHash.release` return an error
If a user doesn't care that the manifest failed to be written, they can
simply ignore it. The program will still work; that particular cache
item will simply not be cached.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 967b9825a7 Add "no file inputs" test
It checks whether the cache will respond correctly to inputs that don't
initially depend on filesystem state. In that case, we have to check
for the existence of a manifest file, instead of relying on reading the
list of entries to tell us if the cache is invalid.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 4254d389d3 Add test checking file changes invalidate cache 2020-05-25 13:48:43 -04:00
LeRoyce Pearson b67a9f2281 Switch to using `testing.expect*` in tests 2020-05-25 13:48:43 -04:00
LeRoyce Pearson d457919ff5 Make CacheHash cleanup consistent (always call `release`)
Instead of releasing the manifest file when an error occurs, it is
only released when when `CacheHash.release` is called. This maps better
to what a zig user expects when they do `defer cache_hash.release()`.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 05edfe983c Add `addFilePost` and `addFilePostFetch` functions 2020-05-25 13:48:43 -04:00
LeRoyce Pearson af730c64bd Put base64 alphabet into a named constant 2020-05-25 13:48:43 -04:00
LeRoyce Pearson d770dae1b8 Add documentation to CacheHash API 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 67d6432d10 Check for problematic timestamps 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 73d2747084 Open file with exclusive lock 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 204aa7dc1a Remove unnecessary contents field from File
It was causing a segfault on `mipsel` architecture, not sure why other
architectures weren't affected.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson c88ece3679 Remove error union from CacheHash.final 2020-05-25 13:48:43 -04:00
LeRoyce Pearson dfb53beb52 Check if inode matches inode from manifest 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 7917f25b0a Update cache_hash to zig master 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 16c5499098 Remove up files created in test at end of test 2020-05-25 13:48:43 -04:00
LeRoyce Pearson fffd59e6c4 Remove file handle from CacheHash
A file handle is not the same thing as an inode index number.
Eventually the inode will be checked as well, but there needs to be
a way to get the inode in `std` first.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 21d7430696 Replace ArrayList in write_manifest with an array 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 061c1fd9ab Use `readAllAlloc`
Now that the memory leak mentioned in #4656 has been fixed.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 4f709d224a Make hash digest same size as in the c API 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 8e4b80522f Return base64 digest instead of using an out variable 2020-05-25 13:48:43 -04:00
LeRoyce Pearson e75a6e5144 Rename `cache_file` -> `addFile` 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 50cbf1f3aa Add slice and array support to `add` method 2020-05-25 13:48:43 -04:00
LeRoyce Pearson fde188aadc Make type specific add functions
Basically, move type specific code into their own functions instead
of making `add` a giant function responsible for everything.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson 4173dbdce9 Rename `cache` functions to `add` 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 27bf1f781b Store fs.Dir instead of path to dir 2020-05-25 13:48:43 -04:00
LeRoyce Pearson 55a3925ab7 Rename CacheHashFile -> File 2020-05-25 13:48:43 -04:00
LeRoyce Pearson c8062321b3 Use fs.File 2020-05-25 13:48:43 -04:00