Commit Graph

2159 Commits

Author SHA1 Message Date
Andrew Kelley
061c8be049
Merge pull request #5684 from squeek502/fs-file-dir-ops
Add tests for using directory operations on files
2020-06-25 19:08:30 -04:00
data-man
77bb2dc094 Use writer in benchmarks 2020-06-25 19:07:25 -04:00
Ryan Liptak
dcdbb7006c Add tests for using directory operations on files 2020-06-25 03:49:58 -07:00
Ryan Liptak
f50ed94174 Windows: Fix fs.Dir.openDir not handling STATUS_NOT_A_DIRECTORY
Now correctly returns error.NotDir
2020-06-25 03:49:58 -07:00
Andrew Kelley
41c6cc9001
Merge pull request #5677 from kubkon/fstatat
[libstd]: implement fstatat in WASI plus fix on macOS
2020-06-25 00:01:38 -04:00
Andrew Kelley
d337469e44
Merge pull request #5583 from ziglang/zig-ast-to-zir
self-hosted: hook up Zig AST to ZIR
2020-06-24 22:37:58 -04:00
Code Hz
7875649c24 Pdb.openFile use []const u8 instead of []u8 2020-06-24 22:27:30 -04:00
Andrew Kelley
20b4a2cf2c self-hosted: add compare output test for new AST->ZIR code 2020-06-24 21:28:42 -04:00
Andrew Kelley
e42b7702eb Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-24 15:36:59 -04:00
Jakub Konka
d40e367b73 Reformat using if-else where appropriate 2020-06-24 21:00:21 +02:00
Jakub Konka
c63b23d684 Use fstatat on macOS (otherwise uses 32bit) 2020-06-24 21:00:21 +02:00
Jakub Konka
be78b7b648 Implement fstatat targeting WASI
Also, add more informative `@compileError` in a few `std.os` functions
that would otherwise yield a cryptic compile error when targeting
WASI. Finally, enhance docs in a few places and add test case for
`fstatat`.
2020-06-24 21:00:21 +02:00
antlilja
e60be30824 Remove unreachable else prongs 2020-06-24 19:03:32 +02:00
Alexandros Naskos
50b70bd77f @asyncCall now requires an argument tuple 2020-06-24 14:07:39 +03:00
Jakub Konka
5fed725e0a
Remove some leftover debugging checks 2020-06-23 23:59:32 +02:00
Jakub Konka
66e5205047 Refactor PreopenList.find()
This commit generalizes `std.fs.wasi.PreopenList.find(...)` allowing
search by `std.fs.wasi.PreopenType` union type rather than by dir
name. In the future releases of WASI, it is expected to have more
preopen types (or capabilities) than just directories. This commit
aligns itself with that vision.

This is a potentially breaking change. However, since `std.fs.wasi.PreopenList`
wasn't made part of any Zig release yet, I think we should be OK
to introduce those changes without pointing to any deprecations.
2020-06-23 21:54:36 +02:00
antlilja
46106b018c Add expectWithinEpsilon + test 2020-06-23 18:08:15 +02:00
antlilja
2fc2355fc3 Add expectWithinMargin and test 2020-06-23 18:05:32 +02:00
Andrew Kelley
6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Andrew Kelley
78c6d39cd4
Merge pull request #5667 from cartr/windows-arguments-unclosed-quote
In std.process.ArgIteratorWindows, don't treat unclosed quotes like they're escaped
2020-06-22 20:07:43 -04:00
Jakub Konka
923c0feda1 Add std.fs.File.readAllAlloc tests
This commit adds some unit tests for `std.fs.File.readAllAlloc`
function. It also updates the docs of `Reader.readNoEof`
which were outdated, and swaps `inStream()` for  `reader()` in
`File.readAllAlloc` with the former being deprecated.
2020-06-22 20:03:21 -04:00
Andrew Kelley
6ff6ac866d
Merge pull request #5666 from kubkon/symlinkat-readlinkat
[libstd]: enhance std.os.{symlinkat, readlinkat} coverage
2020-06-22 20:02:27 -04:00
Andrew Kelley
44bd0a2670
Merge pull request #5662 from shtanton/meta-cast
Adds std.meta.cast and uses it to simplify translate-c
2020-06-22 19:54:30 -04:00
prime31
65ef74e2cd
try allocation of pointer type when parsing (#5665)
* `try` allocation of pointer type when parsing

* fixes pointer destroy compile error
2020-06-22 17:30:02 +03:00
Carter Sande
7cb41a415a ArgIteratorWindows: simplify quote state tracking 2020-06-22 03:03:30 -07:00
Carter Sande
8faa85ac19 ArgIteratorWindows: don't treat unclosed quotes like they're escaped 2020-06-22 03:03:20 -07:00
Jakub Konka
c950f0c6c3 Enhance std.os.readlinkat coverage
Adds Windows stub (still needs to be implemented on Windows),
adds WASI implementation, adds unit test testing basic chain of
ops: create file -> symlink -> readlink.
2020-06-22 09:40:06 +02:00
Jakub Konka
64078ca924 Enhance std.os.symlinkat coverage
Fixes `std.os.symlinkat` compile errors, adds Windows stub (still
needs to be implemented), adds WASI implementation.
2020-06-22 09:14:51 +02:00
Charlie Stanton
8c15cfe3da Compacts switch statements and string literal 2020-06-21 21:48:12 +01:00
Charlie Stanton
6f47513009 Adds std.meta.cast and uses it to simplify translate-c 2020-06-21 18:24:59 +01:00
Nameless
56220449ab Add errors to windows.WSAStartup and WSACleanup 2020-06-21 00:13:06 -04:00
Andrew Kelley
faf783e595 implement new stat functionality for WASI 2020-06-20 22:09:47 -04:00
Andrew Kelley
225f196842 std.fs: fix shadowing stat with a local variable 2020-06-20 20:43:56 -04:00
Andrew Kelley
0a9672fb86 rework zig fmt to avoid unnecessary realpath() calls
* add `std.fs.Dir.stat`
 * zig fmt checks for sym link loops using inodes instead of using
   realpath
2020-06-20 19:46:14 -04:00
Andrew Kelley
da549a72e1 zig fmt 2020-06-20 18:39:15 -04:00
Andrew Kelley
d87cd06296 rework zig fmt to use less syscalls and open fds
* `std.fs.Dir.Entry.Kind` is moved to `std.fs.File.Kind`
 * `std.fs.File.Stat` gains the `kind` field, so performing a stat() on
   a File now tells what kind of file it is. On Windows this only will
   distinguish between directories and files.
 * rework zig fmt logic so that in the case of opening a file and
   discovering it to be a directory, it closes the file descriptor
   before re-opening it with O_DIRECTORY, using fewer simultaneous open
   file descriptors when walking a directory tree.
 * rework zig fmt logic so that it pays attention to the kind of
   directory entries, and when it sees a sub-directory it attempts to
   open it as a directory rather than a file, reducing the number of
   open() syscalls when walking a directory tree.
2020-06-20 18:27:37 -04:00
data-man
5229f6ec68 Use writer in std.fmt 2020-06-20 18:23:57 +00:00
Haze Booth
237c5429b0 Don't attempt to use io from thin air 2020-06-19 02:06:27 -04:00
Andrew Kelley
c9a0ec25e0 self-hosted: add Tracy integration
This tool helps give an intuitive picture of performance. This will help
us understand where to improve the code.
2020-06-18 21:55:37 -04:00
Andrew Kelley
0d18eda1d6
Merge pull request #5348 from ifreund/std-log
Introduce std.log
2020-06-18 21:40:06 -04:00
Andrew Kelley
c70633eacd
Merge pull request #5203 from tadeokondrak/@type-for-even-more-types
implement @typeInfo for Frame and implement @Type for Frame, EnumLiteral, and ErrorSet
2020-06-18 21:25:03 -04:00
Andrew Kelley
f7bcc8e040 rework zig fmt to only make one allocation
taking advantage of the fstat size
2020-06-18 21:08:30 -04:00
Cassidy Dingenskirchen
8b49487c33 Fix fs.File.mode() not returning mode_t on windows 2020-06-18 20:41:40 -04:00
Michael Rees
bd17a373cc Add std.unicode.Utf8Iterator.peek 2020-06-18 20:35:03 -04:00
Andrew Kelley
5ea0f589c9
Merge pull request #5625 from antlilja/master
Improve support for f128 and comptime_float operations
2020-06-18 20:32:43 -04:00
Vexu
caaa26c9f0 reference emit_raw in std lib tests 2020-06-18 20:17:53 -04:00
Andrew Kelley
81f766eecd self-hosted parser: make a function pointer comptime 2020-06-18 17:12:56 -04:00
Andrew Kelley
7e58c56ca7 self-hosted: implement Decl lookup
* Take advantage of coercing anonymous struct literals to struct types.
 * Reworks Module to favor Zig source as the primary use case.
   Breaks ZIR compilation, which will have to be restored in a future commit.
 * Decl uses src_index rather then src, pointing to an AST Decl node
   index, or ZIR Module Decl index, rather than a byte offset.
 * ZIR instructions have an `analyzed_inst` field instead of Module
   having a hash table.
 * Module.Fn loses the `fn_type` field since it is redundant with
   its `owner_decl` `TypedValue` type.
 * Implement Type and Value copying. A ZIR Const instruction's TypedValue
   is copied to the Decl arena during analysis, which allows freeing the
   ZIR text instructions post-analysis.
 * Don't flush the ELF file if there are compilation errors.
 * Function return types allow arbitrarily complex expressions.
 * AST->ZIR for function calls and return statements.
2020-06-18 17:12:56 -04:00
Andrew Kelley
b4eac0414a stage2: hook up Zig AST to ZIR
* Introduce the concept of anonymous Decls
 * Primitive Hello, World with inline asm works
 * There is still an unsolved problem of how to manage ZIR instructions
   memory when generating from AST. Currently it leaks.
2020-06-18 17:12:56 -04:00
Andrew Kelley
4a38799631 make file and fn_name fields of SourceLocation also null-terminated
One of the main motivating use cases for this language feature is
tracing/profiling tools, which expect null-terminated strings for these
values. Since the data is statically allocated, making them
additionally null-terminated comes at no cost.

This prevents the requirement of compile-time code to convert to
null-termination, which could increase the compilation time of
code with tracing enabled.

See #2029
2020-06-18 17:09:10 -04:00
Vexu
a5379aa3ee
implement @src 2020-06-18 21:11:09 +03:00
Isaac Freund
c3e0224792
Add std.debug.print for "printf debugging" 2020-06-17 18:36:44 +02:00
antlilja
eb7fad28f8 Improve f128 standard library support
* Add functions: floor128, ceil128, trunc128 and round128
* Add corresponding tests
2020-06-17 18:18:45 +02:00
Isaac Freund
8e5393a779
Deprecate std.debug.warn 2020-06-17 02:14:52 +02:00
Isaac Freund
0bd067d19a
Introduce std.log
std.log provides 8 log levels and corresponding logging functions. It
allows the user to override the logging "backend" by defining root.log
and to override the default log level by defining root.log_level.

Logging functions accept a scope parameter which allows the implementer
of the logging "backend" to filter logging by library as well as level.

Using the standardized syslog [1] log levels ensures that std.log will
be flexible enough to work for as many use-cases as possible. If we were
to stick with only 3/4 log levels, std.log would be insufficient for
large and/or complex projects such as a kernel or display server.

[1]: https://tools.ietf.org/html/rfc5424#section-6.2.1
2020-06-17 02:14:52 +02:00
Andrew Kelley
9781342042
Merge pull request #5607 from daurnimator/cleanup-debug-stderr
std: clean up debug stderr variables
2020-06-16 18:27:44 -04:00
Jonathan Marler
f0b8791da7 ArrayList(u8) support writer interface 2020-06-16 18:26:54 -04:00
tgschultz
38e69a9e6a Added test to ensure minimum number of bytes is emitted for writes 2020-06-16 16:20:59 +00:00
tgschultz
a0160d776f Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:59 +00:00
tgschultz
00ec81b0dc Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:59 +00:00
tgschultz
928d3ee9ea Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:58 +00:00
tgschultz
e94eba5df5 Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:58 +00:00
tgschultz
7f24860737 Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:58 +00:00
tgschultz
8978fe94cf Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:58 +00:00
daurnimator
af592f0ddd
std: remove std.debug.getStderrStream
Rather than migrate to new 'writer' interface, just remove it
2020-06-15 23:51:25 +10:00
daurnimator
ce30357532
std: clean up debug stderr variables
- stderr_file_writer was unused
  - stderr_stream was a pointer to a stream, rather than a stream
  - other functions assumed that getStderrStream has already been called
2020-06-15 23:48:33 +10:00
Vexu
e7207bc267
add workaround for #5599 2020-06-14 20:13:02 +03:00
Carter Sande
09cded209d Add strict_align to pre-v6 ARM targets
This matches GCC's and Clang's default behavior for these targets.
2020-06-12 13:43:12 -04:00
Andrew Kelley
866651a5a3
Merge pull request #5589 from kubkon/preopens-example
Add doc example for extracting WASI preopens
2020-06-12 13:40:30 -04:00
Alexandros Naskos
1bc92b1fde Fix formatting of floating point values with the B and Bi specifiers 2020-06-12 13:38:12 -04:00
Cassidy Dingenskirchen
57f1ed5325 Fix a few std.sort.sort invocations 2020-06-12 13:33:31 -04:00
Jakub Konka
200f9ea6fb Add unit test for std.fs.wasi.PreopenList 2020-06-11 23:00:02 +02:00
Jakub Konka
c7721bb368 Add custom format method for Preopen struct 2020-06-11 22:31:08 +02:00
Jonathan Marler
a282ac7a91 Support Reader for InStream 2020-06-09 13:36:17 -04:00
Jakub Konka
8ffa8ed9a8 Expose full llvm intrinsic 2020-06-09 00:22:34 -04:00
Jakub Konka
146be2a8cb Use builtins in std.heap.WasmAllocator 2020-06-09 00:22:17 -04:00
Jonathan Marler
12051b02f1 fix memory errors 2020-06-09 00:17:22 -04:00
Jonathan Marler
7481582774 support Writer instead of OutStream
Start implementing https://github.com/ziglang/zig/issues/4917 which is to rename instream/outstream to reader/writer.  This first change allows code to use Writer/writer instead of OutStream/outStream, but still maintains the old outstream names with "Deprecated" comments.
2020-06-08 22:59:28 -04:00
Andrew Kelley
05d284c842 update sort callsite to new API 2020-06-08 16:33:35 -04:00
Andrew Kelley
d4d954abd2 std.sort: give comparator functions a context parameter 2020-06-08 15:16:40 -04:00
Ian Simonson
a6d1ef64d7 tcpConnectToHost try all addresses in AddressList
The AddressList returned can contain more than one item
e.g. the ipv4 and ipv6 addresses for a given hostname.
Previously if a server had multiple addresses but
was not listening on one of them Zig would give up
immediately.

Now on std.os.ConnectError.ConnectionRefused Zig will
try the next address in the list. Zig still gives up on
all other errors as they are related to the system and
system resources rather than whether the remote server
is listening on a particular address.
2020-06-07 22:39:35 +10:00
Ian Simonson
983f93c840 Test case for tcpConnectToHost fix 2020-06-07 22:39:35 +10:00
Ryan Liptak
f839d34baa std.os.windows.OpenFile: Handle FILE_IS_A_DIRECTORY status
Fixes #5533
2020-06-04 22:53:23 -04:00
Ryan Liptak
95a5f6bf2d Windows: Handle ERROR_DIRECTORY in std.fs.deleteDirAbsolute when called on a file path
ERROR_DIRECTORY (267) is returned from kernel32.RemoveDirectoryW if the path is not a directory. Note also that os.DirectDirError already includes NotDir

Before: error.Unexpected: GetLastError(267): The directory name is invalid.
After: error: NotDir
2020-06-04 22:52:53 -04:00
Ryan Liptak
f7b6957fb4 Windows: Fix std.fs.Dir.deleteDir() deleting files
Would previously delete files, now correctly returns error.NotDir. Fixes #5536
2020-06-04 22:51:58 -04:00
Vexu
fd067fbe8b
add workaround for #5525 2020-06-04 13:11:23 +03:00
Jesse Rudolph
3fba076f92 demonstrate start + len > new_items.len 2020-06-03 06:29:50 -05:00
Jesse Rudolph
c0a0193c0a add replaceRange() function to ArrayList
generalizes functionality of ArrayList.insertSlice() to overwrite
a range of elements in the list and to grow or shrink the list as needed
to accommodate size difference of the replacing slice and the range
of existing elements.
2020-06-02 17:00:01 -05:00
Andrew Kelley
7fd937fef4 cleanups
* improve docs
 * add TODO comments for things that don't have open issues
 * remove redundant namespacing of struct fields
 * guard against ioctl returning EINTR
 * remove the general std.os.ioctl function in favor of the specific
   ioctl_SIOCGIFINDEX function. This allows us to have a more precise
   error set, and more type-safe API.
2020-06-02 15:28:46 -04:00
Luna
0d091dc923 Replace os.linux to os.system 2020-06-02 14:56:19 -04:00
Luna
6623efd7d4 Change ioctl's request type to i32 2020-06-02 14:56:19 -04:00
Luna
6d3d1152ea Add declaration for libc ioctl 2020-06-02 14:56:19 -04:00
Luna
7c71054286 Replace syscall3 to os.ioctl 2020-06-02 14:56:19 -04:00
Luna
09c01ea7b9 Use resolveIp when looking up addresses on linux 2020-06-02 14:56:19 -04:00
Luna
c8468bed42 Add std.os.ioctl 2020-06-02 14:56:19 -04:00
Luna
c7b790ded6 net.test: only call resolveIp6 when os is linux 2020-06-02 14:56:06 -04:00
Luna
15efe03d1f Add tests for overflow 2020-06-02 14:56:06 -04:00
Luna
b72c862725 Use IFNAMESIZE for scope id value 2020-06-02 14:56:06 -04:00
Luna
aebf28eba3 Make ifru fields sentinel-terminated 2020-06-02 14:56:06 -04:00
Luna
c60daa255f Replace C types in declarations 2020-06-02 14:56:06 -04:00
Luna
2fa9cf51ff Plug resolveIp6 into IPv6 tests 2020-06-02 14:56:06 -04:00
Luna
64e55a74de Add validation for scope ids 2020-06-02 14:56:06 -04:00
Luna
10ea2db5cb Replace C shorts by integer types 2020-06-02 14:56:06 -04:00
Luna
11a06d4341 Remove warn() calls 2020-06-02 14:56:06 -04:00
Luna
cb649b769c Fix ifreq definition 2020-06-02 14:56:06 -04:00
Luna
c50ac9a764 Change Unsupported to InterfaceNotFound 2020-06-02 14:56:06 -04:00
Luna
38109d48a3 Make interface name null-terminated before syscall 2020-06-02 14:56:06 -04:00
Luna
5919831529 Stop using mem.len on array 2020-06-02 14:56:06 -04:00
Luna
901aab8761 Add ioctl errors 2020-06-02 14:56:06 -04:00
Luna
2c641c93da Only resolve scope id when needed 2020-06-02 14:56:06 -04:00
Luna
f02f4c0880 Fix typo and add if_nametoindex 2020-06-02 14:56:06 -04:00
Luna
9c200035f3 Add some interface structs to linux bits 2020-06-02 14:56:06 -04:00
Luna
b816303122 Add basics of resolveIp6
Instead of streaming the scope id digits to an u32, we keep a [32]u8 in
the stack and fill it up with the characters we get for scope id.
2020-06-02 14:56:05 -04:00
Andrew Kelley
bae0c9b554 std.HashMap: allow ensureCapacity with a zero parameter 2020-06-02 14:41:45 -04:00
Jesse Rudolph
100aa6fbaf pass allocator to self.resize() in appendNTimes() 2020-06-02 09:59:13 -05:00
Alexandros Naskos
aa1a727284 Allow carriare return in comments 2020-06-02 00:56:05 -04:00
Andrew Kelley
c6764fd254
Merge pull request #5475 from marler8997/windowsDns
support name resolution on windows
2020-06-01 15:33:05 -04:00
Andrew Kelley
8f4bc77260
Merge pull request #5449 from data-man/more_traits
Add more traits
2020-06-01 14:50:01 -04: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
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
LeRoyce Pearson
86fe88bbcb Use std.fs.base64_encoder in std.cache_hash 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
8c8813a5cf Add filesystem base64 decoder 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
ce5b2286f1 Support caching bools; make caching values infallible 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
de341b8fb8 Fix memory leak in cache_hash 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
8a77c1c637 Add cache method; add support for caching integers 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
3158dc424e Partially implement cache hash API in zig 2020-05-25 13:48:43 -04:00
data-man
0ecdbdb3cb Support comptime floats in std.fmt 2020-05-25 12:48:59 -04:00
Alexandros Naskos
65d827183b Added custom build step id, made tests.zig steps use it 2020-05-25 11:36:12 +03:00
Alexandros Naskos
d268e0cf2e Added and id and a cast function to build steps 2020-05-25 11:20:31 +03:00
Andrew Kelley
3052fd84c8 fix regression in std.os.windows.fromSysTime 2020-05-25 00:37:47 -04:00
Andrew Kelley
53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
LeRoyce Pearson
c6e7d0fcfd Use better names for darwin timestart 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
b85a191398 Fix compile errors for MacOS 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
2dfe798217 Use once to init _timestart in thread safe way 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
7586ce0023 Implement a faster way to get nanoseconds on darwin 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
bb46894115 Add std.time.nanoTimestamp function 2020-05-24 21:40:08 -04:00
Jethro Nederhof
4b1a846471
target: Implement running OS version detection for FreeBSD (#5416)
* target: Implement OS version detection for FreeBSD

Fixes #4582

* freebsd version: handle errors explicitly
2020-05-24 20:52:13 -04:00
data-man
db0c30446a Supports vectors in mem.zeroes 2020-05-24 20:48:29 -04:00
data-man
b13dd3cf61 Treat vectors as indexable 2020-05-24 20:44:17 -04:00
Andrew Kelley
dd05f2be80 run zig fmt on std lib 2020-05-24 10:04:09 -04:00
Andrew Kelley
1c0b7ddda8 fix regression in AST node iteration
the new iteration code caused an integer underflow for function
prototypes with no parameters. now fixed.
2020-05-24 10:03:26 -04:00
Andrew Kelley
2ff3995a70
Merge pull request #5378 from ziglang/speed-up-stage2-parsing
improve std.zig.parse performance using flat arrays for AST nodes and tokens
2020-05-24 09:44:08 -04:00
Andrew Kelley
f771545a7e revert std.zig.ast iterator changes back to master branch API 2020-05-23 20:14:38 -04:00
Jethro Nederhof
f83fd47b14 os/bits/freebsd audit 2020-05-24 10:08:43 +10:00
Jethro Nederhof
b504169fef FreeBSD: missing networking constants 2020-05-24 10:08:43 +10:00
Andrew Kelley
8f6d7b3208 std: update singly linked list tests to new API 2020-05-23 16:38:43 -04:00
Greg Anders
64955deb72 Add poll definitions for Darwin 2020-05-22 13:21:34 -04:00
Andrew Kelley
8df0841d6a stage2 parser: token ids in their own array
To prevent cache misses, token ids go in their own array, and the
start/end offsets go in a different one.

perf measurement before:
         2,667,914      cache-misses:u
     2,139,139,935      instructions:u
       894,167,331      cycles:u

perf measurement after:
         1,757,723      cache-misses:u
     2,069,932,298      instructions:u
       858,105,570      cycles:u
2020-05-22 12:34:12 -04:00
Andrew Kelley
295bca9b5f stage2 parser: don't append doc comments to the list
The DocComment AST node now only points to the first doc comment token.
API users are expected to iterate over the following tokens directly.

After this commit there are no more linked lists in use in the
self-hosted AST API.

Performance impact is negligible. Memory usage slightly reduced.
2020-05-22 00:28:59 -04:00
Andrew Kelley
1dac9e71b5 std.testing: fix a crash when printing diffs 2020-05-22 00:27:51 -04:00
Andrew Kelley
8252c8b9d6 stage2 parser: different multiline string literal parsing strategy
and using flat memory rather than singly linked list

roughly equivalent performance, slightly reduced memory usage, better
API.
2020-05-21 23:25:15 -04:00
Andrew Kelley
19de259936 stage2 parser: arrays and structs directly in memory after the node
Slightly reduced memory usage. Roughly the same API and perf.
2020-05-21 22:52:45 -04:00