Browse Source

Fixed issue where a DynamicMethod was being collected when it shouldn't have been.

Turns out that the Console.WriteLine was just putting off the inevitable.

git-svn-id: https://mono-soc-2010.googlecode.com/svn/trunk/cppinterop@18 a470b8cb-0e6f-1642-1b45-71e107334c4b
pull/1/head
alexander.corrado 15 years ago
parent
commit
66f18ae900
  1. 3
      CPPPOC/Main.cs
  2. 15
      Mono.VisualC.Interop/ABI/VTable.cs
  3. 2
      Mono.VisualC.Interop/ABI/VTableCOM.cs
  4. 23
      Mono.VisualC.Interop/ABI/VTableManaged.cs

3
CPPPOC/Main.cs

@ -19,7 +19,8 @@ namespace CPPPOC @@ -19,7 +19,8 @@ namespace CPPPOC
CSimpleClass csc1 = new CSimpleClass(CreateCSimpleSubClass(10));
CSimpleClass csc2 = new CSimpleClass(2);
try {
//TODO: This still calls managed V0 on CSimpleClass first, even though it's an
// instance of a more-derived class.
csc1.V0(25, 50);
csc1.M0();
Console.WriteLine("Managed code got value: {0}", csc1.value);

15
Mono.VisualC.Interop/ABI/VTable.cs

@ -17,8 +17,11 @@ using System.Runtime.InteropServices; @@ -17,8 +17,11 @@ using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public abstract class VTable : IDisposable {
protected IntPtr basePtr, vtPtr;
protected Delegate[] overrides;
public virtual int EntryCount { get; protected set; }
public virtual int EntryCount {
get { return overrides.Length; }
}
public virtual int EntrySize {
get { return Marshal.SizeOf (typeof (IntPtr)); }
}
@ -29,16 +32,14 @@ namespace Mono.VisualC.Interop.ABI { @@ -29,16 +32,14 @@ namespace Mono.VisualC.Interop.ABI {
// Creates a new VTable
public VTable (Delegate[] overrides)
{
EntryCount = overrides.Length;
Console.WriteLine ("VTable entry count: {0}", EntryCount);
basePtr = IntPtr.Zero;
vtPtr = IntPtr.Zero;
this.overrides = overrides;
this.basePtr = IntPtr.Zero;
this.vtPtr = IntPtr.Zero;
}
public virtual void WriteOverrides (Delegate[] overrides)
protected virtual void WriteOverrides (int offset)
{
IntPtr vtEntryPtr;
int offset = 0;
for (int i = 0; i < EntryCount; i++) {
if (overrides [i] != null) // managed override

2
Mono.VisualC.Interop/ABI/VTableCOM.cs

@ -25,7 +25,7 @@ namespace Mono.VisualC.Interop.ABI { @@ -25,7 +25,7 @@ namespace Mono.VisualC.Interop.ABI {
select entry).Count();
vtPtr = Marshal.AllocHGlobal ((EntryCount + managedOverrides) * EntrySize);
WriteOverrides (entries);
WriteOverrides (0);
}
public override MethodInfo PrepareVirtualCall (MethodInfo target, ILGenerator callsite, FieldInfo vtableField,

23
Mono.VisualC.Interop/ABI/VTableManaged.cs

@ -16,31 +16,26 @@ using System.Runtime.InteropServices; @@ -16,31 +16,26 @@ using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public class VTableManaged : VTable {
private Type[] delegateTypes;
private ModuleBuilder implModule;
public VTableManaged (ModuleBuilder implModule, Delegate[] entries) : base(entries)
{
this.implModule = implModule;
this.delegateTypes = new Type [EntryCount];
for (int i = 0; i < EntryCount; i++) {
if (entries [i] != null)
delegateTypes [i] = entries [i].GetType ();
}
this.vtPtr = Marshal.AllocHGlobal (EntryCount * EntrySize);
vtPtr = Marshal.AllocHGlobal (EntryCount * EntrySize);
WriteOverrides (entries);
WriteOverrides (0);
}
public override MethodInfo PrepareVirtualCall (MethodInfo target, ILGenerator callsite, FieldInfo vtableField,
LocalBuilder native, int vtableIndex)
{
if (delegateTypes [vtableIndex] == null)
delegateTypes [vtableIndex] = Util.GetDelegateTypeForMethodInfo (implModule, target);
Type delegateType;
if (overrides [vtableIndex] != null)
delegateType = overrides [vtableIndex].GetType ();
else
delegateType = Util.GetDelegateTypeForMethodInfo (implModule, target);
MethodInfo getDelegate = typeof (VTableManaged).GetMethod ("GetDelegateForNative").MakeGenericMethod (delegateTypes [vtableIndex]);
MethodInfo getDelegate = typeof (VTableManaged).GetMethod ("GetDelegateForNative").MakeGenericMethod (delegateType);
// load this._vtable
callsite.Emit (OpCodes.Ldarg_0);
@ -60,7 +55,7 @@ namespace Mono.VisualC.Interop.ABI { @@ -60,7 +55,7 @@ namespace Mono.VisualC.Interop.ABI {
callsite.Emit (OpCodes.Throw);
callsite.MarkLabel (notNull);
return delegateTypes [vtableIndex].GetMethod ("Invoke");
return delegateType.GetMethod ("Invoke");
}

Loading…
Cancel
Save