Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic Marshal.StructureToPtr #6044

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

ThomasGoulet73
Copy link
Contributor

Description

Use generic Marshal.StructureToPtr instead of the non-generic. I removed the customs UnsafeNativeMethods.StructureToPtr which justs forwards to Marshal.StructureToPtr because it causes linker warnings because Marshal.StructureToPtr is annotated while UnsafeNativeMethods.StructureToPtr isn't.

Almost every call to Marshal.StructureToPtr were already using the generic overload without the need to change the code.

Contributes to #3811

Customer Impact

None, same behavior as the non-generic.

Regression

No

Testing

I manually tested a few of the generic and non-generic and they gave the same result.

Risk

None, same behavior as the non-generic.

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner February 1, 2022 04:48
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Feb 1, 2022
@ghost ghost requested review from fabiant3, ryalanms and SamBent February 1, 2022 04:48
@@ -38,7 +38,8 @@ override protected bool ReleaseHandle()
}

// uiaCondition is one of the Uia condition structs - eg UiaCoreApi.UiaAndOrCondition
internal static SafeConditionMemoryHandle AllocateConditionHandle(object uiaCondition)
internal static SafeConditionMemoryHandle AllocateConditionHandle<T>(T uiaCondition)
Copy link
Contributor Author

@ThomasGoulet73 ThomasGoulet73 Feb 1, 2022

Choose a reason for hiding this comment

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

Using generics here allows to call the generic version of Marshal.StructureToPtr and also to avoid boxing of uiaCondition. Every call to AllocateConditionHandle passes a struct for uiaCondition.

@kant2002
Copy link
Contributor

kant2002 commented Feb 1, 2022

Thank you!

@bmarinov
Copy link

Hey all, any comment on this PR from the repo / code owners would be appreciated. The PR has been open for two months and it looks like a minor change that is not breaking anything. CC @SamBent / @fabiant3 / @vishalmsft / @singhashish-wpf

Context: .NET Core 3.1 is EoL at the end of the year. Trimming is unstable and practically unusable in production with any subsequent .NET versions. There has been little to no progress on #3811 with duplicates being closed with no comment regarding the original issue.

@singhashish-wpf singhashish-wpf merged commit d6df6b8 into dotnet:main Mar 30, 2022
@ThomasGoulet73 ThomasGoulet73 deleted the generic-structuretoptr branch March 30, 2022 17:10
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2022
@ghost ghost assigned ThomasGoulet73 May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants