@zigc/lib 0.16.0-dev.3041 → 0.16.0-dev.3061
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/compiler_rt/mulo.zig +6 -1
- package/package.json +1 -1
- package/std/Build/Step/ConfigHeader.zig +4 -0
- package/std/Io/Threaded.zig +151 -119
- package/std/crypto/codecs/base64_hex_ct.zig +12 -2
- package/std/zig/llvm/Builder.zig +107 -48
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Nurul Huda (Apon).
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/compiler_rt/mulo.zig
CHANGED
|
@@ -19,7 +19,12 @@ comptime {
|
|
|
19
19
|
inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
|
|
20
20
|
overflow.* = 0;
|
|
21
21
|
const min = math.minInt(ST);
|
|
22
|
-
const res: ST =
|
|
22
|
+
const res: ST = if (ST == i128 and builtin.target.cpu.arch.isWasm()) res: {
|
|
23
|
+
// Despite compiler-rt being built with `-fno-builtin`, LLVM still converts this function to
|
|
24
|
+
// a call to `__muloti4` on WASM. This is an upstream bug: circumvent it by directly calling
|
|
25
|
+
// the "lower-level" compiler-rt routine for this wrapping multiplication.
|
|
26
|
+
break :res @import("mulXi3.zig").__multi3(a, b);
|
|
27
|
+
} else a *% b;
|
|
23
28
|
// Hacker's Delight section Overflow subsection Multiplication
|
|
24
29
|
// case a=-2^{31}, b=-1 problem, because
|
|
25
30
|
// on some machines a*b = -2^{31} with overflow
|
package/package.json
CHANGED
|
@@ -109,6 +109,10 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
|
|
|
109
109
|
return config_header;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
pub fn addIdent(config_header: *ConfigHeader, name: []const u8, value: []const u8) void {
|
|
113
|
+
config_header.values.put(name, .{ .ident = value }) catch @panic("OOM");
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
pub fn addValue(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) void {
|
|
113
117
|
return addValueInner(config_header, name, T, value) catch @panic("OOM");
|
|
114
118
|
}
|
package/std/Io/Threaded.zig
CHANGED
|
@@ -13482,21 +13482,80 @@ fn netLookupFallible(
|
|
|
13482
13482
|
const name = host_name.bytes;
|
|
13483
13483
|
assert(name.len <= HostName.max_len);
|
|
13484
13484
|
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13485
|
+
// On Linux, glibc provides getaddrinfo_a which is capable of supporting our semantics.
|
|
13486
|
+
// However, musl's POSIX-compliant getaddrinfo is not, so we bypass it.
|
|
13487
|
+
|
|
13488
|
+
if (builtin.target.isGnuLibC()) {
|
|
13489
|
+
// TODO use getaddrinfo_a / gai_cancel
|
|
13490
|
+
}
|
|
13491
|
+
|
|
13492
|
+
if (native_os == .linux or is_windows) {
|
|
13493
|
+
if (IpAddress.parseIp6(name, options.port)) |addr| {
|
|
13494
|
+
if (options.family == .ip4) return error.UnknownHostName;
|
|
13495
|
+
if (copyCanon(options.canonical_name_buffer, name)) |canon| {
|
|
13496
|
+
try resolved.putAll(t_io, &.{
|
|
13497
|
+
.{ .address = addr },
|
|
13498
|
+
.{ .canonical_name = canon },
|
|
13499
|
+
});
|
|
13500
|
+
} else {
|
|
13501
|
+
try resolved.putOne(t_io, .{ .address = addr });
|
|
13502
|
+
}
|
|
13503
|
+
return;
|
|
13504
|
+
} else |_| {}
|
|
13505
|
+
|
|
13506
|
+
if (IpAddress.parseIp4(name, options.port)) |addr| {
|
|
13507
|
+
if (options.family == .ip6) return error.UnknownHostName;
|
|
13508
|
+
if (copyCanon(options.canonical_name_buffer, name)) |canon| {
|
|
13509
|
+
try resolved.putAll(t_io, &.{
|
|
13510
|
+
.{ .address = addr },
|
|
13511
|
+
.{ .canonical_name = canon },
|
|
13512
|
+
});
|
|
13513
|
+
} else {
|
|
13514
|
+
try resolved.putOne(t_io, .{ .address = addr });
|
|
13515
|
+
}
|
|
13516
|
+
return;
|
|
13517
|
+
} else |_| {}
|
|
13518
|
+
|
|
13519
|
+
if (t.lookupHosts(host_name, resolved, options)) return else |err| switch (err) {
|
|
13520
|
+
error.UnknownHostName => {},
|
|
13521
|
+
else => |e| return e,
|
|
13522
|
+
}
|
|
13523
|
+
|
|
13524
|
+
// RFC 6761 Section 6.3.3
|
|
13525
|
+
// Name resolution APIs and libraries SHOULD recognize
|
|
13526
|
+
// localhost names as special and SHOULD always return the IP
|
|
13527
|
+
// loopback address for address queries and negative responses
|
|
13528
|
+
// for all other query types.
|
|
13529
|
+
|
|
13530
|
+
// Check for equal to "localhost(.)" or ends in ".localhost(.)"
|
|
13531
|
+
const localhost = if (name[name.len - 1] == '.') "localhost." else "localhost";
|
|
13532
|
+
if (std.mem.endsWith(u8, name, localhost) and
|
|
13533
|
+
(name.len == localhost.len or name[name.len - localhost.len] == '.'))
|
|
13534
|
+
{
|
|
13535
|
+
var results_buffer: [3]HostName.LookupResult = undefined;
|
|
13536
|
+
var results_index: usize = 0;
|
|
13537
|
+
if (options.family != .ip4) {
|
|
13538
|
+
results_buffer[results_index] = .{ .address = .{ .ip6 = .loopback(options.port) } };
|
|
13539
|
+
results_index += 1;
|
|
13540
|
+
}
|
|
13541
|
+
if (options.family != .ip6) {
|
|
13542
|
+
results_buffer[results_index] = .{ .address = .{ .ip4 = .loopback(options.port) } };
|
|
13543
|
+
results_index += 1;
|
|
13544
|
+
}
|
|
13545
|
+
if (options.canonical_name_buffer) |buf| {
|
|
13546
|
+
const canon_name = "localhost";
|
|
13547
|
+
const canon_name_dest = buf[0..canon_name.len];
|
|
13548
|
+
canon_name_dest.* = canon_name.*;
|
|
13549
|
+
results_buffer[results_index] = .{ .canonical_name = .{ .bytes = canon_name_dest } };
|
|
13550
|
+
results_index += 1;
|
|
13551
|
+
}
|
|
13552
|
+
try resolved.putAll(t_io, results_buffer[0..results_index]);
|
|
13553
|
+
return;
|
|
13498
13554
|
}
|
|
13499
13555
|
|
|
13556
|
+
if (native_os == .linux) return t.lookupDnsSearch(host_name, resolved, options);
|
|
13557
|
+
|
|
13558
|
+
comptime assert(is_windows);
|
|
13500
13559
|
var DnsQueryEx = t.dl.DnsQueryEx.load(.acquire);
|
|
13501
13560
|
//var DnsCancelQuery = t.dl.DnsCancelQuery.load(.acquire);
|
|
13502
13561
|
var DnsFree = t.dl.DnsFree.load(.acquire);
|
|
@@ -13540,6 +13599,7 @@ fn netLookupFallible(
|
|
|
13540
13599
|
else => |status| return windows.unexpectedStatus(status),
|
|
13541
13600
|
}
|
|
13542
13601
|
}
|
|
13602
|
+
try Thread.checkCancel();
|
|
13543
13603
|
const current_thread = Thread.current;
|
|
13544
13604
|
var lookup_dns: LookupDnsWindows = .{
|
|
13545
13605
|
.threaded = t,
|
|
@@ -13562,126 +13622,71 @@ fn netLookupFallible(
|
|
|
13562
13622
|
}
|
|
13563
13623
|
] = 0;
|
|
13564
13624
|
//var cancel_token: windows.DNS.QUERY.CANCEL = undefined;
|
|
13625
|
+
// Workaround various bugs by attempting a synchronous non-wire query first
|
|
13565
13626
|
switch (DnsQueryEx.?(&.{
|
|
13566
13627
|
.Version = 1,
|
|
13567
13628
|
.QueryName = &host_name_w,
|
|
13568
13629
|
.QueryType = if (options.family == .ip4) .A else .AAAA,
|
|
13569
13630
|
.QueryOptions = .{
|
|
13631
|
+
.NO_WIRE_QUERY = true,
|
|
13632
|
+
.NO_HOSTS_FILE = true, // handled above
|
|
13570
13633
|
.ADDRCONFIG = true,
|
|
13571
13634
|
.DUAL_ADDR = options.family == null,
|
|
13572
|
-
.MULTICAST_WAIT = true,
|
|
13573
13635
|
},
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
//&cancel_token,
|
|
13577
|
-
null)) {
|
|
13636
|
+
}, &lookup_dns.results, null)) {
|
|
13637
|
+
.SUCCESS => try lookup_dns.completedFallible(),
|
|
13578
13638
|
// We must wait for the APC routine.
|
|
13579
|
-
.
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
} else switch (status) {
|
|
13639
|
+
.DNS_REQUEST_PENDING => unreachable, // `pQueryCompletionCallback` was `null`
|
|
13640
|
+
.DNS_ERROR_RECORD_DOES_NOT_EXIST => switch (DnsQueryEx.?(&.{
|
|
13641
|
+
.Version = 1,
|
|
13642
|
+
.QueryName = &host_name_w,
|
|
13643
|
+
.QueryType = if (options.family == .ip4) .A else .AAAA,
|
|
13644
|
+
.QueryOptions = .{
|
|
13645
|
+
.NO_HOSTS_FILE = true, // handled above
|
|
13646
|
+
.ADDRCONFIG = true,
|
|
13647
|
+
.DUAL_ADDR = options.family == null,
|
|
13648
|
+
.MULTICAST_WAIT = true,
|
|
13649
|
+
},
|
|
13650
|
+
.pQueryCompletionCallback = if (current_thread) |_| &LookupDnsWindows.completed else null,
|
|
13651
|
+
}, &lookup_dns.results,
|
|
13652
|
+
//&cancel_token,
|
|
13653
|
+
null)) {
|
|
13595
13654
|
.SUCCESS => try lookup_dns.completedFallible(),
|
|
13596
|
-
|
|
13597
|
-
|
|
13655
|
+
// We must wait for the APC routine.
|
|
13656
|
+
.DNS_REQUEST_PENDING => {
|
|
13657
|
+
assert(current_thread != null); // `pQueryCompletionCallback` was `null`
|
|
13658
|
+
while (!@atomicLoad(bool, &lookup_dns.done, .acquire)) {
|
|
13659
|
+
// Once we get here we must not return from the function until the
|
|
13660
|
+
// operation completes, thereby releasing references to `host_name_w`,
|
|
13661
|
+
// `lookup_dns.results`, and `cancel_token`.
|
|
13662
|
+
const alertable_syscall = AlertableSyscall.start() catch |err| switch (err) {
|
|
13663
|
+
error.Canceled => |e| {
|
|
13664
|
+
//_ = DnsCancelQuery.?(&cancel_token);
|
|
13665
|
+
while (!@atomicLoad(bool, &lookup_dns.done, .acquire)) waitForApcOrAlert();
|
|
13666
|
+
return e;
|
|
13667
|
+
},
|
|
13668
|
+
};
|
|
13669
|
+
waitForApcOrAlert();
|
|
13670
|
+
alertable_syscall.finish();
|
|
13671
|
+
}
|
|
13672
|
+
},
|
|
13673
|
+
else => |status| lookup_dns.results.QueryStatus = status,
|
|
13598
13674
|
},
|
|
13599
13675
|
else => |status| lookup_dns.results.QueryStatus = status,
|
|
13600
13676
|
}
|
|
13601
13677
|
switch (lookup_dns.results.QueryStatus) {
|
|
13602
13678
|
.SUCCESS => return,
|
|
13603
13679
|
.DNS_REQUEST_PENDING => unreachable, // already handled
|
|
13604
|
-
.INVALID_NAME,
|
|
13680
|
+
.INVALID_NAME,
|
|
13681
|
+
.DNS_ERROR_RCODE_NAME_ERROR,
|
|
13682
|
+
.DNS_INFO_NO_RECORDS,
|
|
13683
|
+
.DNS_ERROR_INVALID_NAME_CHAR,
|
|
13684
|
+
.DNS_ERROR_RECORD_DOES_NOT_EXIST,
|
|
13685
|
+
=> return error.UnknownHostName,
|
|
13605
13686
|
else => |err| return windows.unexpectedError(err),
|
|
13606
13687
|
}
|
|
13607
13688
|
}
|
|
13608
13689
|
|
|
13609
|
-
// On Linux, glibc provides getaddrinfo_a which is capable of supporting our semantics.
|
|
13610
|
-
// However, musl's POSIX-compliant getaddrinfo is not, so we bypass it.
|
|
13611
|
-
|
|
13612
|
-
if (builtin.target.isGnuLibC()) {
|
|
13613
|
-
// TODO use getaddrinfo_a / gai_cancel
|
|
13614
|
-
}
|
|
13615
|
-
|
|
13616
|
-
if (native_os == .linux) {
|
|
13617
|
-
if (options.family != .ip4) {
|
|
13618
|
-
if (IpAddress.parseIp6(name, options.port)) |addr| {
|
|
13619
|
-
if (copyCanon(options.canonical_name_buffer, name)) |canon| {
|
|
13620
|
-
try resolved.putAll(t_io, &.{
|
|
13621
|
-
.{ .address = addr },
|
|
13622
|
-
.{ .canonical_name = canon },
|
|
13623
|
-
});
|
|
13624
|
-
} else {
|
|
13625
|
-
try resolved.putOne(t_io, .{ .address = addr });
|
|
13626
|
-
}
|
|
13627
|
-
return;
|
|
13628
|
-
} else |_| {}
|
|
13629
|
-
}
|
|
13630
|
-
|
|
13631
|
-
if (options.family != .ip6) {
|
|
13632
|
-
if (IpAddress.parseIp4(name, options.port)) |addr| {
|
|
13633
|
-
if (copyCanon(options.canonical_name_buffer, name)) |canon| {
|
|
13634
|
-
try resolved.putAll(t_io, &.{
|
|
13635
|
-
.{ .address = addr },
|
|
13636
|
-
.{ .canonical_name = canon },
|
|
13637
|
-
});
|
|
13638
|
-
} else {
|
|
13639
|
-
try resolved.putOne(t_io, .{ .address = addr });
|
|
13640
|
-
}
|
|
13641
|
-
return;
|
|
13642
|
-
} else |_| {}
|
|
13643
|
-
}
|
|
13644
|
-
|
|
13645
|
-
t.lookupHosts(host_name, resolved, options) catch |err| switch (err) {
|
|
13646
|
-
error.UnknownHostName => {},
|
|
13647
|
-
else => |e| return e,
|
|
13648
|
-
};
|
|
13649
|
-
|
|
13650
|
-
// RFC 6761 Section 6.3.3
|
|
13651
|
-
// Name resolution APIs and libraries SHOULD recognize
|
|
13652
|
-
// localhost names as special and SHOULD always return the IP
|
|
13653
|
-
// loopback address for address queries and negative responses
|
|
13654
|
-
// for all other query types.
|
|
13655
|
-
|
|
13656
|
-
// Check for equal to "localhost(.)" or ends in ".localhost(.)"
|
|
13657
|
-
const localhost = if (name[name.len - 1] == '.') "localhost." else "localhost";
|
|
13658
|
-
if (std.mem.endsWith(u8, name, localhost) and
|
|
13659
|
-
(name.len == localhost.len or name[name.len - localhost.len] == '.'))
|
|
13660
|
-
{
|
|
13661
|
-
var results_buffer: [3]HostName.LookupResult = undefined;
|
|
13662
|
-
var results_index: usize = 0;
|
|
13663
|
-
if (options.family != .ip4) {
|
|
13664
|
-
results_buffer[results_index] = .{ .address = .{ .ip6 = .loopback(options.port) } };
|
|
13665
|
-
results_index += 1;
|
|
13666
|
-
}
|
|
13667
|
-
if (options.family != .ip6) {
|
|
13668
|
-
results_buffer[results_index] = .{ .address = .{ .ip4 = .loopback(options.port) } };
|
|
13669
|
-
results_index += 1;
|
|
13670
|
-
}
|
|
13671
|
-
if (options.canonical_name_buffer) |buf| {
|
|
13672
|
-
const canon_name = "localhost";
|
|
13673
|
-
const canon_name_dest = buf[0..canon_name.len];
|
|
13674
|
-
canon_name_dest.* = canon_name.*;
|
|
13675
|
-
results_buffer[results_index] = .{ .canonical_name = .{ .bytes = canon_name_dest } };
|
|
13676
|
-
results_index += 1;
|
|
13677
|
-
}
|
|
13678
|
-
try resolved.putAll(t_io, results_buffer[0..results_index]);
|
|
13679
|
-
return;
|
|
13680
|
-
}
|
|
13681
|
-
|
|
13682
|
-
return t.lookupDnsSearch(host_name, resolved, options);
|
|
13683
|
-
}
|
|
13684
|
-
|
|
13685
13690
|
if (native_os == .openbsd) {
|
|
13686
13691
|
// TODO use getaddrinfo_async / asr_abort
|
|
13687
13692
|
}
|
|
@@ -14510,8 +14515,32 @@ fn lookupHosts(
|
|
|
14510
14515
|
resolved: *Io.Queue(HostName.LookupResult),
|
|
14511
14516
|
options: HostName.LookupOptions,
|
|
14512
14517
|
) !void {
|
|
14513
|
-
const
|
|
14514
|
-
|
|
14518
|
+
const path_w = if (is_windows) path_w: {
|
|
14519
|
+
var path_w_buf: [windows.PATH_MAX_WIDE:0]u16 = undefined;
|
|
14520
|
+
const system_dir = windows.getSystemDirectoryWtf16Le();
|
|
14521
|
+
const suffix = [_]u16{
|
|
14522
|
+
'\\', 'd', 'r', 'i', 'v', 'e', 'r', 's', '\\', 'e', 't', 'c', '\\', 'h', 'o', 's', 't', 's',
|
|
14523
|
+
};
|
|
14524
|
+
@memcpy(path_w_buf[0..system_dir.len], system_dir);
|
|
14525
|
+
@memcpy(path_w_buf[system_dir.len..][0..suffix.len], &suffix);
|
|
14526
|
+
path_w_buf[system_dir.len + suffix.len] = 0;
|
|
14527
|
+
break :path_w wToPrefixedFileW(null, &path_w_buf, .{}) catch |err| switch (err) {
|
|
14528
|
+
error.FileNotFound,
|
|
14529
|
+
error.AccessDenied,
|
|
14530
|
+
=> return error.UnknownHostName,
|
|
14531
|
+
|
|
14532
|
+
error.Canceled => |e| return e,
|
|
14533
|
+
|
|
14534
|
+
else => {
|
|
14535
|
+
// Here we could add more detailed diagnostics to the results queue.
|
|
14536
|
+
return error.DetectingNetworkConfigurationFailed;
|
|
14537
|
+
},
|
|
14538
|
+
};
|
|
14539
|
+
};
|
|
14540
|
+
const file = (if (is_windows)
|
|
14541
|
+
dirOpenFileWtf16(null, path_w.span(), .{})
|
|
14542
|
+
else
|
|
14543
|
+
dirOpenFile(t, .cwd(), "/etc/hosts", .{})) catch |err| switch (err) {
|
|
14515
14544
|
error.FileNotFound,
|
|
14516
14545
|
error.NotDir,
|
|
14517
14546
|
error.AccessDenied,
|
|
@@ -14524,10 +14553,10 @@ fn lookupHosts(
|
|
|
14524
14553
|
return error.DetectingNetworkConfigurationFailed;
|
|
14525
14554
|
},
|
|
14526
14555
|
};
|
|
14527
|
-
defer file
|
|
14556
|
+
defer fileClose(t, &.{file});
|
|
14528
14557
|
|
|
14529
14558
|
var line_buf: [512]u8 = undefined;
|
|
14530
|
-
var file_reader = file.reader(
|
|
14559
|
+
var file_reader = file.reader(t.io(), &line_buf);
|
|
14531
14560
|
return t.lookupHostsReader(host_name, resolved, options, &file_reader.interface) catch |err| switch (err) {
|
|
14532
14561
|
error.ReadFailed => switch (file_reader.err.?) {
|
|
14533
14562
|
error.Canceled => |e| return e,
|
|
@@ -14567,14 +14596,17 @@ fn lookupHostsReader(
|
|
|
14567
14596
|
error.EndOfStream => break,
|
|
14568
14597
|
};
|
|
14569
14598
|
reader.toss(@min(1, reader.bufferedLen()));
|
|
14570
|
-
var split_it = std.mem.splitScalar(u8, line,
|
|
14599
|
+
var split_it = std.mem.splitScalar(u8, if (is_windows and std.mem.endsWith(u8, line, "\r"))
|
|
14600
|
+
line[0 .. line.len - 1]
|
|
14601
|
+
else
|
|
14602
|
+
line, '#');
|
|
14571
14603
|
const no_comment_line = split_it.first();
|
|
14572
14604
|
|
|
14573
14605
|
var line_it = std.mem.tokenizeAny(u8, no_comment_line, " \t");
|
|
14574
14606
|
const ip_text = line_it.next() orelse continue;
|
|
14575
14607
|
var first_name_text: ?[]const u8 = null;
|
|
14576
14608
|
while (line_it.next()) |name_text| {
|
|
14577
|
-
if (std.
|
|
14609
|
+
if (std.ascii.eqlIgnoreCase(name_text, host_name.bytes)) {
|
|
14578
14610
|
if (first_name_text == null) first_name_text = name_text;
|
|
14579
14611
|
break;
|
|
14580
14612
|
}
|
|
@@ -304,7 +304,7 @@ pub const base64 = struct {
|
|
|
304
304
|
return (lt(x, 26) & (x +% 'A')) |
|
|
305
305
|
(ge(x, 26) & lt(x, 52) & (x +% 'a' -% 26)) |
|
|
306
306
|
(ge(x, 52) & lt(x, 62) & (x +% '0' -% 52)) |
|
|
307
|
-
(eq(x, 62) & '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
|
|
307
|
+
(eq(x, 62) & if (urlsafe) '-' else '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
fn byteFromChar(c: u8, comptime urlsafe: bool) u8 {
|
|
@@ -312,7 +312,7 @@ pub const base64 = struct {
|
|
|
312
312
|
(ge(c, 'A') & le(c, 'Z') & (c -% 'A')) |
|
|
313
313
|
(ge(c, 'a') & le(c, 'z') & (c -% 'a' +% 26)) |
|
|
314
314
|
(ge(c, '0') & le(c, '9') & (c -% '0' +% 52)) |
|
|
315
|
-
(eq(c, '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
|
|
315
|
+
(eq(c, if (urlsafe) '-' else '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
|
|
316
316
|
return x | (eq(x, 0) & ~eq(c, 'A'));
|
|
317
317
|
}
|
|
318
318
|
|
|
@@ -453,6 +453,16 @@ test "hex with ignored chars" {
|
|
|
453
453
|
try testing.expectEqualSlices(u8, &expected, bin);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
test "base64 urlsafe" {
|
|
457
|
+
const input = [_]u8{ 0xfb, 0xff };
|
|
458
|
+
var enc_buf: [4]u8 = undefined;
|
|
459
|
+
var dec_buf: [2]u8 = undefined;
|
|
460
|
+
const encoded = try base64.encode(&enc_buf, &input, .urlsafe);
|
|
461
|
+
try testing.expectEqualSlices(u8, "-_8=", encoded);
|
|
462
|
+
const decoded = try base64.decode(&dec_buf, encoded, .urlsafe);
|
|
463
|
+
try testing.expectEqualSlices(u8, &input, decoded);
|
|
464
|
+
}
|
|
465
|
+
|
|
456
466
|
test "base64 with ignored chars" {
|
|
457
467
|
const encoded = "dGVzdCBi\r\nYXNlNjQ=\n";
|
|
458
468
|
const expected = "test base64";
|
package/std/zig/llvm/Builder.zig
CHANGED
|
@@ -2343,12 +2343,13 @@ pub const Global = struct {
|
|
|
2343
2343
|
none = maxInt(u32),
|
|
2344
2344
|
_,
|
|
2345
2345
|
|
|
2346
|
-
pub fn unwrap(
|
|
2347
|
-
var cur =
|
|
2346
|
+
pub fn unwrap(orig_index: Index, builder: *const Builder) Index {
|
|
2347
|
+
var cur = orig_index;
|
|
2348
2348
|
while (true) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2349
|
+
switch (builder.globals.values()[@intFromEnum(cur)].kind) {
|
|
2350
|
+
.replaced => |replacement| cur = replacement,
|
|
2351
|
+
else => return cur,
|
|
2352
|
+
}
|
|
2352
2353
|
}
|
|
2353
2354
|
}
|
|
2354
2355
|
|
|
@@ -2388,8 +2389,12 @@ pub const Global = struct {
|
|
|
2388
2389
|
return self.ptrConst(builder).type;
|
|
2389
2390
|
}
|
|
2390
2391
|
|
|
2391
|
-
pub fn toConst(
|
|
2392
|
-
return @enumFromInt(@intFromEnum(Constant.first_global) + @intFromEnum(
|
|
2392
|
+
pub fn toConst(global: Index) Constant {
|
|
2393
|
+
return @enumFromInt(@intFromEnum(Constant.first_global) + @intFromEnum(global));
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
pub fn toValue(global: Index) Value {
|
|
2397
|
+
return global.toConst().toValue();
|
|
2393
2398
|
}
|
|
2394
2399
|
|
|
2395
2400
|
pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
|
|
@@ -2450,6 +2455,42 @@ pub const Global = struct {
|
|
|
2450
2455
|
self.ptr(builder).kind = .{ .replaced = .none };
|
|
2451
2456
|
}
|
|
2452
2457
|
|
|
2458
|
+
/// Replaces whatever this `Global` currently contains with a new `Function`. Similar to
|
|
2459
|
+
/// `Builder.addFunction`, but the same `Global` is reused.
|
|
2460
|
+
pub fn toNewFunction(global: Index, builder: *Builder) Allocator.Error!Function.Index {
|
|
2461
|
+
try builder.functions.ensureUnusedCapacity(builder.gpa, 1);
|
|
2462
|
+
errdefer comptime unreachable;
|
|
2463
|
+
const function: Function.Index = @enumFromInt(builder.functions.items.len);
|
|
2464
|
+
builder.functions.appendAssumeCapacity(.{
|
|
2465
|
+
.global = global,
|
|
2466
|
+
.strip = undefined,
|
|
2467
|
+
});
|
|
2468
|
+
global.ptr(builder).kind = .{ .function = function };
|
|
2469
|
+
return function;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/// Replaces whatever this `Global` currently contains with a new `Variable`. Similar to
|
|
2473
|
+
/// `Builder.addVariable`, but the same `Global` is reused.
|
|
2474
|
+
pub fn toNewVariable(global: Index, builder: *Builder) Allocator.Error!Variable.Index {
|
|
2475
|
+
try builder.variables.ensureUnusedCapacity(builder.gpa, 1);
|
|
2476
|
+
errdefer comptime unreachable;
|
|
2477
|
+
const variable: Variable.Index = @enumFromInt(builder.variables.items.len);
|
|
2478
|
+
builder.variables.appendAssumeCapacity(.{ .global = global });
|
|
2479
|
+
global.ptr(builder).kind = .{ .variable = variable };
|
|
2480
|
+
return variable;
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
/// Replaces whatever this `Global` currently contains with a new `Alias`. Similar to
|
|
2484
|
+
/// `Builder.addAlias`, but the same `Global` is reused.
|
|
2485
|
+
pub fn toNewAlias(global: Index, builder: *Builder) Allocator.Error!Alias.Index {
|
|
2486
|
+
try builder.aliases.ensureUnusedCapacity(builder.gpa, 1);
|
|
2487
|
+
errdefer comptime unreachable;
|
|
2488
|
+
const alias: Alias.Index = @enumFromInt(builder.aliases.items.len);
|
|
2489
|
+
builder.aliass.appendAssumeCapacity(.{ .global = global, .aliasee = .none });
|
|
2490
|
+
global.ptr(builder).kind = .{ .alias = alias };
|
|
2491
|
+
return alias;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2453
2494
|
fn updateDsoLocal(self: Index, builder: *Builder) void {
|
|
2454
2495
|
const self_ptr = self.ptr(builder);
|
|
2455
2496
|
switch (self_ptr.linkage) {
|
|
@@ -2494,13 +2535,6 @@ pub const Global = struct {
|
|
|
2494
2535
|
self.renameAssumeCapacity(builder.next_replaced_global, builder);
|
|
2495
2536
|
self.ptr(builder).kind = .{ .replaced = other.unwrap(builder) };
|
|
2496
2537
|
}
|
|
2497
|
-
|
|
2498
|
-
fn getReplacement(self: Index, builder: *const Builder) Index {
|
|
2499
|
-
return switch (builder.globals.values()[@intFromEnum(self)].kind) {
|
|
2500
|
-
.replaced => |replacement| replacement,
|
|
2501
|
-
else => .none,
|
|
2502
|
-
};
|
|
2503
|
-
}
|
|
2504
2538
|
};
|
|
2505
2539
|
};
|
|
2506
2540
|
|
|
@@ -2593,22 +2627,6 @@ pub const Variable = struct {
|
|
|
2593
2627
|
return self.toConst(builder).toValue();
|
|
2594
2628
|
}
|
|
2595
2629
|
|
|
2596
|
-
pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
|
|
2597
|
-
return self.ptrConst(builder).global.setLinkage(linkage, builder);
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2600
|
-
pub fn setVisibility(self: Index, visibility: Visibility, builder: *Builder) void {
|
|
2601
|
-
return self.ptrConst(builder).global.setVisibility(visibility, builder);
|
|
2602
|
-
}
|
|
2603
|
-
|
|
2604
|
-
pub fn setDllStorageClass(self: Index, class: DllStorageClass, builder: *Builder) void {
|
|
2605
|
-
return self.ptrConst(builder).global.setDllStorageClass(class, builder);
|
|
2606
|
-
}
|
|
2607
|
-
|
|
2608
|
-
pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void {
|
|
2609
|
-
return self.ptrConst(builder).global.setUnnamedAddr(unnamed_addr, builder);
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
2630
|
pub fn setThreadLocal(self: Index, thread_local: ThreadLocal, builder: *Builder) void {
|
|
2613
2631
|
self.ptr(builder).thread_local = thread_local;
|
|
2614
2632
|
}
|
|
@@ -9692,8 +9710,12 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9692
9710
|
|
|
9693
9711
|
if (self.variables.items.len > 0) {
|
|
9694
9712
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9695
|
-
for (self.variables.items) |variable| {
|
|
9696
|
-
if
|
|
9713
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
9714
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
9715
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
9716
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
9717
|
+
else => continue,
|
|
9718
|
+
}
|
|
9697
9719
|
const global = variable.global.ptrConst(self);
|
|
9698
9720
|
metadata_formatter.need_comma = true;
|
|
9699
9721
|
defer metadata_formatter.need_comma = undefined;
|
|
@@ -9723,8 +9745,12 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9723
9745
|
|
|
9724
9746
|
if (self.aliases.items.len > 0) {
|
|
9725
9747
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9726
|
-
for (self.aliases.items) |alias| {
|
|
9727
|
-
if
|
|
9748
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
9749
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
9750
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
9751
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
9752
|
+
else => continue,
|
|
9753
|
+
}
|
|
9728
9754
|
const global = alias.global.ptrConst(self);
|
|
9729
9755
|
metadata_formatter.need_comma = true;
|
|
9730
9756
|
defer metadata_formatter.need_comma = undefined;
|
|
@@ -9750,7 +9776,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9750
9776
|
defer attribute_groups.deinit(self.gpa);
|
|
9751
9777
|
|
|
9752
9778
|
for (0.., self.functions.items) |function_i, function| {
|
|
9753
|
-
if
|
|
9779
|
+
// Skip the function if its global has been repurposed for something else.
|
|
9780
|
+
switch (function.global.ptrConst(self).kind) {
|
|
9781
|
+
.function => |f| if (@intFromEnum(f) != function_i) continue,
|
|
9782
|
+
else => continue,
|
|
9783
|
+
}
|
|
9754
9784
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9755
9785
|
const function_index: Function.Index = @enumFromInt(function_i);
|
|
9756
9786
|
const global = function.global.ptrConst(self);
|
|
@@ -13687,20 +13717,32 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13687
13717
|
self.aliases.items.len,
|
|
13688
13718
|
);
|
|
13689
13719
|
|
|
13690
|
-
for (self.variables.items) |variable| {
|
|
13691
|
-
if
|
|
13720
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
13721
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
13722
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
13723
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
13724
|
+
else => continue,
|
|
13725
|
+
}
|
|
13692
13726
|
|
|
13693
13727
|
globals.putAssumeCapacity(variable.global, {});
|
|
13694
13728
|
}
|
|
13695
13729
|
|
|
13696
|
-
for (self.functions.items) |function| {
|
|
13697
|
-
if
|
|
13730
|
+
for (self.functions.items, 0..) |function, function_i| {
|
|
13731
|
+
// Skip the function if its global has been repurposed for something else.
|
|
13732
|
+
switch (function.global.ptrConst(self).kind) {
|
|
13733
|
+
.function => |f| if (@intFromEnum(f) != function_i) continue,
|
|
13734
|
+
else => continue,
|
|
13735
|
+
}
|
|
13698
13736
|
|
|
13699
13737
|
globals.putAssumeCapacity(function.global, {});
|
|
13700
13738
|
}
|
|
13701
13739
|
|
|
13702
|
-
for (self.aliases.items) |alias| {
|
|
13703
|
-
if
|
|
13740
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
13741
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
13742
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
13743
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
13744
|
+
else => continue,
|
|
13745
|
+
}
|
|
13704
13746
|
|
|
13705
13747
|
globals.putAssumeCapacity(alias.global, {});
|
|
13706
13748
|
}
|
|
@@ -13742,8 +13784,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13742
13784
|
defer section_map.deinit(self.gpa);
|
|
13743
13785
|
try section_map.ensureUnusedCapacity(self.gpa, globals.count());
|
|
13744
13786
|
|
|
13745
|
-
for (self.variables.items) |variable| {
|
|
13746
|
-
if
|
|
13787
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
13788
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
13789
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
13790
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
13791
|
+
else => continue,
|
|
13792
|
+
}
|
|
13747
13793
|
|
|
13748
13794
|
const section = blk: {
|
|
13749
13795
|
if (variable.section == .none) break :blk 0;
|
|
@@ -13789,8 +13835,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13789
13835
|
});
|
|
13790
13836
|
}
|
|
13791
13837
|
|
|
13792
|
-
for (self.functions.items) |func| {
|
|
13793
|
-
if
|
|
13838
|
+
for (self.functions.items, 0..) |func, func_i| {
|
|
13839
|
+
// Skip the function if its global has been repurposed for something else.
|
|
13840
|
+
switch (func.global.ptrConst(self).kind) {
|
|
13841
|
+
.function => |f| if (@intFromEnum(f) != func_i) continue,
|
|
13842
|
+
else => continue,
|
|
13843
|
+
}
|
|
13794
13844
|
|
|
13795
13845
|
const section = blk: {
|
|
13796
13846
|
if (func.section == .none) break :blk 0;
|
|
@@ -13830,8 +13880,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13830
13880
|
});
|
|
13831
13881
|
}
|
|
13832
13882
|
|
|
13833
|
-
for (self.aliases.items) |alias| {
|
|
13834
|
-
if
|
|
13883
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
13884
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
13885
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
13886
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
13887
|
+
else => continue,
|
|
13888
|
+
}
|
|
13835
13889
|
|
|
13836
13890
|
const strtab = alias.global.strtab(self);
|
|
13837
13891
|
|
|
@@ -14635,8 +14689,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
14635
14689
|
};
|
|
14636
14690
|
|
|
14637
14691
|
for (self.functions.items, 0..) |func, func_index| {
|
|
14692
|
+
// Skip the function if its global has been repurposed for something else.
|
|
14693
|
+
switch (func.global.ptrConst(self).kind) {
|
|
14694
|
+
.function => |f| if (@intFromEnum(f) != func_index) continue,
|
|
14695
|
+
else => continue,
|
|
14696
|
+
}
|
|
14697
|
+
|
|
14638
14698
|
const FunctionBlock = ir.ModuleBlock.FunctionBlock;
|
|
14639
|
-
if (func.global.getReplacement(self) != .none) continue;
|
|
14640
14699
|
|
|
14641
14700
|
if (func.instructions.len == 0) continue;
|
|
14642
14701
|
|