Commit Graph

293 Commits (5f7b97e84c7e2bc7682510e97996ad30147026d0)

Author SHA1 Message Date
Andrew Kelley 659c1bdeee
Merge branch 'wasi-run-tests' of https://github.com/fengb/zig into fengb-wasi-run-tests 2019-11-25 17:53:26 -05:00
Andrew Kelley bdf3680be1
zig fmt 2019-11-25 13:53:13 -05:00
Andrew Kelley 29e438fd1f
more sentinel-terminated pointers std lib integration
See #3767
2019-11-25 00:43:36 -05:00
Andrew Kelley 15d415e10b
make std.mem.toSlice use null terminated pointers
and fix the fallout
2019-11-24 21:21:05 -05:00
Andrew Kelley 47f06be369
string literals are now null terminated
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.
2019-11-21 20:43:41 -05:00
Benjamin Feng b88bb93af3 WASI isatty 2019-11-19 20:17:00 -06:00
Andrew Kelley 3cf5c2c62b
fix regressed tests and update docs to use "type coercion" 2019-11-08 15:57:25 -05:00
Andrew Kelley e0db54e89d
update the codebase to use `@as` 2019-11-08 15:57:24 -05:00
Andrew Kelley 2723ffc2b2
fixups and zig fmt 2019-11-08 01:52:23 -05:00
Andrew Kelley fbbcf2f30d
Merge branch 'adaptive_lock' of https://github.com/kprotty/zig into kprotty-adaptive_lock 2019-11-08 01:21:22 -05:00
kprotty bb4abfdc78 Use `system` instead of `builtin.link_libc` 2019-11-07 16:36:33 -06:00
kprotty 12e68cbeb6 pthread_sched_yield -> sched_yield 2019-11-07 16:33:25 -06:00
kprotty b535e86cc0 move SpinLock definitions around 2019-11-07 15:32:20 -06:00
Andrew Kelley 6c17282062
std.os.read can fail with ConnectionResetByPeer 2019-11-04 14:40:30 -05:00
Luna 2e0dd5733f add FileNotFound to os.ConnectError error set 2019-11-02 15:49:15 -04:00
Luna d535bf2c7d add FileNotFound error to os.connect 2019-11-02 15:49:15 -04:00
Andrew Kelley f749bf0942
std.os: fix sendto, poll, recvfrom when linking libc
Thank you to Brendan Hansknecht for this patch.
2019-11-02 15:15:56 -04:00
Andrew Kelley 61d5a0bf48
Merge branch 'std.net' 2019-10-30 21:30:16 -04:00
Tse 33cc204481 DragonFlyBSD support 2019-10-30 21:21:58 -04:00
Andrew Kelley 0de862e8ba
make std.net more portable
* Delete `std.net.TmpWinAddr`. I don't think that was ever meant to
   be a real thing.
 * Delete `std.net.OsAddress`. This abstraction was not helpful.
 * Rename `std.net.Address` to `std.net.IpAddress`. It is now an extern
   union of IPv4 and IPv6 addresses.
 * Move `std.net.parseIp4` and `std.net.parseIp6` to the
   `std.net.IpAddress` namespace. They now return `IpAddress` instead of
   `u32` and `std.net.Ip6Addr`, which is deleted.
 * Add `std.net.IpAddress.parse` which accepts a port and parses either
   an IPv4 or IPv6 address.
 * Add `std.net.IpAddress.parseExpectingFamily` which additionally
   accepts a `family` parameter.
 * `std.net.IpAddress.initIp4` and `std.net.IpAddress.initIp6` are
   improved to directly take the address fields instead of a weird
   in-between type.
 * `std.net.IpAddress.port` is renamed to `std.net.IpAddress.getPort`.
 * Added `std.net.IpAddress.setPort`.
 * `os.sockaddr` struct on all targets is improved to match the
   corresponding system struct. Previously I had made it a union of
   sockaddr_in, sockaddr_in6, and sockaddr_un. The new abstraction for
   this is now `std.net.IpAddress`.
 * `os.sockaddr` and related bits are added for Windows.
 * `os.sockaddr` and related bits now have the `zero` fields default
   to zero initialization, and `len` fields default to the correct size.
   This is enough to abstract the differences across targets, and so
   no more switch on the target OS is needed in `std.net.IpAddress`.
 * Add the missing `os.sockaddr_un` on FreeBSD and NetBSD.
 * `std.net.IpAddress.initPosix` now takes a pointer to `os.sockaddr`.
2019-10-30 20:22:05 -04:00
Andrew Kelley c3d816a98e
std lib networking improvements, especially non-blocking I/O
* delete the std/event/net directory
 * `std.event.Loop.waitUntilFdReadable` and related functions
   no longer have possibility of failure. On Linux, they fall
   back to poll() and then fall back to sleep().
 * add some missing `noasync` decorations in `std.event.Loop`
 * redo the `std.net.Server` API. it's quite nice now, but
   shutdown does not work cleanly. There is a race condition with
   close() that I am actively working on.
 * move `std.io.OutStream` to its own file to match `std.io.InStream`.
   I started working on making `write` integrated with evented I/O,
   but it got tricky so I backed off and filed #3557. However
   I did integrate `std.os.writev` and `std.os.pwritev` with evented I/O.
 * add `std.Target.stack_align`
 * move networking tests to `lib/std/net/test.zig`
 * add `std.net.tcpConnectToHost` and `std.net.tcpConnectToAddress`.
 * rename `error.UnknownName` to `error.UnknownHostName` within the
   context of DNS resolution.
 * add `std.os.readv`, which is integrated with evented I/O.
 * `std.os.preadv`, is now integrated with evented I/O.
 * `std.os.accept4` now asserts that ENOTSOCK and EOPNOTSUPP never
    occur (misuse of API), instead of returning errors.
 * `std.os.connect` is now integrated with evented I/O.
   `std.os.connect_async` is gone. Just use `std.os.connect`.
 * fix false positive dependency loop regarding async function frames
 * add more compile notes to help when dependency loops occur
   in determining whether a function is async.
 * ir: change an assert to ir_assert to make it easier to find
   workarounds for when such an assert is triggered. In this case
   it was trying to parse an IPv4 address at comptime.
2019-10-29 22:59:30 -04:00
Andrew Kelley 8d3b7689ad
std.net: port the RFC 3484/6724 destination...
...address selection from musl libc
2019-10-29 16:10:14 -04:00
Andrew Kelley 9ade31faaf
implement CNAME expansion 2019-10-29 14:03:39 -04:00
Andrew Kelley 67058b9b70
basic DNS address resolution for linux without libc 2019-10-29 02:19:22 -04:00
Luna d4e41c5bc6 std: make addr_size parameter be a pointer to socklen_t
removes ptrCast
2019-10-26 22:05:17 -03:00
Luna bf16fc210b fix std.os.accept4
- add WouldBlock to list of errors in AcceptError
 - ptrCast addr_size to the system's socklen_t, instead of assuming it's
    usize
2019-10-26 22:00:50 -03:00
Andrew Kelley 55c282ed51
os.dup2: handle EBAF 2019-10-24 21:13:05 -04:00
Andrew Kelley 60cd11bd4b
get rid of std.os.foo.is_the_target
It had the downside of running all the comptime blocks and resolving
all the usingnamespaces of each system, when just trying to discover if
the current system is a particular one.

For Darwin, where it's nice to use `std.Target.current.isDarwin()`, this
demonstrates the utility that #425 would provide.
2019-10-24 01:14:52 -04:00
Andrew Kelley 8591731f2b
refAllDecls in a test block to limit when it gets run 2019-10-24 00:32:18 -04:00
Andrew Kelley 17eb24a7e4
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
  `@import("std").builtin`. The target-related types are moved
  to `std.Target`. This allows the data types to have methods, such as
  `std.Target.current.isDarwin()`.
 * `std.os.windows.subsystem` is moved to
   `std.Target.current.subsystem`.
 * Remove the concept of the panic package from the compiler
   implementation. Instead, `std.builtin.panic` is always the panic
   function. It checks for `@hasDecl(@import("root"), "panic")`,
   or else provides a default implementation.

This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 19:09:49 -04:00
Andrew Kelley e839250c51
Merge branch 'stratact-no-dir-allocators'
closes #2885
closes #2886
closes #2888
closes #3249
2019-10-21 23:54:29 -04:00
Andrew Kelley a5cc758036
std.os.accept4: improve docs and integrate with evented I/O 2019-10-21 23:23:11 -04:00
Jonathan Marler 87b11617b5 Fix accept function API
The sockaddr pointer and size of the accept function points to a data structure that can only be determined at runtime.  The only requirement is that it must be large enough to hold 2 bytes for the address family value.  Typeical usage of the socket API is for UDP/TCP IPv4 and IPv6 sockets, which use sockaddr_in and sockaddr_in6.  And some sockets can actually support both simultaneously in which case the app may want to have access to the size of the returned sockaddr.  Operating systems can even support custom protocols where they use custom sockaddr data structures.  In this case the standard library would have no knowledge of the actual size of the sockaddr being passed into the accept function.  In this case the standard library should defer to the app to pass in the size of their structure.
2019-10-21 23:12:35 -04:00
Andrew Kelley fc6f84f3f0 fix os.unlinkatW implementation 2019-10-21 20:58:53 -04:00
Andrew Kelley ef67c49785
[wip] use NtDll APIs on Windows to implement std.fs.Dir 2019-10-21 14:18:01 -04:00
Andrew Kelley 5b1a492012
breaking: improve std.fs directory handling API
* Added `std.c.unlinkat` and `std.os.unlinkat`.
 * Removed `std.fs.MAX_BUF_BYTES` (this declaration never made it to
   master branch)
 * Added `std.fs.Dir.deleteTree` to be used on an open directory handle.
 * `std.fs.deleteTree` has better behavior for both relative and
   absolute paths. For absolute paths, it opens the base directory
   and uses that handle for subsequent operations. For relative paths,
   it does a similar strategy, using the cwd handle.
 * The error set of `std.fs.deleteTree` is improved to no longer have
   these possible errors:
   - OutOfMemory
   - FileTooBig
   - IsDir
   - DirNotEmpty
   - PathAlreadyExists
   - NoSpaceLeft
 * Added `std.fs.Dir.posix_cwd` which is a statically initialized
   directory representing the current working directory.
 * The error set of `std.Dir.open` is improved to no longer have these
   possible errors:
   - FileTooBig
   - IsDir
   - NoSpaceLeft
   - PathAlreadyExists
   - OutOfMemory
 * Added more alternative functions to `std.fs` for when the path
   parameter is a null terminated string. This can sometimes be more
   effecient on systems which have an ABI based on  null terminated
   strings.
 * Added `std.fs.Dir.openDir`, `std.fs.Dir.deleteFile`, and
   `std.fs.Dir.deleteDir` which all operate on an open directory handle.
 * `std.fs.Walker.Entry` now has a `dir` field, which can be used to do
   operations directly on `std.fs.Walker.Entry.basename`, avoiding
   `error.NameTooLong` for deeply nested paths.
 * Added more docs to `std.os.OpenError`

This commit does the POSIX components for these changes. I plan to
follow up shortly with a commit for Windows.
2019-10-20 21:48:23 -04:00
Andrew Kelley 8cf3a4d586
[breaking] standardize std.os execve functions
* `std.os.execve` had the wrong name; it should have been
   `std.os.execvpe`. This is now corrected.
 * introduce `std.os.execveC` which does not look at PATH, and uses
   null terminated parameters, matching POSIX ABIs. It does not
   require an allocator.
 * fix typo nonsense doc comment in `std.fs.MAX_PATH_BYTES`.
 * introduce `std.os.execvpeC`, which is like `execvpe` except it
   uses null terminated parameters, matching POSIX ABIs, and thus
   does not require an allocator.
 * `std.os.execvpe` implementation is reworked to only convert
   parameters and then delegate to `std.os.execvpeC`.
 * `std.os.execvpeC` improved to handle `ENOTDIR`. See #3415
2019-10-16 15:24:48 -04:00
Andrew Kelley 6082c14753
generated docs: add optional type support 2019-10-10 20:32:17 -04:00
Alva 0fc97015e2 Correct std.os.connect_async docs 2019-10-09 13:15:39 -04:00
Andrew Kelley e0f0e2aace
generated docs: error sets in fn docs 2019-10-08 18:09:08 -04:00
SamTebbs33 bed4bfa69a Replace code occurences of --override-std-dir with --override-lib-dir 2019-10-01 07:29:24 -04:00
Andrew Kelley dc299166cf
std.os.fstat: EINVAL => unreachable
Related: #3291
2019-09-27 17:17:24 -04:00
Andrew Kelley ed36dbbd9c
mv std/ lib/
that's all this commit does. further commits will fix cli flags and
such.

see #2221
2019-09-25 23:35:41 -04:00