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:
Rachel Hestilow 2002-06-14 18:27:04 +00:00
parent eea6465cf2
commit 3bb3c5e4ff
14 changed files with 170 additions and 26 deletions

View file

@ -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> 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
* generator/GenBase.cs: new method AppendCustom, moved from ObjectGen. * generator/GenBase.cs: new method AppendCustom, moved from ObjectGen.

View file

@ -80,6 +80,7 @@ glib/Makefile
pango/Makefile pango/Makefile
atk/Makefile atk/Makefile
gdk/Makefile gdk/Makefile
gdk.imaging/Makefile
gtk/Makefile gtk/Makefile
sample/Makefile sample/Makefile
]) ])

View file

@ -58,9 +58,14 @@ namespace GtkSharp.Generation {
string cname = elem.GetAttribute("cname"); string cname = elem.GetAttribute("cname");
string name = ((XmlElement)elem.ParentNode).GetAttribute("name"); 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\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\")]");
sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig); sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + isig);
sw.WriteLine(); sw.WriteLine();
if (clash) { if (clash) {
@ -71,13 +76,22 @@ namespace GtkSharp.Generation {
mname = mname.Substring(0, idx) + mname.Substring(idx+1, 1).ToUpper() + mname.Substring(idx+2); 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{");
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 { } else {
sw.WriteLine("\t\tpublic " + name + sig); sw.WriteLine("\t\tpublic " + safety + name + sig);
sw.WriteLine("\t\t{"); sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(sw, false);
sw.WriteLine("\t\t\tRaw = " + cname + call + ";"); sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
if (parms != null)
parms.HandleException (sw);
} }
sw.WriteLine("\t\t}"); sw.WriteLine("\t\t}");

View file

@ -56,6 +56,7 @@ namespace GtkSharp.Generation {
char sep = Path.DirectorySeparatorChar; char sep = Path.DirectorySeparatorChar;
string dir = ".." + sep + ns.ToLower() + sep + "generated"; string dir = ".." + sep + ns.ToLower() + sep + "generated";
if (!Directory.Exists(dir)) { if (!Directory.Exists(dir)) {
Console.WriteLine ("creating " + dir);
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
} }
String filename = dir + sep + Name + ".cs"; String filename = dir + sep + Name + ".cs";

View file

@ -123,13 +123,19 @@ namespace GtkSharp.Generation {
Statistics.ThrottledCount++; Statistics.ThrottledCount++;
return; return;
} }
string safety;
if (parms != null && parms.ThrowsException)
safety = "unsafe ";
else
safety = "";
sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) +
"\", CallingConvention=CallingConvention.Cdecl)]"); "\", 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.WriteLine();
sw.Write("\t\tpublic "); sw.Write("\t\tpublic " + safety);
bool is_get = (parms != null && parms.IsAccessor && Name.Substring(0, 3) == "Get"); bool is_get = (parms != null && parms.IsAccessor && Name.Substring(0, 3) == "Get");
if (is_get) { if (is_get) {
s_ret = parms.AccessorReturnType; s_ret = parms.AccessorReturnType;
@ -149,12 +155,16 @@ namespace GtkSharp.Generation {
if (is_get || m_ret == "void") { if (is_get || m_ret == "void") {
sw.WriteLine(cname + call + ";"); sw.WriteLine(cname + call + ";");
} else { } else {
sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call) + ";"); sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";");
} }
if (is_get) if (parms != null)
sw.WriteLine ("\t\t\treturn " + parms.AccessorName + ";"); 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}"); sw.Write("\t\t}");
if (is_get) if (is_get)

View file

@ -69,7 +69,7 @@ namespace GtkSharp.Generation {
Console.Write("Name: " + name + " Type: " + type + " "); Console.Write("Name: " + name + " Type: " + type + " ");
return false; return false;
} }
if (p_elem.HasAttribute("array")) { if (p_elem.HasAttribute("array")) {
cs_type += "[]"; cs_type += "[]";
m_type += "[]"; m_type += "[]";
@ -77,9 +77,12 @@ namespace GtkSharp.Generation {
if (need_sep) { if (need_sep) {
call_string += ", "; call_string += ", ";
signature += ", ";
import_sig += ", "; import_sig += ", ";
signature_types += ":"; if (type != "GError**")
{
signature += ", ";
signature_types += ":";
}
} else { } else {
need_sep = true; need_sep = true;
} }
@ -87,9 +90,14 @@ namespace GtkSharp.Generation {
if (p_elem.HasAttribute("pass_as")) { if (p_elem.HasAttribute("pass_as")) {
signature += p_elem.GetAttribute("pass_as") + " "; signature += p_elem.GetAttribute("pass_as") + " ";
} }
signature += (cs_type + " " + name); if (type == "GError**")
signature_types += cs_type; call_string += "&";
else
{
signature += (cs_type + " " + name);
signature_types += cs_type;
}
call_string += call_parm; call_string += call_parm;
import_sig += (m_type + " " + name); import_sig += (m_type + " " + name);
} }
@ -99,6 +107,7 @@ namespace GtkSharp.Generation {
public void Initialize (StreamWriter sw, bool is_get) public void Initialize (StreamWriter sw, bool is_get)
{ {
string name;
foreach (XmlNode parm in elem.ChildNodes) { foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") { if (parm.Name != "parameter") {
continue; continue;
@ -107,7 +116,7 @@ namespace GtkSharp.Generation {
XmlElement p_elem = (XmlElement) parm; XmlElement p_elem = (XmlElement) parm;
string type = SymbolTable.GetCSType(p_elem.GetAttribute ("type")); string type = SymbolTable.GetCSType(p_elem.GetAttribute ("type"));
string name = MangleName(p_elem.GetAttribute("name")); name = MangleName(p_elem.GetAttribute("name"));
if (is_get) { if (is_get) {
sw.WriteLine ("\t\t\t" + type + " " + name + ";"); sw.WriteLine ("\t\t\t" + type + " " + name + ";");
} }
@ -116,9 +125,18 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\t" + name + " = new " + type + "();"); sw.WriteLine("\t\t\t" + name + " = new " + type + "();");
} }
} }
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 { public bool IsAccessor {
get { get {
int length = 0; int length = 0;
@ -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 { public string AccessorReturnType {
get { get {
foreach (XmlNode parm in elem.ChildNodes) { foreach (XmlNode parm in elem.ChildNodes) {

View file

@ -52,6 +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**");
// 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");
@ -70,6 +71,7 @@ namespace GtkSharp.Generation {
dlls.Add("Pango", "pango-1.0"); dlls.Add("Pango", "pango-1.0");
dlls.Add("Atk", "atk-1.0"); dlls.Add("Atk", "atk-1.0");
dlls.Add("Gdk", "gdk-x11-2.0"); dlls.Add("Gdk", "gdk-x11-2.0");
dlls.Add("Gdk.Imaging", "gdk_pixbuf-2.0");
dlls.Add("Gtk", "gtk-x11-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
View 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); }
}
}
}

View file

@ -3,12 +3,12 @@ MCS=mcs
all: linux all: linux
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/gdk-imaging-sharp.dll /out:gtk-sharp.dll /recurse:*.cs
linux: gtk-sharp.dll linux: gtk-sharp.dll
gtk-sharp.dll: *.cs generated/*.cs 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: clean:
rm -f *.dll rm -f *.dll

View file

@ -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))) ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT)))
CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe
MCS=mcs MCS=mcs

View file

@ -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))) ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT)))
CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe

View file

@ -7,10 +7,16 @@ unlink ($file);
%ns = ( "Atk" => "atk-1.0.2/atk", %ns = ( "Atk" => "atk-1.0.2/atk",
"Pango" => "pango-1.0.2/pango", "Pango" => "pango-1.0.2/pango",
"Gdk" => "gtk+-2.0.3/gdk", "Gdk" => "gtk+-2.0.3/gdk",
"Gdk.Imaging" => "gtk+-2.0.3/gdk-pixbuf",
"Gtk" => "gtk+-2.0.3/gtk"); "Gtk" => "gtk+-2.0.3/gtk");
%c_ns = ( "Gdk.Imaging" => "Gdk");
foreach $key (keys %ns) { foreach $key (keys %ns) {
$dir = $ns{$key}; $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");
} }

View file

@ -13,11 +13,17 @@ use XML::LibXML;
use Metadata; use Metadata;
if (!$ARGV[0]) { 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]; $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 # 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 # 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 = $doc->createElement('namespace');
$ns_elem->setAttribute('name', $ns); $ns_elem->setAttribute('name', $out_ns);
$root->appendChild($ns_elem); $root->appendChild($ns_elem);
############################################################## ##############################################################