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 {
get { return type_info.VirtualMethods.Count; } get { return type_info.VirtualMethods.Count; }
} }
public virtual int EntrySize { public virtual int EntrySize {
get { return Marshal.SizeOf (typeof (IntPtr)); } get { return IntPtr.Size; }
} }
// Subclasses should allocate vtPtr and then call WriteOverrides // Subclasses should allocate vtPtr and then call WriteOverrides

18
src/Mono.Cxxi/CppTypeInfo.cs

@ -142,6 +142,10 @@ namespace Mono.Cxxi {
#region Type Layout #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 // the extra padding to allocate at the top of the class before the fields begin
// (by default, just the vtable pointer) // (by default, just the vtable pointer)
public virtual int FieldOffsetPadding { public virtual int FieldOffsetPadding {
@ -149,7 +153,10 @@ namespace Mono.Cxxi {
} }
public virtual int NativeSize { 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 { public virtual int GCHandleOffset {
@ -169,6 +176,7 @@ namespace Mono.Cxxi {
return; return;
var baseVMethodCount = baseType.virtual_methods.Count; var baseVMethodCount = baseType.virtual_methods.Count;
baseType = baseType.Clone ();
switch (location) { switch (location) {
@ -197,7 +205,6 @@ namespace Mono.Cxxi {
case BaseVirtualMethods.NewVTable: case BaseVirtualMethods.NewVTable:
baseType = baseType.Clone ();
baseType.IsPrimaryBase = (base_classes.Count == 0); baseType.IsPrimaryBase = (base_classes.Count == 0);
// offset all previously added bases // offset all previously added bases
@ -208,8 +215,11 @@ namespace Mono.Cxxi {
gchandle_offset_delta += baseType.GCHandleOffset; gchandle_offset_delta += baseType.GCHandleOffset;
baseType.gchandle_offset_delta += native_size_without_padding + CountBases (b => !b.IsPrimaryBase) * IntPtr.Size; 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; break;
} }

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

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

Loading…
Cancel
Save