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

SAL annotations are incorrectly being interpreted as Optional #805

Closed
kennykerr opened this issue Feb 12, 2022 · 2 comments
Closed

SAL annotations are incorrectly being interpreted as Optional #805

kennykerr opened this issue Feb 12, 2022 · 2 comments
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working

Comments

@kennykerr
Copy link
Contributor

kennykerr commented Feb 12, 2022

The SAL annotation for IWeakReferenceSource.GetWeakReference indicates that its parameter is __RPC__deref_out_opt, which indicates that the caller must provide a valid pointer - it is not optional - but that it may return a null pointer back to the caller. The two canonical implementations (WRL and C++/WinRT) both treat it as required and will AV if a valid pointer is not provided.

The metadata should remove the [Optional] attribute to correctly describe APIs with this annotation.

@kennykerr kennykerr changed the title IWeakReferenceSource.GetWeakReference is not optional SAL annotations are incorrectly being interpreted as Optional Feb 12, 2022
@kennykerr
Copy link
Contributor Author

This seems to be a much larger problem of misapplying [Optional] to certain SAL annotations. For example, IMLOperatorKernelContext.GetInputTensor is said to have an optional out parameter but that's not what the _COM_Outptr_result_maybenull_ annotation means. That annotation means that the parameter is required but that null may be returned to the caller.

@riverar
Copy link
Collaborator

riverar commented Feb 12, 2022

Think #803 is also related, and overall related to SAL annotation parser needing some tweaks.

else if (salAttr.P1.StartsWith("__RPC__"))
{
// TODO: Handle ecount, xcount and others that deal with counts
string[] parts = salAttr.P1.Split('_');
foreach (var part in parts)
{
switch (part)
{
case "in":
isIn = true;
break;
case "out":
isOut = true;
break;
case "inout":
isIn = isOut = true;
break;
case "opt":
isOpt = true;
break;
}
}
break;
}

@mikebattista mikebattista added the bug Something isn't working label Feb 14, 2022
@mikebattista mikebattista added the broken api An API is inaccurate and could lead to runtime failure label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants