2002-06-20 Mike Kestner <mkestner@speakeasy.net>

* 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

svn path=/trunk/gtk-sharp/; revision=5351
This commit is contained in:
Mike Kestner 2002-06-20 01:45:13 +00:00
parent 2854aa2e16
commit dbfe6207a7
7 changed files with 49 additions and 36 deletions

View file

@ -1,3 +1,12 @@
2002-06-20 Mike Kestner <mkestner@speakeasy.net>
* 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 <mkestner@speakeasy.net> 2002-06-19 Mike Kestner <mkestner@speakeasy.net>
* generator/Parameters.cs : csc build error fixes * generator/Parameters.cs : csc build error fixes

View file

@ -91,10 +91,10 @@ namespace GtkSharp.Generation {
signature += p_elem.GetAttribute("pass_as") + " "; signature += p_elem.GetAttribute("pass_as") + " ";
} }
if (type == "GError**") if (type == "GError**") {
call_string += "&"; call_string += "out ";
else import_sig += "out ";
{ } else {
signature += (cs_type + " " + name); signature += (cs_type + " " + name);
signature_types += cs_type; signature_types += cs_type;
} }
@ -127,14 +127,14 @@ namespace GtkSharp.Generation {
} }
if (ThrowsException) if (ThrowsException)
sw.WriteLine ("\t\t\tGLib.GError* {0} = null;", name); sw.WriteLine ("\t\t\tIntPtr error;");
} }
public void HandleException (StreamWriter sw) public void HandleException (StreamWriter sw)
{ {
if (!ThrowsException) if (!ThrowsException)
return; 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 { public bool IsAccessor {
@ -160,19 +160,10 @@ namespace GtkSharp.Generation {
public bool ThrowsException { public bool ThrowsException {
get { get {
XmlNode last_parm = null; if ((elem.ChildNodes == null) || (elem.ChildNodes.Count < 1))
foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") {
continue;
}
last_parm = parm;
}
if (last_parm == null)
return false; return false;
XmlElement p_elem = (XmlElement) last_parm; XmlElement p_elem = (XmlElement) elem.ChildNodes[elem.ChildNodes.Count - 1];
string type = p_elem.GetAttribute("type"); string type = p_elem.GetAttribute("type");
return (type == "GError**"); return (type == "GError**");
} }

View file

@ -52,7 +52,7 @@ namespace GtkSharp.Generation {
simple_types.Add ("uint1", "bool"); simple_types.Add ("uint1", "bool");
simple_types.Add ("GPtrArray", "System.IntPtr[]"); simple_types.Add ("GPtrArray", "System.IntPtr[]");
simple_types.Add ("GType", "int"); simple_types.Add ("GType", "int");
simple_types.Add ("GError", "GLib.GError**"); simple_types.Add ("GError", "IntPtr");
// FIXME: These ought to be handled properly. // FIXME: These ought to be handled properly.
simple_types.Add ("GList", "System.IntPtr"); simple_types.Add ("GList", "System.IntPtr");

View file

@ -9,31 +9,28 @@ namespace GLib {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)] public class GException : Exception
public unsafe struct GError
{ {
[MarshalAs (UnmanagedType.U4)] IntPtr errptr;
public uint domain;
[MarshalAs (UnmanagedType.I4)]
public int code;
[MarshalAs (UnmanagedType.LPStr)]
public string message;
}
public unsafe class GException : Exception public GException (IntPtr errptr) : base ()
{
GError *errptr;
unsafe public GException (GError *errptr) : base (errptr->message)
{ {
this.errptr = errptr; 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")] [DllImport("glib-2.0")]
unsafe static extern void g_clear_error (GError **errptr); static extern void g_clear_error (IntPtr errptr);
~GException () ~GException ()
{ {
unsafe { g_clear_error (&errptr); } g_clear_error (errptr);
} }
} }
} }

View file

@ -5,6 +5,7 @@ INCLUDES = $(GTK_CFLAGS) -I$(top_srcdir)
libgtksharpglue_la_SOURCES = \ libgtksharpglue_la_SOURCES = \
value.c \ value.c \
textiter.c \ textiter.c \
error.c \
# #
libgtksharpglue.dll: $(libgtksharpglue_la_OBJECTS) libgtksharpglue.rc libgtksharpglue.def libgtksharpglue.dll: $(libgtksharpglue_la_OBJECTS) libgtksharpglue.rc libgtksharpglue.def

15
glue/error.c Executable file
View file

@ -0,0 +1,15 @@
/* error.c : Glue to access GError values.
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*
* <c> 2002 Mike Kestner
*/
#include <glib.h>
gchar *
gtksharp_error_get_message (GError *err)
{
return err->message;
}

View file

@ -1,5 +1,5 @@
all: windows all: windows
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