-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add support enum and char types in Format-Hex cmdlet #8191
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
Conversation
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.
bool is 1 byte, not 4.
There is a difference between sizeof and Marshal.SizeOf, see See the sizeof documentation, also this blog.
BitConverter.GetBytes(bool) works on managed memory and returns a 1 byte array.
I do think this code should use the managed representation for primitive types.
If Format-Hex is enhanced to support an arbitrary ValueType, then we should probably have a discussion about which representation is more useful because in some cases, the unmanaged layout might be more useful.
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.
We could add -Unmanaged switch and by default do managed output.
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.
Possibly, but we could also check the attributes on the struct, e.g. most structs used for interop specify [StructLayout(LayoutKind.Sequential)].
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.
It looks unnecessarily complicated, especially since CoreCLR/CoreFX uses some tricks to align structures. Seems this attribute does not always mean interop.
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.
So we agree that this should be 1 byte by default?
0db3b4e to
badc8b1
Compare
badc8b1 to
8608802
Compare
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
8608802 to
c5e7da2
Compare
|
@SteveL-MSFT @daxian-dbw Could you please review the PR? |
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.
So we agree that this should be 1 byte by default?
c5e7da2 to
4147dda
Compare
|
Rebased to get latest CI's updates. |
|
@vexx32 @daxian-dbw Could you please look the PR before we merge? |
vexx32
left a comment
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.
Looks pretty solid! Couple comments I would love to clarify before we merge, if we can. 😄
| if (baseType.IsArray) | ||
| { | ||
| baseType = baseType.GetElementType(); | ||
| dynamic o = inputObject; |
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.
Is this used? I don't see this used anywhere after this code point.
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.
In next line. Name is very short and not readable.
Renamed.
| isBool = true; | ||
| } | ||
|
|
||
| var elementSize = Marshal.SizeOf(baseType); |
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.
I could be wrong, but wasn't one of @lzybkr's comments that this would return the wrong size for boolean values?
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.
I think it is ok - only local bool var-s have 4 byte size, rest - 1 byte.
PR Summary
Fix #3358
Now
charandenumtypes (and arrays of these types) is supported.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests