Skip _unmanaged emission when struct layout matches _managed variant#1683
Skip _unmanaged emission when struct layout matches _managed variant#1683MukundaKatta wants to merge 3 commits into
Conversation
Under COM source generators, struct fields with managed-type pointers always demote to the _unmanaged form, so a struct's _managed and _unmanaged projections are byte-for-byte identical. Emitting both forces callers (e.g. ID2D1DeviceContext.CreateBitmapFromDxgiSurface) into a redundant _unmanaged variant. Skip the suffix for structs in this mode and route callers to the safe variant. Fixes microsoft#1682.
| return false; | ||
| } | ||
|
|
||
| // Source generators force every managed-pointer struct field through the unmanaged projection, |
There was a problem hiding this comment.
What is the expected impact for built-in COM? I know I looked into this and the logic for when a struct needed to be managed vs unmanaged was fairly convoluted and had to do with whether there was a self-reference cycle detected in the structs and I didn't have time to keep digging in.
Is the goal to leave built-in COM alone and only try to improve this for the source-generated outputs?
|
@jevansaks no impact on built-in COM. The new path is gated behind |
|
Sorry for the delay, I just merged a PR to enable all the test cases running in PR so if you could merge in latest origin/main we can get that pipeline queued? |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@MukundaKatta I've updated your branch to latest and fixed the basic build errors. Now seeing test failures in the PR run. You should be able to see these and investigate them. Thanks! |
Closes #1682.
CreateBitmapFromDxgiSurfacewas projected as_unmanagedeven though the_managedvariant had identical signature and marshaling, forcing callers intounsafefor no benefit. Added a layout-equality check before_unmanagedemission so structs that match the safe variant are routed there.Test in
test/Microsoft.Windows.CsWin32.Tests/COMTests.cs.