From 89fccce9139d677d1d22f299eb7d86a06ac442cc Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Fri, 26 Sep 2025 14:30:39 +0400 Subject: [PATCH 1/3] =?UTF-8?q?fix=20#1588:=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=B0=20=D0=BF=D1=80=D0=BE=D0=BF=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20=D0=B2=20COM-=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=BA=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Machine/Contexts/COMWrapperContext.cs | 2 +- .../Machine/Contexts/ContextValuesMarshaller.cs | 14 ++++---------- src/ScriptEngine/Machine/MachineInstance.cs | 9 ++++++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs b/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs index ae7c4a931..769ec27c3 100644 --- a/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs +++ b/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs @@ -146,7 +146,7 @@ public static object MarshalIValue(IValue val) } else { - retValue = ContextValuesMarshaller.ConvertToCLRObject(val) ?? Missing.Value; + retValue = ContextValuesMarshaller.ConvertToCLRObject(val); } return retValue; diff --git a/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs b/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs index 620f447b5..61fa550e7 100644 --- a/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs +++ b/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs @@ -251,19 +251,13 @@ public static object ConvertToCLRObject(IValue val) case DataType.Number: return val.AsNumber(); case DataType.String: return val.AsString(); case DataType.Undefined: return null; + case DataType.NotAValidValue: return Missing.Value; } - object result; - - if (val.DataType == DataType.Object) - result = val.AsObject(); - if (val.GetRawValue() is IObjectWrapper wrapped) - result = wrapped.UnderlyingObject; - else - throw ValueMarshallingException.NoConversionToCLR(val.GetType()); - - return result; + return wrapped.UnderlyingObject; + + throw ValueMarshallingException.NoConversionToCLR(val.GetType()); } public static T CastToCLRObject(IValue val) diff --git a/src/ScriptEngine/Machine/MachineInstance.cs b/src/ScriptEngine/Machine/MachineInstance.cs index 095a4773d..9da551706 100644 --- a/src/ScriptEngine/Machine/MachineInstance.cs +++ b/src/ScriptEngine/Machine/MachineInstance.cs @@ -1020,7 +1020,7 @@ private void CallContext(IRuntimeContextInstance instance, int index, ref Method IValue[] realArgs; if (instance.DynamicMethodSignatures) { - realArgs = PrepareDynamicArgs(argValues); + realArgs = PrepareDynamicArgs(instance, argValues); } else { @@ -1053,8 +1053,11 @@ private void CallContext(IRuntimeContextInstance instance, int index, ref Method NextInstruction(); } - private static IValue[] PrepareDynamicArgs(IValue[] factArgs) + private static IValue[] PrepareDynamicArgs(IRuntimeContextInstance context, IValue[] factArgs) { + if (context is COMWrapperContext) + return factArgs; + var realArgs = new IValue[factArgs.Length]; for (int i = 0; i < factArgs.Length; i++) { @@ -1161,7 +1164,7 @@ private void PrepareContextCallArguments(int arg, out IRuntimeContextInstance co if (context.DynamicMethodSignatures) { - argValues = PrepareDynamicArgs(factArgs); + argValues = PrepareDynamicArgs(context, factArgs); } else { From 3b64399d5efd33f0d8200070b3065f3d311126aa Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Sun, 19 Oct 2025 21:51:08 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BA=20#1588=20=D0=B8=20#1597:=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0=20=D0=BE=D0=B1=D1=8A?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D1=85=20=D1=82=D0=B8=D0=BF=D0=BE?= =?UTF-8?q?=D0=B2=20as-is?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Machine/Contexts/ContextValuesMarshaller.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs b/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs index 61fa550e7..2124c0ed6 100644 --- a/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs +++ b/src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs @@ -254,9 +254,12 @@ public static object ConvertToCLRObject(IValue val) case DataType.NotAValidValue: return Missing.Value; } - if (val.GetRawValue() is IObjectWrapper wrapped) - return wrapped.UnderlyingObject; - + if (val.GetRawValue() is IObjectWrapper wrapped) + return wrapped.UnderlyingObject; + + if (val.DataType == DataType.Object) + return val.AsObject(); + throw ValueMarshallingException.NoConversionToCLR(val.GetType()); } From f5130bd921838dd17debe84e7066d2cf6040685a Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Sun, 19 Oct 2025 22:37:49 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BA=20#1597:=20wrapper=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=BC=D0=B5=D0=BD=D1=8F=D1=82=D1=8C=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=D0=B0=20ByRef?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Machine/Contexts/COMWrapperContext.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs b/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs index 769ec27c3..4eddba075 100644 --- a/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs +++ b/src/ScriptEngine/Machine/Contexts/COMWrapperContext.cs @@ -115,8 +115,14 @@ protected static (object[] values, ParameterModifier[] flags) MarshalArguments(I var flags = new ParameterModifier(arguments.Length); for (int i = 0; i < arguments.Length; i++) { - values[i] = MarshalIValue(arguments[i]); - flags[i] = arguments[i] is IVariable; + if (arguments[i] is IVariable v) + { + values[i] = new System.Runtime.InteropServices.VariantWrapper(MarshalIValue(v.Value)); + flags[i] = true; + } + else + values[i] = MarshalIValue(arguments[i]); + } flagsArray[0] = flags; @@ -200,6 +206,7 @@ public static IValue CreateIValue(object objParam) return ValueFactory.Create(); var type = objParam.GetType(); + Console.WriteLine($"objt={type.FullName} isI:{objParam is IValue} A:{type.IsArray} asg:{typeof(IValue).IsAssignableFrom(type)} nP:{!type.IsPrimitive} "); if (typeof(IValue).IsAssignableFrom(type)) { return (IValue)objParam;