-
Notifications
You must be signed in to change notification settings - Fork 93
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
Preserve null terminating character in ref Span<char>
parameters
#1296
base: main
Are you sure you want to change the base?
Conversation
@JeremyKuhne @AaronRobinsonMSFT This change seems like the right one for the original issue. But the fact that it required a test change to compensate well-describes the breaking change that it entails. |
This doesn't seem like a good solution for all the reasons assumed. The issue here is treating a I think the correct solution here is to fix up the generated API and use the same type in the signature for the same type in all places. Right now the return is The API in question is a bit weird and playing games with the C/C++ defintion of strings, perhaps mistake (3) or even (4). I would fix the types to all match in the same way they match the C/C++ definition and make them play well together. if (pwszPrevCDFTag != null && pwszPrevCDFTag.LastIndexOf('\0') == -1) throw new ("Required null terminator missing.", "pwszPrevCDFTag"); I think the above /cc @jkoritzinsky |
Thank you very much for your analysis, @AaronRobinsonMSFT. I don't understand it all yet. But if your high-level point is we shouldn't accept |
This is precisely my point and why the |
So far, the friendly overloads try to avoid allocations or requiring allocations. In this case where they use |
That is a completely reasonable approach in this case. This approach then does mean that |
Personally, I'd be very careful exposing too much help around buffers that need null terminated with low-level .NET types. For more complicated scenarios I'd either avoid the risk or create wrapper One example of encapsulation WinForms uses for buffers is For read-only in parameters on .NET (not .NET Framework) you can use One option I have tried that works down-level is to create an encapsulating type for in "null terminated string" parameters: public readonly ref struct StringSpan
{
private readonly ReadOnlySpan<char> _span;
private readonly string? _string;
// ... |
Thanks.
That is in fact what |
Fixes #1295