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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ public BlockSyntax GenerateStubBody(int index, ImmutableArray<FunctionPointerUnm
}

tryStatements.AddRange(statements.NotifyForSuccessfulInvoke);

// Keep the this object alive across the native call, similar to how we handle marshalling managed delegates.
// We do this right after the NotifyForSuccessfulInvoke phase as that phase is where the delegate objects are kept alive.
// If we ever move the "this" object handling out of this type, we'll move the handling to be emitted in that phase.
// GC.KeepAlive(this);
tryStatements.Add(
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
ParseTypeName(TypeNames.System_GC),
IdentifierName("KeepAlive")),
ArgumentList(SingletonSeparatedList(Argument(ThisExpression()))))));

tryStatements.AddRange(statements.Unmarshal);

List<StatementSyntax> allStatements = setupStatements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static class TypeNames

public const string System_Exception = "System.Exception";

public const string System_GC = "System.GC";

public const string System_Type = "System.Type";

public const string System_Int16 = "System.Int16";
Expand Down