Skip to content

Commit 0d3c2e2

Browse files
authored
[tests] Add new cecil test to verify the correct [BindingImpl] on methods using blocks. (#23680)
1 parent 2cf81a6 commit 0d3c2e2

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/Accessibility/AXSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static bool IsAssistiveAccessEnabled {
5858
[SupportedOSPlatform ("maccatalyst18.0")]
5959
[SupportedOSPlatform ("macos15.0")]
6060
[SupportedOSPlatform ("tvos18.0")]
61+
[BindingImpl (BindingImplOptions.Optimizable)]
6162
public unsafe static void OpenSettingsFeature (AXSettingsFeature feature, Action<NSError?> completionHandler)
6263
{
6364
delegate* unmanaged<IntPtr, IntPtr, void> trampoline = &OpenSettingsFeatureCompletionHandler;

src/Security/SecProtocolOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ public void SetTlsPreSharedKeyIdentityHint (DispatchData pskIdentityHint)
463463
[SupportedOSPlatform ("macos")]
464464
[SupportedOSPlatform ("ios")]
465465
[SupportedOSPlatform ("maccatalyst")]
466+
[BindingImpl (BindingImplOptions.Optimizable)]
466467
public void SetChallengeBlock (SecProtocolChallenge challenge, DispatchQueue queue)
467468
{
468469
unsafe {
@@ -487,6 +488,7 @@ public void SetChallengeBlock (SecProtocolChallenge challenge, DispatchQueue que
487488
[SupportedOSPlatform ("macos")]
488489
[SupportedOSPlatform ("ios")]
489490
[SupportedOSPlatform ("maccatalyst")]
491+
[BindingImpl (BindingImplOptions.Optimizable)]
490492
public void SetVerifyBlock (SecProtocolVerify verify, DispatchQueue queue)
491493
{
492494
unsafe {
@@ -511,6 +513,7 @@ public void SetVerifyBlock (SecProtocolVerify verify, DispatchQueue queue)
511513
[SupportedOSPlatform ("macos")]
512514
[SupportedOSPlatform ("ios13.0")]
513515
[SupportedOSPlatform ("maccatalyst")]
516+
[BindingImpl (BindingImplOptions.Optimizable)]
514517
public void SetPreSharedKeySelectionBlock (SecProtocolPreSharedKeySelection selection, DispatchQueue queue)
515518
{
516519
unsafe {

src/VideoToolbox/VTRawProcessingSession.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ unsafe static extern VTStatus VTRAWProcessingSessionSetParameterChangedHander (
114114

115115
/// <summary>Provide a callback that will be called when the VTRawProcessingPlugin changes the set of processing parameters.</summary>
116116
/// <param name="handler">The callback that will be called. Set to null to remove the current handler.</param>
117+
[BindingImpl (BindingImplOptions.Optimizable)]
117118
public unsafe VTStatus SetParameterChangedHandler (VTRawProcessingParameterChangeHandler? handler)
118119
{
119120
if (handler is null) {
@@ -147,6 +148,7 @@ unsafe static extern VTStatus VTRAWProcessingSessionProcessFrame (
147148
/// <param name="inputPixelBuffer">The input video frame to process.</param>
148149
/// <param name="frameOptions">An optional dictionary of options.</param>
149150
/// <param name="handler">The callback that will be called when processing is complete.</param>
151+
[BindingImpl (BindingImplOptions.Optimizable)]
150152
public unsafe VTStatus ProcessFrame (CVPixelBuffer inputPixelBuffer, NSDictionary? frameOptions, VTRawProcessingOutputHandler handler)
151153
{
152154
delegate* unmanaged<IntPtr, VTStatus, IntPtr, void> trampoline = &VTRawProcessingOutputHandlerCallback;

tests/cecil-tests/BlittablePInvokes.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ public void CheckForBlockLiterals ()
438438
foreach (var info in Helper.NetPlatformImplementationAssemblyDefinitions) {
439439
var assembly = info.Assembly;
440440
foreach (var type in assembly.EnumerateTypes ()) {
441+
if (type.Is ("ObjCRuntime", "BlockLiteral"))
442+
continue;
443+
441444
foreach (var method in type.EnumerateMethods (m => m.HasBody)) {
442445
var body = method.Body;
443446
foreach (var instr in body.Instructions) {
@@ -458,14 +461,25 @@ public void CheckForBlockLiterals ()
458461
switch (targetMethod.Name) {
459462
case "SetupBlock":
460463
case "SetupBlockUnsafe":
461-
break;
464+
var location = method.RenderLocation (instr);
465+
var message = $"The call to {targetMethod.Name} in {method.AsFullName ()} must be converted to new Block syntax.";
466+
failures [message] = new (message, location);
467+
continue;
468+
case ".ctor":
469+
if (!method.HasBindingImplAttribute (out var bindingImplOptions)) {
470+
var loc = method.RenderLocation (body.Instructions.First ());
471+
var msg = $"{method.AsFullName ()}: needs [BindingImpl (BindingImplOptions.Optimizable)] because this method creates a BlockLiteral.";
472+
failures [msg] = new (msg, loc);
473+
} else if ((bindingImplOptions & BindingImplOptions.Optimizable) != BindingImplOptions.Optimizable) {
474+
var loc = method.RenderLocation (body.Instructions.First ());
475+
var msg = $"{method.AsFullName ()}: has the required [BindingImpl] attribute (because this method creates a BlockLiteral), but the BindingImplOptions.Optimizable flag isn't set.";
476+
failures [msg] = new (msg, loc);
477+
}
478+
continue;
462479
default:
463480
continue;
464481
}
465482

466-
var location = method.RenderLocation (instr);
467-
var message = $"The call to {targetMethod.Name} in {method.AsFullName ()} must be converted to new Block syntax.";
468-
failures [message] = new (message, location);
469483
}
470484
}
471485
}
@@ -475,10 +489,6 @@ public void CheckForBlockLiterals ()
475489
}
476490

477491
static HashSet<string> knownFailuresBlockLiterals = new HashSet<string> {
478-
"The call to SetupBlock in ObjCRuntime.BlockLiteral.CreateBlockForDelegate(System.Delegate, System.Delegate, System.String) must be converted to new Block syntax.",
479-
"The call to SetupBlock in ObjCRuntime.BlockLiteral.GetBlockForDelegate(System.Reflection.MethodInfo, System.Object, System.UInt32, System.String) must be converted to new Block syntax.",
480-
"The call to SetupBlock in ObjCRuntime.BlockLiteral.SetupBlock(System.Delegate, System.Delegate) must be converted to new Block syntax.",
481-
"The call to SetupBlock in ObjCRuntime.BlockLiteral.SetupBlockUnsafe(System.Delegate, System.Delegate) must be converted to new Block syntax.",
482492
};
483493

484494
[Test]

0 commit comments

Comments
 (0)