-
Notifications
You must be signed in to change notification settings - Fork 971
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
Cleanup EDITSTREAM #2816
Cleanup EDITSTREAM #2816
Conversation
c51cc89
to
0cc9710
Compare
MC, and (I suspect) test failures |
0cc9710
to
5aee73d
Compare
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.
Have you tested it in any way?
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.EDITSTREAM.cs
Outdated
Show resolved
Hide resolved
hmm there may be different padding on 64 bit vs. 32 bit structs. @weltkante if you have any immediate things you notice |
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.EDITSTREAM.cs
Outdated
Show resolved
Hide resolved
public uint dwError; | ||
public IntPtr pfnCallback; |
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.
hmm there may be different padding on 64 bit vs. 32 bit structs. @weltkante if you have any immediate things you notice
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
#ifdef _WIN32
#include <pshpack4.h>
#elif !defined(RC_INVOKED)
#pragma pack(4)
#endif
This is which forces Pack=4
in 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 the sizeof
in 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:
- Writing tests that check the size
- Testing interop in both x86 and x64
- Using a cross-compiled native dll to expose the C
sizeof
for structs (in addition to other native helpers for testing)
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.
- Writing tests that check the size
TBD.
- Testing interop in both x86 and x64
I have raised #2879 for CI enhancements. [EDIT] Merged
- Using a cross-compiled native dll to expose the C
sizeof
for structs (in addition to other native helpers for testing)
@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.
5aee73d
to
b65cce2
Compare
b65cce2
to
77bd65e
Compare
Codecov Report
@@ Coverage Diff @@
## master #2816 +/- ##
===================================================
+ Coverage 60.27793% 60.37459% +0.09666%
===================================================
Files 1249 1249
Lines 433633 434552 +919
Branches 38850 38849 -1
===================================================
+ Hits 261385 262359 +974
+ Misses 166879 166822 -57
- Partials 5369 5371 +2
|
77bd65e
to
f2b81bb
Compare
f2b81bb
to
a9271e5
Compare
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.
What happened to EDITSTREAM
clean up? Why do we have only test changes?
a9271e5
to
914d728
Compare
I was testing to see whether my changes regressed any tests. Turns out we may have a bug. I wrote the tests against full .NET Framework but they fail on .NET Core - it looks like
|
I can't quite follow, when I look at the In short, if there is no Text or SelectedText then SelectedRtf is empty. That behavior also happens on Desktop for me and IMHO its reasonable behavior. Note that there exist different versions of the RTF control and maybe you're running your Desktop tests against an older version which behaved differently. .NET Core only supports using the newest version. |
08eaae9
to
ace6d19
Compare
Yeah seems like this was the problem. Cheers! |
src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.SF.cs
Outdated
Show resolved
Hide resolved
ace6d19
to
909cf71
Compare
909cf71
to
df8798e
Compare
Docs: dotnet/docs#17085 |
@weltkante any more concerns? |
Proposed Changes
Microsoft Reviewers: Open in CodeFlow