From 5e2f0369183776a09c50de13a14e641cb7d3c487 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 9 Sep 2024 15:13:55 -0400 Subject: [PATCH] FFI invocation fix where data conversion is required --- BeefLibs/corlib/src/Reflection/MethodInfo.bf | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/BeefLibs/corlib/src/Reflection/MethodInfo.bf b/BeefLibs/corlib/src/Reflection/MethodInfo.bf index b191726e..31a62546 100644 --- a/BeefLibs/corlib/src/Reflection/MethodInfo.bf +++ b/BeefLibs/corlib/src/Reflection/MethodInfo.bf @@ -610,7 +610,12 @@ namespace System.Reflection List ffiParamList = scope .(16); List ffiArgList = scope .(16); - List tempVariants = scope .(4); + List tempVariants = scope .(4); + defer + { + for (var variant in tempVariants) + variant.Dispose(); + } var target; @@ -761,15 +766,17 @@ namespace System.Reflection if (underlyingType == paramType) handled = true; - + if (!handled) { if (!underlyingType.IsSubtypeOf(paramType)) { if (Convert.ConvertTo(arg, paramType) case .Ok(var variant)) { - tempVariants.Add(variant); - dataPtr = variant.GetValueData(); + var tempVariant = scope:mixin Variant(); + *tempVariant = variant; + tempVariants.Add(tempVariant); + dataPtr = tempVariant.GetValueData(); } else isValid = false;