GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add support enum and char types in Format-Hex cmdlet by iSazonov · Pull Request #8191 · PowerShell/PowerShell Conversation
|
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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)].
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
8608802 to
c5e7da2
Compare
|
Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw) Could you please review the PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
c5e7da2 to
4147dda
Compare
|
Rebased to get latest CI's updates. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Rain Sallow (/u/ta11ow) (@vexx32) Dongbo Wang (@daxian-dbw) Could you please look the PR before we merge? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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. 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (baseType.IsArray) | ||
| { | ||
| baseType = baseType.GetElementType(); | ||
| dynamic o = inputObject; |
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| isBool = true; | ||
| } | ||
|
|
||
| var elementSize = Marshal.SizeOf(baseType); |
There was a problem 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 Jason Shirk (@lzybkr)'s comments that this would return the wrong size for boolean values?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Format-Hex should support all primitive types (including enums) and arrays of these types - instead of this random assortment.
There was an error while loading. Please reload this page.