2002-06-14 Rachel Hestilow <hestilow@ximian.com>
* glib/GException.cs: Added. * generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws an exception. Call parms.HandleException. * generator/Paramaters.cs: Add property ThrowsException (based on a trailing GError**). If ThrowsException, mask GError in the signature, initialize a GError in Initialize, and add new method HandleException to throw an exception if error != null. * generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type. * gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32: Added. * configure.in, Makefile, makefile.win32: Build gdk.imaging. * gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging. * parser/gapi2xml.pl: Support namespace renaming. * parser/build.pl: Build gdk-pixbuf as gdk.imaging. svn path=/trunk/gtk-sharp/; revision=5281
This commit is contained in:
parent
eea6465cf2
commit
3bb3c5e4ff
14 changed files with 170 additions and 26 deletions
25
ChangeLog
25
ChangeLog
|
@ -1,3 +1,28 @@
|
|||
2002-06-14 Rachel Hestilow <hestilow@ximian.com>
|
||||
|
||||
* glib/GException.cs: Added.
|
||||
|
||||
* generator/Ctor.cs, Method.cs: Tag function as unsafe if it throws
|
||||
an exception. Call parms.HandleException.
|
||||
|
||||
* generator/Paramaters.cs: Add property ThrowsException (based
|
||||
on a trailing GError**). If ThrowsException, mask GError in the
|
||||
signature, initialize a GError in Initialize, and add new method
|
||||
HandleException to throw an exception if error != null.
|
||||
|
||||
* generator/SymbolTable.cs: Add gdk-pixbuf DLL, and GError type.
|
||||
|
||||
* gdk.imaging, gdk.imaging/Makefile.in, gdk.imaging/makefile.win32:
|
||||
Added.
|
||||
|
||||
* configure.in, Makefile, makefile.win32: Build gdk.imaging.
|
||||
|
||||
* gtk/Makefile.in, gtk/makefile.win32: Link against gdk.imaging.
|
||||
|
||||
* parser/gapi2xml.pl: Support namespace renaming.
|
||||
|
||||
* parser/build.pl: Build gdk-pixbuf as gdk.imaging.
|
||||
|
||||
2002-06-09 Rachel Hestilow <hestilow@ximian.com>
|
||||
|
||||
* generator/GenBase.cs: new method AppendCustom, moved from ObjectGen.
|
||||
|
|
|
@ -80,6 +80,7 @@ glib/Makefile
|
|||
pango/Makefile
|
||||
atk/Makefile
|
||||
gdk/Makefile
|
||||
gdk.imaging/Makefile
|
||||
gtk/Makefile
|
||||
sample/Makefile
|
||||
])
|
||||
|
|
|
@ -58,9 +58,14 @@ namespace GtkSharp.Generation {
|
|||
|
||||
string cname = elem.GetAttribute("cname");
|
||||
string name = ((XmlElement)elem.ParentNode).GetAttribute("name");
|
||||
string safety;
|
||||
if (parms != null && parms.ThrowsException)
|
||||
safety = "unsafe ";
|
||||
else
|
||||
safety = "";
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\")]");
|
||||
sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig);
|
||||
sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
||||
if (clash) {
|
||||
|
@ -71,13 +76,22 @@ namespace GtkSharp.Generation {
|
|||
mname = mname.Substring(0, idx) + mname.Substring(idx+1, 1).ToUpper() + mname.Substring(idx+2);
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\tpublic static " + name + " " + mname + sig);
|
||||
sw.WriteLine("\t\tpublic static " + safety + name + " " + mname + sig);
|
||||
sw.WriteLine("\t\t{");
|
||||
sw.WriteLine("\t\t\treturn new " + name + "(" + cname + call + ");");
|
||||
if (parms != null)
|
||||
parms.Initialize(sw, false);
|
||||
sw.WriteLine("\t\t\tIntPtr ret = " + cname + call + ";");
|
||||
if (parms != null)
|
||||
parms.HandleException (sw);
|
||||
sw.WriteLine("\t\t\treturn new " + name + "(ret);");
|
||||
} else {
|
||||
sw.WriteLine("\t\tpublic " + name + sig);
|
||||
sw.WriteLine("\t\tpublic " + safety + name + sig);
|
||||
sw.WriteLine("\t\t{");
|
||||
if (parms != null)
|
||||
parms.Initialize(sw, false);
|
||||
sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
|
||||
if (parms != null)
|
||||
parms.HandleException (sw);
|
||||
}
|
||||
|
||||
sw.WriteLine("\t\t}");
|
||||
|
|
|
@ -56,6 +56,7 @@ namespace GtkSharp.Generation {
|
|||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Console.WriteLine ("creating " + dir);
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + Name + ".cs";
|
||||
|
|
|
@ -124,12 +124,18 @@ namespace GtkSharp.Generation {
|
|||
return;
|
||||
}
|
||||
|
||||
string safety;
|
||||
if (parms != null && parms.ThrowsException)
|
||||
safety = "unsafe ";
|
||||
else
|
||||
safety = "";
|
||||
|
||||
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
|
||||
"\", CallingConvention=CallingConvention.Cdecl)]");
|
||||
sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig);
|
||||
sw.Write("\t\tstatic extern " + safety + m_ret + " " + cname + isig);
|
||||
sw.WriteLine();
|
||||
|
||||
sw.Write("\t\tpublic ");
|
||||
sw.Write("\t\tpublic " + safety);
|
||||
bool is_get = (parms != null && parms.IsAccessor && Name.Substring(0, 3) == "Get");
|
||||
if (is_get) {
|
||||
s_ret = parms.AccessorReturnType;
|
||||
|
@ -149,12 +155,16 @@ namespace GtkSharp.Generation {
|
|||
if (is_get || m_ret == "void") {
|
||||
sw.WriteLine(cname + call + ";");
|
||||
} else {
|
||||
sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call) + ";");
|
||||
sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";");
|
||||
}
|
||||
|
||||
if (parms != null)
|
||||
parms.HandleException (sw);
|
||||
|
||||
if (is_get)
|
||||
sw.WriteLine ("\t\t\treturn " + parms.AccessorName + ";");
|
||||
|
||||
else if (m_ret != "void")
|
||||
sw.WriteLine ("\t\t\treturn ret;");
|
||||
|
||||
sw.Write("\t\t}");
|
||||
if (is_get)
|
||||
|
|
|
@ -77,9 +77,12 @@ namespace GtkSharp.Generation {
|
|||
|
||||
if (need_sep) {
|
||||
call_string += ", ";
|
||||
signature += ", ";
|
||||
import_sig += ", ";
|
||||
if (type != "GError**")
|
||||
{
|
||||
signature += ", ";
|
||||
signature_types += ":";
|
||||
}
|
||||
} else {
|
||||
need_sep = true;
|
||||
}
|
||||
|
@ -88,8 +91,13 @@ namespace GtkSharp.Generation {
|
|||
signature += p_elem.GetAttribute("pass_as") + " ";
|
||||
}
|
||||
|
||||
if (type == "GError**")
|
||||
call_string += "&";
|
||||
else
|
||||
{
|
||||
signature += (cs_type + " " + name);
|
||||
signature_types += cs_type;
|
||||
}
|
||||
call_string += call_parm;
|
||||
import_sig += (m_type + " " + name);
|
||||
}
|
||||
|
@ -99,6 +107,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public void Initialize (StreamWriter sw, bool is_get)
|
||||
{
|
||||
string name;
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
|
@ -107,7 +116,7 @@ namespace GtkSharp.Generation {
|
|||
XmlElement p_elem = (XmlElement) parm;
|
||||
|
||||
string type = SymbolTable.GetCSType(p_elem.GetAttribute ("type"));
|
||||
string name = MangleName(p_elem.GetAttribute("name"));
|
||||
name = MangleName(p_elem.GetAttribute("name"));
|
||||
if (is_get) {
|
||||
sw.WriteLine ("\t\t\t" + type + " " + name + ";");
|
||||
}
|
||||
|
@ -117,6 +126,15 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
if (ThrowsException)
|
||||
sw.WriteLine ("\t\t\tGLib.GError* {0} = null;", name);
|
||||
}
|
||||
|
||||
public void HandleException (StreamWriter sw)
|
||||
{
|
||||
if (!ThrowsException)
|
||||
return;
|
||||
sw.WriteLine ("\t\t\tif (error != null) throw new GLib.GException (error);");
|
||||
}
|
||||
|
||||
public bool IsAccessor {
|
||||
|
@ -140,6 +158,27 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public bool ThrowsException {
|
||||
get {
|
||||
int i = 0;
|
||||
XmlNode last_parm = null;
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
|
||||
last_parm = parm;
|
||||
}
|
||||
|
||||
if (last_parm == null)
|
||||
return false;
|
||||
|
||||
XmlElement p_elem = (XmlElement) last_parm;
|
||||
string type = p_elem.GetAttribute("type");
|
||||
return (type == "GError**");
|
||||
}
|
||||
}
|
||||
|
||||
public string AccessorReturnType {
|
||||
get {
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
|
|
|
@ -52,6 +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**");
|
||||
|
||||
// FIXME: These ought to be handled properly.
|
||||
simple_types.Add ("GList", "System.IntPtr");
|
||||
|
@ -70,6 +71,7 @@ namespace GtkSharp.Generation {
|
|||
dlls.Add("Pango", "pango-1.0");
|
||||
dlls.Add("Atk", "atk-1.0");
|
||||
dlls.Add("Gdk", "gdk-x11-2.0");
|
||||
dlls.Add("Gdk.Imaging", "gdk_pixbuf-2.0");
|
||||
dlls.Add("Gtk", "gtk-x11-2.0");
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
40
glib/GException.cs
Normal file
40
glib/GException.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
// GException.cs : GError handling
|
||||
//
|
||||
// Authors: Rachel Hestilow <hestilow@ximian.com>
|
||||
//
|
||||
// (c) 2002 Rachel Hestilow
|
||||
|
||||
namespace GLib {
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct GError
|
||||
{
|
||||
[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;
|
||||
|
||||
unsafe public GException (GError *errptr) : base (errptr->message)
|
||||
{
|
||||
this.errptr = errptr;
|
||||
}
|
||||
|
||||
[DllImport("glib-2.0")]
|
||||
unsafe static extern void g_clear_error (GError **errptr);
|
||||
~GException ()
|
||||
{
|
||||
unsafe { g_clear_error (&errptr); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,12 +3,12 @@ MCS=mcs
|
|||
all: linux
|
||||
|
||||
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/gdk-imaging-sharp.dll /out:gtk-sharp.dll /recurse:*.cs
|
||||
|
||||
linux: gtk-sharp.dll
|
||||
|
||||
gtk-sharp.dll: *.cs generated/*.cs
|
||||
$(MCS) --unsafe --target library -r System.Drawing -L ../glib -L ../pango -L ../atk -L ../gdk -r glib-sharp -r pango-sharp -r atk-sharp -r gdk-sharp -o gtk-sharp.dll --recurse '*.cs'
|
||||
$(MCS) --unsafe --target library -r System.Drawing -L ../glib -L ../pango -L ../atk -L ../gdk -r glib-sharp -r pango-sharp -r atk-sharp -r gdk-sharp -r gdk-imaging-sharp -o gtk-sharp.dll --recurse '*.cs'
|
||||
|
||||
clean:
|
||||
rm -f *.dll
|
||||
|
|
2
makefile
2
makefile
|
@ -1,4 +1,4 @@
|
|||
DIRS=generator glib pango atk gdk gtk sample
|
||||
DIRS=generator glib pango atk gdk gdk.imaging gtk sample
|
||||
ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT)))
|
||||
CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe
|
||||
MCS=mcs
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
DIRS=generator glib pango atk gdk gtk sample
|
||||
DIRS=generator glib pango atk gdk gdk.imaging gtk sample
|
||||
ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT)))
|
||||
CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe
|
||||
|
||||
|
|
|
@ -7,10 +7,16 @@ unlink ($file);
|
|||
%ns = ( "Atk" => "atk-1.0.2/atk",
|
||||
"Pango" => "pango-1.0.2/pango",
|
||||
"Gdk" => "gtk+-2.0.3/gdk",
|
||||
"Gdk.Imaging" => "gtk+-2.0.3/gdk-pixbuf",
|
||||
"Gtk" => "gtk+-2.0.3/gtk");
|
||||
|
||||
%c_ns = ( "Gdk.Imaging" => "Gdk");
|
||||
|
||||
foreach $key (keys %ns) {
|
||||
$dir = $ns{$key};
|
||||
system ("./gapi_pp.pl $dir | ./gapi2xml.pl $key $file");
|
||||
if (not ($c_key = $c_ns{$key})) {
|
||||
$c_key = $key;
|
||||
}
|
||||
system ("./gapi_pp.pl $dir | ./gapi2xml.pl $c_key $file --out-ns $key");
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,17 @@ use XML::LibXML;
|
|||
use Metadata;
|
||||
|
||||
if (!$ARGV[0]) {
|
||||
die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile>\n";
|
||||
die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile> [--out-ns outns]\n";
|
||||
}
|
||||
|
||||
$ns = $ARGV[0];
|
||||
|
||||
if ($ARGV[2] && $ARGV[2] eq "--out-ns") {
|
||||
$out_ns = $ARGV[3];
|
||||
} else {
|
||||
$out_ns = $ns;
|
||||
}
|
||||
|
||||
##############################################################
|
||||
# If a filename was provided see if it exists. We parse existing files into
|
||||
# a tree and append the namespace to the root node. If the file doesn't
|
||||
|
@ -35,7 +41,7 @@ if ($ARGV[1] && -e $ARGV[1]) {
|
|||
}
|
||||
|
||||
$ns_elem = $doc->createElement('namespace');
|
||||
$ns_elem->setAttribute('name', $ns);
|
||||
$ns_elem->setAttribute('name', $out_ns);
|
||||
$root->appendChild($ns_elem);
|
||||
|
||||
##############################################################
|
||||
|
|
Loading…
Add table
Reference in a new issue