From 6825982069ca8a1129d73149df54ebc7a1a65fb3 Mon Sep 17 00:00:00 2001 From: Alex Corrado Date: Sat, 3 Dec 2011 18:11:40 -0500 Subject: [PATCH] Minor CppTypeInfo clean up. Add HasVTable property --- src/Mono.Cxxi/Abi/CppAbi.cs | 2 +- src/Mono.Cxxi/CppTypeInfo.cs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Mono.Cxxi/Abi/CppAbi.cs b/src/Mono.Cxxi/Abi/CppAbi.cs index d6169b8f..f6b535b6 100644 --- a/src/Mono.Cxxi/Abi/CppAbi.cs +++ b/src/Mono.Cxxi/Abi/CppAbi.cs @@ -766,7 +766,7 @@ namespace Mono.Cxxi.Abi { if (targetTypeInfo == null) targetTypeInfo = GetTypeInfo (targetType); // FIXME: woof. do we really have to do this? - if (targetTypeInfo != null && targetTypeInfo.VirtualMethods.Any ()) { + if (targetTypeInfo != null && targetTypeInfo.HasVTable) { il.Emit (OpCodes.Ldloca, cppip); il.Emit (OpCodes.Call, cppip_native); il.Emit (OpCodes.Call, cppip_tomanaged.MakeGenericMethod (targetType)); diff --git a/src/Mono.Cxxi/CppTypeInfo.cs b/src/Mono.Cxxi/CppTypeInfo.cs index eab84552..afa7baeb 100644 --- a/src/Mono.Cxxi/CppTypeInfo.cs +++ b/src/Mono.Cxxi/CppTypeInfo.cs @@ -93,6 +93,8 @@ namespace Mono.Cxxi { internal EmitInfo emit_info; // <- will be null when the type is done being emitted public bool TypeComplete { get { return emit_info == null; } } + #region Construction + public CppTypeInfo (CppLibrary lib, string typeName, Type interfaceType, Type nativeLayout, Type/*?*/ wrapperType) : this () { @@ -140,6 +142,8 @@ namespace Mono.Cxxi { return this.MemberwiseClone () as CppTypeInfo; } + #endregion + #region Type Layout public virtual int Alignment { @@ -301,7 +305,7 @@ namespace Mono.Cxxi { var baseTypeInfo = GetCastInfo (instance.GetType (), targetType, out offset); var result = new CppInstancePtr (instance.Native, offset); - if (offset > 0 && instance.Native.IsManagedAlloc && baseTypeInfo.VirtualMethods.Count != 0) { + if (offset > 0 && instance.Native.IsManagedAlloc && baseTypeInfo.HasVTable) { // we might need to paste the managed base-in-derived vtptr here --also inits native_vtptr baseTypeInfo.VTable.InitInstance (ref result); } @@ -336,10 +340,14 @@ namespace Mono.Cxxi { #region V-Table + public virtual bool HasVTable { + get { return VirtualMethods.Any (); } + } + public virtual VTable VTable { get { CompleteType (); - if (!virtual_methods.Any ()) + if (!HasVTable) return null; if (lazy_vtable == null)