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

修复Binding结构体赋值时抛出的NotImplementedException异常 #609

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4736,10 +4736,24 @@ void StLocSub(StackObject* esp, StackObject* v, int idx, IList<object> mStack)
if (v->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
CopyStackValueType(esp, v, mStack);
FreeStackValueType(esp);
}
else if(v->ObjectType == ObjectTypes.Object)
{
var dst = ILIntepreter.ResolveReference(esp);
if(dst != null)
{
var ct = domain.GetTypeByIndex(dst->Value) as CLRType;
var binder = ct.ValueTypeBinder;
v->ObjectType = ObjectTypes.ValueTypeObjectReference;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

将值类型绑定的对象往object存的语义是将该对象装箱,因此正确的做法应该是调用StackObject.ToObject(esp)拿到object, 再存入mStack[v->Value]中,然后FreeStackValueType(esp);

int addr = ((IntPtr)dst).ToInt32();
v->Value = addr;
}
else
throw new NotImplementedException();
}
else
throw new NotImplementedException();
FreeStackValueType(esp);
break;
default:
*v = *esp;
Expand Down
24 changes: 24 additions & 0 deletions TestCases/TestValueTypeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,29 @@ public static void UnitTest_10047()
if(Math.Abs(arr2[0].X - 1244)>0.001f)
throw new Exception();
}

public static void UnitTest_10048()
{
var pos = new TestVector3(0f, 0.8f, 0.5f);
var obj = pos as object;
UnitTest_10048Sub(obj);
}

static void UnitTest_10048Sub(object param = null)
{
var context = new UnitTest_10048Context( param);
object data = context.data;
Console.WriteLine("data:" + data.ToString());
}

public class UnitTest_10048Context
{
public object data;

public UnitTest_10048Context(object data = null)
{
this.data = data;
}
}
}
}