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

Fix bug in test regarding GC'd delegate instance. #34901

Merged
merged 1 commit into from
Apr 13, 2020
Merged
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 @@ -10,35 +10,35 @@ partial class FunctionPtr
public delegate bool DelegateWithLong(long l); //Singlecast delegate
public delegate void MultiDelegateWithLong(long l); //Multicast delegate

public static DelegateWithLong s_DelWithLongBool = new DelegateWithLong(MethodWithLongBool);
public static MultiDelegateWithLong s_MultidelWithLong = new MultiDelegateWithLong(MethodWithLong);

public static void RunGetFcnPtrSingleMulticastTest()
{
Console.WriteLine($"Running {nameof(RunGetFcnPtrSingleMulticastTest)}...");

DelegateWithLong del = new DelegateWithLong(Method);
MultiDelegateWithLong multidel = new MultiDelegateWithLong(Method2);

{
IntPtr fcnptr = Marshal.GetFunctionPointerForDelegate<DelegateWithLong>(del);
IntPtr fcnptr = Marshal.GetFunctionPointerForDelegate<DelegateWithLong>(s_DelWithLongBool);
Assert.IsTrue(FunctionPointerNative.CheckFcnPtr(fcnptr));
}

{
IntPtr fcnptr = Marshal.GetFunctionPointerForDelegate<MultiDelegateWithLong>(multidel);
IntPtr fcnptr = Marshal.GetFunctionPointerForDelegate<MultiDelegateWithLong>(s_MultidelWithLong);
FunctionPointerNative.CheckFcnPtr(fcnptr);
}
}

bool Method(long l)
{
if (l != 999999999999)
return false;
else
return true;
}
private static bool MethodWithLongBool(long l)
{
if (l != 999999999999)
return false;
else
return true;
}

void Method2(long l)
{
if (l != 999999999999)
throw new Exception("Failed multicast call");
}
private static void MethodWithLong(long l)
{
if (l != 999999999999)
throw new Exception("Failed multicast call");
}
}