From 8191911b26d671f2fdbbd3f015ac00161cee10c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20G=2E=20Aragoneses?= Date: Mon, 22 Dec 2008 17:02:09 +0000 Subject: [PATCH] =?UTF-8?q?2008-12-22=20=20Andr=C3=A9s=20G.=20Aragoneses?= =?UTF-8?q?=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * generator/InterfaceGen.cs: use the new GLib API to detect instances that don't implement GInterfaces. * glib/GType.cs: add new API for checking if an IntPtr instance implements a certain GType. [Fixes #448009] svn path=/trunk/gtk-sharp/; revision=121990 --- ChangeLog | 8 ++++++++ generator/InterfaceGen.cs | 2 ++ glib/GType.cs | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index ad082b401..7adbfa13b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-12-22 Andrés G. Aragoneses + + * generator/InterfaceGen.cs: use the new GLib API to detect + instances that don't implement GInterfaces. + * glib/GType.cs: add new API for checking if an IntPtr instance + implements a certain GType. + [Fixes #448009] + 2008-12-20 Stephane Delcroix * glib/Timeout.cs: map AddSeconds (). diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 2319c9839..763fb57ce 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -177,6 +177,8 @@ namespace GtkSharp.Generation { sw.WriteLine (); sw.WriteLine ("\t\tpublic " + Name + "Adapter (IntPtr handle)"); sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\tif (!GLib.GType.IsInstance (handle, _gtype))"); + sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"The gobject doesn't implement the GInterface of this adapter\", \"handle\");"); sw.WriteLine ("\t\t\tthis.handle = handle;"); sw.WriteLine ("\t\t}"); sw.WriteLine (); diff --git a/glib/GType.cs b/glib/GType.cs index 5053290f6..1c1f7dcf9 100755 --- a/glib/GType.cs +++ b/glib/GType.cs @@ -334,6 +334,16 @@ namespace GLib { return Marshal.ReadIntPtr (klass); } + internal static bool Is (IntPtr type, GType is_a_type) + { + return g_type_is_a (type, is_a_type.Val); + } + + public static bool IsInstance (IntPtr raw, GType type) + { + return GType.Is (ValFromInstancePtr (raw), type); + } + [DllImport("libgobject-2.0-0.dll")] static extern IntPtr g_type_class_peek (IntPtr gtype); @@ -354,5 +364,8 @@ namespace GLib { [DllImport("libgobject-2.0-0.dll")] static extern IntPtr g_type_register_static (IntPtr parent, IntPtr name, ref GTypeInfo info, int flags); + + [DllImport("libgobject-2.0-0.dll")] + static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type); } }