Skip to content

Use blittable Byte for C bool and Int32 for hb_bool_t delegate callbacks - #5479

Merged
mattleibow merged 1 commit into
mainfrom
mattleibow-delegate-proxies-byte-returns-and-modern
Oct 30, 2026
Merged

mattleibow merged 1 commit into
mainfrom
mattleibow-delegate-proxies-byte-returns-and-modern

Conversation

@mattleibow

@mattleibow mattleibow commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Match each unmanaged callback's actual native Boolean representation: one-byte Byte for Skia C/C++ bool, four-byte Int32 for HarfBuzz hb_bool_t. Generated callback delegates, unmanaged function pointers and their implementations use the same blittable ABI types. Public managed Boolean delegate/API types remain unchanged. This is 49 changed files, including 40 generated files.

What was wrong before

The pre-change generated HarfBuzz callback declaration already had an attribute; this was not a missing-attribute problem:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
internal unsafe delegate bool FontGetNominalGlyphProxyDelegate(...);

But HarfBuzz 14.4.0's src/hb-common.h declares:

typedef int hb_bool_t;

I1 means a signed one-byte native value. It does not mean “use a four-byte int and then convert to bool.” In the traditional delegate-marshalling path, a managed bool normally marshals as a four-byte Windows BOOL; I1 explicitly requests one byte instead. That was the wrong native width for HarfBuzz's int typedef.

Native callback type Native width on supported targets Before: marshalled delegate Before: unmanaged function pointer Now: both paths
Skia C/C++ bool 1 byte bool + MarshalAs(I1) requested the correct width Raw managed bool; the attribute cannot repair this no-marshalling signature Byte / byte
HarfBuzz hb_bool_t (typedef int) 4 bytes bool + MarshalAs(I1) requested the wrong, one-byte width Raw managed bool also did not match the native four-byte int Int32 / int

[UnmanagedCallersOnly] and delegate* unmanaged[Cdecl] do not perform Boolean marshalling. Putting [MarshalAs] on the method does not insert a conversion stub. bool with four-byte MarshalAs(UnmanagedType.Bool) can represent a native four-byte Boolean on the traditional marshalled path, but it does not solve the direct unmanaged callback path. Explicit blittable integers give both paths the correct native representation.

The Mono ARM64 interpreter investigation exposed a distinct runtime problem with raw managed bool: the MONO_TYPE_BOOLEAN return-copy path used a one-byte strb store, leaving upper bits of return-register storage unchanged. Apple ARM64 C++ callers can test the whole w0 register, so a managed false could be observed as true. See dotnet/runtime#136578. Native declarations still need to be matched independently of that bug: using byte for HarfBuzz merely because register extension can make it appear to work would remain an ABI mismatch.

The old declarations could appear correct for common 0/1 results when a compiler/runtime happened to extend return registers appropriately. That incidental behavior did not make the HarfBuzz signature correct.

Why this is correct

  • GetManagedFunctionArguments and GetFunctionPointerType in BaseTool.cs, together with Generator.cs, map native C/C++ bool to Byte and the configured HarfBuzz hb_bool_t ("Boolean" mapping) to Int32. Generator changes and regenerated declarations stay together.
  • Both legacy [UnmanagedFunctionPointer] delegates and modern [UnmanagedCallersOnly]/unmanaged function pointers use these same blittable types. MarshalAs(I1) is removed from the integer callback signatures because no Boolean marshalling is required.
  • Managed results are normalized to 0 or 1 using the correct return type; native Boolean inputs are converted with != 0. Public managed callers still use bool.
  • Handwritten proxy conversions cover six read-stream Boolean callbacks, one write-stream callback, the Graphite mipmapped input, eight HarfBuzz font callbacks and two Unicode callbacks. False-returning font/Unicode tests check the results.
  • The small related FontGetGlyphNameProxyImplementation guard returns 0 when the user's delegate returns false, before copying its output name. This is an explicit callback-correctness change, not hidden as a mechanical type edit.

Shared user-data/closure allocation work is separately reviewable in #5518. Stream callback exception containment, EOF error state, fork/native-destruction cleanup and their tests are preserved in #5464, not dropped.

Related issues

Related to #3377 and dotnet/runtime#136578.

Native stack 5513: #5475 (merged) → #5479 → #5483 → #5464 → #5476 → #5518. The allocation-only last layer is not a prerequisite for the earlier fixes.

Required skia PR

None.

Areas affected

  • Managed API (binding/)
  • Native / C API (externals/skia/src/c, include/c)
  • Generated P/Invoke bindings
  • Native dependency or Skia update (libpng, HarfBuzz, FreeType, zlib, milestone bump, …)
  • Views & integrations (MAUI, Uno, WPF, WinUI, Blazor, …)
  • Rendering output / visual behavior
  • Performance
  • Tests
  • Build, packaging, or CI
  • Documentation or samples

Changes

No public managed signatures or native C/C++ declarations change. Internal callback signatures now match those existing native declarations.

Behavior

  • Callback delegates/function pointers/implementations use one-byte Byte for Skia native bool and four-byte Int32 for HarfBuzz native hb_bool_t, avoiding the former HarfBuzz width mismatch and unsupported reliance on Boolean marshalling at direct unmanaged entry points.
  • FontGetGlyphNameProxyImplementation returns failure without copying the output name when the managed delegate returns false.

Testing

Existing validation evidence for ABI-only commit 13a79064199:

  • pwsh -NoLogo -NoProfile -File ./utils/generate.ps1 — passed, regeneration produced 0 diff.
  • dotnet build binding/SkiaSharp/SkiaSharp.csproj — passed, all configured target frameworks, 0 errors.
  • dotnet build binding/HarfBuzzSharp/HarfBuzzSharp.csproj — passed, all configured target frameworks, 0 errors.
  • dotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0 — passed on macOS ARM64 using source-matched Skia 748bc0c0116c native binaries: core 6,475; gallery 50; singleton 1; Direct3D 2; Vulkan 4 passed; 0 failures, existing skips unchanged.
  • False-return regression coverage: HBFontFuncsTest.FalseReturningDelegatesShouldReturnFalse and HBUnicodeFuncsTest.FalseReturningComposeAndDecomposeDelegatesShouldReturnFalse.

The native hb_bool_t typedef and pre-change generated bool/I1 declarations were checked directly for this explanation. Traditional Skia I1 marshalling is not being described as a width bug. The historical ARM64 interpreter failure is distinct from the native-width mismatch; the local macOS suite is not a claim that every runtime/architecture was executed again. This description update changes no code.

Checklist

  • Tests added or updated (if omitted, explain why above)
  • Changes above lists all public API and behavioral changes (or "None.")
  • New/changed public API? Added or updated accurate source /// documentation and regenerated bindings when applicable
  • Native change? Companion mono/skia PR linked above and bindings regenerated

@github-actions

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

Add the automation/staging label to build and publish a documentation preview for this PR.

Removing the label removes the preview. While the label is present, each new commit updates it.


This comment is automatically updated by the documentation staging workflow.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 5479

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 5479"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-5479/packages --name skiasharp-pr-5479
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-5479

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

📊 SkiaSharp benchmarks — PR #5479

⭐ this PR (full source build) vs 🌙 nightly · Linux · Windows · macOS

Informational only — this never blocks the PR. 🟢 faster / less allocation · 🔴 slower / more allocation; moves under 5% are hidden as noise.

⏱️ Times are raw BenchmarkDotNet means, and the ⭐ PR and baseline legs run on separate CI runners, so microbenchmarks can swing run-to-run — treat small time deltas as noise. Allocations are deterministic and the reliable signal. The interactive perf-dashboard (linked below) applies smoothing for the trend view.

Highlights

⏱️ Time — 🔴 19 slower · 🟢 65 faster

  • 🔴 RuntimeEffectShaderBenchmark.DrawFrame · Linux · 3.03 ms → 5.74 ms (+90%)
  • 🔴 MatrixMapPointsBenchmark.MapPoints(Points: 256) · Windows · 171.1 ns → 285.3 ns (+67%)
  • 🔴 SceneRenderBenchmark.RenderFrame(Complexity: 4) · Linux · 19.18 ms → 31.12 ms (+62%)
  • 🔴 SceneRenderBenchmark.RenderFrame(Complexity: 1) · Linux · 4.14 ms → 6.68 ms (+61%)
  • 🔴 MatrixMapPointsBenchmark.MapPoints(Points: 4096) · Linux · 2.70 µs → 4.05 µs (+50%)
  • …and 79 more (see details below)

📦 Allocations — 🔴 1 more alloc · 🟢 0 less alloc

  • 🔴 RuntimeEffectShaderBenchmark.DrawFrame · Linux · 680 B → 730 B (+7%)
Full per-OS benchmark deltas

Linux

⏱️ Time (vs 🌙 nightly 4.156.0-nightly.26529.13)

Benchmark baseline this PR Δ
RuntimeEffectShaderBenchmark.DrawFrame 3.03 ms 5.74 ms 🔴 +90%
SceneRenderBenchmark.RenderFrame(Complexity: 4) 19.18 ms 31.12 ms 🔴 +62%
SceneRenderBenchmark.RenderFrame(Complexity: 1) 4.14 ms 6.68 ms 🔴 +61%
MatrixMapPointsBenchmark.MapPoints(Points: 4096) 2.70 µs 4.05 µs 🔴 +50%
MatrixMapPointsBenchmark.MapPoints(Points: 256) 230.2 ns 307.7 ns 🔴 +34%
ColorMathBenchmark.UnPreMultiply(Colors: 4096) 12.98 µs 9.30 µs 🟢 -28%
ColorMathBenchmark.PreMultiply(Colors: 4096) 14.50 µs 10.80 µs 🟢 -26%
ColorMathBenchmark.ToColor(Colors: 4096) 14.44 µs 10.86 µs 🟢 -25%
CanvasDrawBenchmark.Draw(Shapes: 512) 35.22 ms 42.83 ms 🔴 +22%
CanvasDrawBenchmark.Draw(Shapes: 64) 4.40 ms 5.35 ms 🔴 +21%
MatrixOpsBenchmark.Invert(Count: 4096) 150.28 µs 121.43 µs 🟢 -19%
MatrixMapPointsBenchmark.MapPoint(Points: 4096) 80.59 µs 65.61 µs 🟢 -19%
MatrixMapPointsBenchmark.MapPoint(Points: 256) 5.00 µs 4.11 µs 🟢 -18%
PathBoundsBenchmark.TightBounds(Points: 1024) 12.32 µs 10.17 µs 🟢 -17%
RasterImageLifecycleBenchmark.CreateDataWithReleaseProc(Count: 256) 97.95 µs 114.74 µs 🔴 +17%
MatrixOpsBenchmark.Concat(Count: 4096) 240.95 µs 212.19 µs 🟢 -12%
ColorParseBenchmark.Parse(Iterations: 1000) 76.93 µs 69.33 µs 🟢 -10%
RasterImageLifecycleBenchmark.CreateRasterImage(Count: 256) 239.00 µs 261.78 µs 🔴 +10%
MatrixMapPointsBenchmark.MapRadius(Points: 256) 15.85 µs 14.35 µs 🟢 -9%
MatrixMapPointsBenchmark.MapVector(Points: 4096) 193.42 µs 177.74 µs 🟢 -8%
MatrixMapPointsBenchmark.MapRadius(Points: 4096) 247.26 µs 229.68 µs 🟢 -7%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 256) 962.19 µs 1.03 ms 🔴 +7%
ColorMathBenchmark.ToColorF(Colors: 4096) 14.10 µs 14.95 µs 🔴 +6%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 1024) 2.06 ms 2.17 ms 🔴 +5%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 64) 260.09 µs 273.59 µs 🔴 +5%

📦 Allocations (vs 🌙 nightly 4.156.0-nightly.26529.13)

Benchmark baseline this PR Δ
RuntimeEffectShaderBenchmark.DrawFrame 680 B 730 B 🔴 +7%

Windows

⏱️ Time (vs 🌙 nightly 4.156.0-nightly.26529.13)

Benchmark baseline this PR Δ
MatrixMapPointsBenchmark.MapPoints(Points: 256) 171.1 ns 285.3 ns 🔴 +67%
RuntimeEffectShaderBenchmark.DrawFrame 1.13 ms 662.86 µs 🟢 -41%
MatrixMapPointsBenchmark.MapPoint(Points: 256) 2.47 µs 1.47 µs 🟢 -40%
MatrixMapPointsBenchmark.MapPoint(Points: 4096) 40.41 µs 24.66 µs 🟢 -39%
ColorMathBenchmark.ToColor(Colors: 4096) 14.59 µs 9.48 µs 🟢 -35%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 64) 247.48 µs 161.98 µs 🟢 -35%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 256) 918.50 µs 603.18 µs 🟢 -34%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 256) 1.24 ms 828.13 µs 🟢 -33%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 64) 327.17 µs 221.54 µs 🟢 -32%
ColorMathBenchmark.PreMultiply(Colors: 4096) 13.03 µs 9.10 µs 🟢 -30%
CanvasDrawBenchmark.Draw(Shapes: 64) 2.68 ms 1.92 ms 🟢 -28%
ColorMathBenchmark.UnPreMultiply(Colors: 4096) 11.19 µs 8.04 µs 🟢 -28%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 2048) 10.47 ms 7.58 ms 🟢 -28%
CanvasDrawBenchmark.Draw(Shapes: 512) 21.35 ms 15.65 ms 🟢 -27%
MatrixOpsBenchmark.Concat(Count: 4096) 216.68 µs 160.56 µs 🟢 -26%
MatrixMapPointsBenchmark.MapPoints(Points: 4096) 2.32 µs 2.91 µs 🔴 +26%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 1024) 2.63 ms 2.00 ms 🟢 -24%
MatrixOpsBenchmark.Invert(Count: 4096) 128.81 µs 99.06 µs 🟢 -23%
ColorParseBenchmark.Parse(Iterations: 1000) 75.55 µs 58.20 µs 🟢 -23%
MatrixMapPointsBenchmark.MapVector(Points: 256) 7.65 µs 6.15 µs 🟢 -20%
MatrixMapPointsBenchmark.MapRect(Points: 256) 10.49 µs 8.44 µs 🟢 -20%
PathBoundsBenchmark.TightBounds(Points: 64) 1.50 µs 1.21 µs 🟢 -19%
MatrixMapPointsBenchmark.MapRadius(Points: 256) 9.09 µs 7.38 µs 🟢 -19%
MatrixMapPointsBenchmark.MapVector(Points: 4096) 122.09 µs 101.35 µs 🟢 -17%
SceneRenderBenchmark.RenderFrame(Complexity: 1) 2.25 ms 1.91 ms 🟢 -15%
…and 8 more

macOS

⏱️ Time (vs 🌙 nightly 4.156.0-nightly.26529.13)

Benchmark baseline this PR Δ
ColorMathBenchmark.UnPreMultiply(Colors: 4096) 10.12 µs 8.12 µs 🟢 -20%
MatrixMapPointsBenchmark.MapRadius(Points: 4096) 134.55 µs 109.59 µs 🟢 -19%
MatrixMapPointsBenchmark.MapRect(Points: 256) 4.00 µs 3.29 µs 🟢 -18%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 64) 285.91 µs 235.30 µs 🟢 -18%
MatrixMapPointsBenchmark.MapPoint(Points: 256) 1.51 µs 1.24 µs 🟢 -18%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 2048) 7.53 ms 6.26 ms 🟢 -17%
MatrixOpsBenchmark.Concat(Count: 4096) 144.11 µs 119.77 µs 🟢 -17%
MatrixOpsBenchmark.Invert(Count: 4096) 81.23 µs 94.93 µs 🔴 +17%
PathBoundsBenchmark.TightBounds(Points: 1024) 10.67 µs 8.98 µs 🟢 -16%
SceneRenderBenchmark.RenderFrame(Complexity: 1) 1.48 ms 1.29 ms 🟢 -13%
MatrixMapPointsBenchmark.MapVector(Points: 256) 3.02 µs 2.64 µs 🟢 -13%
SceneRenderBenchmark.RenderFrame(Complexity: 4) 6.68 ms 5.88 ms 🟢 -12%
MatrixMapPointsBenchmark.MapRadius(Points: 256) 7.58 µs 6.73 µs 🟢 -11%
ColorMathBenchmark.PreMultiply(Colors: 4096) 10.34 µs 9.21 µs 🟢 -11%
ColorParseBenchmark.Parse(Iterations: 1000) 72.59 µs 65.47 µs 🟢 -10%
ColorMathBenchmark.ToColor(Colors: 4096) 23.82 µs 21.54 µs 🟢 -10%
LargeImageScaleBenchmark.UpscaleOpaque(Size: 2048) 3.20 ms 2.91 ms 🟢 -9%
CanvasDrawBenchmark.Draw(Shapes: 64) 1.77 ms 1.63 ms 🟢 -8%
LargeImageScaleBenchmark.UpscaleOpaque(Size: 1024) 780.25 µs 727.57 µs 🟢 -7%
CanvasDrawBenchmark.Draw(Shapes: 512) 12.88 ms 12.01 ms 🟢 -7%
MatrixMapPointsBenchmark.MapPoints(Points: 256) 178.9 ns 167.1 ns 🟢 -7%
MatrixMapPointsBenchmark.MapPoints(Points: 4096) 2.08 µs 1.95 µs 🟢 -6%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 256) 961.77 µs 1.02 ms 🔴 +6%
ColorMathBenchmark.ToColorF(Colors: 4096) 5.86 µs 5.54 µs 🟢 -5%
PathBoundsBenchmark.TightBounds(Points: 64) 924.7 ns 974.2 ns 🔴 +5%
…and 1 more

📈 Full interactive perf-dashboard & run details →

@mattleibow
mattleibow requested a balanced review from Copilot October 28, 2026 17:16
@mattleibow

Copy link
Copy Markdown
Contributor Author

@dalexsoto review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not cover recovery after callback exceptions, leaving error-state resets on successful Rewind/Seek/Move and preservation on failed repositioning unverified.

1 open issue
What changed in this PR

This PR hardens SkiaSharp and HarfBuzzSharp native callbacks by replacing callback bool values with blittable bytes, containing managed stream exceptions, and simplifying callback state storage.

Changes:

  • Updates the generator, generated callback signatures, and proxy implementations to use byte.
  • Adds stream exception containment and error-state tracking, with regression tests for stream failures and false-returning HarfBuzz callbacks.
  • Replaces closure-based callback state with direct user-data handles and a shared state object.
File Description
utils/​SkiaSharpGenerator/​Generate/​Generator.cs Removes callback boolean marshalling attributes.
utils/​SkiaSharpGenerator/​BaseTool.cs Maps callback booleans to bytes.
tests/​Tests/​SkiaSharp/​SKManagedWStreamTest.cs Tests throwing write-stream callbacks.
tests/​Tests/​SkiaSharp/​SKManagedStreamTest.cs Tests callback failures and disposed-stream termination.
tests/​Tests/​HarfBuzzSharp/​HBUnicodeFuncsTest.cs Tests false-returning Unicode callbacks.
tests/​Tests/​HarfBuzzSharp/​HBFontFuncsTest.cs Tests false-returning font callbacks.
binding/​SkiaSharp/​SKAbstractManagedStream.cs Adds callback error-state storage.
binding/​SkiaSharp/​Generated/​SKManagedWStreamWriteProxyDelegate.generated.cs Changes write delegate return to byte.
binding/​SkiaSharp/​Generated/​SKManagedWStreamDelegates.generated.cs Updates write function-pointer signature.
binding/​SkiaSharp/​Generated/​SKManagedStreamSeekProxyDelegate.generated.cs Changes seek delegate return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamRewindProxyDelegate.generated.cs Changes rewind delegate return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamMoveProxyDelegate.generated.cs Changes move delegate return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamIsAtEndProxyDelegate.generated.cs Changes EOF delegate return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamHasPositionProxyDelegate.generated.cs Changes position-capability return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamHasLengthProxyDelegate.generated.cs Changes length-capability return to byte.
binding/​SkiaSharp/​Generated/​SKManagedStreamDelegates.generated.cs Updates stream function-pointer signatures.
binding/​SkiaSharp/​Generated/​SKGraphiteImageProviderProxyDelegate.generated.cs Changes mipmapping parameter to byte.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedWStreamWriteProxyDelegate.generated.cs Updates write proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamSeekProxyDelegate.generated.cs Updates seek proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamRewindProxyDelegate.generated.cs Updates rewind proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamMoveProxyDelegate.generated.cs Updates move proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamIsAtEndProxyDelegate.generated.cs Updates EOF proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamHasPositionProxyDelegate.generated.cs Updates position-capability proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKManagedStreamHasLengthProxyDelegate.generated.cs Updates length-capability proxy declarations.
binding/​SkiaSharp/​Generated/​DelegateProxies_SKGraphiteImageProviderProxyDelegate.generated.cs Updates image-provider proxy declarations.
binding/​SkiaSharp/​DelegateProxies.wstream.cs Contains write-stream callback exceptions.
binding/​SkiaSharp/​DelegateProxies.stream.cs Contains exceptions and tracks stream error recovery.
binding/​SkiaSharp/​DelegateProxies.cs Converts mipmapping byte to managed boolean.
binding/​HarfBuzzSharp/​Generated/​UnicodeDecomposeProxyDelegate.generated.cs Changes decomposition return to byte.
binding/​HarfBuzzSharp/​Generated/​UnicodeComposeProxyDelegate.generated.cs Changes composition return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetVariationGlyphProxyDelegate.generated.cs Changes variation-glyph return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetNominalGlyphProxyDelegate.generated.cs Changes nominal-glyph return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphProxyDelegate.generated.cs Changes glyph lookup return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphOriginProxyDelegate.generated.cs Changes glyph-origin return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphNameProxyDelegate.generated.cs Changes glyph-name return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphFromNameProxyDelegate.generated.cs Changes name lookup return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphExtentsProxyDelegate.generated.cs Changes glyph-extents return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetGlyphContourPointProxyDelegate.generated.cs Changes contour-point return to byte.
binding/​HarfBuzzSharp/​Generated/​FontGetFontExtentsProxyDelegate.generated.cs Changes font-extents return to byte.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_UnicodeDecomposeProxyDelegate.generated.cs Updates decomposition proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_UnicodeComposeProxyDelegate.generated.cs Updates composition proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetVariationGlyphProxyDelegate.generated.cs Updates variation-glyph proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetNominalGlyphProxyDelegate.generated.cs Updates nominal-glyph proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetGlyphOriginProxyDelegate.generated.cs Updates glyph-origin proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetGlyphNameProxyDelegate.generated.cs Updates glyph-name proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetGlyphFromNameProxyDelegate.generated.cs Updates name lookup proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetGlyphExtentsProxyDelegate.generated.cs Updates glyph-extents proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetGlyphContourPointProxyDelegate.generated.cs Updates contour-point proxy declarations.
binding/​HarfBuzzSharp/​Generated/​DelegateProxies_FontGetFontExtentsProxyDelegate.generated.cs Updates font-extents proxy declarations.
binding/​HarfBuzzSharp/​Generated/​BufferMessageProxyDelegate.generated.cs Changes buffer-message return to byte.
binding/​HarfBuzzSharp/​DelegateProxies.unicode.cs Converts Unicode callback results to bytes.
binding/​HarfBuzzSharp/​DelegateProxies.font.cs Converts font results and short-circuits failed name lookups.
binding/​Binding.Shared/​DelegateProxies.shared.cs Replaces closures with direct callback state storage.

Review effort: Balanced

@mattleibow
mattleibow force-pushed the mattleibow-delegate-proxies-byte-returns-and-modern branch from baee8fe to 146011d Compare October 28, 2026 17:43
dalexsoto
dalexsoto previously approved these changes Oct 28, 2026

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all 53 changed generator, generated-binding, callback, user-data and test files with their native ABI, stream error-state and ownership consumers, including a separate final blocker search. The callback representations, stream error containment and recovery, and handle ownership match the reviewed native and generated contracts. The intended unmanaged-callback exception containment and resolved recovery-test concerns are not being re-blocked; no author-reported runtime or performance validation is claimed. No independent high-confidence blocker remains in this bounded static review; no executed runtime or whole-pipeline certification is claimed.

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all 53 changed generator, generated-binding, callback, user-data and test files with their native ABI, stream error-state and ownership consumers, including a separate final blocker search.

Release a partially created fork before converting its exception to null (binding/SkiaSharp/DelegateProxies.stream.cs:24-25)

The new catch makes a failed native Fork return null, but SKManagedStream.OnFork can already have allocated its native duplicate before the exception. After one successful Duplicate has cached snapshotData, disposing the underlying MemoryStream and invoking Fork on the still-live SKManagedStream enters the cache fast path, allocates a new SkMemoryStream, and then throws while reading stream.Position. The catch discards that duplicate pointer. Each failed Fork leaks the native stream and its SKData reference; disposing the original wrapper cannot release the retained snapshot.

Fix: Read the underlying position before allocating the duplicate, or destroy the just-created native stream in SKManagedStream.OnFork on every exception before rethrowing to this containment proxy. Add coverage with an already-cached snapshot and a subsequently failing Position getter.

The intended unmanaged-callback exception containment and resolved recovery-test concerns are not being re-blocked; no author-reported runtime or performance validation is claimed.

This is a static source-contract finding, not an executed runtime reproduction.

@github-project-automation github-project-automation Bot moved this from Approved to Changes Requested in SkiaSharp Backlog Oct 30, 2026
@mattleibow

Copy link
Copy Markdown
Contributor Author

Release a partially created fork before converting its exception to null (binding/SkiaSharp/DelegateProxies.stream.cs:24-25)

Fixed in 51417bc300a: SKManagedStream.OnFork and SKAbstractManagedStream.OnFork now destroy the newly allocated native stream via SkiaApi.sk_stream_destroy in a catch block before rethrowing if reading stream.Position or seeking fails after OnDuplicate()/OnCreateNew(), and FailedForkAfterCachedSnapshotReleasesNativeDuplicateAndSnapshotReference verifies that snapshotData's native reference count is not leaked.

Base automatically changed from mattleibow-fix-post-gc-handledictionary-test-assert to main October 30, 2026 08:44
@mattleibow
mattleibow requested a max review from Copilot October 30, 2026 08:48
@mattleibow
mattleibow force-pushed the mattleibow-delegate-proxies-byte-returns-and-modern branch from 51417bc to c92a9c8 Compare October 30, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A throwing Stream.Dispose() can leave the wrapper holding a freed native handle and stale dictionary entry, while Fork() can swallow a position error and return an incorrectly positioned copy.

2 open issues
1 resolved since last review

Review effort: Max

- Update SkiaSharpGenerator to emit blittable Byte for C bool and Int32 for
  HarfBuzz hb_bool_t (and omit [MarshalAs(UnmanagedType.I1)]) on generated
  delegate types, unmanaged function pointers, and DelegateProxies
  implementations, avoiding non-blittable bool return ABI issues under
  [UnmanagedCallersOnly] and Mono's ARM64 interpreter (dotnet/runtime#136578).
- Update mechanical boolean conversions in SkiaSharp and HarfBuzzSharp
  DelegateProxies implementations (including early-returning 0 on failed
  FontGetGlyphName lookups before copying the name span) and add
  false-returning HarfBuzz callback tests.

Co-authored-by: Copilot App <[email protected]>
@mattleibow
mattleibow force-pushed the mattleibow-delegate-proxies-byte-returns-and-modern branch from 533564d to 13a7906 Compare October 30, 2026 10:07
@mattleibow mattleibow changed the title Use blittable byte for delegate callbacks and harden DelegateProxies Use blittable Byte for C bool and Int32 for hb_bool_t delegate callbacks Oct 30, 2026
@dalexsoto

Copy link
Copy Markdown
Member

@mattleibow I cannot complete this review request in this iteration: the PR was restacked and its review scope changed while the prior exact-revision review was in progress. That result cannot serve as a review of the new revision. I am withholding a formal decision until the complete current scope and moved integration paths have been rechecked; this request remains tracked.

@mattleibow

Copy link
Copy Markdown
Contributor Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all 49 changed files in the ABI-only layer, including the generated bindings and the relevant native callback signatures. Skia Boolean and HarfBuzz hb_bool_t representations and calling conventions agree across the marshalled and direct unmanaged callback paths; no high-confidence blocker remains in this scope.

Broader stream exception containment, recovery, fork and native-close cleanup intentionally belong to the upper #5464 layer and are not certified by this ABI review. This is a bounded static-source review, not an executed runtime, produced-output or whole-pipeline certification.

@github-project-automation github-project-automation Bot moved this from Changes Requested to Approved in SkiaSharp Backlog Oct 30, 2026
@mattleibow
mattleibow merged commit e2b78a3 into main Oct 30, 2026
131 checks passed
@mattleibow
mattleibow deleted the mattleibow-delegate-proxies-byte-returns-and-modern branch October 30, 2026 14:37
@github-project-automation github-project-automation Bot moved this from Approved to Done in SkiaSharp Backlog Oct 30, 2026
@github-actions github-actions Bot added this to the 4.156.0-rc.1 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants