From 016891bb7aac571c266f19ceccfefce6cbcef173 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Sat, 5 Apr 2014 17:11:13 +0200 Subject: [PATCH] generator: Fix generation of SetGValue method Some types need special methods to convert an object to a GLib.Value. The type system will look for a SetGValue method with a "ref GLib.Value" parameter and invoke it. A special case in the generation is needed because this is a non-static method with the Handle being passed as the second parameter and the GLib.Value as the first. Without this fix, the generator would generate the Handle for the first parameter and then the GLib.Value. Signed-off-by: Bertrand Lorentz --- generator/OpaqueGen.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index 45be933ea..7ca2cc443 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -59,8 +59,8 @@ namespace GtkSharp.Generation { SymbolTable table = SymbolTable.Table; - Method ref_, unref, dispose; - GetSpecialMethods (out ref_, out unref, out dispose); + Method ref_, unref, dispose, set_gvalue; + GetSpecialMethods (out ref_, out unref, out dispose, out set_gvalue); if (IsDeprecated) sw.WriteLine ("\t[Obsolete]"); @@ -184,6 +184,17 @@ namespace GtkSharp.Generation { sw.WriteLine (); } #endif + if (set_gvalue != null) { + sw.WriteLine ("\t\t[DllImport(\"{0}\", CallingConvention = CallingConvention.Cdecl)]", LibraryName); + sw.WriteLine ("\t\tstatic extern void {0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName); + sw.WriteLine (); + sw.WriteLine ("\t\tpublic void SetGValue (ref GLib.Value val)"); + sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\t{0} (ref val, Handle);", set_gvalue.CName); + sw.WriteLine ("\t\t}"); + sw.WriteLine (); + } + sw.WriteLine ("#endregion"); sw.WriteLine ("\t}"); @@ -194,7 +205,7 @@ namespace GtkSharp.Generation { Statistics.OpaqueCount++; } - void GetSpecialMethods (out Method ref_, out Method unref, out Method dispose) + void GetSpecialMethods (out Method ref_, out Method unref, out Method dispose, out Method set_gvalue) { ref_ = CheckSpecialMethod (GetMethod ("Ref")); unref = CheckSpecialMethod (GetMethod ("Unref")); @@ -206,6 +217,9 @@ namespace GtkSharp.Generation { dispose = GetMethod ("Dispose"); } dispose = CheckSpecialMethod (dispose); + + set_gvalue = GetMethod ("SetGValue"); + Methods.Remove ("SetGValue"); } Method CheckSpecialMethod (Method method)