Skip to content

Commit 9c3842d

Browse files
mandel-macaqueGitHub Actions Autoformatter
andauthored
[RGen] Add pre-conversion variable for Block callbacks. (#23073)
We are not yet fully doing the convesions needed for a block callback in the native invoker call. We need the following: ```csharp [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] unsafe global::AudioUnit.AudioUnitStatus Invoke (ref global::AudioUnit.AudioUnitRenderActionFlags actionFlags, ref global::AudioToolbox.AudioTimeStamp timestamp, uint frameCount, nint outputBusNumber, global::AudioToolbox.AudioBuffers outputData, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDAURenderPullInputBlock))]global::AudioUnit.AURenderPullInputBlock? pullInputBlock) { var outputData__handle__ = outputData.GetHandle (); using var block_pullInputBlock = Trampolines.SDAURenderPullInputBlock.CreateNullableBlock (pullInputBlock); BlockLiteral *block_ptr_pullInputBlock = null; if (pullInputBlock is not null) block_ptr_pullInputBlock = &block_pullInputBlock; var ret = (AudioUnitStatus) invoker (BlockPointer, (AudioUnitRenderActionFlags*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<AudioUnitRenderActionFlags> (ref actionFlags), (global::AudioToolbox.AudioTimeStamp*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<global::AudioToolbox.AudioTimeStamp> (ref timestamp), frameCount, outputBusNumber, outputData__handle__, (IntPtr) block_ptr_pullInputBlock); GC.KeepAlive (outputData); return ret!; } ``` This change adds the declaration of the 'block_pullInputBlock', we will add the assigment in comming PRs to make the reviews easier. --------- Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
1 parent ffdbc23 commit 9c3842d

File tree

9 files changed

+209
-20
lines changed

9 files changed

+209
-20
lines changed

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.KnownTypes.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static partial class BindingSyntaxFactory {
9191
@namespace: ["ObjCRuntime"],
9292
@class: "ThrowHelper");
9393

94+
public static readonly TypeSyntax Trampolines = StringExtensions.GetIdentifierName (
95+
@namespace: ["ObjCRuntime"],
96+
@class: "Trampolines");
97+
9498
// Foundation types
9599

96100
/// <summary>

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,62 @@ internal static (string Name, LocalDeclarationStatementSyntax Declaration) GetRe
897897
return (Name: variableName, Declaration: declaration);
898898
}
899899

900+
/// <summary>
901+
/// Generates a local variable declaration for an auxiliary variable that holds a native block created from a nullable C# delegate.
902+
/// This method is used to handle block parameters that can be null. It generates a call to a static `CreateNullableBlock`
903+
/// method on a trampoline-specific static bridge class. This helper method is responsible for creating the native block
904+
/// if the delegate is not null, or returning `IntPtr.Zero` if it is.
905+
/// </summary>
906+
/// <param name="trampolineName">The name of the trampoline, used to identify the correct static bridge class.</param>
907+
/// <param name="variableName">The name of the C# delegate variable.</param>
908+
/// <param name="blockTypeInfo">The <see cref="TypeInfo"/> of the delegate.</param>
909+
/// <returns>A <see cref="LocalDeclarationStatementSyntax"/> for the auxiliary nullable block variable.</returns>
910+
internal static LocalDeclarationStatementSyntax GetNullableBlockAuxVariable (string trampolineName, string variableName, in TypeInfo blockTypeInfo)
911+
{
912+
var staticBridgeClassName =
913+
Nomenclator.GetTrampolineClassName (trampolineName, Nomenclator.TrampolineClassType.StaticBridgeClass);
914+
// generates the call to create the nullable block
915+
var invocation = InvocationExpression (
916+
MemberAccessExpression (
917+
SyntaxKind.SimpleMemberAccessExpression,
918+
MemberAccessExpression (
919+
SyntaxKind.SimpleMemberAccessExpression,
920+
Trampolines,
921+
IdentifierName (staticBridgeClassName)),
922+
IdentifierName ("CreateNullableBlock").WithTrailingTrivia (Space)))
923+
.WithArgumentList (
924+
ArgumentList (
925+
SingletonSeparatedList (
926+
Argument (IdentifierName (variableName)))));
927+
// variable declarator 'name = invocation'
928+
var declarator = VariableDeclarator (
929+
Identifier (Nomenclator.GetNameForVariableType (variableName, Nomenclator.VariableType.NullableBlock)!).WithTrailingTrivia (Space))
930+
.WithInitializer (
931+
EqualsValueClause (invocation.WithLeadingTrivia (Space)));
932+
// var declaration
933+
return LocalDeclarationStatement (
934+
VariableDeclaration (
935+
IdentifierName (
936+
Identifier (
937+
TriviaList (),
938+
SyntaxKind.VarKeyword,
939+
"var",
940+
"var",
941+
TriviaList (Space))))
942+
.WithVariables (
943+
SingletonSeparatedList (declarator)));
944+
}
945+
946+
/// <summary>
947+
/// Generates a local variable declaration for an auxiliary variable that holds a native block created from a nullable C# delegate.
948+
/// This is a convenience overload for <see cref="GetNullableBlockAuxVariable(string, string, in TypeInfo)"/>.
949+
/// </summary>
950+
/// <param name="trampolineName">The name of the trampoline, used to identify the correct static bridge class.</param>
951+
/// <param name="parameter">The <see cref="DelegateParameter"/> representing the C# delegate.</param>
952+
/// <returns>A <see cref="LocalDeclarationStatementSyntax"/> for the auxiliary nullable block variable.</returns>
953+
internal static LocalDeclarationStatementSyntax GetNullableBlockAuxVariable (string trampolineName, DelegateParameter parameter)
954+
=> GetNullableBlockAuxVariable (trampolineName, parameter.Name, parameter.Type);
955+
900956
/// <summary>
901957
/// Returns the declaration needed for the string field of a given selector.
902958
/// </summary>

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ internal static TypeSyntax GetLowLevelType (in TypeInfo typeInfo)
322322
{ IsPointer: true } => typeInfo.GetIdentifierSyntax (),
323323

324324
// delegate parameter is a NativeHandle
325-
{ IsDelegate: true } => IntPtr,
325+
{ IsDelegate: true } => NativeHandle,
326326

327327
// native enum, return the conversion expression to the native type
328328
{ IsNativeEnum: true} => GetNativeEnumLowLevel (typeInfo),
@@ -1146,43 +1146,45 @@ internal static ImmutableArray<SyntaxNode> GetTrampolinePreNativeInvokeArgumentC
11461146
// based on the trampoline name and the parameter we will lower the parameter to the expected type for the invoker
11471147
// which is the lower type of the parameter
11481148
#pragma warning disable format
1149-
ImmutableArray<SyntaxNode> conversions = parameter.Type switch {
1149+
ImmutableArray<SyntaxNode> conversions = parameter switch {
11501150
// pointer parameter
1151-
{ IsPointer: true } => [],
1151+
{ Type.IsPointer: true } => [],
11521152

1153-
// delegate parameter is a NativeHandle
1154-
{ IsDelegate: true } => [],
1153+
// block delegate parameter is a NativeHandle
1154+
{ Type.IsDelegate: true, IsBlockCallback: true} => [GetNullableBlockAuxVariable (trampolineName, parameter)],
1155+
1156+
{ Type.IsDelegate: true, IsCCallback: true} => [],
11551157

11561158
// return the conversion expression to the native type
1157-
{ IsSmartEnum: true} => [GetNSStringSmartEnumAuxVariable (parameter)!],
1159+
{ Type.IsSmartEnum: true} => [GetNSStringSmartEnumAuxVariable (parameter)!],
11581160

11591161
// boolean, convert it to byte
1160-
{ SpecialType: SpecialType.System_Boolean } => [],
1162+
{ Type.SpecialType: SpecialType.System_Boolean } => [],
11611163

1162-
{ IsArray: true, ArrayElementType: SpecialType.System_String } => [GetNSArrayAuxVariable (parameter)!],
1164+
{ Type.IsArray: true, Type.ArrayElementType: SpecialType.System_String } => [GetNSArrayAuxVariable (parameter)!],
11631165

1164-
{ IsArray: true, ArrayElementIsINativeObject: true } => [GetNSArrayAuxVariable (parameter)!],
1166+
{ Type.IsArray: true, Type.ArrayElementIsINativeObject: true } => [GetNSArrayAuxVariable (parameter)!],
11651167

1166-
{ SpecialType: SpecialType.System_String } => [GetStringAuxVariable (parameter)!],
1168+
{ Type.SpecialType: SpecialType.System_String } => [GetStringAuxVariable (parameter)!],
11671169

1168-
{ IsProtocol: true } => [GetHandleAuxVariable (parameter)!],
1170+
{ Type.IsProtocol: true } => [GetHandleAuxVariable (parameter)!],
11691171

11701172
// special types
11711173

11721174
// CoreMedia.CMSampleBuffer
1173-
{ FullyQualifiedName: "CoreMedia.CMSampleBuffer" } => [GetHandleAuxVariable (parameter)!],
1175+
{ Type.FullyQualifiedName: "CoreMedia.CMSampleBuffer" } => [GetHandleAuxVariable (parameter)!],
11741176

11751177
// AudioToolbox.AudioBuffers
1176-
{ FullyQualifiedName: "AudioToolbox.AudioBuffers" } => [GetHandleAuxVariable (parameter)!],
1178+
{ Type.FullyQualifiedName: "AudioToolbox.AudioBuffers" } => [GetHandleAuxVariable (parameter)!],
11771179

11781180
// general NSObject/INativeObject, has to be after the special types otherwise the special types will
11791181
// fall into the NSObject/INativeObject case
11801182

11811183
// same name, native handle
1182-
{ IsNSObject: true } => [GetHandleAuxVariable (parameter)!],
1184+
{ Type.IsNSObject: true } => [GetHandleAuxVariable (parameter)!],
11831185

11841186
// same name, native handle
1185-
{ IsINativeObject: true } => [GetHandleAuxVariable (parameter)!],
1187+
{ Type.IsINativeObject: true } => [GetHandleAuxVariable (parameter)!],
11861188

11871189
// by default, we will use the parameter name as is and the type of the parameter
11881190
_ => [],

src/rgen/Microsoft.Macios.Generator/Nomenclator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum VariableType {
2626
NSArray,
2727
NSString,
2828
NSStringStruct,
29+
NullableBlock,
2930
PrimitivePointer,
3031
StringPointer,
3132
BindFrom,
@@ -127,6 +128,7 @@ public static string GetTrampolineClassName (string trampolineName, TrampolineCl
127128
VariableType.NSArray => $"nsa_{cleanedName}",
128129
VariableType.NSString => $"ns{cleanedName}",
129130
VariableType.NSStringStruct => $"_s{cleanedName}",
131+
VariableType.NullableBlock => $"block_{cleanedName}",
130132
VariableType.PrimitivePointer => $"converted_{cleanedName}",
131133
VariableType.StringPointer => $"_p{cleanedName}",
132134
VariableType.BindFrom => $"nsb_{cleanedName}",

tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedTrampolinePropertyTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#nullable enable
44

5+
using AudioUnit;
56
using AVFoundation;
67
using CoreGraphics;
78
using CoreImage;
@@ -94,6 +95,14 @@ public partial class TrampolinePropertyTests
9495
const string selSetManualRenderingCallback_X = "setManualRenderingCallback:";
9596
static readonly global::ObjCRuntime.NativeHandle selSetManualRenderingCallback_XHandle = global::ObjCRuntime.Selector.GetHandle ("setManualRenderingCallback:");
9697

98+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
99+
const string selInternalRenderBlockHandlerX = "internalRenderBlockHandler";
100+
static readonly global::ObjCRuntime.NativeHandle selInternalRenderBlockHandlerXHandle = global::ObjCRuntime.Selector.GetHandle ("internalRenderBlockHandler");
101+
102+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
103+
const string selSetInternalRenderBlockHandler_X = "setInternalRenderBlockHandler:";
104+
static readonly global::ObjCRuntime.NativeHandle selSetInternalRenderBlockHandler_XHandle = global::ObjCRuntime.Selector.GetHandle ("setInternalRenderBlockHandler:");
105+
97106
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
98107
static readonly global::ObjCRuntime.NativeHandle class_ptr = global::ObjCRuntime.Class.GetHandle ("TrampolinePropertyTests");
99108

@@ -326,6 +335,27 @@ protected internal TrampolinePropertyTests (global::ObjCRuntime.NativeHandle han
326335
}
327336
}
328337

338+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
339+
public partial global::AudioUnit.AUInternalRenderBlock InternalRenderBlockHandler
340+
{
341+
get
342+
{
343+
global::AudioUnit.AUInternalRenderBlock ret;
344+
if (IsDirectBinding) {
345+
ret = global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("internalRenderBlockHandler"));
346+
} else {
347+
ret = global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("internalRenderBlockHandler"));
348+
}
349+
global::System.GC.KeepAlive (this);
350+
return ret;
351+
}
352+
353+
set
354+
{
355+
throw new NotImplementedException();
356+
}
357+
}
358+
329359
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
330360
public partial global::CoreImage.CIKernelRoiCallback KernelRoiCallback
331361
{

tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedTrampolinePropertyTestsTrampolines.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#nullable enable
44

5+
using AudioUnit;
56
using AVFoundation;
67
using CoreImage;
78
using Foundation;
@@ -498,4 +499,75 @@ public unsafe NIDAVAudioEngineManualRenderingBlock (global::ObjCRuntime.BlockLit
498499
}
499500
}
500501

502+
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
503+
[UserDelegateType (typeof (global::AudioUnit.AUInternalRenderBlock))]
504+
unsafe internal delegate global::AudioUnit.AudioUnitStatus DAUInternalRenderBlock (global::System.IntPtr block_ptr, global::AudioUnit.AudioUnitRenderActionFlags* actionFlags, global::AudioToolbox.AudioTimeStamp* timestamp, uint frameCount, global::System.IntPtr outputBusNumber, global::ObjCRuntime.NativeHandle outputData, global::ObjCRuntime.NativeHandle realtimeEventListHead, global::ObjCRuntime.NativeHandle pullInputBlock);
505+
506+
/// <summary>This class bridges native block invocations that call into C#</summary>
507+
static internal class SDAUInternalRenderBlock
508+
{
509+
[Preserve (Conditional = true)]
510+
[UnmanagedCallersOnly]
511+
[UserDelegateType (typeof (global::AudioUnit.AUInternalRenderBlock))]
512+
internal static unsafe global::AudioUnit.AudioUnitStatus Invoke (global::System.IntPtr block_ptr, global::AudioUnit.AudioUnitRenderActionFlags* actionFlags, global::AudioToolbox.AudioTimeStamp* timestamp, uint frameCount, global::System.IntPtr outputBusNumber, global::ObjCRuntime.NativeHandle outputData, global::ObjCRuntime.NativeHandle realtimeEventListHead, global::ObjCRuntime.NativeHandle pullInputBlock)
513+
{
514+
*actionFlags = default;
515+
*timestamp = default;
516+
var del = global::ObjCRuntime.BlockLiteral.GetTarget<global::AudioUnit.AUInternalRenderBlock> (block_ptr);
517+
if (del is null)
518+
throw ErrorHelper.CreateError (8059, Errors.MX8059, block_ptr, typeof (global::AudioUnit.AUInternalRenderBlock));
519+
var ret = del (ref global::System.Runtime.CompilerServices.Unsafe.AsRef<global::AudioUnit.AudioUnitRenderActionFlags> (actionFlags), ref global::System.Runtime.CompilerServices.Unsafe.AsRef<global::AudioToolbox.AudioTimeStamp> (timestamp), frameCount, outputBusNumber, new global::AudioToolbox.AudioBuffers (outputData), global::ObjCRuntime.Runtime.GetINativeObject<global::AudioUnit.AURenderEventEnumerator> (realtimeEventListHead, false)!, NIDAUInternalRenderBlock.Create (pullInputBlock)!);
520+
return ret;
521+
}
522+
523+
internal static unsafe global::ObjCRuntime.BlockLiteral CreateNullableBlock (global::AudioUnit.AUInternalRenderBlock? callback)
524+
{
525+
if (callback is null)
526+
return default (global::ObjCRuntime.BlockLiteral);
527+
return CreateBlock (callback);
528+
}
529+
530+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
531+
internal static unsafe global::ObjCRuntime.BlockLiteral CreateBlock (global::AudioUnit.AUInternalRenderBlock callback)
532+
{
533+
delegate* unmanaged<global::System.IntPtr, global::AudioUnit.AudioUnitRenderActionFlags*, global::AudioToolbox.AudioTimeStamp*, uint, global::System.IntPtr, global::ObjCRuntime.NativeHandle, global::ObjCRuntime.NativeHandle, global::ObjCRuntime.NativeHandle, global::AudioUnit.AudioUnitStatus> trampoline = &Invoke;
534+
return new global::ObjCRuntime.BlockLiteral (trampoline, callback, typeof (SDAUInternalRenderBlock), nameof (Invoke));
535+
}
536+
}
537+
internal sealed class NIDAUInternalRenderBlock : TrampolineBlockBase
538+
{
539+
DAUInternalRenderBlock invoker;
540+
541+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
542+
public unsafe NIDAUInternalRenderBlock (global::ObjCRuntime.BlockLiteral *block) : base (block)
543+
{
544+
invoker = block->GetDelegateForBlock<DAUInternalRenderBlock> ();
545+
}
546+
547+
[Preserve (Conditional=true)]
548+
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
549+
public unsafe static DAUInternalRenderBlock? Create (IntPtr block)
550+
{
551+
if (block == IntPtr.Zero)
552+
return null;
553+
var del = (DAUInternalRenderBlock) GetExistingManagedDelegate (block);
554+
return del ?? new NIDAUInternalRenderBlock ((global::ObjCRuntime.BlockLiteral *) block).Invoke;
555+
}
556+
557+
unsafe global::AudioUnit.AudioUnitStatus Invoke (ref global::AudioUnit.AudioUnitRenderActionFlags actionFlags, ref global::AudioToolbox.AudioTimeStamp timestamp, uint frameCount, global::System.IntPtr outputBusNumber, global::AudioToolbox.AudioBuffers outputData, global::AudioUnit.AURenderEventEnumerator realtimeEventListHead, global::AudioUnit.AURenderPullInputBlock? pullInputBlock)
558+
{
559+
if (outputData is null)
560+
global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputData));
561+
var outputData__handle__ = outputData.GetHandle ();
562+
if (realtimeEventListHead is null)
563+
global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (realtimeEventListHead));
564+
var realtimeEventListHead__handle__ = realtimeEventListHead.GetHandle ();
565+
var block_pullInputBlock = global::ObjCRuntime.Trampolines.SDAUInternalRenderBlock.CreateNullableBlock (pullInputBlock);
566+
var ret = invoker (BlockLiteral, (global::AudioUnit.AudioUnitRenderActionFlags*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<global::AudioUnit.AudioUnitRenderActionFlags> (ref actionFlags), (global::AudioToolbox.AudioTimeStamp*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<global::AudioToolbox.AudioTimeStamp> (ref timestamp), frameCount, outputBusNumber, outputData__handle__, realtimeEventListHead__handle__, NIDAUInternalRenderBlock.Create (pullInputBlock)!);
567+
global::System.GC.KeepAlive (outputData);
568+
global::System.GC.KeepAlive (realtimeEventListHead);
569+
return ret;
570+
}
571+
}
572+
501573
}

tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/TrampolinePropertyTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Macios.Generator.Tests.Classes.Data;
1414
using Foundation;
1515
using ObjCBindings;
1616
using ObjCRuntime;
17+
using AudioUnit;
1718

1819
namespace TestNamespace;
1920

@@ -62,4 +63,7 @@ public partial class TrampolinePropertyTests {
6263
// Property using AVAssetImageGenerator.AsynchronouslyForTimeCompletionHandler
6364
[Export<Property> ("manualRenderingCallback", ArgumentSemantic.Copy)]
6465
public partial AVAudioEngineManualRenderingBlock ManualRendering { get; set; }
66+
67+
[Export<Property> ("internalRenderBlockHandler", ArgumentSemantic.Copy)]
68+
public partial AUInternalRenderBlock InternalRenderBlockHandler { get; set; }
6569
}

tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryTrampolineTests.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ public void MyMethod (Callback cb) {}
22372237
yield return [
22382238
ccallbackParameter,
22392239
"DCallback",
2240-
$"unsafe internal delegate void DCallback ({Global ("System")}.IntPtr block_ptr, {Global ("System")}.IntPtr callbackParameter);",
2240+
$"unsafe internal delegate void DCallback ({Global ("System")}.IntPtr block_ptr, {Global ("ObjCRuntime")}.NativeHandle callbackParameter);",
22412241
];
22422242

22432243
var nativeEnumParameter = @"
@@ -2879,7 +2879,7 @@ public void MyMethod (Callback cb) {}
28792879

28802880
yield return [
28812881
ccallbackParameter,
2882-
$"{Global ("System")}.IntPtr callbackParameter"
2882+
$"{Global ("ObjCRuntime")}.NativeHandle callbackParameter"
28832883
];
28842884

28852885
var blockParameter = @"
@@ -2896,7 +2896,7 @@ public void MyMethod (Callback cb) {}
28962896

28972897
yield return [
28982898
blockParameter,
2899-
$"{Global ("System")}.IntPtr callbackParameter",
2899+
$"{Global ("ObjCRuntime")}.NativeHandle callbackParameter",
29002900
];
29012901

29022902
var nativeEnumParameter = @"
@@ -3279,7 +3279,7 @@ public void MyMethod (Callback cb) {}
32793279

32803280
yield return [
32813281
ccallbackParameter,
3282-
$"internal static unsafe void Invoke ({Global ("System")}.IntPtr block_ptr, {Global ("System")}.IntPtr callbackParameter)",
3282+
$"internal static unsafe void Invoke ({Global ("System")}.IntPtr block_ptr, {Global ("ObjCRuntime")}.NativeHandle callbackParameter)",
32833283
];
32843284

32853285
var nativeEnumParameter = @"
@@ -3651,7 +3651,7 @@ public void MyMethod (Callback cb) {}
36513651

36523652
yield return [
36533653
ccallbackParameter,
3654-
$"delegate* unmanaged<{Global ("System")}.IntPtr, {Global ("System")}.IntPtr, void> trampoline = &Invoke;",
3654+
$"delegate* unmanaged<{Global ("System")}.IntPtr, {Global ("ObjCRuntime")}.NativeHandle, void> trampoline = &Invoke;",
36553655
];
36563656

36573657
var nativeEnumParameter = @"
@@ -4837,6 +4837,24 @@ public void MyMethod (Callback cb) {}
48374837
cmSampleBuffer,
48384838
"var cmSampleBuffer__handle__ = cmSampleBuffer!.GetNonNullHandle (nameof (cmSampleBuffer));\n",
48394839
];
4840+
4841+
var blockParameter = @"
4842+
using System;
4843+
using ObjCRuntime;
4844+
4845+
namespace NS {
4846+
public delegate void Callback ([BlockCallback] Action? callbackParameter);
4847+
public class MyClass {
4848+
public void MyMethod (Callback cb) {}
4849+
}
4850+
}
4851+
";
4852+
4853+
yield return [
4854+
"someTrampolineName",
4855+
blockParameter,
4856+
$"var block_callbackParameter = {Global ("ObjCRuntime.Trampolines.")}{Nomenclator.GetTrampolineClassName ("someTrampolineName", Nomenclator.TrampolineClassType.StaticBridgeClass)}.CreateNullableBlock (callbackParameter);\n",
4857+
];
48404858
}
48414859

48424860
IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();

tests/rgen/Microsoft.Macios.Generator.Tests/NomenclatorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public IEnumerator<object []> GetEnumerator ()
158158
yield return [exampleParameter, Nomenclator.VariableType.NSArray, $"nsa_{exampleParameter.Name}"];
159159
yield return [exampleParameter, Nomenclator.VariableType.NSString, $"ns{exampleParameter.Name}"];
160160
yield return [exampleParameter, Nomenclator.VariableType.NSStringStruct, $"_s{exampleParameter.Name}"];
161+
yield return [exampleParameter, Nomenclator.VariableType.NullableBlock, $"block_{exampleParameter.Name}"];
161162
yield return [exampleParameter, Nomenclator.VariableType.BindFrom, $"nsb_{exampleParameter.Name}"];
162163
}
163164

0 commit comments

Comments
 (0)