Commit Graph

371 Commits

Author SHA1 Message Date
John Schmidt 63ee6e6625 Rename mem.bswapAllFields to byteSwapAllFields
To match the renaming of `@bswap` to `@byteSwap` in
https://github.com/ziglang/zig/commit/1fdb24827fb51351d5e31103069619668fae31c4.
2022-01-28 21:03:21 -05:00
Mikhail Popov 100b8a244c Add std.mem.minMax() and std.mem.IndexOfMinMax()
For finding the minimum and maximum values (and indices)
in a slice in a single pass.
2022-01-27 21:22:00 +02:00
Mikhail Popov dddbd2f511 std.mem: Add functions to find the index of the mimimum/maximum value in a slice. 2022-01-27 19:58:27 +02:00
Josh Hannaford 178cd60a5e Update the documentation for std.mem.sliceTo for readability 2022-01-26 00:49:17 -05:00
Ali Chraghi 042b770d62 std: Skip comptime struct fields in mem.zeroes() (#10406)
closes #9934
2021-12-27 23:33:11 -05:00
Isaac Freund 9f9f215305 stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
Lee Cannon 066eaa5e9c allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
Lee Cannon f68cda738a allocgate: split free out from resize 2021-11-30 23:32:48 +00:00
Lee Cannon 9377f32c08 allocgate: utilize a *const vtable field 2021-11-30 23:32:48 +00:00
Lee Cannon 80bbf234e0 allocgate: fix failing tests 2021-11-30 23:32:48 +00:00
Lee Cannon 1093b09a98 allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon 47bc13bc59 allocgate: dont use a dummy temporary for stateless allocators 2021-11-30 23:32:47 +00:00
Lee Cannon 85de022c56 allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley 902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Fabio Arnold da7baf7dae std.mem.indexOfPos should return start_index when needle length is zero (#10220)
Closes #10216
2021-11-25 20:56:38 -05:00
Trioct b644d49365 Fix type error for u8 in writeIntSlice 2021-11-21 16:47:39 -05:00
Andrew Kelley 6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Coleman Broaddus e14fcd60cb FIX resize() for non u8 element types. (#9806) 2021-09-22 12:09:16 +03:00
Robin Voetter c5945467ac Address Spaces: Pointer and function info in @Type 2021-09-20 02:29:04 +02:00
jdmichaud 49c9975484 zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
Andrew Kelley d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Ryan Liptak 493822ac3b Update mem.split/mem.tokenize doc comments
Follow up to #9531
2021-08-11 21:19:03 -04:00
Ryan Liptak 05fd20dc10 Make mem.split and mem.tokenize generic instead of assuming u8
This allows these functions to work on slices of u16, etc
2021-08-06 01:53:07 -07:00
Andrew Kelley d979dd9b58 stage2: improve AstGen FileNotFound error message
Partially addresses #9203. It fixes the first case, but not the second
one mentioned in the issue.
2021-07-02 15:27:00 -07:00
Tom Maenan Read Cutting 177b1b6bf9 Add fat/universal dylib support to zig ld
With this change zig ld can link with dynamic libraries
contained within a fat/universal file that had multiple
seperate binaries embedded within it for multi-arch
support (in macOS).

Whilst zig can still only create single-architecture
executables - the ability to link with fat libraries is
useful for cases where they are the easiest (or only)
option to link against.
2021-06-25 08:38:47 +02:00
Jacob G-W 9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Andrew Kelley b973e0a3e3 fix doc comments copy paste typo 2021-06-06 18:05:06 -07:00
LemonBoy 0c091f8b09 std: Add helpers to safely align pointers
Add two helpers to ensure people won't ignore some edge cases such as
pointers overflowing the address space.

Also fix #8924 to some degree, the amount of unchecked alignForward is
still scary.
2021-06-06 18:04:16 -07:00
Kenta Iwasaki 4909aa1da4 os/bits: remove duplicate sockaddr_storage for dragonfly 2021-06-01 18:35:13 +09:00
Kenta Iwasaki 6950e4c294 x/os/net: remove unnecessary comptime prefix in resolveScopeID() 2021-06-01 18:24:43 +09:00
Matthew Borkowski 54f774f796 make writeIntSlice functions work for signed integers 2021-05-28 19:43:58 -04:00
Matthew Borkowski d7bf4f8070 fix Boyer-Moore-Horspool algorithm in indexOfPos and lastIndexOf when element type is larger than a byte 2021-05-22 20:51:17 -04:00
Andrew Kelley 7cd9b30e0a Merge pull request #7664 from marler8997/fixWindowsPaths
implement nt path conversion for windows
2021-05-22 17:58:59 -04:00
Matthew Borkowski f4101c1153 fix accidental quadratic dependence on haystack length in replace and replacementSize (#8859) 2021-05-22 10:55:28 +02:00
Jonathan Marler b0116afd8a handle relative paths with too many ".." 2021-05-21 01:29:40 -06:00
Jonathan Marler a72ad61cd4 have collapseRepeats return slice intead of just len 2021-05-20 14:00:41 -06:00
Jonathan Marler 666584067a implement nt path conversion for windows 2021-05-20 14:00:40 -06:00
Andrew Kelley c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Isaac Freund cd7b5a3718 std/mem: add sliceTo(), deprecate spanZ(), lenZ()
The current spanZ() function will not scan for a 0 terminator if the
type is not 0 terminated. This encourages using 0 terminated array
types to bind C arrays which hold 0 terminated strings. However, this is
a big footgun as nothing in the C type system guarantees there to be a
0 terminator at the end of the array and if there is none this becomes
Illegal Behavior in Zig.

To solve this, deprecate spanZ() and lenZ(), adding a new sliceTo()
function that always scans for the given terminator even if the type is
not sentinel terminated.
2021-05-12 11:24:49 +02:00
Andrew Kelley 5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Veikka Tuominen fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Andrew Kelley df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
jumpnbrownweasel bf67a3fdc9 #8454 Fix for std.mem.replacementSize adjacent matches bug. (#8455)
* #8454 Fix for std.mem.replacementSize adjacent matches bug.

When two 'needle' values are adjacent in the 'input' slice, the size is not
counted correctly. The 2nd 'needle' value is not matched because the index is
incremented by one after changing the index to account for the first value.

The impact is the the size returned is incorrect, and could cause UB when this
amount is used to size of the buffer passed to std.mem.replace.

* Apply changes from PR review:

- Add assert checking that the needle is non-empty and doc for this.
- Add minimal test that an empty input works.
- Use testing.expectEqualStrings.
2021-04-25 19:16:24 -04:00
Andrew Kelley 507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
Andrew Kelley 429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Nuno Leiria 0d96a284e8 std: Add reset to TokenIterator 2021-03-20 22:01:09 -07:00
LemonBoy e47b754b28 std: Prevent null pointer deref in mem.len{,Z}
Closes #8140
2021-03-07 14:58:45 +02:00
Martin Wickham 7613e51a57 Add some bit set variants 2021-03-01 18:52:15 -08:00
root 236db6232f Fix interger overflow when calling joinZ with empty slices 2021-01-27 12:01:18 +02:00
Rohlem c96272f618 std.os.windows.GetFinalPathNameByHandle: remove intermediate buffers
... and mem.copy operations. Requires slightly larger input buffers than result length. Add helper functions std.mem.alignInBytes and std.mem.alignInSlice.
2021-01-11 17:48:19 -07:00