Commit Graph

1913 Commits (0a9672fb86b84658f8780f57e769be45e41f3034)

Author SHA1 Message Date
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 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 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
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
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