49 Commits

Author SHA1 Message Date
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
Vexu
538d9a5dd8
remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Bas van den Berg
f7aa4f5280 Processed review comments. Updated documentation, used the typinfo for field access, generate compile error on allowzero and set C poitners to null 2020-02-24 22:15:04 +01:00
Bas van den Berg
195195d238 vectors do not support iterating, do not support them (for now) 2020-02-24 20:50:51 +01:00
Bas van den Berg
0972b2a8fe implement zeroes for non extern structs and native types 2020-02-24 20:38:33 +01:00
xackus
7664c3bc11 remove @bytesToSlice, @sliceToBytes from tests, docs 2020-02-23 18:03:50 +01:00
xackus
783e8ad031 remove @bytesToSlice, @sliceToBytes from std lib 2020-02-21 19:46:53 +01:00
xackus
fdae5f5a07 implement bytesAsSlice, sliceAsBytes 2020-02-21 19:40:29 +01:00
Andrew Kelley
4b02a39aa9
self-hosted libc detection
* libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
2020-02-16 13:25:30 -05:00
daurnimator
6ea6d5a4bd
std: use testing.allocator in tests 2020-02-14 19:15:09 +11:00
Andrew Kelley
3b622f4494
fix off-by-one error in std.unicode.utf8ToUtf16LeWithNull
and fix larger-than-one-byte sentinels when being freed

Thank you to João Pedro for identifying both problems and
providing example code to solve them.

closes #4413
2020-02-09 14:56:19 -05:00
daurnimator
5cc4932461
std: allocator interface sets freed memory to undefined 2020-01-21 03:17:40 +11:00
Timon Kruiper
0deab8fd3b Add std.mem.zeroes to the standard library
This zero initializes the type passed in. Can be used to zero
initialize c structs.
2020-01-06 19:24:17 -05:00
Andrew Kelley
5575e2a168
std.mem.compare: breaking API changes
* `std.mem.Compare` is now `std.math.Order` and the enum tags
   renamed to follow new style convention.
 * `std.mem.compare` is renamed to `std.mem.order`.
 * new function `std.math.order`
2020-01-01 18:08:40 -05:00
Andrew Kelley
8918cb06fc
sentinel slicing improvements
* add runtime safety for slicing pointers, arrays, and slices.
 * slicing without a sentinel value results in non-sentineled slice
 * improved `std.debug.panic` handling of panic-during-panic
2019-12-20 18:28:59 -05:00
Andrew Kelley
26f3c2d061
fix std.mem.addNullByte and implement sentinel slicing
see #3770
2019-12-20 18:28:56 -05:00
Robin Voetter
4b4fbe3887
Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Andrew Kelley
bf3ac66150
remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
   many (trivial) edits to Zig source code. Array values no longer
   coerced to slices; however one may use `&` to obtain a reference to
   an array value, which may then be coerced to a slice.

 * Adds `IrInstruction::dump`, for debugging purposes. It's useful to
   call to inspect the instruction when debugging Zig IR.

 * Fixes bugs with result location semantics. See the new behavior test
   cases, and compile error test cases.

 * Fixes bugs with `@typeInfo` not properly resolving const values.

 * Behavior tests are passing but std lib tests are not yet. There
   is more work to do before merging this branch.
2019-11-27 03:37:50 -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
7597735bad
update the stage1 implementation to the new proposal
See #3731
2019-11-23 04:45:35 -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
Andrew Kelley
e0db54e89d
update the codebase to use @as 2019-11-08 15:57:24 -05:00
Andrew Kelley
6ee3cabe5c
allow type coercion from *[0]T to E![]const T
This is an unambiguous, safe cast.
2019-11-06 20:44:15 -05: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
Nathan Michaels
6fdeaac338 Add some documentation for standard library things. (#3540)
* Add some documentation for standard library things.

Added a bunch of descriptions for array_list.
Added some usage notes for failing_allocator.
Documented some of mem.Allocator.
2019-10-28 03:57:23 -04:00
Emeka Nkurumeh
700bb19a90 fix std.mem.AsBytesReturnType (#3442)
closes #3334
2019-10-16 18:15:52 -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