@zigc/lib 0.17.0-dev.690 → 0.17.0-dev.704

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.
@@ -350,6 +350,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
350
350
  \\ disallowed Panics when cache would be poisoned
351
351
  \\ ignored A little poison never hurt anybody
352
352
  \\ --print-configuration Render configuration as .zon to stdout
353
+ \\ --print-configuration-path Print the path to the binary configuration file to stdout
353
354
  \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
354
355
  \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
355
356
  \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
@@ -1843,10 +1843,10 @@ pub fn relativePath(maker: *const Maker, arena: Allocator, relative: Configurati
1843
1843
  .root_dir = graph.zig_lib_directory,
1844
1844
  .sub_path = sub_path,
1845
1845
  },
1846
- .install_prefix => maker.install_paths.prefix,
1847
- .install_lib => maker.install_paths.lib,
1848
- .install_bin => maker.install_paths.bin,
1849
- .install_include => maker.install_paths.include,
1846
+ .install_prefix => try maker.install_paths.prefix.join(arena, sub_path),
1847
+ .install_lib => try maker.install_paths.lib.join(arena, sub_path),
1848
+ .install_bin => try maker.install_paths.bin.join(arena, sub_path),
1849
+ .install_include => try maker.install_paths.include.join(arena, sub_path),
1850
1850
  };
1851
1851
  }
1852
1852
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zigc/lib",
3
- "version": "0.17.0-dev.690",
3
+ "version": "0.17.0-dev.704",
4
4
  "description": "Zig standard library and libc headers (shared across all platforms)",
5
5
  "repository": {
6
6
  "type": "git",
package/std/Io/Reader.zig CHANGED
@@ -226,10 +226,16 @@ pub fn streamExact64(r: *Reader, w: *Writer, n: u64) StreamError!void {
226
226
 
227
227
  /// "Pump" exactly `n` bytes from the reader to the writer.
228
228
  ///
229
- /// When draining `w`, ensures that at least `preserve_len` bytes remain
230
- /// buffered.
231
- ///
232
- /// Asserts `Writer.buffer` capacity exceeds `preserve_len`.
229
+ /// On success, at least `preserve_len` bytes will remain buffered if there are
230
+ /// enough buffered bytes to do so.
231
+ /// The amount buffered by the writer after the call will only be less than
232
+ /// `preserve_len` if `w.end + n` is less than `preserve_len` before the call.
233
+ /// The intentionally preserved bytes will include up to `preserve_len -| n` bytes from
234
+ /// the previously buffered bytes, plus `@min(n, preserve_len)` of the newly
235
+ /// "pumped" bytes.
236
+ ///
237
+ /// Asserts `Writer.buffer` capacity is at least `preserve_len`.
238
+ /// `n` can be greater than the `Writer.buffer` capacity.
233
239
  pub fn streamExactPreserve(r: *Reader, w: *Writer, preserve_len: usize, n: usize) StreamError!void {
234
240
  if (w.end + n <= w.buffer.len) {
235
241
  @branchHint(.likely);
@@ -242,11 +248,10 @@ pub fn streamExactPreserve(r: *Reader, w: *Writer, preserve_len: usize, n: usize
242
248
  remaining -= try r.stream(w, .limited(remaining - preserve_len));
243
249
  if (w.end + remaining <= w.buffer.len) return streamExact(r, w, remaining);
244
250
  }
245
- // All the next bytes received must be preserved.
246
- if (preserve_len < w.end) {
247
- @memmove(w.buffer[0..preserve_len], w.buffer[w.end - preserve_len ..][0..preserve_len]);
248
- w.end = preserve_len;
249
- }
251
+ // Offset the amount preserved by the amount we have left to stream
252
+ // since the remaining bytes are always going to be part of that
253
+ // preservation.
254
+ try w.rebase(preserve_len -| remaining, remaining);
250
255
  return streamExact(r, w, remaining);
251
256
  }
252
257
 
@@ -2300,6 +2305,50 @@ fn testLeb128(comptime T: type, encoded: []const u8) !T {
2300
2305
  return result;
2301
2306
  }
2302
2307
 
2308
+ test streamExactPreserve {
2309
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 5, .stream_len = 5 });
2310
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 9, .preserve = 5, .stream_len = 2 });
2311
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 5, .stream_len = 6 });
2312
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 6, .stream_len = 6 });
2313
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 5, .stream_len = 10 });
2314
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 6, .stream_len = 10 });
2315
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 6, .stream_len = 11 });
2316
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 6, .stream_len = 80 });
2317
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 6, .stream_len = 85 });
2318
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 10, .stream_len = 6 });
2319
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 10, .stream_len = 11 });
2320
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 10, .stream_len = 80 });
2321
+ try testStreamExactPreserve(.{ .buf_len = 10, .fill_len = 5, .preserve = 10, .stream_len = 85 });
2322
+ }
2323
+
2324
+ fn testStreamExactPreserve(options: struct { buf_len: u4, fill_len: u4, preserve: u4, stream_len: u8 }) !void {
2325
+ assert(options.fill_len <= options.buf_len);
2326
+ assert(options.preserve <= options.buf_len);
2327
+
2328
+ var input: [256]u8 = undefined;
2329
+ for (&input, 0..) |*val, i| {
2330
+ val.* = @as(u8, @intCast(i % 26)) + 'a';
2331
+ }
2332
+ const expected_out = input[0 .. options.fill_len + options.stream_len];
2333
+ const expected_preserved = expected_out[expected_out.len -| options.preserve..];
2334
+
2335
+ var r: Reader = .fixed(&input);
2336
+ var out_buf: [256]u8 = undefined;
2337
+ var fw: Writer = .fixed(&out_buf);
2338
+ var indirect_buffer: [16]u8 = undefined;
2339
+ var twi: std.testing.WriterIndirect = .init(&fw, indirect_buffer[0..options.buf_len]);
2340
+ const w = &twi.interface;
2341
+
2342
+ try r.streamExact(w, options.fill_len);
2343
+ try r.streamExactPreserve(w, options.preserve, options.stream_len);
2344
+
2345
+ try std.testing.expectEqualStrings(expected_preserved, w.buffer[w.end -| options.preserve..w.end]);
2346
+
2347
+ try w.flush();
2348
+
2349
+ try std.testing.expectEqualStrings(expected_out, fw.buffered());
2350
+ }
2351
+
2303
2352
  test {
2304
2353
  _ = Limited;
2305
2354
  }
package/std/Io/Writer.zig CHANGED
@@ -417,7 +417,8 @@ pub fn writableSliceGreedyPreserve(w: *Writer, preserve: usize, minimum_len: usi
417
417
  return w.buffer[w.end..];
418
418
  }
419
419
 
420
- /// Asserts the provided buffer has total capacity enough for `len`.
420
+ /// Asserts the provided buffer has total capacity enough for `len`
421
+ /// and `preserve` combined.
421
422
  ///
422
423
  /// Advances the buffer end position by `len`.
423
424
  ///
@@ -755,8 +756,14 @@ pub fn writeByte(w: *Writer, byte: u8) Error!void {
755
756
  }
756
757
  }
757
758
 
758
- /// When draining the buffer, ensures that at least `preserve` bytes
759
- /// remain buffered.
759
+ /// On success, at least `preserve` bytes will remain buffered if there are
760
+ /// enough buffered bytes to do so.
761
+ /// The amount buffered by the writer after the call will only be less than
762
+ /// `preserve` if `w.end + 1` is less than `preserve` before the call.
763
+ /// The intentionally preserved bytes will include up to `preserve -| 1` bytes from
764
+ /// the previously buffered bytes, plus the newly written byte.
765
+ ///
766
+ /// Asserts buffer capacity is at least `preserve`.
760
767
  pub fn writeBytePreserve(w: *Writer, preserve: usize, byte: u8) Error!void {
761
768
  if (w.buffer.len - w.end != 0) {
762
769
  @branchHint(.likely);
@@ -784,6 +791,19 @@ test splatByteAll {
784
791
  try testing.expectEqualStrings(&@as([45]u8, @splat('7')), aw.writer.buffered());
785
792
  }
786
793
 
794
+ /// Writes the same byte many times, performing the underlying write call as
795
+ /// many times as necessary.
796
+ ///
797
+ /// On success, at least `preserve` bytes will remain buffered if there are
798
+ /// enough buffered bytes to do so.
799
+ /// The amount buffered by the writer after the call will only be less than
800
+ /// `preserve` if `w.end + n` is less than `preserve` before the call.
801
+ /// The intentionally preserved bytes will include up to `preserve -| n` bytes from
802
+ /// the previously buffered bytes, plus `@min(n, preserve_len)` of the newly
803
+ /// written bytes.
804
+ ///
805
+ /// Asserts buffer capacity is at least `preserve`.
806
+ /// `n` can be greater than the buffer capacity.
787
807
  pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void {
788
808
  const new_end = w.end + n;
789
809
  if (new_end <= w.buffer.len) {
@@ -2504,15 +2524,14 @@ pub fn Hashing(comptime Hasher: type) type {
2504
2524
 
2505
2525
  fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
2506
2526
  const this: *@This() = @alignCast(@fieldParentPtr("writer", w));
2507
- const hasher = &this.hasher;
2508
- hasher.update(w.buffered());
2527
+ this.hasher.update(w.buffered());
2509
2528
  w.end = 0;
2510
2529
  var n: usize = 0;
2511
2530
  for (data[0 .. data.len - 1]) |slice| {
2512
- hasher.update(slice);
2531
+ this.hasher.update(slice);
2513
2532
  n += slice.len;
2514
2533
  }
2515
- for (0..splat) |_| hasher.update(data[data.len - 1]);
2534
+ for (0..splat) |_| this.hasher.update(data[data.len - 1]);
2516
2535
  return n + splat * data[data.len - 1].len;
2517
2536
  }
2518
2537
  };
@@ -57,8 +57,7 @@ pub const ArrayHashMap = Custom;
57
57
  /// the (well defined) behavior when mixing insertions and deletions with iteration.
58
58
  ///
59
59
  /// This type does not store an `Allocator` field - the `Allocator` must be passed in
60
- /// with each function call that requires it. See `ArrayHashMap` for a type that stores
61
- /// an `Allocator` field for convenience.
60
+ /// with each function call that requires it.
62
61
  ///
63
62
  /// Can be initialized directly using the default field values.
64
63
  ///