Skip to content
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

mention that PWSTR and PSTR are strings #589

Closed
smasher164 opened this issue Jul 27, 2021 · 7 comments
Closed

mention that PWSTR and PSTR are strings #589

smasher164 opened this issue Jul 27, 2021 · 7 comments

Comments

@smasher164
Copy link
Member

PWSTR and PSTR are uint16_t*. Is it possible to extend the metadata with info that they are string-like?

@tdakkota notes in golang/go#43838 (comment) that setting a TypeAttribute of AnsiClass/UnicodeClass or giving it ELEMENT_TYPE_STRING are possibilities.

Currently, windows-rs and zigwin32gen maintain a list of well-known types to deal with these.

@weltkante
Copy link

weltkante commented Aug 3, 2021

Currently, windows-rs and zigwin32gen maintain a list of well-known types to deal with these.

That probably can't be avoided. Nothing against annotating PWSTR and PSTR but there are other string-like types (probably mostly in the APIs involving COM) which require usage of specific allocators and string manipulation functions (i.e. not just a zero terminated sequence of characters), so projections always have to special case these.

If there's an annotation to be interoduced you need to chose the semantic of being a "string-like type" very carefully for it to have any value, otherwise it provides no gain if you still have to differentiate between the different string-like types in the projection anyways.

@smasher164
Copy link
Member Author

you need to chose the semantic of being a "string-like type"

Right. This doesn't need to be a single piece of metadata. I think it would be useful to know information about the expected string, like whether it's null-terminated, its encoding, etc...

@marler8997
Copy link
Contributor

marler8997 commented Aug 3, 2021

Since I think these are the only 2 types the metadata uses to represent strings (i.e. pointers to null-terminated character arrays), I don't see a benefit to creating new attribute for this. Unless there are more types that would use these new attributes? Otherwise, checking for the specially named types PSTR and PWSTR wouldn't be much different than checking for a new "string-like" attribute.

@mikebattista
Copy link
Contributor

@sotteson1 @kennykerr what are your thoughts on this? If WinRT is using ELEMENT_TYPE_STRING, should we be using it here?

@kennykerr
Copy link
Contributor

That is already used by WinRT to represent HSTRING so that would be incompatible with language projections that support both WinRT and Win32. What we have now is a reasonable compromise to support both.

@mikebattista
Copy link
Contributor

That probably can't be avoided. Nothing against annotating PWSTR and PSTR but there are other string-like types (probably mostly in the APIs involving COM) which require usage of specific allocators and string manipulation functions (i.e. not just a zero terminated sequence of characters), so projections always have to special case these.

BSTR is one such example, right?

That is already used by WinRT to represent HSTRING so that would be incompatible with language projections that support both WinRT and Win32. What we have now is a reasonable compromise to support both.

Ok. Is this a Won't Fix? Or is there anything we can/should do here?

@kennykerr
Copy link
Contributor

We already have types for PSTR, PWSTR, BSTR, and so on. I don't there's anything to do here. Language projections must deal with these "well-known" types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants