bizinvoke: make class ref interop work with null pointers

This commit is contained in:
nattthebear 2017-05-27 14:40:15 -04:00
parent b737959d11
commit b649927360
1 changed files with 11 additions and 0 deletions

View File

@ -478,6 +478,12 @@ namespace BizHawk.Common.BizInvoke
{
// non ref of class can just be passed as pointer
var loc = il.DeclareLocal(type, true);
var end = il.DefineLabel();
var isNull = il.DefineLabel();
il.Emit(OpCodes.Ldarg, (short)idx);
il.Emit(OpCodes.Brfalse, isNull);
il.Emit(OpCodes.Ldarg, (short)idx);
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Stloc, loc);
@ -486,6 +492,11 @@ namespace BizHawk.Common.BizInvoke
il.Emit(IntPtr.Size == 4 ? OpCodes.Ldc_I4_4 : OpCodes.Ldc_I4_8);
il.Emit(OpCodes.Conv_I);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Br, end);
il.MarkLabel(isNull);
LoadConstant(il, IntPtr.Zero);
il.MarkLabel(end);
return typeof(IntPtr);
}