diff --git a/ChangeLog b/ChangeLog index f94f1b751..3d594c268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-06-20 Mike Kestner + + * generator/Parameters.cs : GError handling overhaul + * generator/SymbolTable.cs : map GError to IntPtr + * glib/GException.cs : Refactor to use glue. + * glue/Makefile.am : add the error.c file. + * glue/error.c : glue for error message string access + * gtk/makefile.win32 : ref the gdk-imaging-sharp assembly + 2002-06-19 Mike Kestner * generator/Parameters.cs : csc build error fixes diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 7a533d4fe..08ad1d330 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -91,10 +91,10 @@ namespace GtkSharp.Generation { signature += p_elem.GetAttribute("pass_as") + " "; } - if (type == "GError**") - call_string += "&"; - else - { + if (type == "GError**") { + call_string += "out "; + import_sig += "out "; + } else { signature += (cs_type + " " + name); signature_types += cs_type; } @@ -127,14 +127,14 @@ namespace GtkSharp.Generation { } if (ThrowsException) - sw.WriteLine ("\t\t\tGLib.GError* {0} = null;", name); + sw.WriteLine ("\t\t\tIntPtr error;"); } public void HandleException (StreamWriter sw) { if (!ThrowsException) return; - sw.WriteLine ("\t\t\tif (error != null) throw new GLib.GException (error);"); + sw.WriteLine ("\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);"); } public bool IsAccessor { @@ -160,19 +160,10 @@ namespace GtkSharp.Generation { public bool ThrowsException { get { - XmlNode last_parm = null; - foreach (XmlNode parm in elem.ChildNodes) { - if (parm.Name != "parameter") { - continue; - } - - last_parm = parm; - } - - if (last_parm == null) + if ((elem.ChildNodes == null) || (elem.ChildNodes.Count < 1)) return false; - - XmlElement p_elem = (XmlElement) last_parm; + + XmlElement p_elem = (XmlElement) elem.ChildNodes[elem.ChildNodes.Count - 1]; string type = p_elem.GetAttribute("type"); return (type == "GError**"); } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 81dd1a741..a8723f4b9 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -52,7 +52,7 @@ namespace GtkSharp.Generation { simple_types.Add ("uint1", "bool"); simple_types.Add ("GPtrArray", "System.IntPtr[]"); simple_types.Add ("GType", "int"); - simple_types.Add ("GError", "GLib.GError**"); + simple_types.Add ("GError", "IntPtr"); // FIXME: These ought to be handled properly. simple_types.Add ("GList", "System.IntPtr"); diff --git a/glib/GException.cs b/glib/GException.cs index 08e97b43f..3c5744f62 100644 --- a/glib/GException.cs +++ b/glib/GException.cs @@ -9,31 +9,28 @@ namespace GLib { using System; using System.Runtime.InteropServices; - [StructLayout(LayoutKind.Sequential)] - public unsafe struct GError + public class GException : Exception { - [MarshalAs (UnmanagedType.U4)] - public uint domain; - [MarshalAs (UnmanagedType.I4)] - public int code; - [MarshalAs (UnmanagedType.LPStr)] - public string message; - } - - public unsafe class GException : Exception - { - GError *errptr; + IntPtr errptr; - unsafe public GException (GError *errptr) : base (errptr->message) + public GException (IntPtr errptr) : base () { this.errptr = errptr; } + [DllImport("gtksharpglue")] + static extern string gtksharp_error_get_message (IntPtr errptr); + public override string Message { + get { + return gtksharp_error_get_message (errptr); + } + } + [DllImport("glib-2.0")] - unsafe static extern void g_clear_error (GError **errptr); + static extern void g_clear_error (IntPtr errptr); ~GException () { - unsafe { g_clear_error (&errptr); } + g_clear_error (errptr); } } } diff --git a/glue/Makefile.am b/glue/Makefile.am index 58999a0f3..2f7351b1a 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -5,6 +5,7 @@ INCLUDES = $(GTK_CFLAGS) -I$(top_srcdir) libgtksharpglue_la_SOURCES = \ value.c \ textiter.c \ + error.c \ # libgtksharpglue.dll: $(libgtksharpglue_la_OBJECTS) libgtksharpglue.rc libgtksharpglue.def diff --git a/glue/error.c b/glue/error.c new file mode 100755 index 000000000..060c57049 --- /dev/null +++ b/glue/error.c @@ -0,0 +1,15 @@ +/* error.c : Glue to access GError values. + * + * Author: Mike Kestner + * + * 2002 Mike Kestner + */ + +#include + +gchar * +gtksharp_error_get_message (GError *err) +{ + return err->message; +} + diff --git a/gtk/makefile.win32 b/gtk/makefile.win32 index 4cbe995e4..2eb9d1fe1 100644 --- a/gtk/makefile.win32 +++ b/gtk/makefile.win32 @@ -1,5 +1,5 @@ all: windows windows: - $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /r:../gdk/gdk-sharp.dll /out:gtk-sharp.dll /recurse:*.cs + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /r:../gdk/gdk-sharp.dll /r:../gdk.imaging/gdk-imaging-sharp.dll /out:gtk-sharp.dll /recurse:*.cs