Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/ObjCRuntime/TrampolineBlockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

using System.ComponentModel;

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace ObjCRuntime {

// infrastucture code - not intended to be used directly by user code
/// <summary>Base type for Objective-C trampoline blocks.</summary>
// infrastructure code - not intended to be used directly by user code
[EditorBrowsable (EditorBrowsableState.Never)]
public abstract class TrampolineBlockBase {

Expand All @@ -23,6 +23,8 @@ internal TrampolineBlockBase (IntPtr block, bool owns)
}
}

/// <summary>Initializes a new instance from a block literal pointer.</summary>
/// <param name="block">A pointer to a native <see cref="BlockLiteral"/>.</param>
protected unsafe TrampolineBlockBase (BlockLiteral* block)
: this ((IntPtr) block, false)
{
Expand All @@ -33,12 +35,19 @@ protected unsafe TrampolineBlockBase (BlockLiteral* block)
Runtime.ReleaseBlockOnMainThread (blockPtr);
}

/// <summary>Gets the native block pointer for this instance.</summary>
/// <value>The native block pointer.</value>
protected IntPtr BlockPointer {
get { return blockPtr; }
}

protected unsafe static object GetExistingManagedDelegate (IntPtr block)
/// <summary>Gets the existing managed delegate for a block if it wraps managed code.</summary>
/// <param name="block">The native block pointer.</param>
/// <returns>The managed delegate if this is a managed block; otherwise, <see langword="null"/>.</returns>
protected unsafe static object? GetExistingManagedDelegate (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (!BlockLiteral.IsManagedBlock (block))
return null;
return ((BlockLiteral*) block)->Target;
Expand Down
2 changes: 1 addition & 1 deletion src/UIKit/UICellAccessory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public unsafe NIDUICellAccessoryPosition (BlockLiteral* block) : base (block)
{
if (block == IntPtr.Zero)
return null;
var del = (UICellAccessoryPosition) GetExistingManagedDelegate (block);
var del = (UICellAccessoryPosition?) GetExistingManagedDelegate (block);
return del ?? new NIDUICellAccessoryPosition ((BlockLiteral*) block).Invoke;
}

Expand Down
2 changes: 1 addition & 1 deletion src/UIKit/UIConfigurationColorTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public unsafe NIDUIConfigurationColorTransformerHandler (BlockLiteral* block) :
{
if (block == IntPtr.Zero)
return null;
var del = (UIConfigurationColorTransformerHandler) GetExistingManagedDelegate (block);
var del = (UIConfigurationColorTransformerHandler?) GetExistingManagedDelegate (block);
return del ?? new NIDUIConfigurationColorTransformerHandler ((BlockLiteral*) block).Invoke;
}

Expand Down
2 changes: 1 addition & 1 deletion src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ void GenerateTrampolinesForQueue (TrampolineInfo [] queue)
print ("public unsafe static {0}? Create (IntPtr block)\n{{", ti.UserDelegate); indent++;
print ("if (block == IntPtr.Zero)"); indent++;
print ("return null;"); indent--;
print ($"var del = ({ti.UserDelegate}) GetExistingManagedDelegate (block);");
print ($"var del = ({ti.UserDelegate}?) GetExistingManagedDelegate (block);");
print ($"return del ?? new {ti.NativeInvokerName} ((BlockLiteral *) block).Invoke;");
indent--; print ("}");
print ("");
Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15322,9 +15322,7 @@ M:ObjCRuntime.ThrowHelper.ThrowArgumentNullException(System.String)
M:ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException(System.String,System.Object,System.String)
M:ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException(System.String,System.String)
M:ObjCRuntime.ThrowHelper.ThrowObjectDisposedException(System.Object)
M:ObjCRuntime.TrampolineBlockBase.#ctor(ObjCRuntime.BlockLiteral*)
M:ObjCRuntime.TrampolineBlockBase.Finalize
M:ObjCRuntime.TrampolineBlockBase.GetExistingManagedDelegate(System.IntPtr)
M:ObjCRuntime.TransientAttribute.#ctor
M:OpenGL.CGLContext.Release
M:OpenGL.CGLContext.Retain
Expand Down Expand Up @@ -22960,7 +22958,6 @@ P:ObjCRuntime.ObjCException.Message
P:ObjCRuntime.ObjCException.Name
P:ObjCRuntime.ObjCException.NSException
P:ObjCRuntime.ObjCException.Reason
P:ObjCRuntime.TrampolineBlockBase.BlockPointer
P:OSLog.IOSLogEntryFromProcess.ActivityIdentifier
P:OSLog.IOSLogEntryFromProcess.Process
P:OSLog.IOSLogEntryFromProcess.ProcessIdentifier
Expand Down
Loading