Commit Graph

227 Commits

Author SHA1 Message Date
r00ster91 2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Andrew Kelley 629f0d23b5 Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
Ali Chraghi 3db3cf7790 std.sort: add pdqsort and heapsort 2023-05-23 17:55:59 -07:00
Ryan Liptak 2129f28953 Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
2023-05-13 13:45:05 -07:00
Ryan Liptak 815e53b147 Update all std.mem.tokenize calls to their appropriate function
Everywhere that can now use `tokenizeScalar` should get a nice little performance boost.
2023-05-13 13:45:04 -07:00
dweiller bd3360e03d convert s[start..start+len] to s[start..][0..len] 2023-05-07 15:55:21 +10:00
Andrew Kelley 125221cce9 std: update to use @memcpy directly 2023-04-28 13:24:43 -07:00
Andrew Kelley 6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Andrew Kelley a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
Jon 529064856a std.net.StreamServer.Options: add reuse_port 2023-04-24 12:23:22 +03:00
hequn f56f3c5824 Enable IPv4 mapped address conversion in linux version getAddressList (#14916)
It seems like the original code of setsockopt is not effective because
i catch the EINVAL branch when uncomment this code, it should call
setsockopt before the bind call.

This should fix issue #14900.

Co-authored-by: Qun He <hawkbee@qq.com>
2023-03-17 15:58:02 -04:00
Nameless 0a4130f364 std.http: handle relative redirects 2023-03-09 14:55:13 -06:00
Nameless 8d86194b6e add error sets to tcpConnect* and tls.Client.init 2023-03-09 14:54:26 -06:00
Andrew Kelley aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Isaac Freund 186e805838 std.net.Address: clarify unix socket getOsSockLen 2023-01-23 14:49:06 +01:00
Isaac Freund faf2fd18d3 std: eliminate pointless meta.assumeSentinel() usage
This fixes a bug in std.net caused during the introduction of
meta.assumeSentinel due to the unfortunate semantics of mem.span()

This leaves only 3 remaining uses of meta.assumeSentinel() in the
standard library, each of which could be a simple @ptrCast([*:0]T, foo)
instead. I think this function should likely be removed.
2023-01-23 12:19:53 +01:00
Jarred Sumner a9eb463202 Make res nullable in getaddrinfo 2023-01-19 23:08:15 +02:00
Andrew Kelley 86308ba1e1 std.net.getAddressList: call WSAStartup on Windows 2023-01-17 00:08:42 -07:00
praschke 3ab43988c1 std.net: check for localhost names before asking DNS
the old implementation asks DNS before checking if it shouldn't.
additionally, it did not catch absolute 'localhost.' names.
2023-01-10 18:09:07 -05:00
Andrew Kelley e4a9b19a14 std.crypto.tls.Client: rework the read function
Here's what I landed on for the TLS client. It's 16896 bytes
(max_ciphertext_record_len is 16640). I believe this is the theoretical
minimum size, give or take a few bytes.

These constraints are satisfied:
 * a call to the readvAdvanced() function makes at most one call to the
   underlying readv function
 * iovecs are provided by the API, and used by the implementation for
   underlying readv() calls to the socket
 * the theoretical minimum number of memcpy() calls are issued in all
   circumstances
 * decryption is only performed once for any given TLS record
 * large read buffers are fully exploited

This is accomplished by using the partial read buffer to storing both
cleartext and ciphertext.
2023-01-02 16:57:16 -07:00
Andrew Kelley 940d368e7e std.crypto.tls.Client: fix the read function
The read function has been renamed to readAdvanced since it has slightly
different semantics than typical read functions, specifically regarding
the end-of-file. A higher level read function is implemented on top.

Now, API users may pass small buffers to the read function and
everything will work fine. This is done by re-decrypting the same
ciphertext record with each call to read() until the record is finished
being transmitted.

If the buffer supplied to read() is large enough, then any given
ciphertext record will only be decrypted once, since it decrypts
directly to the read() buffer and therefore does not need any memcpy. On
the other hand, if the buffer supplied to read() is small, then the
ciphertext is decrypted into a stack buffer, a subset is copied to the
read() buffer, and then the entire ciphertext record is saved for the
next call to read().
2023-01-02 16:57:16 -07:00
Andrew Kelley 920e5bc4ff std.crypto.Tls: discard ChangeCipherSpec messages
The next step here is to decrypt encrypted records
2023-01-02 16:57:15 -07:00
Andrew Kelley d2f5d0b199 std.crypto.Tls: parse the ServerHello handshake 2023-01-02 16:57:15 -07:00
Andrew Kelley ba44513c2f std.http reorg; introduce std.crypto.Tls
TLS is capable of sending a Client Hello
2023-01-02 16:57:15 -07:00
Veikka Tuominen 622311fb9a update uses of overflow arithmetic builtins 2022-12-27 15:13:14 +02:00
r00ster91 6b7d9b34e8 api(std.ascii): remove deprecated decls 2022-12-09 21:57:17 +01:00
Andrew Kelley ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Nick Cernis 8a5818535b Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)
* Export invalidFmtErr

To allow consistent use of "invalid format string" compile error
response for badly formatted format strings.

See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340.

* Replace format compile errors with invalidFmtErr

- Provides more consistent compile errors.
- Gives user info about the type of the badly formated value.

* Rename invalidFmtErr as invalidFmtError

For consistency. Zig seems to use “Error” more often than “Err”.

* std: add invalid format string checks to remaining custom formatters

* pass reference-trace to comp when building build file; fix checkobjectstep
2022-11-12 21:03:24 +02:00
r00ster cff5d9c805 std.mem: add first method to SplitIterator and SplitBackwardsIterator 2022-07-25 22:04:30 +03:00
Veikka Touminen 819c868bbf std.net.getAddressList: fix segfault on bad hostname
Fixes #12065
2022-07-23 13:54:24 +03:00
Veikka Tuominen 413577c881 std: adjust for stage2 semantics 2022-06-07 21:27:07 +03:00
Veikka Tuominen 6d44c0a16c std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
Jakub Konka ba0f72363a Merge pull request #10576 from schmee/macos-resolve-ip
Use libc if_nametoindex for macOS when parsing IPs
2022-01-15 00:47:12 +01:00
John Schmidt c992164dc7 Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
bryfry 0d45c72d3e Use allocPrintZ to avoid needing assumeSentinel 2022-01-14 00:17:38 -05:00
John Schmidt 66fe5bb0d8 Use libc if_nametoindex if available when parsing IPs
Fixes https://github.com/ziglang/zig/issues/10521 and makes a couple of
additional tests pass when linking libc.
2022-01-12 19:32:46 +01:00
Ali Chraghi 005e869abd update function name in error 2021-12-02 12:35:17 -08:00
Lee Cannon 1093b09a98 allocgate: renamed getAllocator function to allocator 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
Andrew Kelley 6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Kirjastonhoitaja e1bf350b4d net.Address: Fix writing 0-bytes when formatting Unix addresses
The entire 'path' array would get written to the formatting function,
when it should instead be treated as a regular zero-terminated string.

Note that this doesn't handle abstract paths on Linux, those paths
*start* with a \0 byte and are hence treated as empty strings instead.
But fixing that would require more adjustments than just formatting, in
particular to getOsSockLen().
2021-09-16 11:35:12 +02:00
Andrew Kelley 7f03cfe161 std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc
 * stage2 is building from source on x86_64-linux
 * down to 38 remaining uses of `usingnamespace`
2021-09-01 17:54:06 -07: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
Frank Denis 2ccd023c6a Ip4Address parser: reject 0-prefixed components (#9538)
Some parsers interpret these as octal, some don't, and the confusion can lead to vulnerabilities.

Return error.NonCanonical when parsing IPv4 addresses with 0 prefixes.
2021-08-09 22:44:23 +02:00
Ryan Liptak d31352ee85 Update all usages of mem.split/mem.tokenize for generic version 2021-08-06 02:01:47 -07:00
Jacob G-W 9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Andrew Kelley 83677074f9 std: update regarding std.builtin reorganization
There are also some regressed std.fmt tests here and I haven't figured
out what's wrong yet.
2021-05-17 16:08:09 -07:00
Andrew Kelley 429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Benjamin Graf c70832bc41 replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00