Browse Source

Account for alignment when calculating NativeSize, and fix bug with cloning base CppTypeInfos.

pull/1/head
Alex Corrado 14 years ago
parent
commit
a69511b6e6
  1. 2
      src/Mono.Cxxi/Abi/VTable.cs
  2. 18
      src/Mono.Cxxi/CppTypeInfo.cs
  3. 5
      src/Mono.Cxxi/Util/LazyGeneratedList.cs

2
src/Mono.Cxxi/Abi/VTable.cs

@ -48,7 +48,7 @@ namespace Mono.Cxxi.Abi { @@ -48,7 +48,7 @@ namespace Mono.Cxxi.Abi {
get { return type_info.VirtualMethods.Count; }
}
public virtual int EntrySize {
get { return Marshal.SizeOf (typeof (IntPtr)); }
get { return IntPtr.Size; }
}
// Subclasses should allocate vtPtr and then call WriteOverrides

18
src/Mono.Cxxi/CppTypeInfo.cs

@ -142,6 +142,10 @@ namespace Mono.Cxxi { @@ -142,6 +142,10 @@ namespace Mono.Cxxi {
#region Type Layout
public virtual int Alignment {
get { return IntPtr.Size; }
}
// the extra padding to allocate at the top of the class before the fields begin
// (by default, just the vtable pointer)
public virtual int FieldOffsetPadding {
@ -149,7 +153,10 @@ namespace Mono.Cxxi { @@ -149,7 +153,10 @@ namespace Mono.Cxxi {
}
public virtual int NativeSize {
get { return native_size_without_padding + FieldOffsetPadding; }
get {
var basesize = native_size_without_padding + FieldOffsetPadding;
return basesize + (basesize % Alignment);
}
}
public virtual int GCHandleOffset {
@ -169,6 +176,7 @@ namespace Mono.Cxxi { @@ -169,6 +176,7 @@ namespace Mono.Cxxi {
return;
var baseVMethodCount = baseType.virtual_methods.Count;
baseType = baseType.Clone ();
switch (location) {
@ -197,7 +205,6 @@ namespace Mono.Cxxi { @@ -197,7 +205,6 @@ namespace Mono.Cxxi {
case BaseVirtualMethods.NewVTable:
baseType = baseType.Clone ();
baseType.IsPrimaryBase = (base_classes.Count == 0);
// offset all previously added bases
@ -208,8 +215,11 @@ namespace Mono.Cxxi { @@ -208,8 +215,11 @@ namespace Mono.Cxxi {
gchandle_offset_delta += baseType.GCHandleOffset;
baseType.gchandle_offset_delta += native_size_without_padding + CountBases (b => !b.IsPrimaryBase) * IntPtr.Size;
baseType.vt_overrides = baseType.vt_overrides.Clone (); // managed override tramps will be regenerated with correct gchandle offset
baseType.lazy_vtable = new VTable (baseType);
// ensure managed override tramps will be regenerated with correct gchandle offset
baseType.vt_overrides = new LazyGeneratedList<Delegate> (baseType.virtual_methods.Count, i => Library.Abi.GetManagedOverrideTrampoline (baseType, i));
baseType.VTableOverrides = new ReadOnlyCollection<Delegate> (baseType.vt_overrides);
baseType.lazy_vtable = null;
break;
}

5
src/Mono.Cxxi/Util/LazyGeneratedList.cs

@ -47,11 +47,6 @@ namespace Mono.Cxxi.Util { @@ -47,11 +47,6 @@ namespace Mono.Cxxi.Util {
this.count = count;
}
public virtual LazyGeneratedList<TItem> Clone ()
{
return new LazyGeneratedList<TItem> (count, generator);
}
public IEnumerator<TItem> GetEnumerator ()
{
for (int i = 0; i < Count; i++)

Loading…
Cancel
Save