-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cleanup EDITSTREAM #2816
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
Merged
Merged
Cleanup EDITSTREAM #2816
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.EDITSTREAM.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal partial class Interop | ||
| { | ||
| internal static partial class Richedit | ||
| { | ||
| [StructLayout(LayoutKind.Sequential, Pack = 4)] | ||
| public struct EDITSTREAM | ||
| { | ||
| public UIntPtr dwCookie; | ||
| public uint dwError; | ||
| public IntPtr pfnCallback; | ||
| } | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.EDITSTREAMCALLBACK.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
|
|
||
| internal partial class Interop | ||
| { | ||
| internal static partial class Richedit | ||
| { | ||
| public delegate int EDITSTREAMCALLBACK(IntPtr dwCookie, IntPtr pbBuff, int cb, out int pcb); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.SF.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
|
|
||
| internal partial class Interop | ||
| { | ||
| internal static partial class Richedit | ||
| { | ||
| [Flags] | ||
| public enum SF : uint | ||
| { | ||
| TEXT = 0x0001, | ||
| RTF = 0x0002, | ||
| RTFNOOBJS = 0x0003, | ||
| TEXTIZED = 0x0004, | ||
| UNICODE = 0x0010, | ||
| USECODEPAGE = 0x0020, | ||
| NCRFORNONASCII = 0x0040, | ||
| RTFVAL = 0x0700, | ||
| F_PWD = 0x0800, | ||
| F_KEEPDOCINFO = 0x1000, | ||
| F_PERSISTVIEWSCALE = 0x2000, | ||
| F_PLAINRTF = 0x4000, | ||
| F_SELECTION = 0x8000, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/System.Windows.Forms.Primitives/tests/Interop/Richedit/EDITSTREAMTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Xunit; | ||
| using static Interop.Richedit; | ||
|
|
||
| namespace System.Windows.Forms.Tests.Interop.Richedit | ||
| { | ||
| public class EDITSTREAMTests : IClassFixture<ThreadExceptionFixture> | ||
| { | ||
| [WinFormsFact] | ||
| public unsafe void EditStream_Size_Get_ReturnsExpected() | ||
| { | ||
| if (IntPtr.Size == 4) | ||
| { | ||
| Assert.Equal(12, sizeof(EDITSTREAM)); | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(20, sizeof(EDITSTREAM)); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are adding 4 byte undesired padding in 64bit between these fields. You can solve this without making two structs by forcing alignment to 4 byte instead of keeping it at native size. So adding a
[StructLayout(LayoutKind.Sequential, Pack = 4)]should do the trick.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, in the header file the place where it deviates from standard packing rules is by declaring
This is which forces
Pack=4in C# terms for all structs in this header file. Only relevant if the struct contains pointers or doubles (i.e. anything larger than 4 byte)It's unfortunate that the headers have these sprinkled around instead of directly on the declarations like C# enforces, you always have to search for them if you want to make sure you are using the right packing rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping it as "unresolved" for the ease of future searching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I'm writing unmanaged struct wrappers I'll sometimes write unit tests that check
sizeof-- particularly for less common or complicated structures. I manually check thesizeofin a C++ dll and hard code the values, but that could also be done in code by having an export that allows you to query.I'd consider:
sizeoffor structs (in addition to other native helpers for testing)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD.
I have raised #2879 for CI enhancements. [EDIT] Merged
@hughbe you were working on #1932. Perhaps it can be leveraged for this purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not going to be merged for sometime as it is waiting on upstream arcade changes.
I have written a bunch of tests to ensure near 100% coverage as well as verifying the size on x86 and x64