Browse Source

Oops that was only a mem leak for value types!

pull/1/head
Alexander Corrado 14 years ago
parent
commit
a7770c3ab4
  1. 19
      src/Mono.Cxxi/Abi/Impl/ItaniumAbi.cs

19
src/Mono.Cxxi/Abi/Impl/ItaniumAbi.cs

@ -227,6 +227,7 @@ namespace Mono.Cxxi.Abi {
{ {
var il = typeInfo.emit_info.current_il; var il = typeInfo.emit_info.current_il;
var method = psig.OrigMethod; var method = psig.OrigMethod;
var returnType = method.ReturnType;
var hiddenReturnByValue = ReturnByHiddenArgument (typeInfo, method); var hiddenReturnByValue = ReturnByHiddenArgument (typeInfo, method);
LocalBuilder returnValue = null; LocalBuilder returnValue = null;
@ -235,10 +236,10 @@ namespace Mono.Cxxi.Abi {
{ {
returnValue = il.DeclareLocal (typeof (CppInstancePtr)); returnValue = il.DeclareLocal (typeof (CppInstancePtr));
if (typeof (ICppObject).IsAssignableFrom (method.ReturnType)) if (typeof (ICppObject).IsAssignableFrom (returnType))
il.Emit (OpCodes.Ldc_I4, GetTypeInfo (method.ReturnType).NativeSize); il.Emit (OpCodes.Ldc_I4, GetTypeInfo (returnType).NativeSize);
else if (method.ReturnType.IsValueType) else if (returnType.IsValueType)
il.Emit (OpCodes.Ldc_I4, Marshal.SizeOf (method.ReturnType)); il.Emit (OpCodes.Ldc_I4, Marshal.SizeOf (returnType));
il.Emit (OpCodes.Newobj, cppip_fromsize); il.Emit (OpCodes.Newobj, cppip_fromsize);
il.Emit (OpCodes.Stloc, returnValue); il.Emit (OpCodes.Stloc, returnValue);
@ -249,11 +250,13 @@ namespace Mono.Cxxi.Abi {
base.EmitNativeCall (typeInfo, nativeMethod, psig, nativePtr); base.EmitNativeCall (typeInfo, nativeMethod, psig, nativePtr);
if (hiddenReturnByValue) { if (hiddenReturnByValue) {
EmitCreateCppObjectFromNative (il, method.ReturnType, returnValue); EmitCreateCppObjectFromNative (il, returnType, returnValue);
// FIXME: This dispose should prolly be in a Finally block.. if (returnType.IsValueType) {
il.Emit (OpCodes.Ldloca, returnValue); // FIXME: This dispose should prolly be in a Finally block..
il.Emit (OpCodes.Call, cppip_dispose); il.Emit (OpCodes.Ldloca, returnValue);
il.Emit (OpCodes.Call, cppip_dispose);
}
} }
} }

Loading…
Cancel
Save