-
Notifications
You must be signed in to change notification settings - Fork 465
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
Simplify header handling in HSTRING #1747
Conversation
Let's merge #1749 first just to be sure we don't break anything. 😉 |
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 good! I added a few comments, but they're mostly just (bad) ideas to consider for the future.
} | ||
|
||
#[repr(C)] | ||
struct Shared { | ||
count: RefCount, | ||
buffer_start: u16, |
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'm guessing this is this way to match the way things already were in COM-land, but it's a little weird to me that buffer_start
is not zero-sized.
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.
Not having this as a zero-sized type caused some confusion that I was discussing with @kennykerr - namely, that we allocate std::mem::size_of::<Header> + 2 * length_of_hstring
bytes we're allocating enough space for string data that fits all of the contents accounted for by length_of_hstring
plus a terminating null u16
which length_of_string
does not account for but that extra u16
in Header
does.
Definitely something to consider...
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 just the way the HSTRING
was implemented internally by the OS, so it helps to keep the header representation similar for clarity. Note that an empty, or zero-length, HSTRING
is internally represented by a null pointer so there will never be a zero-length header.
b7adc8b
to
6b3afb6
Compare
@kennykerr this should be ready to go now. While I have your attention, it seems we're debug asserting in |
It is strictly a bug in the language projection if this debug assert is true. I added it just to validate my implementation was correct when I first wrote the code but it can never happen, short of a logic bug in the |
This simplifies the
HSTRING
header and adds more safety documentation.