From 816c946790cb01c7399729a3bed0286f1bd306f9 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 9 Sep 2013 20:35:31 +0300 Subject: [PATCH] Added a hard-coded for the time being option indicating whether the wrapped lib is 32-bit and used that option to generate the v-table offsets. Signed-off-by: Dimitar Dobrev --- src/Generator/AST/VTables.cs | 5 +++-- src/Generator/Driver.cs | 2 ++ src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Generator/AST/VTables.cs b/src/Generator/AST/VTables.cs index f7e15e76..d3894996 100644 --- a/src/Generator/AST/VTables.cs +++ b/src/Generator/AST/VTables.cs @@ -83,7 +83,8 @@ namespace CppSharp.AST throw new NotSupportedException(); } - public static string GetVirtualCallDelegate(INamedDecl method, Class @class, out string delegateId) + public static string GetVirtualCallDelegate(INamedDecl method, Class @class, + bool is32Bit, out string delegateId) { var virtualCallBuilder = new StringBuilder(); virtualCallBuilder.AppendFormat( @@ -106,7 +107,7 @@ namespace CppSharp.AST } virtualCallBuilder.AppendFormat( - "void* slot = *((void**) vtable + {0} * IntPtr.Size);", i); + "void* slot = *((void**) vtable + {0} * {1});", i, is32Bit ? 4 : 8); virtualCallBuilder.AppendLine(); string @delegate = method.Name + "Delegate"; diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index b57b71e3..1e153420 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -280,6 +280,8 @@ namespace CppSharp { get { return GeneratorKind == LanguageGeneratorKind.CLI; } } + + public bool Is32Bit { get { return true; } } } public class InvalidOptionException : Exception diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index fa200f82..cfa1821f 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1574,7 +1574,7 @@ namespace CppSharp.Generators.CSharp private void GenerateVirtualTableFunctionCall(Function method, Class @class) { string delegateId; - Write(VTables.GetVirtualCallDelegate(method, @class, out delegateId)); + Write(VTables.GetVirtualCallDelegate(method, @class, Driver.Options.Is32Bit, out delegateId)); GenerateFunctionCall(delegateId, method.Parameters, method); }