@amritk/nish-aarch64-linux 0.47.0 → 0.48.0

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.
@@ -141,6 +141,7 @@ import {
141
141
  } from "nish/net/http-compress"
142
142
  import { netClose, netMss, netRead, netShutdown, netWrite, netWrite2, tcpAccept } from "nish:net"
143
143
  import {
144
+ HTTP1_BAD_WINDOW,
144
145
  HTTP1_BODY,
145
146
  HTTP1_CHUNKED,
146
147
  HTTP1_CLOSED,
@@ -154,7 +155,7 @@ import {
154
155
  HTTP1_UPGRADE,
155
156
  Http1Parser,
156
157
  http1BytesAre,
157
- http1WriteChunk,
158
+ http1TryWriteChunk,
158
159
  http1WriteLastChunk,
159
160
  http1WriteResponseHead,
160
161
  } from "nish/net/http1-codec"
@@ -2090,7 +2091,12 @@ export class Http1Connection {
2090
2091
  return H1_AGAIN
2091
2092
  }
2092
2093
  if (chunked) {
2093
- this.outputEnd = http1WriteChunk(this.output, this.outputEnd, buf, off, take)
2094
+ // The window was checked on entry, and `take` only shortens it.
2095
+ const end: i32 = http1TryWriteChunk(this.output, this.outputEnd, buf, off, take)
2096
+ if (end === HTTP1_BAD_WINDOW) {
2097
+ return H1_INVALID
2098
+ }
2099
+ this.outputEnd = end
2094
2100
  } else {
2095
2101
  this.outputEnd = http1ServerCopy(this.output, this.outputEnd, buf, off, take)
2096
2102
  if (this.responseFraming >= 0) {
package/std/raster.ts CHANGED
@@ -730,7 +730,9 @@ export const rasterPushTrail = (trail: RasterTrail, x: f64, y: f64): void => {
730
730
  /**
731
731
  * A trail as a line of discs from oldest to newest, each larger and more
732
732
  * opaque than the one before: a streak that fades out behind what made it.
733
- * A point at `v` is drawn at pixel `offset + v * scale`.
733
+ * A point at `v` is drawn at pixel `offset + v * scale`. A `head` set
734
+ * outside the ring still draws the points `count` slots behind it that land
735
+ * in the ring, as an in-range head does, and no others.
734
736
  *
735
737
  * @param pixels - the frame, row-major
736
738
  * @param width - the frame's width in pixels
@@ -760,29 +762,41 @@ export const rasterTrail = (
760
762
  const n: i32 = toI32(xs.length)
761
763
  const count: i32 = Math.min(trail.count, n)
762
764
  const head: i32 = trail.head
763
- if (count <= 0 || head < 0 || head >= n) {
765
+ // The oldest point is `count` slots behind the head, wrapping once. A head
766
+ // out of the ring (a caller can set the field) still has the slots that land
767
+ // in it drawn. Point i sits at `head - count + i`, counted in f64, where it
768
+ // is exact for any head, so no sum can overflow. The points before slot 0
769
+ // wrap to the ring's end and are older than the rest, so they are drawn
770
+ // first, as one run of slots, and the others as a second.
771
+ if (count <= 0) {
764
772
  return
765
773
  }
766
- // The oldest point is `count` slots behind the head, wrapping; `slot` walks
767
- // forward from it.
768
- let slot: i32 = head - count
769
- if (slot < 0) {
770
- slot = slot + n
771
- }
772
- for (let i: i32 = 0; i < count; i++) {
773
- // `slot` is always in the ring, so the first test never ends the walk; it
774
- // is what proves the index.
775
- if (slot < 0 || slot >= n) {
776
- return
777
- }
778
- if (slot < toI32(ys.length)) {
779
- const f: f64 = (toF64(i) + 1.0) / (toF64(count) + 1.0)
780
- const radius: f64 = r * (f * 0.6 + 0.4)
781
- const cx: f64 = offsetX + xs[slot] * scale
782
- const cy: f64 = offsetY + ys[slot] * scale
783
- rasterDisc(pixels, width, height, cx, cy, radius * scale, colour, alpha * f)
774
+ const size: f64 = toF64(n)
775
+ const ysLength: i32 = toI32(ys.length)
776
+ const first: f64 = toF64(head) - toF64(count)
777
+ const steps: f64 = toF64(count) + 1.0
778
+ for (let pass: i32 = 0; pass < 2; pass++) {
779
+ // Point i of this run sits at slot `base + i`.
780
+ const base: f64 = pass === 0 ? first + size : first
781
+ const lo: f64 = Math.max(base, 0.0)
782
+ const hi: f64 = Math.min(base + toF64(count), size)
783
+ if (lo < hi) {
784
+ const end: i32 = toI32(hi)
785
+ // How far along the trail the point is, from 1 for the oldest.
786
+ let step: f64 = lo - base + 1.0
787
+ for (let slot: i32 = toI32(lo); slot < end; slot++) {
788
+ // The first two are always true in the run and prove the indexes; the
789
+ // third skips a slot a shorter `ys` does not hold.
790
+ if (slot >= 0 && slot < n && slot < ysLength) {
791
+ const f: f64 = step / steps
792
+ const radius: f64 = r * (f * 0.6 + 0.4)
793
+ const cx: f64 = offsetX + xs[slot] * scale
794
+ const cy: f64 = offsetY + ys[slot] * scale
795
+ rasterDisc(pixels, width, height, cx, cy, radius * scale, colour, alpha * f)
796
+ }
797
+ step = step + 1.0
798
+ }
784
799
  }
785
- slot = slot + 1 >= n ? 0 : slot + 1
786
800
  }
787
801
  }
788
802
 
package/std/synth.ts CHANGED
@@ -47,7 +47,15 @@ const SYNTH_SAMPLE_LIMIT: f64 = 2147483647.0
47
47
  */
48
48
  export const synthSilence = (seconds: f64, sampleRate: i32): f64[] => {
49
49
  const want: f64 = seconds * toF64(sampleRate)
50
- const n: i32 = want >= 1.0 && want < SYNTH_SAMPLE_LIMIT ? toI32(want) : 1
50
+ let n: i32 = 1
51
+ if (want >= 1.0 && want < SYNTH_SAMPLE_LIMIT) {
52
+ const k: i32 = toI32(want)
53
+ // Never false: `want` is at least 1 here. The test is what proves the
54
+ // array length is not negative.
55
+ if (k >= 1) {
56
+ n = k
57
+ }
58
+ }
51
59
  const out: f64[] = new Array<f64>(n)
52
60
  out.fill(0.0)
53
61
  return out