| Newsgroups |
gmane.comp.gnome.mono.patches |
| Message-ID |
<00000141a2cd17e5-cdcb3d0b-e831-4ee1-9081-51f6ab19472d-000000@email.amazonses.com> |
Branch: refs/heads/master
Home: https://github.com/mono/gtk-sharp
Compare: https://github.com/mono/gtk-sharp/compare/62f0285177c8...90e834327e83
Commit: 3eefa37272a3bc10be70e736b4e5ff82351b7826
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 13:39:31 GMT
URL: https://github.com/mono/gtk-sharp/commit/3eefa37272a3bc10be70e736b4e5ff82351b7826
generator: Bumped parser_version to 3
Added support for new closure and destroy attributes from which we can
determine which callback a parameter belongs to.
Changed paths:
M generator/MethodBody.cs
M generator/Parameter.cs
M generator/Parameters.cs
M generator/Parser.cs
Modified: generator/MethodBody.cs
===================================================================
@@ -101,17 +101,26 @@ public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, strin
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(gen_info);
+
+ int closure = i + 1;
+ if (p.Closure >= 0)
+ closure = p.Closure;
+
+ int destroyNotify = i + 2;
+ if (p.DestroyNotify >= 0)
+ destroyNotify = p.DestroyNotify;
+
switch (p.Scope) {
case "notified":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
- sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [i + 1].Name);
- sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [i + 2].CSType, parameters [i + 2].Name);
+ sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [closure].Name);
+ sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [destroyNotify].CSType, parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
- sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [i + 1].Name);
- sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [i + 2].Name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [closure].Name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\t} else {");
- sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [i + 1].Name, name);
- sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [i + 2].Name, parameters [i + 2].CSType);
+ sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [closure].Name, name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [destroyNotify].Name, parameters [destroyNotify].CSType);
sw.WriteLine (indent + "\t\t\t}");
break;
Modified: generator/Parameter.cs
===================================================================
@@ -236,6 +236,30 @@ public Parameter (XmlElement e)
}
}
+ int closure = -1;
+ public int Closure {
+ get {
+ if(closure == -1 && elem.HasAttribute ("closure"))
+ closure = int.Parse(elem.GetAttribute ("closure"));
+ return closure;
+ }
+ set {
+ closure = value;
+ }
+ }
+
+ int destroynotify = -1;
+ public int DestroyNotify {
+ get {
+ if (destroynotify == -1 && elem.HasAttribute ("destroy"))
+ destroynotify = int.Parse (elem.GetAttribute ("destroy"));
+ return destroynotify;
+ }
+ set {
+ destroynotify = value;
+ }
+ }
+
public virtual string[] Prepare {
get {
IGeneratable gen = Generatable;
Modified: generator/Parameters.cs
===================================================================
@@ -80,6 +80,14 @@ public bool IsHidden (Parameter p)
return true;
if (HasCB || HideData) {
+
+ foreach (Parameter param in param_list) {
+ if (param.Closure == idx)
+ return true;
+ else if (param.DestroyNotify == idx)
+ return true;
+ }
+
if (p.IsUserData && (idx == Count - 1))
return true;
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
Modified: generator/Parser.cs
===================================================================
@@ -29,7 +29,7 @@ namespace GtkSharp.Generation {
using System.Xml.Schema;
public class Parser {
- const int curr_parser_version = 2;
+ const int curr_parser_version = 3;
private XmlDocument Load (string filename, string schema_file)
{
Commit: 4b470cadbb42536633f12eb8dfb107ff8d247c95
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 13:41:14 GMT
URL: https://github.com/mono/gtk-sharp/commit/4b470cadbb42536633f12eb8dfb107ff8d247c95
generator: Added GThread type
Changed paths:
M generator/SymbolTable.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -126,6 +126,7 @@ public SymbolTable ()
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
+ AddType (new ManualGen ("GThread", "GLib.Thread", "null"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
Commit: c14277f391b138c91661ea00c9f3e69612f6f8b0
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 13:43:23 GMT
URL: https://github.com/mono/gtk-sharp/commit/c14277f391b138c91661ea00c9f3e69612f6f8b0
generator: GThread type should be SimpleGen
Changed paths:
M generator/SymbolTable.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -126,13 +126,14 @@ public SymbolTable ()
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
- AddType (new ManualGen ("GThread", "GLib.Thread", "null"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})", "GLib.GType.None"));
AddType (new ByRefGen ("GValue", "GLib.Value"));
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null"));
+ AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
+
// FIXME: These ought to be handled properly.
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
Commit: 115659f46b2ee3b592121c806515f59f5592838d
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 13:52:47 GMT
URL: https://github.com/mono/gtk-sharp/commit/115659f46b2ee3b592121c806515f59f5592838d
generator: fixed Equals/GetHashCode for no fields or padding
Fixed Equals/GetHashCode methods when struct has no fields,
or field is padding.
Changed paths:
M generator/StructBase.cs
M generator/StructField.cs
Modified: generator/StructBase.cs
===================================================================
@@ -115,12 +115,16 @@ protected void GenEqualsAndHash (StreamWriter sw)
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\tbool isEqual = true;");
+ sb.Append ("this.GetType ().FullName.GetHashCode ()");
foreach (StructField field in fields) {
+ if (field.IsPadding)
+ continue;
if (field.IsBitfield) {
if (need_field) {
- sw.WriteLine ("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields);
- if (sb.Length > 0)
+ sw.WriteLine ("\t\t\tisEqual &= bitfield{0}.Equals (other._bitfield{0});", bitfields);
+ //if (sb.Length > 0)
sb.Append (" ^ ");
sb.Append ("_bitfield");
sb.Append (bitfields++);
@@ -129,14 +133,14 @@ protected void GenEqualsAndHash (StreamWriter sw)
}
} else {
need_field = true;
- sw.WriteLine ("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName);
- if (sb.Length > 0)
+ sw.WriteLine ("\t\t\tisEqual &= {0}.Equals (other.{0});", field.EqualityName);
+ //if (sb.Length > 0)
sb.Append (" ^ ");
sb.Append (field.EqualityName);
sb.Append (".GetHashCode ()");
}
}
- sw.WriteLine ("\t\t\treturn true;");
+ sw.WriteLine ("\t\t\treturn isEqual;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
Modified: generator/StructField.cs
===================================================================
@@ -89,7 +89,7 @@ public class StructField : FieldBase {
}
}
- bool IsPadding {
+ public bool IsPadding {
get {
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
}
Commit: 94da3fb2abdf8d6f840704cb568e787011967a13
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 14:27:47 GMT
URL: https://github.com/mono/gtk-sharp/commit/94da3fb2abdf8d6f840704cb568e787011967a13
generator: faster Equals implementation
Changed paths:
M generator/StructBase.cs
Modified: generator/StructBase.cs
===================================================================
@@ -1,8 +1,11 @@
// GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class.
//
-// Author: Mike Kestner <[email protected]>
+// Authors:
+// Mike Kestner <[email protected]>
+// Stephan Sundermann <[email protected]>
//
// Copyright (c) 2001-2003 Mike Kestner
+// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@@ -111,36 +114,43 @@ protected void GenEqualsAndHash (StreamWriter sw)
{
int bitfields = 0;
bool need_field = true;
- StringBuilder sb = new StringBuilder ();
+ StringBuilder hashcode = new StringBuilder ();
+ StringBuilder equals = new StringBuilder ();
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\tbool isEqual = true;");
- sb.Append ("this.GetType ().FullName.GetHashCode ()");
+ hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
+ equals.Append ("true");
foreach (StructField field in fields) {
if (field.IsPadding)
continue;
if (field.IsBitfield) {
if (need_field) {
- sw.WriteLine ("\t\t\tisEqual &= bitfield{0}.Equals (other._bitfield{0});", bitfields);
- //if (sb.Length > 0)
- sb.Append (" ^ ");
- sb.Append ("_bitfield");
- sb.Append (bitfields++);
- sb.Append (".GetHashCode ()");
+ equals.Append (" && _bitfield");
+ equals.Append (bitfields);
+ equals.Append (".Equals (other._bitfield");
+ equals.Append (bitfields);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append ("_bitfield");
+ hashcode.Append (bitfields++);
+ hashcode.Append (".GetHashCode ()");
need_field = false;
}
} else {
need_field = true;
- sw.WriteLine ("\t\t\tisEqual &= {0}.Equals (other.{0});", field.EqualityName);
- //if (sb.Length > 0)
- sb.Append (" ^ ");
- sb.Append (field.EqualityName);
- sb.Append (".GetHashCode ()");
+ equals.Append (" && ");
+ equals.Append (field.EqualityName);
+ equals.Append (".Equals (other.");
+ equals.Append (field.EqualityName);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append (field.EqualityName);
+ hashcode.Append (".GetHashCode ()");
}
}
- sw.WriteLine ("\t\t\treturn isEqual;");
+ sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
@@ -152,7 +162,7 @@ protected void GenEqualsAndHash (StreamWriter sw)
return;
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\treturn {0};", sb.ToString ());
+ sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
Commit: 8d4ec22ef2ec442648e146e8f6957a9855c7aa25
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 15:46:19 GMT
URL: https://github.com/mono/gtk-sharp/commit/8d4ec22ef2ec442648e146e8f6957a9855c7aa25
generator: Added throws attribute to parameters
This enables gapi to decide whether a parameter is
really throwing or should be handled as a usual parameter.
Changed paths:
M generator/Parameters.cs
Modified: generator/Parameters.cs
===================================================================
@@ -49,6 +49,18 @@ public Parameters (XmlElement elem, bool first_is_instance)
get { return param_list.Count; }
}
+ // gapi assumes GError** parameters to be error parameters in version 1 and 2
+ private bool throws = false;
+ public bool Throws {
+ get {
+ if (ParserVersion <= 2)
+ return true;
+ if (!throws && elem.HasAttribute ("throws"))
+ throws = elem.GetAttributeAsBoolean ("throws");
+ return throws;
+ }
+ }
+
public int VisibleCount {
get {
int visible = 0;
@@ -76,7 +88,7 @@ public bool IsHidden (Parameter p)
if (p.IsCount)
return true;
- if (p.CType == "GError**")
+ if (p.CType == "GError**" && Throws)
return true;
if (HasCB || HideData) {
@@ -212,7 +224,7 @@ public bool Validate (LogWriter log)
}
}
}
- } else if (p.CType == "GError**")
+ } else if (p.CType == "GError**" && Throws)
p = new ErrorParameter (parm);
else if (gen is StructBase || gen is ByRefGen) {
p = new StructParameter (parm);
@@ -277,5 +289,12 @@ public bool Validate (LogWriter log)
return String.Join (", ", result);
}
}
+
+ private int ParserVersion {
+ get {
+ XmlElement root = elem.OwnerDocument.DocumentElement;
+ return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
+ }
+ }
}
}
Commit: b5806d2a1b351092380352f1550ed9db2b809851
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 15:54:29 GMT
URL: https://github.com/mono/gtk-sharp/commit/b5806d2a1b351092380352f1550ed9db2b809851
generator: fixed string[] return types
Changed paths:
M generator/ReturnValue.cs
M glib/Marshaller.cs
Modified: generator/ReturnValue.cs
===================================================================
@@ -160,7 +160,7 @@ public string ToNative (string var)
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
} else if (is_null_term)
- return String.Format ("GLib.Marshaller.StringArrayToNullTermPointer ({0})", var);
+ return String.Format ("GLib.Marshaller.StringArrayToNullTermStrvPointer ({0})", var);
else if (is_array)
return String.Format ("GLib.Marshaller.ArrayToArrayPtr ({0})", var);
Modified: glib/Marshaller.cs
===================================================================
@@ -170,7 +170,7 @@ public static IntPtr StringToFilenamePtr (string str)
return ret.Replace ("%", "%%");
}
- internal static IntPtr StringArrayToStrvPtr (string[] strs)
+ public static IntPtr StringArrayToStrvPtr (string[] strs)
{
IntPtr[] ptrs = StringArrayToNullTermPointer (strs);
IntPtr ret = g_malloc (new UIntPtr ((ulong) (ptrs.Length * IntPtr.Size)));
@@ -178,6 +178,11 @@ internal static IntPtr StringArrayToStrvPtr (string[] strs)
return ret;
}
+ public static IntPtr StringArrayToNullTermStrvPointer (string[] strs)
+ {
+ return StringArrayToStrvPtr (strs);
+ }
+
public static IntPtr[] StringArrayToNullTermPointer (string[] strs)
{
if (strs == null)
Commit: c53147c1c4decc8bb97274c911a352d228e4bee6
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:45:42 GMT
URL: https://github.com/mono/gtk-sharp/commit/c53147c1c4decc8bb97274c911a352d228e4bee6
generator: Added constants to gapi
Unfortunately, gir marks all integers as gint regardless
of its size. We have to check if the value will really
fit into a int, that is why there is an automatic fallback
to long.
Changed paths:
M generator/ClassBase.cs
M generator/ClassGen.cs
M generator/Makefile.am
M generator/ObjectGen.cs
M generator/OpaqueGen.cs
M generator/generator.csproj
Added paths:
A generator/Constant.cs
Modified: generator/ClassBase.cs
===================================================================
@@ -34,6 +34,7 @@ public abstract class ClassBase : GenBase {
private IDictionary<string, Property> props = new Dictionary<string, Property> ();
private IDictionary<string, ObjectField> fields = new Dictionary<string, ObjectField> ();
private IDictionary<string, Method> methods = new Dictionary<string, Method> ();
+ private IDictionary<string, Constant> constants = new Dictionary<string, Constant>();
protected IList<string> interfaces = new List<string>();
protected IList<string> managed_interfaces = new List<string>();
protected IList<Ctor> ctors = new List<Ctor>();
@@ -108,6 +109,11 @@ public abstract class ClassBase : GenBase {
ctors.Add (new Ctor (member, this));
break;
+ case "constant":
+ name = member.GetAttribute ("name");
+ constants.Add (name, new Constant (member));
+ break;
+
default:
break;
}
@@ -156,6 +162,14 @@ public override bool Validate ()
methods.Remove (method.Name);
invalids.Clear ();
+ foreach (Constant con in constants.Values) {
+ if (!con.Validate (log))
+ invalids.Add (con);
+ }
+ foreach (Constant con in invalids)
+ constants.Remove (con.Name);
+ invalids.Clear ();
+
foreach (Ctor ctor in ctors) {
if (!ctor.Validate (log))
invalids.Add (ctor);
@@ -199,6 +213,7 @@ protected virtual bool IsNodeNameHandled (string name)
case "implements":
case "constructor":
case "disabledefaultconstructor":
+ case "constant":
return true;
default:
@@ -221,6 +236,12 @@ protected void GenFields (GenerationInfo gen_info)
field.Generate (gen_info, "\t\t");
}
+ protected void GenConstants (GenerationInfo gen_info)
+ {
+ foreach (Constant con in constants.Values)
+ con.Generate (gen_info, "\t\t");
+ }
+
private void ParseImplements (XmlElement member)
{
foreach (XmlNode node in member.ChildNodes) {
Modified: generator/ClassGen.cs
===================================================================
@@ -77,9 +77,10 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine (" {");
sw.WriteLine ();
+ GenConstants (gen_info);
GenProperties (gen_info, null);
GenMethods (gen_info, null, null);
-
+
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
Added: generator/Constant.cs
===================================================================
@@ -0,0 +1,64 @@
+using System;
+using System.Xml;
+using System.IO;
+
+namespace GtkSharp.Generation
+{
+ public class Constant
+ {
+ private readonly XmlElement elem;
+ private readonly string name;
+ private readonly string value;
+ private readonly string ctype;
+
+ public Constant (XmlElement elem)
+ {
+ this.elem = elem;
+ this.name = elem.GetAttribute ("name");
+ this.value = elem.GetAttribute ("value");
+ this.ctype = elem.GetAttribute ("ctype");
+ }
+
+ public string Name {
+ get {
+ return this.name;
+ }
+ }
+ public string ConstType {
+ get {
+ if (IsString)
+ return "string";
+ // gir registers all integer values as gint even for numbers which do not fit into a gint
+ // if the number is too big for an int, try to fit it into a long
+ if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length < 20 && long.Parse (value) > Int32.MaxValue)
+ return "long";
+ return SymbolTable.Table.GetMarshalType (ctype);
+ }
+ }
+
+ public bool IsString {
+ get {
+ return (SymbolTable.Table.GetCSType (ctype) == "string");
+ }
+ }
+
+ public virtual bool Validate (LogWriter log)
+ {
+ if (ConstType == String.Empty) {
+ log.Warn ("{0} type is missing or wrong", Name);
+ return false;
+ }
+ if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length >= 20) {
+ return false;
+ }
+ return true;
+ }
+
+ public virtual void Generate (GenerationInfo gen_info, string indent)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("{0}public const {1} {2} = {3}{4}{3};", indent, ConstType, Name, IsString ? "\"": String.Empty, value);
+ }
+ }
+}
Modified: generator/Makefile.am
===================================================================
@@ -19,6 +19,7 @@ sources = \
CodeGenerator.cs \
ConstFilenameGen.cs \
ConstStringGen.cs \
+ Constant.cs \
Ctor.cs \
DefaultSignalHandler.cs \
EnumGen.cs \
Modified: generator/ObjectGen.cs
===================================================================
@@ -195,9 +195,10 @@ public override void Generate (GenerationInfo gen_info)
GenSignals (gen_info, null);
}
+ GenConstants (gen_info);
GenClassMembers (gen_info, cs_parent);
GenMethods (gen_info, null, null);
-
+
if (interfaces.Count != 0) {
var all_methods = new Dictionary<string, Method> ();
foreach (Method m in Methods.Values) {
Modified: generator/OpaqueGen.cs
===================================================================
@@ -79,7 +79,8 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine (" {");
sw.WriteLine ();
-
+
+ GenConstants (gen_info);
GenFields (gen_info);
GenMethods (gen_info, null, null);
GenCtors (gen_info);
Modified: generator/generator.csproj
===================================================================
@@ -91,6 +91,7 @@
<Compile Include="Parameter.cs" />
<Compile Include="ArrayParameter.cs" />
<Compile Include="Options.cs" />
+ <Compile Include="Constant.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DESIGN" />
Commit: edde96c5bec6956bcd5f45edd92c283c7b326724
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:46:44 GMT
URL: https://github.com/mono/gtk-sharp/commit/edde96c5bec6956bcd5f45edd92c283c7b326724
generator: fixed writeable and readable detection
Changed paths:
M generator/FieldBase.cs
Modified: generator/FieldBase.cs
===================================================================
@@ -42,13 +42,13 @@ public virtual bool Validate (LogWriter log)
protected virtual bool Readable {
get {
- return elem.GetAttribute ("readable") != "false";
+ return elem.HasAttribute ("readable") && elem.GetAttributeAsBoolean ("readable");
}
}
protected virtual bool Writable {
get {
- return elem.GetAttribute ("writeable") != "false";
+ return elem.HasAttribute ("writeable") && elem.GetAttributeAsBoolean ("writeable");
}
}
Commit: f6219b97e07d1652e16b296b40d2a449e4f8a59c
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:47:21 GMT
URL: https://github.com/mono/gtk-sharp/commit/f6219b97e07d1652e16b296b40d2a449e4f8a59c
generator: Added count param detection for return values
Changed paths:
M generator/CallbackGen.cs
M generator/ReturnValue.cs
Modified: generator/CallbackGen.cs
===================================================================
@@ -56,6 +56,8 @@ public override bool Validate ()
if (!String.IsNullOrEmpty (retval.CountParameterName))
retval.CountParameter = parms.GetCountParameter (retval.CountParameterName);
+ if (retval.CountParameterIndex >= 0)
+ retval.CountParameter = parms[retval.CountParameterIndex];
return valid;
}
Modified: generator/ReturnValue.cs
===================================================================
@@ -32,6 +32,7 @@ public class ReturnValue {
bool elements_owned;
bool owned;
string array_length_param = String.Empty;
+ int array_length_param_index = -1;
string ctype = String.Empty;
string default_value = String.Empty;
string element_ctype = String.Empty;
@@ -43,6 +44,8 @@ public ReturnValue (XmlElement elem)
is_null_term = elem.GetAttributeAsBoolean ("null_term_array");
is_array = elem.GetAttributeAsBoolean ("array") || elem.HasAttribute ("array_length_param");
array_length_param = elem.GetAttribute ("array_length_param");
+ if (elem.HasAttribute ("array_length_param_length"))
+ array_length_param_index = int.Parse (elem.GetAttribute ("array_length_param_index"));
elements_owned = elem.GetAttributeAsBoolean ("elements_owned");
owned = elem.GetAttributeAsBoolean ("owned");
ctype = elem.GetAttribute("type");
@@ -60,6 +63,10 @@ public ReturnValue (XmlElement elem)
get { return array_length_param; }
}
+ public int CountParameterIndex {
+ get { return array_length_param_index; }
+ }
+
public string CType {
get {
return ctype;
Commit: c5909d32fb2b61244cf2b63f826978ce421e8e95
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:47:45 GMT
URL: https://github.com/mono/gtk-sharp/commit/c5909d32fb2b61244cf2b63f826978ce421e8e95
generator: fixed string array return type for virtual_methods
Changed paths:
M generator/ReturnValue.cs
Modified: generator/ReturnValue.cs
===================================================================
@@ -133,7 +133,9 @@ public ReturnValue (XmlElement elem)
get {
if (IGen == null)
return String.Empty;
- return IGen.MarshalType + (is_array || is_null_term ? "[]" : String.Empty);
+ if (is_array || is_null_term)
+ return "IntPtr";
+ return IGen.MarshalType;
}
}
Commit: dc4e7f30b9ba6ebe2457d26fd6efbb1aec812629
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:48:05 GMT
URL: https://github.com/mono/gtk-sharp/commit/dc4e7f30b9ba6ebe2457d26fd6efbb1aec812629
generator: Added long long conversion
Changed paths:
M generator/SymbolTable.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -69,6 +69,7 @@ public SymbolTable ()
AddType (new SimpleGen ("guint32", "uint", "0"));
AddType (new SimpleGen ("gint64", "long", "0"));
AddType (new SimpleGen ("guint64", "ulong", "0"));
+ AddType (new SimpleGen ("unsigned long long", "ulong", "0"));
AddType (new SimpleGen ("long long", "long", "0"));
AddType (new SimpleGen ("gfloat", "float", "0.0"));
AddType (new SimpleGen ("float", "float", "0.0"));
Commit: fd2fb44f99f2f36d4d8c5e0253bbb644f933699e
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 16:55:34 GMT
URL: https://github.com/mono/gtk-sharp/commit/fd2fb44f99f2f36d4d8c5e0253bbb644f933699e
generator: readable&writable attribs to be backwards compat
Changed paths:
M generator/FieldBase.cs
M generator/Parameters.cs
M generator/Parser.cs
Modified: generator/FieldBase.cs
===================================================================
@@ -42,12 +42,16 @@ public virtual bool Validate (LogWriter log)
protected virtual bool Readable {
get {
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
+ return elem.GetAttribute ("readable") != "false";
return elem.HasAttribute ("readable") && elem.GetAttributeAsBoolean ("readable");
}
}
protected virtual bool Writable {
get {
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
+ return elem.GetAttribute ("writeable") != "false";
return elem.HasAttribute ("writeable") && elem.GetAttributeAsBoolean ("writeable");
}
}
Modified: generator/Parameters.cs
===================================================================
@@ -53,7 +53,7 @@ public Parameters (XmlElement elem, bool first_is_instance)
private bool throws = false;
public bool Throws {
get {
- if (ParserVersion <= 2)
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return true;
if (!throws && elem.HasAttribute ("throws"))
throws = elem.GetAttributeAsBoolean ("throws");
@@ -289,12 +289,5 @@ public bool Validate (LogWriter log)
return String.Join (", ", result);
}
}
-
- private int ParserVersion {
- get {
- XmlElement root = elem.OwnerDocument.DocumentElement;
- return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
- }
- }
}
}
Modified: generator/Parser.cs
===================================================================
@@ -187,6 +187,12 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
return result;
}
+ internal static int GetVersion (XmlElement document_element)
+ {
+ XmlElement root = document_element;
+ return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
+ }
+
private IGeneratable ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
Commit: 747a4ad871d86103134c5b63d2ecd64298cbfb9d
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-08 18:22:16 GMT
URL: https://github.com/mono/gtk-sharp/commit/747a4ad871d86103134c5b63d2ecd64298cbfb9d
generator: Added conversion for unions
Also removed all assumptions for parameters when
ParserVersion >= 3
Changed paths:
M generator/Makefile.am
M generator/Parameters.cs
M generator/Parser.cs
M generator/StructBase.cs
M generator/StructField.cs
M generator/SymbolTable.cs
M generator/generator.csproj
Added paths:
A generator/UnionGen.cs
Modified: generator/Makefile.am
===================================================================
@@ -64,6 +64,7 @@ sources = \
StructField.cs \
StructGen.cs \
SymbolTable.cs \
+ UnionGen.cs \
VirtualMethod.cs \
VMSignature.cs \
XmlElementExtensions.cs
Modified: generator/Parameters.cs
===================================================================
@@ -93,23 +93,23 @@ public bool IsHidden (Parameter p)
if (HasCB || HideData) {
- foreach (Parameter param in param_list) {
- if (param.Closure == idx)
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) >= 3) {
+ foreach (Parameter param in param_list) {
+ if (param.Closure == idx)
+ return true;
+ if (param.DestroyNotify == idx)
+ return true;
+ }
+ } else {
+ if (p.IsUserData && (idx == Count - 1))
+ return true;
+ if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
+ return true;
+ if (p.IsUserData && idx > 0 && this [idx - 1].Generatable is CallbackGen)
return true;
- else if (param.DestroyNotify == idx)
+ if (p.IsDestroyNotify && (idx == Count - 1) && this [idx - 1].IsUserData)
return true;
}
-
- if (p.IsUserData && (idx == Count - 1))
- return true;
- if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
- return true;
- if (p.IsUserData && idx > 0 &&
- this [idx - 1].Generatable is CallbackGen)
- return true;
- if (p.IsDestroyNotify && (idx == Count - 1) &&
- this [idx - 1].IsUserData)
- return true;
}
return false;
@@ -234,7 +234,8 @@ public bool Validate (LogWriter log)
param_list.Add (p);
}
- if (has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) < 3 &&
+ has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
this [Count - 3].Scope = "notified";
valid = true;
Modified: generator/Parser.cs
===================================================================
@@ -171,6 +171,9 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
case "class":
result.Add (new ClassGen (ns, elem));
break;
+ case "union":
+ result.Add (new UnionGen (ns, elem));
+ break;
case "struct":
if (is_opaque) {
result.Add (new OpaqueGen (ns, elem));
Modified: generator/StructBase.cs
===================================================================
@@ -110,6 +110,12 @@ public string ReleaseNative (string var)
}
}
+ public virtual bool Union {
+ get {
+ return false;
+ }
+ }
+
protected void GenEqualsAndHash (StreamWriter sw)
{
int bitfields = 0;
@@ -172,12 +178,13 @@ protected new void GenFields (GenerationInfo gen_info)
{
int bitfields = 0;
bool need_field = true;
+ StreamWriter sw = gen_info.Writer;
foreach (StructField field in fields) {
+ if (Union)
+ sw.WriteLine ("\t\t[FieldOffset(0)]");
if (field.IsBitfield) {
if (need_field) {
- StreamWriter sw = gen_info.Writer;
-
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
need_field = false;
}
@@ -221,7 +228,10 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
- sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
+ if (Union)
+ sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
+ else
+ sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
sw.WriteLine ();
Modified: generator/StructField.cs
===================================================================
@@ -80,7 +80,7 @@ public class StructField : FieldBase {
return StudlyName;
else if (IsBitfield)
return Name;
- else if (IsPointer && (gen is StructGen || gen is BoxedGen))
+ else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen))
return Access != "private" ? wrapped_name : Name;
else if (IsPointer && CSType != "string")
return Name;
@@ -148,7 +148,7 @@ public override void Generate (GenerationInfo gen_info, string indent)
acc.WriteAccessors (sw, indent + "\t", Name);
sw.WriteLine (indent + "}");
}
- } else if (IsPointer && (gen is StructGen || gen is BoxedGen)) {
+ } else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen)) {
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
sw.WriteLine ();
if (Access != "private") {
Modified: generator/SymbolTable.cs
===================================================================
@@ -292,6 +292,13 @@ public bool IsStruct(string c_type)
return false;
}
+
+ public bool IsUnion (string c_type)
+ {
+ if (this[c_type] is UnionGen)
+ return true;
+ return false;
+ }
public bool IsEnum(string c_type)
{
Added: generator/UnionGen.cs
===================================================================
@@ -0,0 +1,18 @@
+
+using System.Xml;
+
+namespace GtkSharp.Generation
+{
+ public class UnionGen : StructBase {
+
+ public UnionGen (XmlElement ns, XmlElement elem) : base (ns, elem)
+ {
+ }
+
+ public override bool Union {
+ get {
+ return true;
+ }
+ }
+ }
+}
Modified: generator/generator.csproj
===================================================================
@@ -92,6 +92,7 @@
<Compile Include="ArrayParameter.cs" />
<Compile Include="Options.cs" />
<Compile Include="Constant.cs" />
+ <Compile Include="UnionGen.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DESIGN" />
Commit: 112e2b9598140070a2972117260b5be3e5b814b9
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 11:09:34 GMT
URL: https://github.com/mono/gtk-sharp/commit/112e2b9598140070a2972117260b5be3e5b814b9
generator,glib: Added Mutex, RecMutex, Cond types
Bind these types manually and added generator support
for them.
Changed paths:
M generator/SymbolTable.cs
M glib/Makefile.am
M glib/glib.csproj
Added paths:
A glib/Cond.cs
A glib/Mutex.cs
A glib/RecMutex.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -127,6 +127,9 @@ public SymbolTable ()
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
+ AddType (new ManualGen ("GMutex", "GLib.Mutex"));
+ AddType (new ManualGen ("GRecMutex", "GLib.RecMutex"));
+ AddType (new ManualGen ("GCond", "GLib.Cond"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
Added: glib/Cond.cs
===================================================================
@@ -0,0 +1,70 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+// TODO: generate this as part of the build instead of committing it to the repo
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class Cond : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_broadcast(IntPtr raw);
+
+ public void Broadcast() {
+ g_cond_broadcast(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_clear(IntPtr raw);
+
+ public void Clear() {
+ g_cond_clear(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_init(IntPtr raw);
+
+ public void Init() {
+ g_cond_init(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_signal(IntPtr raw);
+
+ public void Signal() {
+ g_cond_signal(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
+
+ public void Wait(GLib.Mutex mutex) {
+ IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
+ g_cond_wait(Handle, native_mutex);
+ mutex = GLib.Mutex.New (native_mutex);
+ Marshal.FreeHGlobal (native_mutex);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
+
+ public bool WaitUntil(GLib.Mutex mutex, long end_time) {
+ IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
+ bool raw_ret = g_cond_wait_until(Handle, native_mutex, end_time);
+ bool ret = raw_ret;
+ mutex = GLib.Mutex.New (native_mutex);
+ Marshal.FreeHGlobal (native_mutex);
+ return ret;
+ }
+
+ public Cond(IntPtr raw) : base(raw) {}
+
+#endregion
+ }
+}
Modified: glib/Makefile.am
===================================================================
@@ -22,6 +22,7 @@ references =
sources = \
Argv.cs \
ConnectBeforeAttribute.cs \
+ Cond.cs \
DefaultSignalHandlerAttribute.cs \
DestroyNotify.cs \
ExceptionManager.cs \
@@ -48,6 +49,7 @@ sources = \
Markup.cs \
Marshaller.cs \
MissingIntPtrCtorException.cs \
+ Mutex.cs \
NotifyHandler.cs \
Object.cs \
ObjectManager.cs \
@@ -56,6 +58,7 @@ sources = \
Priority.cs \
PropertyAttribute.cs \
PtrArray.cs \
+ RecMutex.cs \
Signal.cs \
SignalArgs.cs \
SignalAttribute.cs \
Added: glib/Mutex.cs
===================================================================
@@ -0,0 +1,110 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+// TODO: generate this as part of the build instead of committing it to the repo
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Explicit)]
+ public partial struct Mutex : IEquatable<Mutex> {
+
+ [FieldOffset(0)]
+ private IntPtr _p;
+ [FieldOffset(0)]
+ [MarshalAs (UnmanagedType.ByValArray, SizeConst=2)]
+ public uint[] I;
+
+ public static GLib.Mutex Zero = new GLib.Mutex ();
+
+ public static GLib.Mutex New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.Mutex.Zero;
+ return (GLib.Mutex) Marshal.PtrToStructure (raw, typeof (GLib.Mutex));
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_clear(IntPtr raw);
+
+ public void Clear() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_mutex_clear(this_as_native);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_init(IntPtr raw);
+
+ public void Init() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_mutex_init(this_as_native);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_lock(IntPtr raw);
+
+ public void Lock() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_mutex_lock(this_as_native);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_mutex_trylock(IntPtr raw);
+
+ public bool Trylock() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ bool raw_ret = g_mutex_trylock(this_as_native);
+ bool ret = raw_ret;
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_unlock(IntPtr raw);
+
+ public void Unlock() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_mutex_unlock(this_as_native);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ static void ReadNative (IntPtr native, ref GLib.Mutex target)
+ {
+ target = New (native);
+ }
+
+ public bool Equals (Mutex other)
+ {
+ return true && _p.Equals (other._p) && I.Equals (other.I);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is Mutex && Equals ((Mutex) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ _p.GetHashCode () ^ I.GetHashCode ();
+ }
+
+#endregion
+ }
+}
Added: glib/RecMutex.cs
===================================================================
@@ -0,0 +1,57 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+// TODO: generate this as part of the build instead of committing it to the repo
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class RecMutex : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_clear(IntPtr raw);
+
+ public void Clear() {
+ g_rec_mutex_clear(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_init(IntPtr raw);
+
+ public void Init() {
+ g_rec_mutex_init(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_lock(IntPtr raw);
+
+ public void Lock() {
+ g_rec_mutex_lock(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_rec_mutex_trylock(IntPtr raw);
+
+ public bool Trylock() {
+ bool raw_ret = g_rec_mutex_trylock(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_unlock(IntPtr raw);
+
+ public void Unlock() {
+ g_rec_mutex_unlock(Handle);
+ }
+
+ public RecMutex(IntPtr raw) : base(raw) {}
+
+#endregion
+ }
+}
Modified: glib/glib.csproj
===================================================================
@@ -87,6 +87,9 @@
<Compile Include="Variant.cs" />
<Compile Include="VariantType.cs" />
<Compile Include="GLibSynchronizationContext.cs" />
+ <Compile Include="Mutex.cs" />
+ <Compile Include="RecMutex.cs" />
+ <Compile Include="Cond.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Core" />
Commit: d01be26f0ccb231abeb8899db872ece5e9805505
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 11:13:15 GMT
URL: https://github.com/mono/gtk-sharp/commit/d01be26f0ccb231abeb8899db872ece5e9805505
generator: added defaultconstructoraccess attrib
Changed paths:
M generator/ObjectGen.cs
Modified: generator/ObjectGen.cs
===================================================================
@@ -261,8 +261,9 @@ protected override void GenCtors (GenerationInfo gen_info)
{
if (!Elem.HasAttribute("parent"))
return;
+ string defaultconstructoraccess = Elem.HasAttribute ("defaultconstructoraccess") ? Elem.GetAttribute ("defaultconstructoraccess") : "public";
- gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
+ gen_info.Writer.WriteLine ("\t\t"+ defaultconstructoraccess + " " + Name + " (IntPtr raw) : base(raw) {}");
if (ctors.Count == 0 && !DisableVoidCtor) {
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(IntPtr.Zero)");
Commit: 29a900e51ef02c390c6f622c86e515b1b5ff4133
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 11:40:56 GMT
URL: https://github.com/mono/gtk-sharp/commit/29a900e51ef02c390c6f622c86e515b1b5ff4133
generator: added conversion for byref structs
The pointer from native is stored inside of a class which
wraps the structure. Fields can be accessed by marshalling
from and to the pointer. glib: Value.Update does now invoke
a private Update() method which is needed to update the new
structures.
Changed paths:
M generator/FieldBase.cs
M generator/Makefile.am
M generator/ObjectField.cs
M generator/Parser.cs
M generator/StructField.cs
M generator/generator.csproj
M glib/Value.cs
Added paths:
A generator/NativeStructGen.cs
Modified: generator/FieldBase.cs
===================================================================
@@ -40,7 +40,7 @@ public virtual bool Validate (LogWriter log)
return true;
}
- protected virtual bool Readable {
+ internal virtual bool Readable {
get {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return elem.GetAttribute ("readable") != "false";
@@ -48,7 +48,7 @@ public virtual bool Validate (LogWriter log)
}
}
- protected virtual bool Writable {
+ internal virtual bool Writable {
get {
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
return elem.GetAttribute ("writeable") != "false";
@@ -58,7 +58,7 @@ public virtual bool Validate (LogWriter log)
protected abstract string DefaultAccess { get; }
- protected string Access {
+ internal string Access {
get {
return elem.HasAttribute ("access") ? elem.GetAttribute ("access") : DefaultAccess;
}
Modified: generator/Makefile.am
===================================================================
@@ -43,6 +43,7 @@ sources = \
MethodBase.cs \
MethodBody.cs \
Method.cs \
+ NativeStructGen.cs \
ObjectField.cs \
ObjectBase.cs \
ObjectGen.cs \
Added: generator/NativeStructGen.cs
===================================================================
@@ -0,0 +1,232 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Xml;
+
+namespace GtkSharp.Generation
+{
+ public class NativeStructGen : HandleBase
+ {
+ IList<StructField> fields = new List<StructField> ();
+ bool need_read_native = false;
+ string native_struct_name;
+
+ public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
+ {
+ native_struct_name = Name + "Impl";
+
+ foreach (XmlNode node in elem.ChildNodes) {
+
+ if (!(node is XmlElement)) continue;
+ XmlElement member = (XmlElement) node;
+
+ switch (node.Name) {
+ case "field":
+ fields.Add (new StructField (member, this));
+ break;
+
+ default:
+ if (!IsNodeNameHandled (node.Name))
+ Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
+ break;
+ }
+ }
+ }
+
+ public override string MarshalType {
+ get {
+ return "IntPtr";
+ }
+ }
+
+ public override string AssignToName {
+ get { return "Handle"; }
+ }
+
+ public override string CallByName ()
+ {
+ return "Handle";
+ }
+
+ public override string CallByName (string var)
+ {
+ return String.Format ("{0} == null ? IntPtr.Zero : {0}.{1}", var, "Handle");
+ }
+
+ public override string FromNative (string var, bool owned)
+ {
+ return "new " + QualifiedName + "( " + var + " )";
+ }
+
+ public override void Generate (GenerationInfo gen_info)
+ {
+ bool need_close = false;
+ if (gen_info.Writer == null) {
+ gen_info.Writer = gen_info.OpenStream (Name);
+ need_close = true;
+ }
+
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("namespace " + NS + " {");
+ sw.WriteLine ();
+ sw.WriteLine ("\tusing System;");
+ sw.WriteLine ("\tusing System.Collections;");
+ sw.WriteLine ("\tusing System.Collections.Generic;");
+ sw.WriteLine ("\tusing System.Runtime.InteropServices;");
+ sw.WriteLine ();
+
+ sw.WriteLine ("#region Autogenerated code");
+ if (IsDeprecated)
+ sw.WriteLine ("\t[Obsolete]");
+ string access = IsInternal ? "internal" : "public";
+ sw.WriteLine ("\t" + access + " partial class {0} : IEquatable<{0}> {{", Name);
+ sw.WriteLine ();
+
+ need_read_native = false;
+ GenNativeStruct (gen_info);
+ GenUpdate (gen_info);
+ GenFields (gen_info);
+ sw.WriteLine ();
+ GenCtors (gen_info);
+ GenMethods (gen_info, null, this);
+ if (need_read_native)
+ GenUpdate (gen_info);
+ GenEqualsAndHash (sw);
+
+ if (!need_close)
+ return;
+
+ sw.WriteLine ("#endregion");
+
+ sw.WriteLine ("\t}");
+ sw.WriteLine ("}");
+ sw.Close ();
+ gen_info.Writer = null;
+ }
+
+ private void GenNativeStruct (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("\t\t[StructLayout(LayoutKind.Sequential)]");
+ sw.WriteLine ("\t\tprivate struct {0} {{", native_struct_name);
+ foreach (StructField field in fields) {
+ field.Generate (gen_info, "\t\t\t");
+ }
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ }
+
+ private void GenUpdate (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("\t\tprivate void Update ()", QualifiedName);
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\tthis.managed_struct = ({0})Marshal.PtrToStructure (this.Handle, typeof({0}));", native_struct_name);
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ }
+
+ protected override void GenCtors (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("\t\tpublic {0} (IntPtr raw)", Name);
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\tthis.Handle = raw;");
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+
+ base.GenCtors (gen_info);
+ }
+
+ protected new void GenFields (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+ sw.WriteLine ("\t\tprivate IntPtr Raw;");
+ sw.WriteLine ("\t\tpublic IntPtr Handle {");
+ sw.WriteLine ("\t\t\tget { return Raw; }");
+ sw.WriteLine ("\t\t\tset { Raw = value; Update ();}");
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ("\t\tprivate {0} managed_struct;", native_struct_name);
+ sw.WriteLine ();
+ foreach (StructField field in fields) {
+ if (!field.Visible)
+ continue;
+ sw.WriteLine ("\t\tpublic {0} {1} {{", SymbolTable.Table.GetCSType (field.CType), field.StudlyName);
+ sw.WriteLine ("\t\t\tget {{ Update(); return {0}.{1}; }}", "managed_struct", field.StudlyName);
+ if (!(SymbolTable.Table [field.CType] is CallbackGen))
+ sw.WriteLine ("\t\t\tset {{ Update(); {0}.{1} = value; Marshal.StructureToPtr({0}, this.Handle, false); }}" , "managed_struct", field.StudlyName);
+ sw.WriteLine ("\t\t}");
+ }
+ }
+
+ protected void GenEqualsAndHash (StreamWriter sw)
+ {
+ int bitfields = 0;
+ bool need_field = true;
+ StringBuilder hashcode = new StringBuilder ();
+ StringBuilder equals = new StringBuilder ();
+
+ sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
+ sw.WriteLine ("\t\t{");
+ hashcode.Append ("this.GetType().FullName.GetHashCode()");
+ equals.Append ("true");
+
+ foreach (StructField field in fields) {
+ if (field.IsPadding || !field.Visible)
+ continue;
+ if (field.IsBitfield) {
+ if (need_field) {
+ equals.Append (" && _bitfield");
+ equals.Append (bitfields);
+ equals.Append (".Equals (other._bitfield");
+ equals.Append (bitfields);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append ("_bitfield");
+ hashcode.Append (bitfields++);
+ hashcode.Append (".GetHashCode ()");
+ need_field = false;
+ }
+ } else {
+ need_field = true;
+ equals.Append (" && ");
+ equals.Append (field.EqualityName);
+ equals.Append (".Equals (other.");
+ equals.Append (field.EqualityName);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append (field.EqualityName);
+ hashcode.Append (".GetHashCode ()");
+ }
+ }
+ sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ sw.WriteLine ("\t\tpublic override bool Equals (object other)");
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ if (Elem.GetAttribute ("nohash") == "true")
+ return;
+ sw.WriteLine ("\t\tpublic override int GetHashCode ()");
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+
+ }
+
+ public override void Prepare (StreamWriter sw, string indent)
+ {
+ sw.WriteLine (indent + "Update ();");
+ }
+ }
+}
+
Modified: generator/ObjectField.cs
===================================================================
@@ -32,7 +32,7 @@ public ObjectField (XmlElement elem, ClassBase container_type) : base (elem, con
ctype = "const-" + CType;
}
- protected override bool Writable {
+ internal override bool Writable {
get {
return elem.GetAttributeAsBoolean ("writeable");
}
Modified: generator/Parser.cs
===================================================================
@@ -140,6 +140,7 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
continue;
bool is_opaque = elem.GetAttributeAsBoolean ("opaque");
+ bool is_native_struct = elem.GetAttributeAsBoolean ("native");
switch (def.Name) {
case "alias":
@@ -177,6 +178,8 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
case "struct":
if (is_opaque) {
result.Add (new OpaqueGen (ns, elem));
+ } else if (is_native_struct) {
+ result.Add (new NativeStructGen (ns, elem));
} else {
result.Add (new StructGen (ns, elem));
}
Modified: generator/StructField.cs
===================================================================
@@ -70,6 +70,13 @@ public class StructField : FieldBase {
}
}
+ bool visible = false;
+ internal bool Visible {
+ get {
+ return visible;
+ }
+ }
+
public string EqualityName {
get {
SymbolTable table = SymbolTable.Table;
@@ -127,6 +134,8 @@ public override void Generate (GenerationInfo gen_info, string indent)
if (Hidden)
return;
+ visible = Access != "private";
+
StreamWriter sw = gen_info.Writer;
SymbolTable table = SymbolTable.Table;
@@ -158,6 +167,7 @@ public override void Generate (GenerationInfo gen_info, string indent)
}
} else if (IsPointer && CSType != "string") {
// FIXME: probably some fields here which should be visible.
+ visible = false;
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
} else {
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);
Modified: generator/generator.csproj
===================================================================
@@ -93,6 +93,7 @@
<Compile Include="Options.cs" />
<Compile Include="Constant.cs" />
<Compile Include="UnionGen.cs" />
+ <Compile Include="NativeStructGen.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DESIGN" />
@@ -102,4 +103,4 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
Modified: glib/Value.cs
===================================================================
@@ -421,10 +421,14 @@ object ToBoxed ()
return (GLib.Opaque) this;
MethodInfo mi = t.GetMethod ("New", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
- if (mi == null)
- return Marshal.PtrToStructure (boxed_ptr, t);
- else
+ if (mi != null)
return mi.Invoke (null, new object[] {boxed_ptr});
+
+ ConstructorInfo ci = t.GetConstructor (new Type[] { typeof(IntPtr) });
+ if (ci != null)
+ return ci.Invoke (new object[] { boxed_ptr });
+
+ return Marshal.PtrToStructure (boxed_ptr, t);
}
public object Val
@@ -548,8 +552,15 @@ public object Val
internal void Update (object val)
{
- if (GType.Is (type, GType.Boxed) && !(val is IWrapper))
- Marshal.StructureToPtr (val, g_value_get_boxed (ref this), false);
+ Type t = GType.LookupType (type);
+ if (GType.Is (type, GType.Boxed) && !(val is IWrapper)) {
+ MethodInfo mi = val.GetType ().GetMethod ("Update", BindingFlags.NonPublic | BindingFlags.Instance);
+ IntPtr boxed_ptr = g_value_get_boxed (ref this);
+ if (mi == null)
+ Marshal.StructureToPtr (val, boxed_ptr, false);
+ else
+ mi.Invoke (val, null);
+ }
}
bool HoldsFlags {
Commit: 33fd293b8479aa4da3528d4562cb64ba45aa60ac
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 12:02:46 GMT
URL: https://github.com/mono/gtk-sharp/commit/33fd293b8479aa4da3528d4562cb64ba45aa60ac
generator: null check for handle (NativeStructGen)
Check Handle against IntPtr.Zero before marshalling.
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -126,7 +126,8 @@ private void GenUpdate (GenerationInfo gen_info)
sw.WriteLine ("\t\tprivate void Update ()", QualifiedName);
sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\tthis.managed_struct = ({0})Marshal.PtrToStructure (this.Handle, typeof({0}));", native_struct_name);
+ sw.WriteLine ("\t\t\tif (Handle != IntPtr.Zero)");
+ sw.WriteLine ("\t\t\t\tthis.managed_struct = ({0})Marshal.PtrToStructure (this.Handle, typeof ({0}));", native_struct_name);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
Commit: 388a2fe65993311d4b4d4ba1903cfc26468b588a
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 13:31:10 GMT
URL: https://github.com/mono/gtk-sharp/commit/388a2fe65993311d4b4d4ba1903cfc26468b588a
generator: added handling of optional parameters
Changed paths:
M generator/Method.cs
M generator/Parameter.cs
M generator/Parameters.cs
M generator/Signature.cs
Modified: generator/Method.cs
===================================================================
@@ -207,6 +207,14 @@ public void GenerateImport (StreamWriter sw)
}
}
+ public void GenerateOverloads (StreamWriter sw)
+ {
+ sw.WriteLine ();
+ sw.WriteLine ("\t\t" + retval.CSType + " " + Name + "(" + (Signature != null ? Signature.WithoutOptional () : "") + ") {");
+ sw.WriteLine ("\t\t\t{0}{1} ({2});", !retval.IsVoid ? "return " : String.Empty, Name, Signature.CallWithoutOptionals ());
+ sw.WriteLine ("\t\t}");
+ }
+
public void Generate (GenerationInfo gen_info, ClassBase implementor)
{
Method comp = null;
@@ -266,6 +274,9 @@ public void Generate (GenerationInfo gen_info, ClassBase implementor)
}
else
gen_info.Writer.WriteLine();
+
+ if (Parameters.HasOptional && !(is_get || is_set))
+ GenerateOverloads (gen_info.Writer);
gen_info.Writer.WriteLine();
Modified: generator/Parameter.cs
===================================================================
@@ -90,6 +90,12 @@ public Parameter (XmlElement e)
}
}
+ internal bool IsOptional {
+ get {
+ return elem.GetAttributeAsBoolean ("allow-none");
+ }
+ }
+
bool is_count;
bool is_count_set;
public bool IsCount {
Modified: generator/Parameters.cs
===================================================================
@@ -142,6 +142,11 @@ public bool IsHidden (Parameter p)
set { is_static = value; }
}
+ bool has_optional;
+ internal bool HasOptional {
+ get { return has_optional;}
+ }
+
public Parameter GetCountParameter (string param_name)
{
foreach (Parameter p in this)
@@ -198,6 +203,9 @@ public bool Validate (LogWriter log)
return false;
}
+ if (p.IsOptional && p.PassAs == String.Empty)
+ has_optional = true;
+
IGeneratable gen = p.Generatable;
if (p.IsArray) {
Modified: generator/Signature.cs
===================================================================
@@ -118,6 +118,44 @@ public override string ToString ()
return String.Join (", ", result);
}
}
+
+ public string WithoutOptional ()
+ {
+ if (parms.Count == 0)
+ return String.Empty;
+
+ var result = new string [parms.Count];
+ int i = 0;
+
+ foreach (Parameter p in parms) {
+ if (p.IsOptional && p.PassAs == String.Empty)
+ continue;
+ result [i] = p.PassAs != String.Empty ? p.PassAs + " " : String.Empty;
+ result [i++] += p.CSType + " " + p.Name;
+ }
+
+ return String.Join (", ", result, 0, i);
+ }
+
+ public string CallWithoutOptionals ()
+ {
+ if (parms.Count == 0)
+ return String.Empty;
+
+ var result = new string [parms.Count];
+ int i = 0;
+
+ foreach (Parameter p in parms) {
+
+ result [i] = p.PassAs != "" ? p.PassAs + " " : "";
+ if (p.IsOptional && p.PassAs == String.Empty)
+ result [i++] += (p.Generatable is StructGen || p.Generatable is BoxedGen) ? (p.CSType + ".Zero") : "null";
+ else
+ result [i++] += p.Name;
+ }
+
+ return String.Join (", ", result);
+ }
}
}
Commit: 972e6257fcde57865197d27bcaac802f7b103c64
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 13:35:36 GMT
URL: https://github.com/mono/gtk-sharp/commit/972e6257fcde57865197d27bcaac802f7b103c64
generator: removed wrong glue code for structs
Changed paths:
M generator/FieldBase.cs
Modified: generator/FieldBase.cs
===================================================================
@@ -176,13 +176,8 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Readable && offsetName != null) {
sw.WriteLine (indent + "\tget {");
sw.WriteLine (indent + "\t\tunsafe {");
- if (is_struct) {
- sw.WriteLine (indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\treturn *raw_ptr;");
- } else {
- sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
- }
+ sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
@@ -203,13 +198,8 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Writable && offsetName != null) {
sw.WriteLine (indent + "\tset {");
sw.WriteLine (indent + "\t\tunsafe {");
- if (is_struct) {
- sw.WriteLine (indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\t*raw_ptr = value;");
- } else {
- sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
- }
+ sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
Commit: 949c538fe39c34969d70d0bbb69057a7e34b1a54
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 13:38:46 GMT
URL: https://github.com/mono/gtk-sharp/commit/949c538fe39c34969d70d0bbb69057a7e34b1a54
generator: IntPtr.Zero for optional IntPtr params
IntPtr.Zero should be passed for optional IntPtr params
instead of null
Changed paths:
M generator/Signature.cs
Modified: generator/Signature.cs
===================================================================
@@ -148,8 +148,14 @@ public string CallWithoutOptionals ()
foreach (Parameter p in parms) {
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
- if (p.IsOptional && p.PassAs == String.Empty)
- result [i++] += (p.Generatable is StructGen || p.Generatable is BoxedGen) ? (p.CSType + ".Zero") : "null";
+ if (p.IsOptional && p.PassAs == String.Empty) {
+ if (p.Generatable is StructGen || p.Generatable is BoxedGen)
+ result [i++] += " .Zero";
+ else if (p.CSType == "System.IntPtr")
+ result [i++] += "System.IntPtr.Zero";
+ else
+ result [i++] += "null";
+ }
else
result [i++] += p.Name;
}
Commit: ddd241915129a4f8ab4849219a6872b1187d94ff
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 13:41:27 GMT
URL: https://github.com/mono/gtk-sharp/commit/ddd241915129a4f8ab4849219a6872b1187d94ff
generator: fix optional parameters again
Changed paths:
M generator/Signature.cs
Modified: generator/Signature.cs
===================================================================
@@ -150,7 +150,7 @@ public string CallWithoutOptionals ()
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
if (p.IsOptional && p.PassAs == String.Empty) {
if (p.Generatable is StructGen || p.Generatable is BoxedGen)
- result [i++] += " .Zero";
+ result [i++] += p.CSType + ".Zero";
else if (p.CSType == "System.IntPtr")
result [i++] += "System.IntPtr.Zero";
else
Commit: 55ab3ab284856ea6498ce595e4528661311747e8
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 13:44:33 GMT
URL: https://github.com/mono/gtk-sharp/commit/55ab3ab284856ea6498ce595e4528661311747e8
generator: fixed glue code for callbacks
Changed paths:
M generator/CallbackGen.cs
M generator/FieldBase.cs
Modified: generator/CallbackGen.cs
===================================================================
@@ -70,6 +70,14 @@ public override bool Validate ()
}
}
+ public string WrapperName {
+ get {
+ if (!valid)
+ return String.Empty;
+ return NS + "Sharp." + Name + "Wrapper";
+ }
+ }
+
public override string MarshalType {
get {
if (valid)
Modified: generator/FieldBase.cs
===================================================================
@@ -156,6 +156,7 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
GenerateImports (gen_info, indent);
SymbolTable table = SymbolTable.Table;
+ IGeneratable gen = table [CType];
StreamWriter sw = gen_info.Writer;
string modifiers = elem.GetAttributeAsBoolean ("new_flag") ? "new " : "";
bool is_struct = table.IsStruct (CType) || table.IsBoxed (CType);
@@ -176,13 +177,19 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Readable && offsetName != null) {
sw.WriteLine (indent + "\tget {");
sw.WriteLine (indent + "\t\tunsafe {");
- sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
+ if (gen is CallbackGen) {
+ sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t {0} del = ({0})Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof({0}));", table.GetMarshalType (CType));
+ sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(del)") + ";");
+ }
+ else {
+ sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
+ }
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
- IGeneratable gen = table [CType];
string to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative ("value") : gen.CallByName ("value");
if (Setter != null) {
@@ -198,8 +205,15 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Writable && offsetName != null) {
sw.WriteLine (indent + "\tset {");
sw.WriteLine (indent + "\t\tunsafe {");
- sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
+ if (gen is CallbackGen) {
+ sw.WriteLine (indent + "\t\t\t{0} wrapper = new {0} (value);", ((CallbackGen)gen).WrapperName);
+ sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate (wrapper.NativeDelegate);");
+ }
+ else {
+ sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
+ }
sw.WriteLine (indent + "\t\t}");
sw.WriteLine (indent + "\t}");
}
Commit: aaa41cd0953b5fb1f38b10b586a4f33dec178bef
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 16:04:47 GMT
URL: https://github.com/mono/gtk-sharp/commit/aaa41cd0953b5fb1f38b10b586a4f33dec178bef
fixup: added copy-node metadata tag
Changed paths:
M parser/gapi-fixup.cs
Modified: parser/gapi-fixup.cs
===================================================================
@@ -1,8 +1,11 @@
// gapi-fixup.cs - xml alteration engine.
//
-// Author: Mike Kestner <[email protected]>
+// Authors:
+// Mike Kestner <[email protected]>
+// Stephan Sundermann <[email protected]>
//
// Copyright (c) 2003 Mike Kestner
+// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@@ -92,6 +95,26 @@ public static int Main (string[] args)
XPathNavigator meta_nav = meta_doc.CreateNavigator ();
XPathNavigator api_nav = api_doc.CreateNavigator ();
+ XPathNodeIterator copy_iter = meta_nav.Select ("/metadata/copy-node");
+ while (copy_iter.MoveNext ()) {
+ string path = copy_iter.Current.GetAttribute ("path", String.Empty);
+ XPathExpression expr = api_nav.Compile (path);
+ string parent = copy_iter.Current.Value;
+ XPathNodeIterator parent_iter = api_nav.Select (parent);
+ bool matched = false;
+ while (parent_iter.MoveNext ()) {
+ XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
+ XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
+ while (path_iter.MoveNext ()) {
+ XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
+ parent_node.AppendChild (node.Clone ());
+ }
+ matched = true;
+ }
+ if (!matched)
+ Console.WriteLine ("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
+ }
+
XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");
while (rmv_iter.MoveNext ()) {
string path = rmv_iter.Current.GetAttribute ("path", "");
Commit: 9abde602ecc3f20500d86c3c05fa6f98be214fa1
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 16:30:10 GMT
URL: https://github.com/mono/gtk-sharp/commit/9abde602ecc3f20500d86c3c05fa6f98be214fa1
glib: add GDate, GDateTime
Add GDate and GDateTime classes to glib, and map
them in the generator's SymbolTable.
(The types TimeZone and TimeVal are also added because
the Date* types depend on them, but there is no need
to map them in the generator.)
Also move the TODOs of other auto-generated classes
to a single TODO in the Makefile
Changed paths:
M generator/SymbolTable.cs
M glib/Cond.cs
M glib/Makefile.am
M glib/Marshaller.cs
M glib/Mutex.cs
M glib/RecMutex.cs
M glib/glib.csproj
Added paths:
A glib/Date.cs
A glib/DateTime.cs
A glib/TimeVal.cs
A glib/TimeZone.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -130,6 +130,8 @@ public SymbolTable ()
AddType (new ManualGen ("GMutex", "GLib.Mutex"));
AddType (new ManualGen ("GRecMutex", "GLib.RecMutex"));
AddType (new ManualGen ("GCond", "GLib.Cond"));
+ AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
+ AddType (new ManualGen ("GDate", "GLib.Date"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
@@ -138,7 +140,6 @@ public SymbolTable ()
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null"));
AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
-
// FIXME: These ought to be handled properly.
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
AddType (new SimpleGen ("GError", "IntPtr", "IntPtr.Zero"));
Modified: glib/Cond.cs
===================================================================
@@ -1,8 +1,6 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
-// TODO: generate this as part of the build instead of committing it to the repo
-
namespace GLib {
using System;
Added: glib/Date.cs
===================================================================
@@ -0,0 +1,478 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class Date : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_date_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_days(IntPtr raw, uint n_days);
+
+ public void AddDays(uint n_days) {
+ g_date_add_days(Handle, n_days);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_months(IntPtr raw, uint n_months);
+
+ public void AddMonths(uint n_months) {
+ g_date_add_months(Handle, n_months);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_years(IntPtr raw, uint n_years);
+
+ public void AddYears(uint n_years) {
+ g_date_add_years(Handle, n_years);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_clamp(IntPtr raw, IntPtr min_date, IntPtr max_date);
+
+ public void Clamp(GLib.Date min_date, GLib.Date max_date) {
+ g_date_clamp(Handle, min_date == null ? IntPtr.Zero : min_date.Handle, max_date == null ? IntPtr.Zero : max_date.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_clear(IntPtr raw, uint n_dates);
+
+ public void Clear(uint n_dates) {
+ g_date_clear(Handle, n_dates);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_compare(IntPtr raw, IntPtr rhs);
+
+ public int Compare(GLib.Date rhs) {
+ int raw_ret = g_date_compare(Handle, rhs == null ? IntPtr.Zero : rhs.Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_days_between(IntPtr raw, IntPtr date2);
+
+ public int DaysBetween(GLib.Date date2) {
+ int raw_ret = g_date_days_between(Handle, date2 == null ? IntPtr.Zero : date2.Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_day(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_day(IntPtr raw, byte day);
+
+ public byte Day {
+ get {
+ byte raw_ret = g_date_get_day(Handle);
+ byte ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_day(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_day_of_year(IntPtr raw);
+
+ public uint DayOfYear {
+ get {
+ uint raw_ret = g_date_get_day_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_iso8601_week_of_year(IntPtr raw);
+
+ public uint Iso8601WeekOfYear {
+ get {
+ uint raw_ret = g_date_get_iso8601_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_julian(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_julian(IntPtr raw, uint julian_date);
+
+ public uint Julian {
+ get {
+ uint raw_ret = g_date_get_julian(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_julian(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_monday_week_of_year(IntPtr raw);
+
+ public uint MondayWeekOfYear {
+ get {
+ uint raw_ret = g_date_get_monday_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_get_month(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_month(IntPtr raw, int month);
+
+ public int Month {
+ get {
+ int raw_ret = g_date_get_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_month(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_sunday_week_of_year(IntPtr raw);
+
+ public uint SundayWeekOfYear {
+ get {
+ uint raw_ret = g_date_get_sunday_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_get_weekday(IntPtr raw);
+
+ public int Weekday {
+ get {
+ int raw_ret = g_date_get_weekday(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern ushort g_date_get_year(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_year(IntPtr raw, ushort year);
+
+ public ushort Year {
+ get {
+ ushort raw_ret = g_date_get_year(Handle);
+ ushort ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_year(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_first_of_month(IntPtr raw);
+
+ public bool IsFirstOfMonth {
+ get {
+ bool raw_ret = g_date_is_first_of_month(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_last_of_month(IntPtr raw);
+
+ public bool IsLastOfMonth {
+ get {
+ bool raw_ret = g_date_is_last_of_month(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_order(IntPtr raw, IntPtr date2);
+
+ public void Order(GLib.Date date2) {
+ g_date_order(Handle, date2 == null ? IntPtr.Zero : date2.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_dmy(IntPtr raw, byte day, int month, ushort y);
+
+ public void SetDmy(byte day, int month, ushort y) {
+ g_date_set_dmy(Handle, day, month, y);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_parse(IntPtr raw, IntPtr str);
+
+ public string Parse {
+ set {
+ IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
+ g_date_set_parse(Handle, native_value);
+ GLib.Marshaller.Free (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time(IntPtr raw, int time_);
+
+ [Obsolete]
+ public int Time {
+ set {
+ g_date_set_time(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time_t(IntPtr raw, IntPtr timet);
+
+ public long TimeT {
+ set {
+ g_date_set_time_t(Handle, new IntPtr (value));
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time_val(IntPtr raw, IntPtr value);
+
+ public GLib.TimeVal TimeVal {
+ set {
+ IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
+ g_date_set_time_val(Handle, native_value);
+ value = GLib.TimeVal.New (native_value);
+ Marshal.FreeHGlobal (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_days(IntPtr raw, uint n_days);
+
+ public void SubtractDays(uint n_days) {
+ g_date_subtract_days(Handle, n_days);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_months(IntPtr raw, uint n_months);
+
+ public void SubtractMonths(uint n_months) {
+ g_date_subtract_months(Handle, n_months);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_years(IntPtr raw, uint n_years);
+
+ public void SubtractYears(uint n_years) {
+ g_date_subtract_years(Handle, n_years);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_to_struct_tm(IntPtr raw, IntPtr tm);
+
+ public void ToStructTm(IntPtr tm) {
+ g_date_to_struct_tm(Handle, tm);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid(IntPtr raw);
+
+ public bool Valid() {
+ bool raw_ret = g_date_valid(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_days_in_month(int month, ushort year);
+
+ public static byte GetDaysInMonth(int month, ushort year) {
+ byte raw_ret = g_date_get_days_in_month(month, year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_monday_weeks_in_year(ushort year);
+
+ public static byte GetMondayWeeksInYear(ushort year) {
+ byte raw_ret = g_date_get_monday_weeks_in_year(year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_sunday_weeks_in_year(ushort year);
+
+ public static byte GetSundayWeeksInYear(ushort year) {
+ byte raw_ret = g_date_get_sunday_weeks_in_year(year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_leap_year(ushort year);
+
+ public static bool IsLeapYear(ushort year) {
+ bool raw_ret = g_date_is_leap_year(year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern UIntPtr g_date_strftime(IntPtr s, UIntPtr slen, IntPtr format, IntPtr date);
+
+ public static ulong Strftime(string s, string format, GLib.Date date) {
+ IntPtr native_s = GLib.Marshaller.StringToPtrGStrdup (s);
+ IntPtr native_format = GLib.Marshaller.StringToPtrGStrdup (format);
+ UIntPtr raw_ret = g_date_strftime(native_s, new UIntPtr ((ulong) System.Text.Encoding.UTF8.GetByteCount (s)), native_format, date == null ? IntPtr.Zero : date.Handle);
+ ulong ret = (ulong) raw_ret;
+ GLib.Marshaller.Free (native_s);
+ GLib.Marshaller.Free (native_format);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_day(byte day);
+
+ public static bool ValidDay(byte day) {
+ bool raw_ret = g_date_valid_day(day);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_dmy(byte day, int month, ushort year);
+
+ public static bool ValidDmy(byte day, int month, ushort year) {
+ bool raw_ret = g_date_valid_dmy(day, month, year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_julian(uint julian_date);
+
+ public static bool ValidJulian(uint julian_date) {
+ bool raw_ret = g_date_valid_julian(julian_date);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_month(int month);
+
+ public static bool ValidMonth(int month) {
+ bool raw_ret = g_date_valid_month(month);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_weekday(int weekday);
+
+ public static bool ValidWeekday(int weekday) {
+ bool raw_ret = g_date_valid_weekday(weekday);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_year(ushort year);
+
+ public static bool ValidYear(ushort year) {
+ bool raw_ret = g_date_valid_year(year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ public Date(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new();
+
+ public Date ()
+ {
+ Raw = g_date_new();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new_dmy(byte day, int month, ushort year);
+
+ public Date (byte day, int month, ushort year)
+ {
+ Raw = g_date_new_dmy(day, month, year);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new_julian(uint julian_day);
+
+ public Date (uint julian_day)
+ {
+ Raw = g_date_new_julian(julian_day);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_free(IntPtr raw);
+
+ protected override void Free (IntPtr raw)
+ {
+ g_date_free (raw);
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_date_free (handle);
+ return false;
+ }
+ }
+
+ ~Date ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
Added: glib/DateTime.cs
===================================================================
@@ -0,0 +1,512 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class DateTime : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_date_time_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add(IntPtr raw, long timespan);
+
+ public GLib.DateTime Add(long timespan) {
+ IntPtr raw_ret = g_date_time_add(Handle, timespan);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_days(IntPtr raw, int days);
+
+ public GLib.DateTime AddDays(int days) {
+ IntPtr raw_ret = g_date_time_add_days(Handle, days);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_full(IntPtr raw, int years, int months, int days, int hours, int minutes, double seconds);
+
+ public GLib.DateTime AddFull(int years, int months, int days, int hours, int minutes, double seconds) {
+ IntPtr raw_ret = g_date_time_add_full(Handle, years, months, days, hours, minutes, seconds);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_hours(IntPtr raw, int hours);
+
+ public GLib.DateTime AddHours(int hours) {
+ IntPtr raw_ret = g_date_time_add_hours(Handle, hours);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_minutes(IntPtr raw, int minutes);
+
+ public GLib.DateTime AddMinutes(int minutes) {
+ IntPtr raw_ret = g_date_time_add_minutes(Handle, minutes);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_months(IntPtr raw, int months);
+
+ public GLib.DateTime AddMonths(int months) {
+ IntPtr raw_ret = g_date_time_add_months(Handle, months);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_seconds(IntPtr raw, double seconds);
+
+ public GLib.DateTime AddSeconds(double seconds) {
+ IntPtr raw_ret = g_date_time_add_seconds(Handle, seconds);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_weeks(IntPtr raw, int weeks);
+
+ public GLib.DateTime AddWeeks(int weeks) {
+ IntPtr raw_ret = g_date_time_add_weeks(Handle, weeks);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_years(IntPtr raw, int years);
+
+ public GLib.DateTime AddYears(int years) {
+ IntPtr raw_ret = g_date_time_add_years(Handle, years);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_difference(IntPtr raw, IntPtr begin);
+
+ public long Difference(GLib.DateTime begin) {
+ long raw_ret = g_date_time_difference(Handle, begin == null ? IntPtr.Zero : begin.Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_format(IntPtr raw, IntPtr format);
+
+ public string Format(string format) {
+ IntPtr native_format = GLib.Marshaller.StringToPtrGStrdup (format);
+ IntPtr raw_ret = g_date_time_format(Handle, native_format);
+ string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
+ GLib.Marshaller.Free (native_format);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_month(IntPtr raw);
+
+ public int DayOfMonth {
+ get {
+ int raw_ret = g_date_time_get_day_of_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_week(IntPtr raw);
+
+ public int DayOfWeek {
+ get {
+ int raw_ret = g_date_time_get_day_of_week(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_year(IntPtr raw);
+
+ public int DayOfYear {
+ get {
+ int raw_ret = g_date_time_get_day_of_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_hour(IntPtr raw);
+
+ public int Hour {
+ get {
+ int raw_ret = g_date_time_get_hour(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_microsecond(IntPtr raw);
+
+ public int Microsecond {
+ get {
+ int raw_ret = g_date_time_get_microsecond(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_minute(IntPtr raw);
+
+ public int Minute {
+ get {
+ int raw_ret = g_date_time_get_minute(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_month(IntPtr raw);
+
+ public int Month {
+ get {
+ int raw_ret = g_date_time_get_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_second(IntPtr raw);
+
+ public int Second {
+ get {
+ int raw_ret = g_date_time_get_second(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern double g_date_time_get_seconds(IntPtr raw);
+
+ public double Seconds {
+ get {
+ double raw_ret = g_date_time_get_seconds(Handle);
+ double ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_get_timezone_abbreviation(IntPtr raw);
+
+ public string TimezoneAbbreviation {
+ get {
+ IntPtr raw_ret = g_date_time_get_timezone_abbreviation(Handle);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_get_utc_offset(IntPtr raw);
+
+ public long UtcOffset {
+ get {
+ long raw_ret = g_date_time_get_utc_offset(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_week_numbering_year(IntPtr raw);
+
+ public int WeekNumberingYear {
+ get {
+ int raw_ret = g_date_time_get_week_numbering_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_week_of_year(IntPtr raw);
+
+ public int WeekOfYear {
+ get {
+ int raw_ret = g_date_time_get_week_of_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_year(IntPtr raw);
+
+ public int Year {
+ get {
+ int raw_ret = g_date_time_get_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_time_get_ymd(IntPtr raw, out int year, out int month, out int day);
+
+ public void GetYmd(out int year, out int month, out int day) {
+ g_date_time_get_ymd(Handle, out year, out month, out day);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_is_daylight_savings(IntPtr raw);
+
+ public bool IsDaylightSavings {
+ get {
+ bool raw_ret = g_date_time_is_daylight_savings(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_local(IntPtr raw);
+
+ public GLib.DateTime ToLocal() {
+ IntPtr raw_ret = g_date_time_to_local(Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_to_timeval(IntPtr raw, IntPtr tv);
+
+ public bool ToTimeval(GLib.TimeVal tv) {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ bool raw_ret = g_date_time_to_timeval(Handle, native_tv);
+ bool ret = raw_ret;
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_timezone(IntPtr raw, IntPtr tz);
+
+ public GLib.DateTime ToTimezone(GLib.TimeZone tz) {
+ IntPtr raw_ret = g_date_time_to_timezone(Handle, tz == null ? IntPtr.Zero : tz.Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_to_unix(IntPtr raw);
+
+ public long ToUnix() {
+ long raw_ret = g_date_time_to_unix(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_utc(IntPtr raw);
+
+ public GLib.DateTime ToUtc() {
+ IntPtr raw_ret = g_date_time_to_utc(Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_compare(IntPtr dt1, IntPtr dt2);
+
+ public static int Compare(IntPtr dt1, IntPtr dt2) {
+ int raw_ret = g_date_time_compare(dt1, dt2);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_equal(IntPtr dt1, IntPtr dt2);
+
+ public static bool Equal(IntPtr dt1, IntPtr dt2) {
+ bool raw_ret = g_date_time_equal(dt1, dt2);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_time_hash(IntPtr datetime);
+
+ public static uint Hash(IntPtr datetime) {
+ uint raw_ret = g_date_time_hash(datetime);
+ uint ret = raw_ret;
+ return ret;
+ }
+
+ public DateTime(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new(IntPtr tz, int year, int month, int day, int hour, int minute, double seconds);
+
+ public DateTime (GLib.TimeZone tz, int year, int month, int day, int hour, int minute, double seconds)
+ {
+ Raw = g_date_time_new(tz == null ? IntPtr.Zero : tz.Handle, year, month, day, hour, minute, seconds);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_timeval_local(IntPtr tv);
+
+ public DateTime (GLib.TimeVal tv)
+ {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ Raw = g_date_time_new_from_timeval_local(native_tv);
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_timeval_utc(IntPtr tv);
+
+ public static DateTime NewFromTimevalUtc(GLib.TimeVal tv)
+ {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ DateTime result = new DateTime (g_date_time_new_from_timeval_utc(native_tv));
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_unix_local(long t);
+
+ public DateTime (long t)
+ {
+ Raw = g_date_time_new_from_unix_local(t);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_unix_utc(long t);
+
+ public static DateTime NewFromUnixUtc(long t)
+ {
+ DateTime result = new DateTime (g_date_time_new_from_unix_utc(t));
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_local(int year, int month, int day, int hour, int minute, double seconds);
+
+ public DateTime (int year, int month, int day, int hour, int minute, double seconds)
+ {
+ Raw = g_date_time_new_local(year, month, day, hour, minute, seconds);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now(IntPtr tz);
+
+ public DateTime (GLib.TimeZone tz)
+ {
+ Raw = g_date_time_new_now(tz == null ? IntPtr.Zero : tz.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now_local();
+
+ public DateTime ()
+ {
+ Raw = g_date_time_new_now_local();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now_utc();
+
+ public static DateTime NewNowUtc()
+ {
+ DateTime result = new DateTime (g_date_time_new_now_utc());
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_utc(int year, int month, int day, int hour, int minute, double seconds);
+
+ public static DateTime NewUtc(int year, int month, int day, int hour, int minute, double seconds)
+ {
+ DateTime result = new DateTime (g_date_time_new_utc(year, month, day, hour, minute, seconds));
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_date_time_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_time_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_date_time_unref (raw);
+ Owned = false;
+ }
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_date_time_unref (handle);
+ return false;
+ }
+ }
+
+ ~DateTime ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
Modified: glib/Makefile.am
===================================================================
@@ -19,10 +19,15 @@ POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
references =
+# TODO: auto-generate at compile time the following classes:
+# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
+
sources = \
Argv.cs \
ConnectBeforeAttribute.cs \
Cond.cs \
+ Date.cs \
+ DateTime.cs \
DefaultSignalHandlerAttribute.cs \
DestroyNotify.cs \
ExceptionManager.cs \
@@ -68,6 +73,8 @@ sources = \
Spawn.cs \
Thread.cs \
Timeout.cs \
+ TimeVal.cs \
+ TimeZone.cs \
ToggleRef.cs \
TypeFundamentals.cs \
TypeInitializerAttribute.cs \
Modified: glib/Marshaller.cs
===================================================================
@@ -348,15 +348,15 @@ public static string[] ArrayPtrToArgv (IntPtr array, int argc)
return unmarshal_32 (array, argc);
}
- static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 0);
- static int utc_offset = (int) (TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds;
+ static System.DateTime local_epoch = new System.DateTime (1970, 1, 1, 0, 0, 0);
+ static int utc_offset = (int) (System.TimeZone.CurrentTimeZone.GetUtcOffset (System.DateTime.Now)).TotalSeconds;
- public static IntPtr DateTimeTotime_t (DateTime time)
+ public static IntPtr DateTimeTotime_t (System.DateTime time)
{
return new IntPtr (((long)time.Subtract (local_epoch).TotalSeconds) - utc_offset);
}
- public static DateTime time_tToDateTime (IntPtr time_t)
+ public static System.DateTime time_tToDateTime (IntPtr time_t)
{
return local_epoch.AddSeconds (time_t.ToInt64 () + utc_offset);
}
Modified: glib/Mutex.cs
===================================================================
@@ -1,8 +1,6 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
-// TODO: generate this as part of the build instead of committing it to the repo
-
namespace GLib {
using System;
Modified: glib/RecMutex.cs
===================================================================
@@ -1,8 +1,6 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
-// TODO: generate this as part of the build instead of committing it to the repo
-
namespace GLib {
using System;
Added: glib/TimeVal.cs
===================================================================
@@ -0,0 +1,105 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct TimeVal : IEquatable<TimeVal> {
+
+ private IntPtr tv_sec;
+ public long TvSec {
+ get {
+ return (long) tv_sec;
+ }
+ set {
+ tv_sec = new IntPtr (value);
+ }
+ }
+ private IntPtr tv_usec;
+ public long TvUsec {
+ get {
+ return (long) tv_usec;
+ }
+ set {
+ tv_usec = new IntPtr (value);
+ }
+ }
+
+ public static GLib.TimeVal Zero = new GLib.TimeVal ();
+
+ public static GLib.TimeVal New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.TimeVal.Zero;
+ return (GLib.TimeVal) Marshal.PtrToStructure (raw, typeof (GLib.TimeVal));
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_time_val_add(IntPtr raw, IntPtr microseconds);
+
+ public void Add(long microseconds) {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_time_val_add(this_as_native, new IntPtr (microseconds));
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_val_to_iso8601(IntPtr raw);
+
+ public string ToIso8601() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ IntPtr raw_ret = g_time_val_to_iso8601(this_as_native);
+ string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_time_val_from_iso8601(IntPtr iso_date, IntPtr time_);
+
+ public static bool FromIso8601(string iso_date, out GLib.TimeVal time_) {
+ IntPtr native_iso_date = GLib.Marshaller.StringToPtrGStrdup (iso_date);
+ IntPtr native_time_ = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (GLib.TimeVal)));
+ bool raw_ret = g_time_val_from_iso8601(native_iso_date, native_time_);
+ bool ret = raw_ret;
+ GLib.Marshaller.Free (native_iso_date);
+ time_ = GLib.TimeVal.New (native_time_);
+ Marshal.FreeHGlobal (native_time_);
+ return ret;
+ }
+
+ static void ReadNative (IntPtr native, ref GLib.TimeVal target)
+ {
+ target = New (native);
+ }
+
+ public bool Equals (TimeVal other)
+ {
+ return true && TvSec.Equals (other.TvSec) && TvUsec.Equals (other.TvUsec);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is TimeVal && Equals ((TimeVal) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ TvSec.GetHashCode () ^ TvUsec.GetHashCode ();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Added: glib/TimeZone.cs
===================================================================
@@ -0,0 +1,146 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class TimeZone : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_time_zone_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_adjust_time(IntPtr raw, int type, long time_);
+
+ public int AdjustTime(int type, long time_) {
+ int raw_ret = g_time_zone_adjust_time(Handle, type, time_);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_find_interval(IntPtr raw, int type, long time_);
+
+ public int FindInterval(int type, long time_) {
+ int raw_ret = g_time_zone_find_interval(Handle, type, time_);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_get_abbreviation(IntPtr raw, int interval);
+
+ public string GetAbbreviation(int interval) {
+ IntPtr raw_ret = g_time_zone_get_abbreviation(Handle, interval);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_get_offset(IntPtr raw, int interval);
+
+ public int GetOffset(int interval) {
+ int raw_ret = g_time_zone_get_offset(Handle, interval);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_time_zone_is_dst(IntPtr raw, int interval);
+
+ public bool IsDst(int interval) {
+ bool raw_ret = g_time_zone_is_dst(Handle, interval);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ public TimeZone(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new(IntPtr identifier);
+
+ public TimeZone (string identifier)
+ {
+ IntPtr native_identifier = GLib.Marshaller.StringToPtrGStrdup (identifier);
+ Raw = g_time_zone_new(native_identifier);
+ GLib.Marshaller.Free (native_identifier);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new_local();
+
+ public TimeZone ()
+ {
+ Raw = g_time_zone_new_local();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new_utc();
+
+ public static TimeZone NewUtc()
+ {
+ TimeZone result = new TimeZone (g_time_zone_new_utc());
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_time_zone_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_time_zone_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_time_zone_unref (raw);
+ Owned = false;
+ }
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_time_zone_unref (handle);
+ return false;
+ }
+ }
+
+ ~TimeZone ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
\ No newline at end of file
Modified: glib/glib.csproj
===================================================================
@@ -90,8 +90,12 @@
<Compile Include="Mutex.cs" />
<Compile Include="RecMutex.cs" />
<Compile Include="Cond.cs" />
+ <Compile Include="Date.cs" />
+ <Compile Include="DateTime.cs" />
+ <Compile Include="TimeVal.cs" />
+ <Compile Include="TimeZone.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Core" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
Commit: 8b101d552541675a925c1f36bc68357a20bb0c65
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 16:44:04 GMT
URL: https://github.com/mono/gtk-sharp/commit/8b101d552541675a925c1f36bc68357a20bb0c65
glib: Mutex is actually opaque
This means that we're modifying the generated code that
we checked in, so then we increase the future TODO about
more information about what we need to fix later.
The changes to Cond are a consequence of the changes to
Mutex because the former uses the latter.
Changed paths:
M glib/Cond.cs
M glib/Makefile.am
M glib/Mutex.cs
Modified: glib/Cond.cs
===================================================================
@@ -43,21 +43,15 @@ public partial class Cond : GLib.Opaque {
static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
public void Wait(GLib.Mutex mutex) {
- IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
- g_cond_wait(Handle, native_mutex);
- mutex = GLib.Mutex.New (native_mutex);
- Marshal.FreeHGlobal (native_mutex);
+ g_cond_wait(Handle, mutex == null ? IntPtr.Zero : mutex.Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
public bool WaitUntil(GLib.Mutex mutex, long end_time) {
- IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
- bool raw_ret = g_cond_wait_until(Handle, native_mutex, end_time);
+ bool raw_ret = g_cond_wait_until(Handle, mutex == null ? IntPtr.Zero : mutex.Handle, end_time);
bool ret = raw_ret;
- mutex = GLib.Mutex.New (native_mutex);
- Marshal.FreeHGlobal (native_mutex);
return ret;
}
Modified: glib/Makefile.am
===================================================================
@@ -21,6 +21,8 @@ references =
# TODO: auto-generate at compile time the following classes:
# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
+# (to do that, we need to fill missing pieces in glib's
+# gobject-introspection metadata upstream)
sources = \
Argv.cs \
Modified: glib/Mutex.cs
===================================================================
@@ -9,66 +9,35 @@ namespace GLib {
using System.Runtime.InteropServices;
#region Autogenerated code
- [StructLayout(LayoutKind.Explicit)]
- public partial struct Mutex : IEquatable<Mutex> {
-
- [FieldOffset(0)]
- private IntPtr _p;
- [FieldOffset(0)]
- [MarshalAs (UnmanagedType.ByValArray, SizeConst=2)]
- public uint[] I;
-
- public static GLib.Mutex Zero = new GLib.Mutex ();
-
- public static GLib.Mutex New(IntPtr raw) {
- if (raw == IntPtr.Zero)
- return GLib.Mutex.Zero;
- return (GLib.Mutex) Marshal.PtrToStructure (raw, typeof (GLib.Mutex));
- }
+ public partial class Mutex : GLib.Opaque {
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_clear(IntPtr raw);
public void Clear() {
- IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
- System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
- g_mutex_clear(this_as_native);
- ReadNative (this_as_native, ref this);
- System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ g_mutex_clear(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_init(IntPtr raw);
public void Init() {
- IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
- System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
- g_mutex_init(this_as_native);
- ReadNative (this_as_native, ref this);
- System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ g_mutex_init(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_lock(IntPtr raw);
public void Lock() {
- IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
- System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
- g_mutex_lock(this_as_native);
- ReadNative (this_as_native, ref this);
- System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ g_mutex_lock(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_mutex_trylock(IntPtr raw);
public bool Trylock() {
- IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
- System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
- bool raw_ret = g_mutex_trylock(this_as_native);
+ bool raw_ret = g_mutex_trylock(Handle);
bool ret = raw_ret;
- ReadNative (this_as_native, ref this);
- System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
return ret;
}
@@ -76,32 +45,10 @@ public partial struct Mutex : IEquatable<Mutex> {
static extern void g_mutex_unlock(IntPtr raw);
public void Unlock() {
- IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
- System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
- g_mutex_unlock(this_as_native);
- ReadNative (this_as_native, ref this);
- System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
- }
-
- static void ReadNative (IntPtr native, ref GLib.Mutex target)
- {
- target = New (native);
+ g_mutex_unlock(Handle);
}
- public bool Equals (Mutex other)
- {
- return true && _p.Equals (other._p) && I.Equals (other.I);
- }
-
- public override bool Equals (object other)
- {
- return other is Mutex && Equals ((Mutex) other);
- }
-
- public override int GetHashCode ()
- {
- return this.GetType().FullName.GetHashCode() ^ _p.GetHashCode () ^ I.GetHashCode ();
- }
+ public Mutex(IntPtr raw) : base(raw) {}
#endregion
}
Commit: e031a4ff18996d8a108bd98081cd175a8f966f38
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 16:51:38 GMT
URL: https://github.com/mono/gtk-sharp/commit/e031a4ff18996d8a108bd98081cd175a8f966f38
generator: auto escape string constants
Changed paths:
M generator/Constant.cs
Modified: generator/Constant.cs
===================================================================
@@ -58,7 +58,13 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
{
StreamWriter sw = gen_info.Writer;
- sw.WriteLine ("{0}public const {1} {2} = {3}{4}{3};", indent, ConstType, Name, IsString ? "\"": String.Empty, value);
+ sw.WriteLine ("{0}public const {1} {2} = {3}{4}{5};",
+ indent,
+ ConstType,
+ Name,
+ IsString ? "@\"": String.Empty,
+ value,
+ IsString ? "\"": String.Empty);
}
}
}
Commit: 139479036b64fade6c1f680119373b3ccc3b9c00
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 16:53:31 GMT
URL: https://github.com/mono/gtk-sharp/commit/139479036b64fade6c1f680119373b3ccc3b9c00
generator: do not generate methods without (C)Name
Changed paths:
M generator/Method.cs
Modified: generator/Method.cs
===================================================================
@@ -84,6 +84,11 @@ public override bool Validate (LogWriter log)
if (!retval.Validate (log) || !base.Validate (log))
return false;
+ if (Name == String.Empty || CName == String.Empty) {
+ log.Warn ("Method has no name or cname.");
+ return false;
+ }
+
Parameters parms = Parameters;
is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName);
is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && HasSetterName);
Commit: 6ab620d6891a90004d9be96235ef741ed6ab1f58
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 17:41:21 GMT
URL: https://github.com/mono/gtk-sharp/commit/6ab620d6891a90004d9be96235ef741ed6ab1f58
generator,glib: added GPollFD and GSource types
GSource type was already there (but was not mapped by
the generator yet) so then the autogenerated methods
have been added manually inside the class after the
custom methods.
Other Source-related class are also generated and added
(but not mapped in the SymbolTable) to glib.
Changed paths:
M generator/SymbolTable.cs
M glib/Makefile.am
M glib/Source.cs
Added paths:
A glib/GLibSharp.SourceDummyMarshalNative.cs
A glib/GLibSharp.SourceFuncNative.cs
A glib/PollFD.cs
A glib/SourceCallbackFuncs.cs
A glib/SourceDummyMarshal.cs
A glib/SourceFunc.cs
A glib/SourceFuncs.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -132,6 +132,8 @@ public SymbolTable ()
AddType (new ManualGen ("GCond", "GLib.Cond"));
AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
AddType (new ManualGen ("GDate", "GLib.Date"));
+ AddType (new ManualGen ("GSource", "GLib.Source"));
+ AddType (new SimpleGen ("GPollFD", "GLib.PollFD", "GLib.PollFD.Zero"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
Added: glib/GLibSharp.SourceDummyMarshalNative.cs
===================================================================
@@ -0,0 +1,92 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLibSharp {
+
+ using System;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+ internal delegate void SourceDummyMarshalNative();
+
+ internal class SourceDummyMarshalInvoker {
+
+ SourceDummyMarshalNative native_cb;
+ IntPtr __data;
+ GLib.DestroyNotify __notify;
+
+ ~SourceDummyMarshalInvoker ()
+ {
+ if (__notify == null)
+ return;
+ __notify (__data);
+ }
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data) : this (native_cb, data, null) {}
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data, GLib.DestroyNotify notify)
+ {
+ this.native_cb = native_cb;
+ __data = data;
+ __notify = notify;
+ }
+
+ internal GLib.SourceDummyMarshal Handler {
+ get {
+ return new GLib.SourceDummyMarshal(InvokeNative);
+ }
+ }
+
+ void InvokeNative ()
+ {
+ native_cb ();
+ }
+ }
+
+ internal class SourceDummyMarshalWrapper {
+
+ public void NativeCallback ()
+ {
+ try {
+ managed ();
+ if (release_on_call)
+ gch.Free ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ }
+ }
+
+ bool release_on_call = false;
+ GCHandle gch;
+
+ public void PersistUntilCalled ()
+ {
+ release_on_call = true;
+ gch = GCHandle.Alloc (this);
+ }
+
+ internal SourceDummyMarshalNative NativeDelegate;
+ GLib.SourceDummyMarshal managed;
+
+ public SourceDummyMarshalWrapper (GLib.SourceDummyMarshal managed)
+ {
+ this.managed = managed;
+ if (managed != null)
+ NativeDelegate = new SourceDummyMarshalNative (NativeCallback);
+ }
+
+ public static GLib.SourceDummyMarshal GetManagedDelegate (SourceDummyMarshalNative native)
+ {
+ if (native == null)
+ return null;
+ SourceDummyMarshalWrapper wrapper = (SourceDummyMarshalWrapper) native.Target;
+ if (wrapper == null)
+ return null;
+ return wrapper.managed;
+ }
+ }
+#endregion
+}
Added: glib/GLibSharp.SourceFuncNative.cs
===================================================================
@@ -0,0 +1,95 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLibSharp {
+
+ using System;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+ internal delegate bool SourceFuncNative(IntPtr user_data);
+
+ internal class SourceFuncInvoker {
+
+ SourceFuncNative native_cb;
+ IntPtr __data;
+ GLib.DestroyNotify __notify;
+
+ ~SourceFuncInvoker ()
+ {
+ if (__notify == null)
+ return;
+ __notify (__data);
+ }
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data, GLib.DestroyNotify notify)
+ {
+ this.native_cb = native_cb;
+ __data = data;
+ __notify = notify;
+ }
+
+ internal GLib.SourceFunc Handler {
+ get {
+ return new GLib.SourceFunc(InvokeNative);
+ }
+ }
+
+ bool InvokeNative (IntPtr user_data)
+ {
+ bool __result = native_cb (__data);
+ return __result;
+ }
+ }
+
+ internal class SourceFuncWrapper {
+
+ public bool NativeCallback (IntPtr user_data)
+ {
+ try {
+ bool __ret = managed (user_data);
+ if (release_on_call)
+ gch.Free ();
+ return __ret;
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ return false;
+ }
+ }
+
+ bool release_on_call = false;
+ GCHandle gch;
+
+ public void PersistUntilCalled ()
+ {
+ release_on_call = true;
+ gch = GCHandle.Alloc (this);
+ }
+
+ internal SourceFuncNative NativeDelegate;
+ GLib.SourceFunc managed;
+
+ public SourceFuncWrapper (GLib.SourceFunc managed)
+ {
+ this.managed = managed;
+ if (managed != null)
+ NativeDelegate = new SourceFuncNative (NativeCallback);
+ }
+
+ public static GLib.SourceFunc GetManagedDelegate (SourceFuncNative native)
+ {
+ if (native == null)
+ return null;
+ SourceFuncWrapper wrapper = (SourceFuncWrapper) native.Target;
+ if (wrapper == null)
+ return null;
+ return wrapper.managed;
+ }
+ }
+#endregion
+}
Modified: glib/Makefile.am
===================================================================
@@ -20,7 +20,9 @@ POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
references =
# TODO: auto-generate at compile time the following classes:
-# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
+# Cond, Date, DateTime, Mutex, PollFD, RecMutex, (half)Source,
+# SourceCallbackFuncs, SourceDummyMarshal, SourceFunc,
+# SourceFuncNative, SourceFuncs, TimeVal, TimeZone
# (to do that, we need to fill missing pieces in glib's
# gobject-introspection metadata upstream)
@@ -62,6 +64,7 @@ sources = \
ObjectManager.cs \
Opaque.cs \
ParamSpec.cs \
+ PollFD.cs \
Priority.cs \
PropertyAttribute.cs \
PtrArray.cs \
@@ -72,6 +75,12 @@ sources = \
SignalClosure.cs \
SList.cs \
Source.cs \
+ SourceFunc.cs \
+ SourceFuncs.cs \
+ SourceDummyMarshal.cs \
+ GLibSharp.SourceFuncNative.cs \
+ GLibSharp.SourceDummyMarshalNative.cs \
+ SourceCallbackFuncs.cs \
Spawn.cs \
Thread.cs \
Timeout.cs \
Added: glib/PollFD.cs
===================================================================
@@ -0,0 +1,67 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct PollFD : IEquatable<PollFD> {
+
+ public int Fd;
+ public ushort Events;
+ public ushort Revents;
+
+ public static GLib.PollFD Zero = new GLib.PollFD ();
+
+ public static GLib.PollFD New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.PollFD.Zero;
+ return (GLib.PollFD) Marshal.PtrToStructure (raw, typeof (GLib.PollFD));
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_pollfd_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_pollfd_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ public bool Equals (PollFD other)
+ {
+ return true && Fd.Equals (other.Fd) && Events.Equals (other.Events) && Revents.Equals (other.Revents);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is PollFD && Equals ((PollFD) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ Fd.GetHashCode () ^ Events.GetHashCode () ^ Revents.GetHashCode ();
+ }
+
+ public static explicit operator GLib.Value (GLib.PollFD boxed)
+ {
+ GLib.Value val = GLib.Value.Empty;
+ val.Init (GLib.PollFD.GType);
+ val.Val = boxed;
+ return val;
+ }
+
+ public static explicit operator GLib.PollFD (GLib.Value val)
+ {
+ return (GLib.PollFD) val.Val;
+ }
+#endregion
+ }
+}
Modified: glib/Source.cs
===================================================================
@@ -43,10 +43,11 @@ internal void Remove ()
proxy_handler = null;
}
}
-
- public class Source {
+
+ public partial class Source : GLib.Opaque {
+
private Source () {}
-
+
internal static Hashtable source_handlers = new Hashtable ();
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
@@ -58,5 +59,343 @@ public static bool Remove (uint tag)
source_handlers.Remove (tag);
return g_source_remove (tag);
}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_context(IntPtr raw);
+
+ public GLib.MainContext Context {
+ get {
+ IntPtr raw_ret = g_source_get_context(Handle);
+ GLib.MainContext ret = raw_ret == IntPtr.Zero ? null : new MainContext (raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_source_get_priority(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_priority(IntPtr raw, int priority);
+
+ public int Priority {
+ get {
+ int raw_ret = g_source_get_priority(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_priority(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_name(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_name(IntPtr raw, IntPtr name);
+
+ public string Name {
+ get {
+ IntPtr raw_ret = g_source_get_name(Handle);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+ set {
+ IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
+ g_source_set_name(Handle, native_value);
+ GLib.Marshaller.Free (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_source_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_add_child_source(IntPtr raw, IntPtr child_source);
+
+ public void AddChildSource(GLib.Source child_source) {
+ g_source_add_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_add_poll(IntPtr raw, IntPtr fd);
+
+ public void AddPoll(GLib.PollFD fd) {
+ IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
+ g_source_add_poll(Handle, native_fd);
+ fd = GLib.PollFD.New (native_fd);
+ Marshal.FreeHGlobal (native_fd);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_source_attach(IntPtr raw, IntPtr context);
+
+ public uint Attach(GLib.MainContext context) {
+ uint raw_ret = g_source_attach(Handle, context == null ? IntPtr.Zero : context.Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+
+ uint Attach() {
+ return Attach (null);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_get_can_recurse(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_can_recurse(IntPtr raw, bool can_recurse);
+
+ public bool CanRecurse {
+ get {
+ bool raw_ret = g_source_get_can_recurse(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_can_recurse(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_get_current_time(IntPtr raw, IntPtr timeval);
+
+ [Obsolete]
+ public void GetCurrentTime(GLib.TimeVal timeval) {
+ IntPtr native_timeval = GLib.Marshaller.StructureToPtrAlloc (timeval);
+ g_source_get_current_time(Handle, native_timeval);
+ timeval = GLib.TimeVal.New (native_timeval);
+ Marshal.FreeHGlobal (native_timeval);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_source_get_id(IntPtr raw);
+
+ public uint Id {
+ get {
+ uint raw_ret = g_source_get_id(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_source_get_ready_time(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_ready_time(IntPtr raw, long ready_time);
+
+ public long ReadyTime {
+ get {
+ long raw_ret = g_source_get_ready_time(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_ready_time(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_source_get_time(IntPtr raw);
+
+ public long Time {
+ get {
+ long raw_ret = g_source_get_time(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_is_destroyed(IntPtr raw);
+
+ public bool IsDestroyed {
+ get {
+ bool raw_ret = g_source_is_destroyed(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_modify_unix_fd(IntPtr raw, IntPtr tag, int new_events);
+
+ public void ModifyUnixFd(IntPtr tag, GLib.IOCondition new_events) {
+ g_source_modify_unix_fd(Handle, tag, (int) new_events);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_source_query_unix_fd(IntPtr raw, IntPtr tag);
+
+ public GLib.IOCondition QueryUnixFd(IntPtr tag) {
+ int raw_ret = g_source_query_unix_fd(Handle, tag);
+ GLib.IOCondition ret = (GLib.IOCondition) raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_child_source(IntPtr raw, IntPtr child_source);
+
+ public void RemoveChildSource(GLib.Source child_source) {
+ g_source_remove_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_poll(IntPtr raw, IntPtr fd);
+
+ public void RemovePoll(GLib.PollFD fd) {
+ IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
+ g_source_remove_poll(Handle, native_fd);
+ fd = GLib.PollFD.New (native_fd);
+ Marshal.FreeHGlobal (native_fd);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_unix_fd(IntPtr raw, IntPtr tag);
+
+ public void RemoveUnixFd(IntPtr tag) {
+ g_source_remove_unix_fd(Handle, tag);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_callback_indirect(IntPtr raw, IntPtr callback_data, IntPtr callback_funcs);
+
+ public void SetCallbackIndirect(IntPtr callback_data, GLib.SourceCallbackFuncs callback_funcs) {
+ IntPtr native_callback_funcs = GLib.Marshaller.StructureToPtrAlloc (callback_funcs);
+ g_source_set_callback_indirect(Handle, callback_data, native_callback_funcs);
+ callback_funcs = GLib.SourceCallbackFuncs.New (native_callback_funcs);
+ Marshal.FreeHGlobal (native_callback_funcs);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_funcs(IntPtr raw, IntPtr value);
+
+ public GLib.SourceFuncs Funcs {
+ set {
+ IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
+ g_source_set_funcs(Handle, native_value);
+ value = GLib.SourceFuncs.New (native_value);
+ Marshal.FreeHGlobal (native_value);
+ }
+ }
+
+ /*
+ * commented out because there is already a custom implementation for Remove
+ *
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove(uint tag);
+
+ public static bool Remove(uint tag) {
+ bool raw_ret = g_source_remove(tag);
+ bool ret = raw_ret;
+ return ret;
+ }
+ */
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove_by_funcs_user_data(IntPtr funcs, IntPtr user_data);
+
+ public static bool RemoveByFuncsUserData(GLib.SourceFuncs funcs, IntPtr user_data) {
+ IntPtr native_funcs = GLib.Marshaller.StructureToPtrAlloc (funcs);
+ bool raw_ret = g_source_remove_by_funcs_user_data(native_funcs, user_data);
+ bool ret = raw_ret;
+ funcs = GLib.SourceFuncs.New (native_funcs);
+ Marshal.FreeHGlobal (native_funcs);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove_by_user_data(IntPtr user_data);
+
+ public static bool RemoveByUserData(IntPtr user_data) {
+ bool raw_ret = g_source_remove_by_user_data(user_data);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_name_by_id(uint tag, IntPtr name);
+
+ public static void SetNameById(uint tag, string name) {
+ IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
+ g_source_set_name_by_id(tag, native_name);
+ GLib.Marshaller.Free (native_name);
+ }
+
+ public Source(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_new(IntPtr source_funcs, uint struct_size);
+
+ public Source (GLib.SourceFuncs source_funcs, uint struct_size)
+ {
+ IntPtr native_source_funcs = GLib.Marshaller.StructureToPtrAlloc (source_funcs);
+ Raw = g_source_new(native_source_funcs, struct_size);
+ source_funcs = GLib.SourceFuncs.New (native_source_funcs);
+ Marshal.FreeHGlobal (native_source_funcs);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_source_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_source_unref (raw);
+ Owned = false;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_destroy(IntPtr raw);
+
+ protected override void Free (IntPtr raw)
+ {
+ g_source_destroy (raw);
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_source_destroy (handle);
+ return false;
+ }
+ }
+
+ ~Source ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
}
-}
+
+}
\ No newline at end of file
Added: glib/SourceCallbackFuncs.cs
===================================================================
@@ -0,0 +1,44 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct SourceCallbackFuncs : IEquatable<SourceCallbackFuncs> {
+
+
+ public static GLib.SourceCallbackFuncs Zero = new GLib.SourceCallbackFuncs ();
+
+ public static GLib.SourceCallbackFuncs New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.SourceCallbackFuncs.Zero;
+ return (GLib.SourceCallbackFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceCallbackFuncs));
+ }
+
+ public bool Equals (SourceCallbackFuncs other)
+ {
+ return true;
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is SourceCallbackFuncs && Equals ((SourceCallbackFuncs) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Added: glib/SourceDummyMarshal.cs
===================================================================
@@ -0,0 +1,10 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+
+ public delegate void SourceDummyMarshal();
+
+}
Added: glib/SourceFunc.cs
===================================================================
@@ -0,0 +1,10 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+
+ public delegate bool SourceFunc(IntPtr user_data);
+
+}
Added: glib/SourceFuncs.cs
===================================================================
@@ -0,0 +1,46 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct SourceFuncs : IEquatable<SourceFuncs> {
+
+ internal GLibSharp.SourceFuncNative closure_callback;
+ internal GLibSharp.SourceDummyMarshalNative closure_marshal;
+
+ public static GLib.SourceFuncs Zero = new GLib.SourceFuncs ();
+
+ public static GLib.SourceFuncs New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.SourceFuncs.Zero;
+ return (GLib.SourceFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceFuncs));
+ }
+
+ public bool Equals (SourceFuncs other)
+ {
+ return true && closure_callback.Equals (other.closure_callback) && closure_callback.Equals (other.closure_callback);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is SourceFuncs && Equals ((SourceFuncs) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ closure_marshal.GetHashCode () ^ closure_marshal.GetHashCode ();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Commit: b868b80deef1a510bce2fe47ef5220ad2d9a8a14
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 17:44:50 GMT
URL: https://github.com/mono/gtk-sharp/commit/b868b80deef1a510bce2fe47ef5220ad2d9a8a14
glib,generator: map MainContext type and expose members
This is needed to reference a MainContext from
external bindings, which need to create a
MainContext using a Handle
Changed paths:
M generator/SymbolTable.cs
M glib/MainContext.cs
Modified: generator/SymbolTable.cs
===================================================================
@@ -133,6 +133,7 @@ public SymbolTable ()
AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
AddType (new ManualGen ("GDate", "GLib.Date"));
AddType (new ManualGen ("GSource", "GLib.Source"));
+ AddType (new ManualGen ("GMainContext", "GLib.MainContext"));
AddType (new SimpleGen ("GPollFD", "GLib.PollFD", "GLib.PollFD.Zero"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
Modified: glib/MainContext.cs
===================================================================
@@ -38,13 +38,13 @@ public MainContext ()
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_ref (IntPtr raw);
- internal MainContext (IntPtr raw)
+ public MainContext (IntPtr raw)
{
handle = raw;
g_main_context_ref (handle);
}
- internal IntPtr Handle {
+ public IntPtr Handle {
get {
return handle;
}
Commit: f958b2247b44de88d5574da7121833e348bc9286
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 17:49:28 GMT
URL: https://github.com/mono/gtk-sharp/commit/f958b2247b44de88d5574da7121833e348bc9286
generator: include api files from XML
Changed paths:
M generator/Parser.cs
Modified: generator/Parser.cs
===================================================================
@@ -111,6 +111,10 @@ public IGeneratable[] Parse (string filename, string schema_file)
continue;
switch (child.Name) {
+ case "include":
+ IGeneratable[] curr_gens = Parse (elem.GetAttribute ("xml"));
+ SymbolTable.Table.AddTypes (curr_gens);
+ break;
case "namespace":
gens.AddRange (ParseNamespace (elem));
break;
Commit: 5eea00f70500e120e4c8028d61bff3d347092c68
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:00:14 GMT
URL: https://github.com/mono/gtk-sharp/commit/5eea00f70500e120e4c8028d61bff3d347092c68
generator: new --gapidir flag to search for xml files
Changed paths:
M generator/CodeGenerator.cs
M generator/Parser.cs
Modified: generator/CodeGenerator.cs
===================================================================
@@ -34,6 +34,7 @@ public static int Main (string[] args)
bool show_help = false;
string dir = "";
string assembly_name = "";
+ string gapidir = "";
string glue_filename = "";
string glue_includes = "";
string gluelib_name = "";
@@ -54,6 +55,8 @@ public static int Main (string[] args)
(string v) => { dir = v; } },
{ "assembly-name=", "Name of the assembly for which the code is generated.",
(string v) => { assembly_name = v; } },
+ { "gapidir=", "GAPI xml data folder.",
+ (string v) => { gapidir = v; } },
{ "glue-filename=", "Filename for the generated C glue code.",
(string v) => { glue_filename = v; } },
{ "glue-includes=", "Content of #include directive to add in the generated C glue code.",
@@ -101,12 +104,12 @@ public static int Main (string[] args)
Parser p = new Parser ();
foreach (string include in includes) {
- IGeneratable[] curr_gens = p.Parse (include, schema_name);
+ IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
table.AddTypes (curr_gens);
}
foreach (string filename in filenames) {
- IGeneratable[] curr_gens = p.Parse (filename, schema_name);
+ IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
table.AddTypes (curr_gens);
gens.AddRange (curr_gens);
}
Modified: generator/Parser.cs
===================================================================
@@ -78,6 +78,11 @@ public IGeneratable[] Parse (string filename)
public IGeneratable[] Parse (string filename, string schema_file)
{
+ return Parse (filename, schema_file, String.Empty);
+ }
+
+ public IGeneratable[] Parse (string filename, string schema_file, string gapidir)
+ {
XmlDocument doc = Load (filename, schema_file);
if (doc == null)
return null;
@@ -112,7 +117,18 @@ public IGeneratable[] Parse (string filename, string schema_file)
switch (child.Name) {
case "include":
- IGeneratable[] curr_gens = Parse (elem.GetAttribute ("xml"));
+ string xmlpath;
+
+ if (File.Exists (Path.Combine (gapidir, elem.GetAttribute ("xml"))))
+ xmlpath = Path.Combine (gapidir, elem.GetAttribute ("xml"));
+ else if (File.Exists (elem.GetAttribute ("xml")))
+ xmlpath = elem.GetAttribute ("xml");
+ else {
+ Console.WriteLine ("Parser: Could not find include " + elem.GetAttribute ("xml"));
+ break;
+ }
+
+ IGeneratable[] curr_gens = Parse (xmlpath);
SymbolTable.Table.AddTypes (curr_gens);
break;
case "namespace":
Commit: c3f7b8e32b4e0d687a601829f39416407c341212
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:05:03 GMT
URL: https://github.com/mono/gtk-sharp/commit/c3f7b8e32b4e0d687a601829f39416407c341212
generator: fixed optional array parameters
Changed paths:
M generator/Signature.cs
Modified: generator/Signature.cs
===================================================================
@@ -149,7 +149,9 @@ public string CallWithoutOptionals ()
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
if (p.IsOptional && p.PassAs == String.Empty) {
- if (p.Generatable is StructGen || p.Generatable is BoxedGen)
+ if (p.IsArray)
+ result [i++] += "null";
+ else if (p.Generatable is StructGen || p.Generatable is BoxedGen)
result [i++] += p.CSType + ".Zero";
else if (p.CSType == "System.IntPtr")
result [i++] += "System.IntPtr.Zero";
Commit: 5f271e04fa71875805694cfeb0cdc6d2137956d0
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:28:38 GMT
URL: https://github.com/mono/gtk-sharp/commit/5f271e04fa71875805694cfeb0cdc6d2137956d0
generator: ignore private structs completely
Don't spam the log with these messages for private structs
(and don't count this in the statistics), as there are too
many. These kind of types are just empty structs marked as
hidden and private.
Changed paths:
M generator/FieldBase.cs
Modified: generator/FieldBase.cs
===================================================================
@@ -32,6 +32,8 @@ public virtual bool Validate (LogWriter log)
{
log.Member = Name;
if (!Ignored && !Hidden && CSType == "") {
+ if (Name == "Priv")
+ return false;
log.Warn ("field has unknown type: " + CType);
Statistics.ThrottledCount++;
return false;
Commit: 2152f4626eb0e30a6132cd50fdd58d00bed9cdea
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:30:14 GMT
URL: https://github.com/mono/gtk-sharp/commit/2152f4626eb0e30a6132cd50fdd58d00bed9cdea
generator: use default value for optional generation
Changed paths:
M generator/Signature.cs
Modified: generator/Signature.cs
===================================================================
@@ -149,14 +149,7 @@ public string CallWithoutOptionals ()
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
if (p.IsOptional && p.PassAs == String.Empty) {
- if (p.IsArray)
- result [i++] += "null";
- else if (p.Generatable is StructGen || p.Generatable is BoxedGen)
- result [i++] += p.CSType + ".Zero";
- else if (p.CSType == "System.IntPtr")
- result [i++] += "System.IntPtr.Zero";
- else
- result [i++] += "null";
+ result [i++] += p.Generatable.DefaultValue;
}
else
result [i++] += p.Name;
Commit: 53312d5fc075af4189b65d12238c5f142415ccb4
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:35:02 GMT
URL: https://github.com/mono/gtk-sharp/commit/53312d5fc075af4189b65d12238c5f142415ccb4
generator: fixed optional array parameters
Changed paths:
M generator/Signature.cs
M generator/StructField.cs
M glib/Marshaller.cs
Modified: generator/Signature.cs
===================================================================
@@ -149,7 +149,10 @@ public string CallWithoutOptionals ()
result [i] = p.PassAs != "" ? p.PassAs + " " : "";
if (p.IsOptional && p.PassAs == String.Empty) {
- result [i++] += p.Generatable.DefaultValue;
+ if (p.IsArray)
+ result [i++] += "null";
+ else
+ result [i++] += p.Generatable.DefaultValue;
}
else
result [i++] += p.Name;
Modified: generator/StructField.cs
===================================================================
@@ -58,6 +58,10 @@ public class StructField : FieldBase {
}
}
+ bool IsNullTermArray {
+ get { return elem.GetAttributeAsBoolean ("null_term_array"); }
+ }
+
public new string CSType {
get {
string type = base.CSType;
@@ -143,9 +147,21 @@ public override void Generate (GenerationInfo gen_info, string indent)
string wrapped_name = SymbolTable.Table.MangleName (CName);
IGeneratable gen = table [CType];
- if (IsArray) {
+ if (IsArray && !IsNullTermArray) {
sw.WriteLine (indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, StudlyName);
+ } else if (IsArray && IsNullTermArray) {
+ sw.WriteLine (indent + "private {0} {1};", "IntPtr", StudlyName+ "Ptr");
+ if ((Readable || Writable) && Access == "public") {
+ sw.WriteLine (indent + "public {0} {1} {{", CSType, StudlyName);
+ if (Readable)
+ sw.WriteLine (indent + "\tget {{ return GLib.Marshaller.StructArrayFromNullTerminatedIntPtr<{0}> ({1}); }}",
+ base.CSType, StudlyName + "Ptr");
+ if (Writable)
+ sw.WriteLine (indent + "\tset {{ {0} = GLib.Marshaller.StructArrayToNullTerminatedStructArrayIntPtr<{1}> (value); }}",
+ StudlyName + "Ptr", base.CSType);
+ sw.WriteLine (indent + "}");
+ }
} else if (IsBitfield) {
base.Generate (gen_info, indent);
} else if (gen is IAccessor) {
Modified: glib/Marshaller.cs
===================================================================
@@ -463,6 +463,39 @@ public static Array ListToArray (ListBase list, System.Type type)
return result;
}
+
+ public static T[] StructArrayFromNullTerminatedIntPtr<T> (IntPtr array)
+ {
+ var res = new List<T> ();
+ IntPtr current = array;
+ T currentStruct = default(T);
+
+ while (current != IntPtr.Zero) {
+ Marshal.PtrToStructure (current, currentStruct);
+ res.Add (currentStruct);
+ current = (IntPtr) ((long)current + Marshal.SizeOf (typeof (T)));
+ }
+
+ return res.ToArray ();
+ }
+
+ public static IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray)
+ {
+ int intPtrSize = Marshal.SizeOf (typeof (IntPtr));
+ IntPtr mem = Marshal.AllocHGlobal ((InputArray.Length + 1) * intPtrSize);
+
+ for (int i = 0; i < InputArray.Length; i++) {
+ IntPtr structPtr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (T)));
+ Marshal.StructureToPtr (InputArray[i], structPtr, false);
+ // jump to next pointer
+ Marshal.WriteIntPtr (mem, structPtr);
+ mem = (IntPtr) ((long)mem + intPtrSize);
+ }
+ // null terminate
+ Marshal.WriteIntPtr (mem, IntPtr.Zero);
+
+ return mem;
+ }
}
}
Commit: 31e2c02e94fc009518eed4454764ed73da4373a2
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:37:18 GMT
URL: https://github.com/mono/gtk-sharp/commit/31e2c02e94fc009518eed4454764ed73da4373a2
generator: public accessor in method overloads
Changed paths:
M generator/Method.cs
Modified: generator/Method.cs
===================================================================
@@ -215,7 +215,7 @@ public void GenerateImport (StreamWriter sw)
public void GenerateOverloads (StreamWriter sw)
{
sw.WriteLine ();
- sw.WriteLine ("\t\t" + retval.CSType + " " + Name + "(" + (Signature != null ? Signature.WithoutOptional () : "") + ") {");
+ sw.WriteLine ("\t\tpublic " + retval.CSType + " " + Name + "(" + (Signature != null ? Signature.WithoutOptional () : "") + ") {");
sw.WriteLine ("\t\t\t{0}{1} ({2});", !retval.IsVoid ? "return " : String.Empty, Name, Signature.CallWithoutOptionals ());
sw.WriteLine ("\t\t}");
}
Commit: 0f79e9af06edd1d20de2c7dafc2c61e98369fc9d
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:42:03 GMT
URL: https://github.com/mono/gtk-sharp/commit/0f79e9af06edd1d20de2c7dafc2c61e98369fc9d
generator: fixicate NativeStructGen
Made NativeStructGen more consistent with the way Gdk.Event
and Pango.Attribute are handled. Also increases performance
because reflection is not needed anymore to marshal these
kind of structs.
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -10,13 +10,9 @@ namespace GtkSharp.Generation
public class NativeStructGen : HandleBase
{
IList<StructField> fields = new List<StructField> ();
- bool need_read_native = false;
- string native_struct_name;
public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
{
- native_struct_name = Name + "Impl";
-
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
@@ -82,18 +78,15 @@ public override void Generate (GenerationInfo gen_info)
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
string access = IsInternal ? "internal" : "public";
- sw.WriteLine ("\t" + access + " partial class {0} : IEquatable<{0}> {{", Name);
+ sw.WriteLine ("\t" + access + " partial class {0} : IEquatable<{0}>{1} {{", Name, Parent == null ? ", GLib.IWrapper" : "");
sw.WriteLine ();
- need_read_native = false;
GenNativeStruct (gen_info);
- GenUpdate (gen_info);
+ GenNativeAccessor (gen_info);
GenFields (gen_info);
sw.WriteLine ();
GenCtors (gen_info);
GenMethods (gen_info, null, this);
- if (need_read_native)
- GenUpdate (gen_info);
GenEqualsAndHash (sw);
if (!need_close)
@@ -112,7 +105,7 @@ private void GenNativeStruct (GenerationInfo gen_info)
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\t[StructLayout(LayoutKind.Sequential)]");
- sw.WriteLine ("\t\tprivate struct {0} {{", native_struct_name);
+ sw.WriteLine ("\t\tprivate struct NativeStruct {");
foreach (StructField field in fields) {
field.Generate (gen_info, "\t\t\t");
}
@@ -120,14 +113,12 @@ private void GenNativeStruct (GenerationInfo gen_info)
sw.WriteLine ();
}
- private void GenUpdate (GenerationInfo gen_info)
+ private void GenNativeAccessor (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
- sw.WriteLine ("\t\tprivate void Update ()", QualifiedName);
- sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\tif (Handle != IntPtr.Zero)");
- sw.WriteLine ("\t\t\t\tthis.managed_struct = ({0})Marshal.PtrToStructure (this.Handle, typeof ({0}));", native_struct_name);
+ sw.WriteLine ("\t\tNativeStruct Native {{", QualifiedName);
+ sw.WriteLine ("\t\t\tget { return (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct)); }");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
@@ -136,11 +127,15 @@ protected override void GenCtors (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
- sw.WriteLine ("\t\tpublic {0} (IntPtr raw)", Name);
- sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\tthis.Handle = raw;");
- sw.WriteLine ("\t\t}");
- sw.WriteLine ();
+ if (Parent == null) {
+ sw.WriteLine ("\t\tpublic {0} (IntPtr raw)", Name);
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\tthis.Handle = raw;");
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ }
+ else
+ sw.Write ("public {0} (IntPtr raw) : base (raw) {}", Name);
base.GenCtors (gen_info);
}
@@ -149,19 +144,20 @@ protected new void GenFields (GenerationInfo gen_info)
{
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\tprivate IntPtr Raw;");
+
sw.WriteLine ("\t\tpublic IntPtr Handle {");
sw.WriteLine ("\t\t\tget { return Raw; }");
- sw.WriteLine ("\t\t\tset { Raw = value; Update ();}");
+ sw.WriteLine ("\t\t\tset { Raw = value; }");
sw.WriteLine ("\t\t}");
- sw.WriteLine ("\t\tprivate {0} managed_struct;", native_struct_name);
sw.WriteLine ();
+
foreach (StructField field in fields) {
if (!field.Visible)
continue;
sw.WriteLine ("\t\tpublic {0} {1} {{", SymbolTable.Table.GetCSType (field.CType), field.StudlyName);
- sw.WriteLine ("\t\t\tget {{ Update(); return {0}.{1}; }}", "managed_struct", field.StudlyName);
+ sw.WriteLine ("\t\t\tget {{ NativeStruct native = Native; return native.{0}; }}", field.StudlyName);
if (!(SymbolTable.Table [field.CType] is CallbackGen))
- sw.WriteLine ("\t\t\tset {{ Update(); {0}.{1} = value; Marshal.StructureToPtr({0}, this.Handle, false); }}" , "managed_struct", field.StudlyName);
+ sw.WriteLine ("\t\t\tset {{ NativeStruct native = Native; native.{0} = value; Marshal.StructureToPtr (native, this.Handle, false); }}", field.StudlyName);
sw.WriteLine ("\t\t}");
}
}
@@ -226,7 +222,7 @@ protected void GenEqualsAndHash (StreamWriter sw)
public override void Prepare (StreamWriter sw, string indent)
{
- sw.WriteLine (indent + "Update ();");
+ sw.WriteLine (indent + "NativeStruct native = Native;");
}
}
}
Commit: edc339baf51653f7599bb499475dc75a4616806f
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:43:12 GMT
URL: https://github.com/mono/gtk-sharp/commit/edc339baf51653f7599bb499475dc75a4616806f
generator: redundant method in NativeStructGen
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -219,11 +219,6 @@ protected void GenEqualsAndHash (StreamWriter sw)
sw.WriteLine ();
}
-
- public override void Prepare (StreamWriter sw, string indent)
- {
- sw.WriteLine (indent + "NativeStruct native = Native;");
- }
}
}
Commit: c5b04cb70e3d8279a4fb622e6b6c38138c2a393e
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:43:44 GMT
URL: https://github.com/mono/gtk-sharp/commit/c5b04cb70e3d8279a4fb622e6b6c38138c2a393e
generator: fixed native struct parent
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -78,7 +78,7 @@ public override void Generate (GenerationInfo gen_info)
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
string access = IsInternal ? "internal" : "public";
- sw.WriteLine ("\t" + access + " partial class {0} : IEquatable<{0}>{1} {{", Name, Parent == null ? ", GLib.IWrapper" : "");
+ sw.WriteLine ("\t" + access + " partial class {0} : {1} IEquatable<{0}> {{", Name, Parent == null ? "GLib.IWrapper," : (Parent.QualifiedName + ","));
sw.WriteLine ();
GenNativeStruct (gen_info);
@@ -135,7 +135,7 @@ protected override void GenCtors (GenerationInfo gen_info)
sw.WriteLine ();
}
else
- sw.Write ("public {0} (IntPtr raw) : base (raw) {}", Name);
+ sw.Write ("public {0} (IntPtr raw) : base (raw) {{}}", Name);
base.GenCtors (gen_info);
}
Commit: f6fef3a402bbfe82d11aadb12edf621d38f842c1
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:44:28 GMT
URL: https://github.com/mono/gtk-sharp/commit/f6fef3a402bbfe82d11aadb12edf621d38f842c1
generator: fixed NativeStructGen's formatting
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -132,10 +132,11 @@ protected override void GenCtors (GenerationInfo gen_info)
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tthis.Handle = raw;");
sw.WriteLine ("\t\t}");
- sw.WriteLine ();
}
else
- sw.Write ("public {0} (IntPtr raw) : base (raw) {{}}", Name);
+ sw.Write ("\t\tpublic {0} (IntPtr raw) : base (raw) {{}}", Name);
+
+ sw.WriteLine ();
base.GenCtors (gen_info);
}
Commit: 21c9c9ff8c46b933de67287f645e21d639865f95
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:47:26 GMT
URL: https://github.com/mono/gtk-sharp/commit/21c9c9ff8c46b933de67287f645e21d639865f95
generator: remove bitfields from Equals/GetHashCode
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -176,32 +176,18 @@ protected void GenEqualsAndHash (StreamWriter sw)
equals.Append ("true");
foreach (StructField field in fields) {
- if (field.IsPadding || !field.Visible)
+ if (field.IsPadding || !field.Visible || field.IsBitfield)
continue;
- if (field.IsBitfield) {
- if (need_field) {
- equals.Append (" && _bitfield");
- equals.Append (bitfields);
- equals.Append (".Equals (other._bitfield");
- equals.Append (bitfields);
- equals.Append (")");
- hashcode.Append (" ^ ");
- hashcode.Append ("_bitfield");
- hashcode.Append (bitfields++);
- hashcode.Append (".GetHashCode ()");
- need_field = false;
- }
- } else {
- need_field = true;
- equals.Append (" && ");
- equals.Append (field.EqualityName);
- equals.Append (".Equals (other.");
- equals.Append (field.EqualityName);
- equals.Append (")");
- hashcode.Append (" ^ ");
- hashcode.Append (field.EqualityName);
- hashcode.Append (".GetHashCode ()");
- }
+
+ need_field = true;
+ equals.Append (" && ");
+ equals.Append (field.EqualityName);
+ equals.Append (".Equals (other.");
+ equals.Append (field.EqualityName);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append (field.EqualityName);
+ hashcode.Append (".GetHashCode ()");
}
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
sw.WriteLine ("\t\t}");
Commit: 50f07d17adb7dc6fd5e48410ae8d2b32599113f8
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:48:24 GMT
URL: https://github.com/mono/gtk-sharp/commit/50f07d17adb7dc6fd5e48410ae8d2b32599113f8
generator: removed redundant allocation
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -156,7 +156,7 @@ protected new void GenFields (GenerationInfo gen_info)
if (!field.Visible)
continue;
sw.WriteLine ("\t\tpublic {0} {1} {{", SymbolTable.Table.GetCSType (field.CType), field.StudlyName);
- sw.WriteLine ("\t\t\tget {{ NativeStruct native = Native; return native.{0}; }}", field.StudlyName);
+ sw.WriteLine ("\t\t\tget {{ return Native.{0}; }}", field.StudlyName);
if (!(SymbolTable.Table [field.CType] is CallbackGen))
sw.WriteLine ("\t\t\tset {{ NativeStruct native = Native; native.{0} = value; Marshal.StructureToPtr (native, this.Handle, false); }}", field.StudlyName);
sw.WriteLine ("\t\t}");
Commit: 587f0f56e76567ba58c18909fc72f8aa4748c52f
Author: Stephan Sundermann <[email protected]> (xDarkice)
Committer: Andrés G. Aragoneses <[email protected]> (knocte)
Date: 2013-10-09 18:49:09 GMT
URL: https://github.com/mono/gtk-sharp/commit/587f0f56e76567ba58c18909fc72f8aa4748c52f
generator: NativeStructGen needs to be partial
Changed paths:
M generator/NativeStructGen.cs
Modified: generator/NativeStructGen.cs
===================================================================
@@ -105,7 +105,7 @@ private void GenNativeStruct (GenerationInfo gen_info)
StreamWriter sw = gen_info.Writer;
sw.WriteLine ("\t\t[StructLayout(LayoutKind.Sequential)]");
- sw.WriteLine ("\t\tprivate struct NativeStruct {");
+ sw.WriteLine ("\t\tprivate partial struct NativeStruct {");
foreach (StructField field in fields) {
field.Generate (gen_info, "\t\t\t");
}
Commit: 90e834327e83d5ede9e64d9bb7c5c9099cfda67c
Author: Bertrand Lorentz <[email protected]> (bl8)
Date: 2013-10-10 13:03:35 GMT
URL: https://github.com/mono/gtk-sharp/commit/90e834327e83d5ede9e64d9bb7c5c9099cfda67c
Merge pull request #71 from knocte/bindinator
generator and glibsharp changes from bindinator's GSoC work
Changed paths:
M generator/CallbackGen.cs
M generator/ClassBase.cs
M generator/ClassGen.cs
M generator/CodeGenerator.cs
M generator/FieldBase.cs
M generator/Makefile.am
M generator/Method.cs
M generator/MethodBody.cs
M generator/ObjectField.cs
M generator/ObjectGen.cs
M generator/OpaqueGen.cs
M generator/Parameter.cs
M generator/Parameters.cs
M generator/Parser.cs
M generator/ReturnValue.cs
M generator/Signature.cs
M generator/StructBase.cs
M generator/StructField.cs
M generator/SymbolTable.cs
M generator/generator.csproj
M glib/MainContext.cs
M glib/Makefile.am
M glib/Marshaller.cs
M glib/Source.cs
M glib/Value.cs
M glib/glib.csproj
M parser/gapi-fixup.cs
Added paths:
A generator/Constant.cs
A generator/NativeStructGen.cs
A generator/UnionGen.cs
A glib/Cond.cs
A glib/Date.cs
A glib/DateTime.cs
A glib/GLibSharp.SourceDummyMarshalNative.cs
A glib/GLibSharp.SourceFuncNative.cs
A glib/Mutex.cs
A glib/PollFD.cs
A glib/RecMutex.cs
A glib/SourceCallbackFuncs.cs
A glib/SourceDummyMarshal.cs
A glib/SourceFunc.cs
A glib/SourceFuncs.cs
A glib/TimeVal.cs
A glib/TimeZone.cs
Modified: generator/CallbackGen.cs
===================================================================
@@ -56,6 +56,8 @@ public override bool Validate ()
if (!String.IsNullOrEmpty (retval.CountParameterName))
retval.CountParameter = parms.GetCountParameter (retval.CountParameterName);
+ if (retval.CountParameterIndex >= 0)
+ retval.CountParameter = parms[retval.CountParameterIndex];
return valid;
}
@@ -68,6 +70,14 @@ public override bool Validate ()
}
}
+ public string WrapperName {
+ get {
+ if (!valid)
+ return String.Empty;
+ return NS + "Sharp." + Name + "Wrapper";
+ }
+ }
+
public override string MarshalType {
get {
if (valid)
Modified: generator/ClassBase.cs
===================================================================
@@ -34,6 +34,7 @@ public abstract class ClassBase : GenBase {
private IDictionary<string, Property> props = new Dictionary<string, Property> ();
private IDictionary<string, ObjectField> fields = new Dictionary<string, ObjectField> ();
private IDictionary<string, Method> methods = new Dictionary<string, Method> ();
+ private IDictionary<string, Constant> constants = new Dictionary<string, Constant>();
protected IList<string> interfaces = new List<string>();
protected IList<string> managed_interfaces = new List<string>();
protected IList<Ctor> ctors = new List<Ctor>();
@@ -108,6 +109,11 @@ public abstract class ClassBase : GenBase {
ctors.Add (new Ctor (member, this));
break;
+ case "constant":
+ name = member.GetAttribute ("name");
+ constants.Add (name, new Constant (member));
+ break;
+
default:
break;
}
@@ -156,6 +162,14 @@ public override bool Validate ()
methods.Remove (method.Name);
invalids.Clear ();
+ foreach (Constant con in constants.Values) {
+ if (!con.Validate (log))
+ invalids.Add (con);
+ }
+ foreach (Constant con in invalids)
+ constants.Remove (con.Name);
+ invalids.Clear ();
+
foreach (Ctor ctor in ctors) {
if (!ctor.Validate (log))
invalids.Add (ctor);
@@ -199,6 +213,7 @@ protected virtual bool IsNodeNameHandled (string name)
case "implements":
case "constructor":
case "disabledefaultconstructor":
+ case "constant":
return true;
default:
@@ -221,6 +236,12 @@ protected void GenFields (GenerationInfo gen_info)
field.Generate (gen_info, "\t\t");
}
+ protected void GenConstants (GenerationInfo gen_info)
+ {
+ foreach (Constant con in constants.Values)
+ con.Generate (gen_info, "\t\t");
+ }
+
private void ParseImplements (XmlElement member)
{
foreach (XmlNode node in member.ChildNodes) {
Modified: generator/ClassGen.cs
===================================================================
@@ -77,9 +77,10 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine (" {");
sw.WriteLine ();
+ GenConstants (gen_info);
GenProperties (gen_info, null);
GenMethods (gen_info, null, null);
-
+
sw.WriteLine ("#endregion");
sw.WriteLine ("\t}");
Modified: generator/CodeGenerator.cs
===================================================================
@@ -34,6 +34,7 @@ public static int Main (string[] args)
bool show_help = false;
string dir = "";
string assembly_name = "";
+ string gapidir = "";
string glue_filename = "";
string glue_includes = "";
string gluelib_name = "";
@@ -54,6 +55,8 @@ public static int Main (string[] args)
(string v) => { dir = v; } },
{ "assembly-name=", "Name of the assembly for which the code is generated.",
(string v) => { assembly_name = v; } },
+ { "gapidir=", "GAPI xml data folder.",
+ (string v) => { gapidir = v; } },
{ "glue-filename=", "Filename for the generated C glue code.",
(string v) => { glue_filename = v; } },
{ "glue-includes=", "Content of #include directive to add in the generated C glue code.",
@@ -101,12 +104,12 @@ public static int Main (string[] args)
Parser p = new Parser ();
foreach (string include in includes) {
- IGeneratable[] curr_gens = p.Parse (include, schema_name);
+ IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
table.AddTypes (curr_gens);
}
foreach (string filename in filenames) {
- IGeneratable[] curr_gens = p.Parse (filename, schema_name);
+ IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
table.AddTypes (curr_gens);
gens.AddRange (curr_gens);
}
Added: generator/Constant.cs
===================================================================
@@ -0,0 +1,70 @@
+using System;
+using System.Xml;
+using System.IO;
+
+namespace GtkSharp.Generation
+{
+ public class Constant
+ {
+ private readonly XmlElement elem;
+ private readonly string name;
+ private readonly string value;
+ private readonly string ctype;
+
+ public Constant (XmlElement elem)
+ {
+ this.elem = elem;
+ this.name = elem.GetAttribute ("name");
+ this.value = elem.GetAttribute ("value");
+ this.ctype = elem.GetAttribute ("ctype");
+ }
+
+ public string Name {
+ get {
+ return this.name;
+ }
+ }
+ public string ConstType {
+ get {
+ if (IsString)
+ return "string";
+ // gir registers all integer values as gint even for numbers which do not fit into a gint
+ // if the number is too big for an int, try to fit it into a long
+ if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length < 20 && long.Parse (value) > Int32.MaxValue)
+ return "long";
+ return SymbolTable.Table.GetMarshalType (ctype);
+ }
+ }
+
+ public bool IsString {
+ get {
+ return (SymbolTable.Table.GetCSType (ctype) == "string");
+ }
+ }
+
+ public virtual bool Validate (LogWriter log)
+ {
+ if (ConstType == String.Empty) {
+ log.Warn ("{0} type is missing or wrong", Name);
+ return false;
+ }
+ if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length >= 20) {
+ return false;
+ }
+ return true;
+ }
+
+ public virtual void Generate (GenerationInfo gen_info, string indent)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("{0}public const {1} {2} = {3}{4}{5};",
+ indent,
+ ConstType,
+ Name,
+ IsString ? "@\"": String.Empty,
+ value,
+ IsString ? "\"": String.Empty);
+ }
+ }
+}
Modified: generator/FieldBase.cs
===================================================================
@@ -32,6 +32,8 @@ public virtual bool Validate (LogWriter log)
{
log.Member = Name;
if (!Ignored && !Hidden && CSType == "") {
+ if (Name == "Priv")
+ return false;
log.Warn ("field has unknown type: " + CType);
Statistics.ThrottledCount++;
return false;
@@ -40,21 +42,25 @@ public virtual bool Validate (LogWriter log)
return true;
}
- protected virtual bool Readable {
+ internal virtual bool Readable {
get {
- return elem.GetAttribute ("readable") != "false";
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
+ return elem.GetAttribute ("readable") != "false";
+ return elem.HasAttribute ("readable") && elem.GetAttributeAsBoolean ("readable");
}
}
- protected virtual bool Writable {
+ internal virtual bool Writable {
get {
- return elem.GetAttribute ("writeable") != "false";
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
+ return elem.GetAttribute ("writeable") != "false";
+ return elem.HasAttribute ("writeable") && elem.GetAttributeAsBoolean ("writeable");
}
}
protected abstract string DefaultAccess { get; }
- protected string Access {
+ internal string Access {
get {
return elem.HasAttribute ("access") ? elem.GetAttribute ("access") : DefaultAccess;
}
@@ -152,6 +158,7 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
GenerateImports (gen_info, indent);
SymbolTable table = SymbolTable.Table;
+ IGeneratable gen = table [CType];
StreamWriter sw = gen_info.Writer;
string modifiers = elem.GetAttributeAsBoolean ("new_flag") ? "new " : "";
bool is_struct = table.IsStruct (CType) || table.IsBoxed (CType);
@@ -172,10 +179,12 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Readable && offsetName != null) {
sw.WriteLine (indent + "\tget {");
sw.WriteLine (indent + "\t\tunsafe {");
- if (is_struct) {
- sw.WriteLine (indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\treturn *raw_ptr;");
- } else {
+ if (gen is CallbackGen) {
+ sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t {0} del = ({0})Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof({0}));", table.GetMarshalType (CType));
+ sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(del)") + ";");
+ }
+ else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(*raw_ptr)") + ";");
}
@@ -183,7 +192,6 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
sw.WriteLine (indent + "\t}");
}
- IGeneratable gen = table [CType];
string to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative ("value") : gen.CallByName ("value");
if (Setter != null) {
@@ -199,10 +207,12 @@ public virtual void Generate (GenerationInfo gen_info, string indent)
} else if (Writable && offsetName != null) {
sw.WriteLine (indent + "\tset {");
sw.WriteLine (indent + "\t\tunsafe {");
- if (is_struct) {
- sw.WriteLine (indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
- sw.WriteLine (indent + "\t\t\t*raw_ptr = value;");
- } else {
+ if (gen is CallbackGen) {
+ sw.WriteLine (indent + "\t\t\t{0} wrapper = new {0} (value);", ((CallbackGen)gen).WrapperName);
+ sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
+ sw.WriteLine (indent + "\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate (wrapper.NativeDelegate);");
+ }
+ else {
sw.WriteLine (indent + "\t\t\t" + table.GetMarshalType (CType) + "* raw_ptr = (" + table.GetMarshalType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");");
sw.WriteLine (indent + "\t\t\t*raw_ptr = " + to_native + ";");
}
Modified: generator/Makefile.am
===================================================================
@@ -19,6 +19,7 @@ sources = \
CodeGenerator.cs \
ConstFilenameGen.cs \
ConstStringGen.cs \
+ Constant.cs \
Ctor.cs \
DefaultSignalHandler.cs \
EnumGen.cs \
@@ -42,6 +43,7 @@ sources = \
MethodBase.cs \
MethodBody.cs \
Method.cs \
+ NativeStructGen.cs \
ObjectField.cs \
ObjectBase.cs \
ObjectGen.cs \
@@ -63,6 +65,7 @@ sources = \
StructField.cs \
StructGen.cs \
SymbolTable.cs \
+ UnionGen.cs \
VirtualMethod.cs \
VMSignature.cs \
XmlElementExtensions.cs
Modified: generator/Method.cs
===================================================================
@@ -84,6 +84,11 @@ public override bool Validate (LogWriter log)
if (!retval.Validate (log) || !base.Validate (log))
return false;
+ if (Name == String.Empty || CName == String.Empty) {
+ log.Warn ("Method has no name or cname.");
+ return false;
+ }
+
Parameters parms = Parameters;
is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName);
is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && HasSetterName);
@@ -207,6 +212,14 @@ public void GenerateImport (StreamWriter sw)
}
}
+ public void GenerateOverloads (StreamWriter sw)
+ {
+ sw.WriteLine ();
+ sw.WriteLine ("\t\tpublic " + retval.CSType + " " + Name + "(" + (Signature != null ? Signature.WithoutOptional () : "") + ") {");
+ sw.WriteLine ("\t\t\t{0}{1} ({2});", !retval.IsVoid ? "return " : String.Empty, Name, Signature.CallWithoutOptionals ());
+ sw.WriteLine ("\t\t}");
+ }
+
public void Generate (GenerationInfo gen_info, ClassBase implementor)
{
Method comp = null;
@@ -266,6 +279,9 @@ public void Generate (GenerationInfo gen_info, ClassBase implementor)
}
else
gen_info.Writer.WriteLine();
+
+ if (Parameters.HasOptional && !(is_get || is_set))
+ GenerateOverloads (gen_info.Writer);
gen_info.Writer.WriteLine();
Modified: generator/MethodBody.cs
===================================================================
@@ -101,17 +101,26 @@ public void Initialize (GenerationInfo gen_info, bool is_get, bool is_set, strin
if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen;
string wrapper = cbgen.GenWrapper(gen_info);
+
+ int closure = i + 1;
+ if (p.Closure >= 0)
+ closure = p.Closure;
+
+ int destroyNotify = i + 2;
+ if (p.DestroyNotify >= 0)
+ destroyNotify = p.DestroyNotify;
+
switch (p.Scope) {
case "notified":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
- sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [i + 1].Name);
- sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [i + 2].CSType, parameters [i + 2].Name);
+ sw.WriteLine (indent + "\t\t\tIntPtr {0};", parameters [closure].Name);
+ sw.WriteLine (indent + "\t\t\t{0} {1};", parameters [destroyNotify].CSType, parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\tif ({0} == null) {{", name);
- sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [i + 1].Name);
- sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [i + 2].Name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = IntPtr.Zero;", parameters [closure].Name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = null;", parameters [destroyNotify].Name);
sw.WriteLine (indent + "\t\t\t} else {");
- sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [i + 1].Name, name);
- sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [i + 2].Name, parameters [i + 2].CSType);
+ sw.WriteLine (indent + "\t\t\t\t{0} = (IntPtr) GCHandle.Alloc ({1}_wrapper);", parameters [closure].Name, name);
+ sw.WriteLine (indent + "\t\t\t\t{0} = GLib.DestroyHelper.NotifyHandler;", parameters [destroyNotify].Name, parameters [destroyNotify].CSType);
sw.WriteLine (indent + "\t\t\t}");
break;
Added: generator/NativeStructGen.cs
===================================================================
@@ -0,0 +1,211 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Xml;
+
+namespace GtkSharp.Generation
+{
+ public class NativeStructGen : HandleBase
+ {
+ IList<StructField> fields = new List<StructField> ();
+
+ public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
+ {
+ foreach (XmlNode node in elem.ChildNodes) {
+
+ if (!(node is XmlElement)) continue;
+ XmlElement member = (XmlElement) node;
+
+ switch (node.Name) {
+ case "field":
+ fields.Add (new StructField (member, this));
+ break;
+
+ default:
+ if (!IsNodeNameHandled (node.Name))
+ Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
+ break;
+ }
+ }
+ }
+
+ public override string MarshalType {
+ get {
+ return "IntPtr";
+ }
+ }
+
+ public override string AssignToName {
+ get { return "Handle"; }
+ }
+
+ public override string CallByName ()
+ {
+ return "Handle";
+ }
+
+ public override string CallByName (string var)
+ {
+ return String.Format ("{0} == null ? IntPtr.Zero : {0}.{1}", var, "Handle");
+ }
+
+ public override string FromNative (string var, bool owned)
+ {
+ return "new " + QualifiedName + "( " + var + " )";
+ }
+
+ public override void Generate (GenerationInfo gen_info)
+ {
+ bool need_close = false;
+ if (gen_info.Writer == null) {
+ gen_info.Writer = gen_info.OpenStream (Name);
+ need_close = true;
+ }
+
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("namespace " + NS + " {");
+ sw.WriteLine ();
+ sw.WriteLine ("\tusing System;");
+ sw.WriteLine ("\tusing System.Collections;");
+ sw.WriteLine ("\tusing System.Collections.Generic;");
+ sw.WriteLine ("\tusing System.Runtime.InteropServices;");
+ sw.WriteLine ();
+
+ sw.WriteLine ("#region Autogenerated code");
+ if (IsDeprecated)
+ sw.WriteLine ("\t[Obsolete]");
+ string access = IsInternal ? "internal" : "public";
+ sw.WriteLine ("\t" + access + " partial class {0} : {1} IEquatable<{0}> {{", Name, Parent == null ? "GLib.IWrapper," : (Parent.QualifiedName + ","));
+ sw.WriteLine ();
+
+ GenNativeStruct (gen_info);
+ GenNativeAccessor (gen_info);
+ GenFields (gen_info);
+ sw.WriteLine ();
+ GenCtors (gen_info);
+ GenMethods (gen_info, null, this);
+ GenEqualsAndHash (sw);
+
+ if (!need_close)
+ return;
+
+ sw.WriteLine ("#endregion");
+
+ sw.WriteLine ("\t}");
+ sw.WriteLine ("}");
+ sw.Close ();
+ gen_info.Writer = null;
+ }
+
+ private void GenNativeStruct (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("\t\t[StructLayout(LayoutKind.Sequential)]");
+ sw.WriteLine ("\t\tprivate partial struct NativeStruct {");
+ foreach (StructField field in fields) {
+ field.Generate (gen_info, "\t\t\t");
+ }
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ }
+
+ private void GenNativeAccessor (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ sw.WriteLine ("\t\tNativeStruct Native {{", QualifiedName);
+ sw.WriteLine ("\t\t\tget { return (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct)); }");
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ }
+
+ protected override void GenCtors (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+
+ if (Parent == null) {
+ sw.WriteLine ("\t\tpublic {0} (IntPtr raw)", Name);
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\tthis.Handle = raw;");
+ sw.WriteLine ("\t\t}");
+ }
+ else
+ sw.Write ("\t\tpublic {0} (IntPtr raw) : base (raw) {{}}", Name);
+
+ sw.WriteLine ();
+
+ base.GenCtors (gen_info);
+ }
+
+ protected new void GenFields (GenerationInfo gen_info)
+ {
+ StreamWriter sw = gen_info.Writer;
+ sw.WriteLine ("\t\tprivate IntPtr Raw;");
+
+ sw.WriteLine ("\t\tpublic IntPtr Handle {");
+ sw.WriteLine ("\t\t\tget { return Raw; }");
+ sw.WriteLine ("\t\t\tset { Raw = value; }");
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+
+ foreach (StructField field in fields) {
+ if (!field.Visible)
+ continue;
+ sw.WriteLine ("\t\tpublic {0} {1} {{", SymbolTable.Table.GetCSType (field.CType), field.StudlyName);
+ sw.WriteLine ("\t\t\tget {{ return Native.{0}; }}", field.StudlyName);
+ if (!(SymbolTable.Table [field.CType] is CallbackGen))
+ sw.WriteLine ("\t\t\tset {{ NativeStruct native = Native; native.{0} = value; Marshal.StructureToPtr (native, this.Handle, false); }}", field.StudlyName);
+ sw.WriteLine ("\t\t}");
+ }
+ }
+
+ protected void GenEqualsAndHash (StreamWriter sw)
+ {
+ int bitfields = 0;
+ bool need_field = true;
+ StringBuilder hashcode = new StringBuilder ();
+ StringBuilder equals = new StringBuilder ();
+
+ sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
+ sw.WriteLine ("\t\t{");
+ hashcode.Append ("this.GetType().FullName.GetHashCode()");
+ equals.Append ("true");
+
+ foreach (StructField field in fields) {
+ if (field.IsPadding || !field.Visible || field.IsBitfield)
+ continue;
+
+ need_field = true;
+ equals.Append (" && ");
+ equals.Append (field.EqualityName);
+ equals.Append (".Equals (other.");
+ equals.Append (field.EqualityName);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append (field.EqualityName);
+ hashcode.Append (".GetHashCode ()");
+ }
+ sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ sw.WriteLine ("\t\tpublic override bool Equals (object other)");
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+ if (Elem.GetAttribute ("nohash") == "true")
+ return;
+ sw.WriteLine ("\t\tpublic override int GetHashCode ()");
+ sw.WriteLine ("\t\t{");
+ sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
+ sw.WriteLine ("\t\t}");
+ sw.WriteLine ();
+
+ }
+ }
+}
+
Modified: generator/ObjectField.cs
===================================================================
@@ -32,7 +32,7 @@ public ObjectField (XmlElement elem, ClassBase container_type) : base (elem, con
ctype = "const-" + CType;
}
- protected override bool Writable {
+ internal override bool Writable {
get {
return elem.GetAttributeAsBoolean ("writeable");
}
Modified: generator/ObjectGen.cs
===================================================================
@@ -195,9 +195,10 @@ public override void Generate (GenerationInfo gen_info)
GenSignals (gen_info, null);
}
+ GenConstants (gen_info);
GenClassMembers (gen_info, cs_parent);
GenMethods (gen_info, null, null);
-
+
if (interfaces.Count != 0) {
var all_methods = new Dictionary<string, Method> ();
foreach (Method m in Methods.Values) {
@@ -260,8 +261,9 @@ protected override void GenCtors (GenerationInfo gen_info)
{
if (!Elem.HasAttribute("parent"))
return;
+ string defaultconstructoraccess = Elem.HasAttribute ("defaultconstructoraccess") ? Elem.GetAttribute ("defaultconstructoraccess") : "public";
- gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
+ gen_info.Writer.WriteLine ("\t\t"+ defaultconstructoraccess + " " + Name + " (IntPtr raw) : base(raw) {}");
if (ctors.Count == 0 && !DisableVoidCtor) {
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(IntPtr.Zero)");
Modified: generator/OpaqueGen.cs
===================================================================
@@ -79,7 +79,8 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine (" {");
sw.WriteLine ();
-
+
+ GenConstants (gen_info);
GenFields (gen_info);
GenMethods (gen_info, null, null);
GenCtors (gen_info);
Modified: generator/Parameter.cs
===================================================================
@@ -90,6 +90,12 @@ public Parameter (XmlElement e)
}
}
+ internal bool IsOptional {
+ get {
+ return elem.GetAttributeAsBoolean ("allow-none");
+ }
+ }
+
bool is_count;
bool is_count_set;
public bool IsCount {
@@ -236,6 +242,30 @@ public Parameter (XmlElement e)
}
}
+ int closure = -1;
+ public int Closure {
+ get {
+ if(closure == -1 && elem.HasAttribute ("closure"))
+ closure = int.Parse(elem.GetAttribute ("closure"));
+ return closure;
+ }
+ set {
+ closure = value;
+ }
+ }
+
+ int destroynotify = -1;
+ public int DestroyNotify {
+ get {
+ if (destroynotify == -1 && elem.HasAttribute ("destroy"))
+ destroynotify = int.Parse (elem.GetAttribute ("destroy"));
+ return destroynotify;
+ }
+ set {
+ destroynotify = value;
+ }
+ }
+
public virtual string[] Prepare {
get {
IGeneratable gen = Generatable;
Modified: generator/Parameters.cs
===================================================================
@@ -49,6 +49,18 @@ public Parameters (XmlElement elem, bool first_is_instance)
get { return param_list.Count; }
}
+ // gapi assumes GError** parameters to be error parameters in version 1 and 2
+ private bool throws = false;
+ public bool Throws {
+ get {
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) <= 2)
+ return true;
+ if (!throws && elem.HasAttribute ("throws"))
+ throws = elem.GetAttributeAsBoolean ("throws");
+ return throws;
+ }
+ }
+
public int VisibleCount {
get {
int visible = 0;
@@ -76,20 +88,28 @@ public bool IsHidden (Parameter p)
if (p.IsCount)
return true;
- if (p.CType == "GError**")
+ if (p.CType == "GError**" && Throws)
return true;
if (HasCB || HideData) {
- if (p.IsUserData && (idx == Count - 1))
- return true;
- if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
- return true;
- if (p.IsUserData && idx > 0 &&
- this [idx - 1].Generatable is CallbackGen)
- return true;
- if (p.IsDestroyNotify && (idx == Count - 1) &&
- this [idx - 1].IsUserData)
- return true;
+
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) >= 3) {
+ foreach (Parameter param in param_list) {
+ if (param.Closure == idx)
+ return true;
+ if (param.DestroyNotify == idx)
+ return true;
+ }
+ } else {
+ if (p.IsUserData && (idx == Count - 1))
+ return true;
+ if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
+ return true;
+ if (p.IsUserData && idx > 0 && this [idx - 1].Generatable is CallbackGen)
+ return true;
+ if (p.IsDestroyNotify && (idx == Count - 1) && this [idx - 1].IsUserData)
+ return true;
+ }
}
return false;
@@ -122,6 +142,11 @@ public bool IsHidden (Parameter p)
set { is_static = value; }
}
+ bool has_optional;
+ internal bool HasOptional {
+ get { return has_optional;}
+ }
+
public Parameter GetCountParameter (string param_name)
{
foreach (Parameter p in this)
@@ -178,6 +203,9 @@ public bool Validate (LogWriter log)
return false;
}
+ if (p.IsOptional && p.PassAs == String.Empty)
+ has_optional = true;
+
IGeneratable gen = p.Generatable;
if (p.IsArray) {
@@ -204,7 +232,7 @@ public bool Validate (LogWriter log)
}
}
}
- } else if (p.CType == "GError**")
+ } else if (p.CType == "GError**" && Throws)
p = new ErrorParameter (parm);
else if (gen is StructBase || gen is ByRefGen) {
p = new StructParameter (parm);
@@ -214,7 +242,8 @@ public bool Validate (LogWriter log)
param_list.Add (p);
}
- if (has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
+ if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) < 3 &&
+ has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
this [Count - 3].Scope = "notified";
valid = true;
Modified: generator/Parser.cs
===================================================================
@@ -29,7 +29,7 @@ namespace GtkSharp.Generation {
using System.Xml.Schema;
public class Parser {
- const int curr_parser_version = 2;
+ const int curr_parser_version = 3;
private XmlDocument Load (string filename, string schema_file)
{
@@ -78,6 +78,11 @@ public IGeneratable[] Parse (string filename)
public IGeneratable[] Parse (string filename, string schema_file)
{
+ return Parse (filename, schema_file, String.Empty);
+ }
+
+ public IGeneratable[] Parse (string filename, string schema_file, string gapidir)
+ {
XmlDocument doc = Load (filename, schema_file);
if (doc == null)
return null;
@@ -111,6 +116,21 @@ public IGeneratable[] Parse (string filename, string schema_file)
continue;
switch (child.Name) {
+ case "include":
+ string xmlpath;
+
+ if (File.Exists (Path.Combine (gapidir, elem.GetAttribute ("xml"))))
+ xmlpath = Path.Combine (gapidir, elem.GetAttribute ("xml"));
+ else if (File.Exists (elem.GetAttribute ("xml")))
+ xmlpath = elem.GetAttribute ("xml");
+ else {
+ Console.WriteLine ("Parser: Could not find include " + elem.GetAttribute ("xml"));
+ break;
+ }
+
+ IGeneratable[] curr_gens = Parse (xmlpath);
+ SymbolTable.Table.AddTypes (curr_gens);
+ break;
case "namespace":
gens.AddRange (ParseNamespace (elem));
break;
@@ -140,6 +160,7 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
continue;
bool is_opaque = elem.GetAttributeAsBoolean ("opaque");
+ bool is_native_struct = elem.GetAttributeAsBoolean ("native");
switch (def.Name) {
case "alias":
@@ -171,9 +192,14 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
case "class":
result.Add (new ClassGen (ns, elem));
break;
+ case "union":
+ result.Add (new UnionGen (ns, elem));
+ break;
case "struct":
if (is_opaque) {
result.Add (new OpaqueGen (ns, elem));
+ } else if (is_native_struct) {
+ result.Add (new NativeStructGen (ns, elem));
} else {
result.Add (new StructGen (ns, elem));
}
@@ -187,6 +213,12 @@ private IList<IGeneratable> ParseNamespace (XmlElement ns)
return result;
}
+ internal static int GetVersion (XmlElement document_element)
+ {
+ XmlElement root = document_element;
+ return root.HasAttribute ("parser_version") ? int.Parse (root.GetAttribute ("parser_version")) : 1;
+ }
+
private IGeneratable ParseSymbol (XmlElement symbol)
{
string type = symbol.GetAttribute ("type");
Modified: generator/ReturnValue.cs
===================================================================
@@ -32,6 +32,7 @@ public class ReturnValue {
bool elements_owned;
bool owned;
string array_length_param = String.Empty;
+ int array_length_param_index = -1;
string ctype = String.Empty;
string default_value = String.Empty;
string element_ctype = String.Empty;
@@ -43,6 +44,8 @@ public ReturnValue (XmlElement elem)
is_null_term = elem.GetAttributeAsBoolean ("null_term_array");
is_array = elem.GetAttributeAsBoolean ("array") || elem.HasAttribute ("array_length_param");
array_length_param = elem.GetAttribute ("array_length_param");
+ if (elem.HasAttribute ("array_length_param_length"))
+ array_length_param_index = int.Parse (elem.GetAttribute ("array_length_param_index"));
elements_owned = elem.GetAttributeAsBoolean ("elements_owned");
owned = elem.GetAttributeAsBoolean ("owned");
ctype = elem.GetAttribute("type");
@@ -60,6 +63,10 @@ public ReturnValue (XmlElement elem)
get { return array_length_param; }
}
+ public int CountParameterIndex {
+ get { return array_length_param_index; }
+ }
+
public string CType {
get {
return ctype;
@@ -126,7 +133,9 @@ public ReturnValue (XmlElement elem)
get {
if (IGen == null)
return String.Empty;
- return IGen.MarshalType + (is_array || is_null_term ? "[]" : String.Empty);
+ if (is_array || is_null_term)
+ return "IntPtr";
+ return IGen.MarshalType;
}
}
@@ -160,7 +169,7 @@ public string ToNative (string var)
string args = ", typeof (" + ElementType + "), " + (owned ? "true" : "false") + ", " + (elements_owned ? "true" : "false");
var = "new " + IGen.QualifiedName + "(" + var + args + ")";
} else if (is_null_term)
- return String.Format ("GLib.Marshaller.StringArrayToNullTermPointer ({0})", var);
+ return String.Format ("GLib.Marshaller.StringArrayToNullTermStrvPointer ({0})", var);
else if (is_array)
return String.Format ("GLib.Marshaller.ArrayToArrayPtr ({0})", var);
Modified: generator/Signature.cs
===================================================================
@@ -118,6 +118,48 @@ public override string ToString ()
return String.Join (", ", result);
}
}
+
+ public string WithoutOptional ()
+ {
+ if (parms.Count == 0)
+ return String.Empty;
+
+ var result = new string [parms.Count];
+ int i = 0;
+
+ foreach (Parameter p in parms) {
+ if (p.IsOptional && p.PassAs == String.Empty)
+ continue;
+ result [i] = p.PassAs != String.Empty ? p.PassAs + " " : String.Empty;
+ result [i++] += p.CSType + " " + p.Name;
+ }
+
+ return String.Join (", ", result, 0, i);
+ }
+
+ public string CallWithoutOptionals ()
+ {
+ if (parms.Count == 0)
+ return String.Empty;
+
+ var result = new string [parms.Count];
+ int i = 0;
+
+ foreach (Parameter p in parms) {
+
+ result [i] = p.PassAs != "" ? p.PassAs + " " : "";
+ if (p.IsOptional && p.PassAs == String.Empty) {
+ if (p.IsArray)
+ result [i++] += "null";
+ else
+ result [i++] += p.Generatable.DefaultValue;
+ }
+ else
+ result [i++] += p.Name;
+ }
+
+ return String.Join (", ", result);
+ }
}
}
Modified: generator/StructBase.cs
===================================================================
@@ -1,8 +1,11 @@
// GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class.
//
-// Author: Mike Kestner <[email protected]>
+// Authors:
+// Mike Kestner <[email protected]>
+// Stephan Sundermann <[email protected]>
//
// Copyright (c) 2001-2003 Mike Kestner
+// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@@ -107,36 +110,53 @@ public string ReleaseNative (string var)
}
}
+ public virtual bool Union {
+ get {
+ return false;
+ }
+ }
+
protected void GenEqualsAndHash (StreamWriter sw)
{
int bitfields = 0;
bool need_field = true;
- StringBuilder sb = new StringBuilder ();
+ StringBuilder hashcode = new StringBuilder ();
+ StringBuilder equals = new StringBuilder ();
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
+ hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
+ equals.Append ("true");
foreach (StructField field in fields) {
+ if (field.IsPadding)
+ continue;
if (field.IsBitfield) {
if (need_field) {
- sw.WriteLine ("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields);
- if (sb.Length > 0)
- sb.Append (" ^ ");
- sb.Append ("_bitfield");
- sb.Append (bitfields++);
- sb.Append (".GetHashCode ()");
+ equals.Append (" && _bitfield");
+ equals.Append (bitfields);
+ equals.Append (".Equals (other._bitfield");
+ equals.Append (bitfields);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append ("_bitfield");
+ hashcode.Append (bitfields++);
+ hashcode.Append (".GetHashCode ()");
need_field = false;
}
} else {
need_field = true;
- sw.WriteLine ("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName);
- if (sb.Length > 0)
- sb.Append (" ^ ");
- sb.Append (field.EqualityName);
- sb.Append (".GetHashCode ()");
+ equals.Append (" && ");
+ equals.Append (field.EqualityName);
+ equals.Append (".Equals (other.");
+ equals.Append (field.EqualityName);
+ equals.Append (")");
+ hashcode.Append (" ^ ");
+ hashcode.Append (field.EqualityName);
+ hashcode.Append (".GetHashCode ()");
}
}
- sw.WriteLine ("\t\t\treturn true;");
+ sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
@@ -148,7 +168,7 @@ protected void GenEqualsAndHash (StreamWriter sw)
return;
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
sw.WriteLine ("\t\t{");
- sw.WriteLine ("\t\t\treturn {0};", sb.ToString ());
+ sw.WriteLine ("\t\t\treturn {0};", hashcode.ToString ());
sw.WriteLine ("\t\t}");
sw.WriteLine ();
@@ -158,12 +178,13 @@ protected new void GenFields (GenerationInfo gen_info)
{
int bitfields = 0;
bool need_field = true;
+ StreamWriter sw = gen_info.Writer;
foreach (StructField field in fields) {
+ if (Union)
+ sw.WriteLine ("\t\t[FieldOffset(0)]");
if (field.IsBitfield) {
if (need_field) {
- StreamWriter sw = gen_info.Writer;
-
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
need_field = false;
}
@@ -207,7 +228,10 @@ public override void Generate (GenerationInfo gen_info)
sw.WriteLine ("#region Autogenerated code");
if (IsDeprecated)
sw.WriteLine ("\t[Obsolete]");
- sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
+ if (Union)
+ sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
+ else
+ sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
string access = IsInternal ? "internal" : "public";
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
sw.WriteLine ();
Modified: generator/StructField.cs
===================================================================
@@ -58,6 +58,10 @@ public class StructField : FieldBase {
}
}
+ bool IsNullTermArray {
+ get { return elem.GetAttributeAsBoolean ("null_term_array"); }
+ }
+
public new string CSType {
get {
string type = base.CSType;
@@ -70,6 +74,13 @@ public class StructField : FieldBase {
}
}
+ bool visible = false;
+ internal bool Visible {
+ get {
+ return visible;
+ }
+ }
+
public string EqualityName {
get {
SymbolTable table = SymbolTable.Table;
@@ -80,7 +91,7 @@ public class StructField : FieldBase {
return StudlyName;
else if (IsBitfield)
return Name;
- else if (IsPointer && (gen is StructGen || gen is BoxedGen))
+ else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen))
return Access != "private" ? wrapped_name : Name;
else if (IsPointer && CSType != "string")
return Name;
@@ -89,7 +100,7 @@ public class StructField : FieldBase {
}
}
- bool IsPadding {
+ public bool IsPadding {
get {
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
}
@@ -127,6 +138,8 @@ public override void Generate (GenerationInfo gen_info, string indent)
if (Hidden)
return;
+ visible = Access != "private";
+
StreamWriter sw = gen_info.Writer;
SymbolTable table = SymbolTable.Table;
@@ -134,9 +147,21 @@ public override void Generate (GenerationInfo gen_info, string indent)
string wrapped_name = SymbolTable.Table.MangleName (CName);
IGeneratable gen = table [CType];
- if (IsArray) {
+ if (IsArray && !IsNullTermArray) {
sw.WriteLine (indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, StudlyName);
+ } else if (IsArray && IsNullTermArray) {
+ sw.WriteLine (indent + "private {0} {1};", "IntPtr", StudlyName+ "Ptr");
+ if ((Readable || Writable) && Access == "public") {
+ sw.WriteLine (indent + "public {0} {1} {{", CSType, StudlyName);
+ if (Readable)
+ sw.WriteLine (indent + "\tget {{ return GLib.Marshaller.StructArrayFromNullTerminatedIntPtr<{0}> ({1}); }}",
+ base.CSType, StudlyName + "Ptr");
+ if (Writable)
+ sw.WriteLine (indent + "\tset {{ {0} = GLib.Marshaller.StructArrayToNullTerminatedStructArrayIntPtr<{1}> (value); }}",
+ StudlyName + "Ptr", base.CSType);
+ sw.WriteLine (indent + "}");
+ }
} else if (IsBitfield) {
base.Generate (gen_info, indent);
} else if (gen is IAccessor) {
@@ -148,7 +173,7 @@ public override void Generate (GenerationInfo gen_info, string indent)
acc.WriteAccessors (sw, indent + "\t", Name);
sw.WriteLine (indent + "}");
}
- } else if (IsPointer && (gen is StructGen || gen is BoxedGen)) {
+ } else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen)) {
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
sw.WriteLine ();
if (Access != "private") {
@@ -158,6 +183,7 @@ public override void Generate (GenerationInfo gen_info, string indent)
}
} else if (IsPointer && CSType != "string") {
// FIXME: probably some fields here which should be visible.
+ visible = false;
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
} else {
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);
Modified: generator/SymbolTable.cs
===================================================================
@@ -69,6 +69,7 @@ public SymbolTable ()
AddType (new SimpleGen ("guint32", "uint", "0"));
AddType (new SimpleGen ("gint64", "long", "0"));
AddType (new SimpleGen ("guint64", "ulong", "0"));
+ AddType (new SimpleGen ("unsigned long long", "ulong", "0"));
AddType (new SimpleGen ("long long", "long", "0"));
AddType (new SimpleGen ("gfloat", "float", "0.0"));
AddType (new SimpleGen ("float", "float", "0.0"));
@@ -126,12 +127,21 @@ public SymbolTable ()
AddType (new ManualGen ("GVariant", "GLib.Variant"));
AddType (new ManualGen ("GVariantType", "GLib.VariantType"));
AddType (new ManualGen ("GValueArray", "GLib.ValueArray"));
+ AddType (new ManualGen ("GMutex", "GLib.Mutex"));
+ AddType (new ManualGen ("GRecMutex", "GLib.RecMutex"));
+ AddType (new ManualGen ("GCond", "GLib.Cond"));
+ AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
+ AddType (new ManualGen ("GDate", "GLib.Date"));
+ AddType (new ManualGen ("GSource", "GLib.Source"));
+ AddType (new ManualGen ("GMainContext", "GLib.MainContext"));
+ AddType (new SimpleGen ("GPollFD", "GLib.PollFD", "GLib.PollFD.Zero"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));
AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})", "GLib.GType.None"));
AddType (new ByRefGen ("GValue", "GLib.Value"));
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null"));
+ AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
// FIXME: These ought to be handled properly.
AddType (new SimpleGen ("GC", "IntPtr", "IntPtr.Zero"));
@@ -289,6 +299,13 @@ public bool IsStruct(string c_type)
return false;
}
+
+ public bool IsUnion (string c_type)
+ {
+ if (this[c_type] is UnionGen)
+ return true;
+ return false;
+ }
public bool IsEnum(string c_type)
{
Added: generator/UnionGen.cs
===================================================================
@@ -0,0 +1,18 @@
+
+using System.Xml;
+
+namespace GtkSharp.Generation
+{
+ public class UnionGen : StructBase {
+
+ public UnionGen (XmlElement ns, XmlElement elem) : base (ns, elem)
+ {
+ }
+
+ public override bool Union {
+ get {
+ return true;
+ }
+ }
+ }
+}
Modified: generator/generator.csproj
===================================================================
@@ -91,6 +91,9 @@
<Compile Include="Parameter.cs" />
<Compile Include="ArrayParameter.cs" />
<Compile Include="Options.cs" />
+ <Compile Include="Constant.cs" />
+ <Compile Include="UnionGen.cs" />
+ <Compile Include="NativeStructGen.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DESIGN" />
@@ -100,4 +103,4 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
Added: glib/Cond.cs
===================================================================
@@ -0,0 +1,62 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class Cond : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_broadcast(IntPtr raw);
+
+ public void Broadcast() {
+ g_cond_broadcast(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_clear(IntPtr raw);
+
+ public void Clear() {
+ g_cond_clear(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_init(IntPtr raw);
+
+ public void Init() {
+ g_cond_init(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_signal(IntPtr raw);
+
+ public void Signal() {
+ g_cond_signal(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
+
+ public void Wait(GLib.Mutex mutex) {
+ g_cond_wait(Handle, mutex == null ? IntPtr.Zero : mutex.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
+
+ public bool WaitUntil(GLib.Mutex mutex, long end_time) {
+ bool raw_ret = g_cond_wait_until(Handle, mutex == null ? IntPtr.Zero : mutex.Handle, end_time);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ public Cond(IntPtr raw) : base(raw) {}
+
+#endregion
+ }
+}
Added: glib/Date.cs
===================================================================
@@ -0,0 +1,478 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class Date : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_date_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_days(IntPtr raw, uint n_days);
+
+ public void AddDays(uint n_days) {
+ g_date_add_days(Handle, n_days);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_months(IntPtr raw, uint n_months);
+
+ public void AddMonths(uint n_months) {
+ g_date_add_months(Handle, n_months);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_add_years(IntPtr raw, uint n_years);
+
+ public void AddYears(uint n_years) {
+ g_date_add_years(Handle, n_years);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_clamp(IntPtr raw, IntPtr min_date, IntPtr max_date);
+
+ public void Clamp(GLib.Date min_date, GLib.Date max_date) {
+ g_date_clamp(Handle, min_date == null ? IntPtr.Zero : min_date.Handle, max_date == null ? IntPtr.Zero : max_date.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_clear(IntPtr raw, uint n_dates);
+
+ public void Clear(uint n_dates) {
+ g_date_clear(Handle, n_dates);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_compare(IntPtr raw, IntPtr rhs);
+
+ public int Compare(GLib.Date rhs) {
+ int raw_ret = g_date_compare(Handle, rhs == null ? IntPtr.Zero : rhs.Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_days_between(IntPtr raw, IntPtr date2);
+
+ public int DaysBetween(GLib.Date date2) {
+ int raw_ret = g_date_days_between(Handle, date2 == null ? IntPtr.Zero : date2.Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_day(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_day(IntPtr raw, byte day);
+
+ public byte Day {
+ get {
+ byte raw_ret = g_date_get_day(Handle);
+ byte ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_day(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_day_of_year(IntPtr raw);
+
+ public uint DayOfYear {
+ get {
+ uint raw_ret = g_date_get_day_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_iso8601_week_of_year(IntPtr raw);
+
+ public uint Iso8601WeekOfYear {
+ get {
+ uint raw_ret = g_date_get_iso8601_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_julian(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_julian(IntPtr raw, uint julian_date);
+
+ public uint Julian {
+ get {
+ uint raw_ret = g_date_get_julian(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_julian(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_monday_week_of_year(IntPtr raw);
+
+ public uint MondayWeekOfYear {
+ get {
+ uint raw_ret = g_date_get_monday_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_get_month(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_month(IntPtr raw, int month);
+
+ public int Month {
+ get {
+ int raw_ret = g_date_get_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_month(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_get_sunday_week_of_year(IntPtr raw);
+
+ public uint SundayWeekOfYear {
+ get {
+ uint raw_ret = g_date_get_sunday_week_of_year(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_get_weekday(IntPtr raw);
+
+ public int Weekday {
+ get {
+ int raw_ret = g_date_get_weekday(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern ushort g_date_get_year(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_year(IntPtr raw, ushort year);
+
+ public ushort Year {
+ get {
+ ushort raw_ret = g_date_get_year(Handle);
+ ushort ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_date_set_year(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_first_of_month(IntPtr raw);
+
+ public bool IsFirstOfMonth {
+ get {
+ bool raw_ret = g_date_is_first_of_month(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_last_of_month(IntPtr raw);
+
+ public bool IsLastOfMonth {
+ get {
+ bool raw_ret = g_date_is_last_of_month(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_order(IntPtr raw, IntPtr date2);
+
+ public void Order(GLib.Date date2) {
+ g_date_order(Handle, date2 == null ? IntPtr.Zero : date2.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_dmy(IntPtr raw, byte day, int month, ushort y);
+
+ public void SetDmy(byte day, int month, ushort y) {
+ g_date_set_dmy(Handle, day, month, y);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_parse(IntPtr raw, IntPtr str);
+
+ public string Parse {
+ set {
+ IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
+ g_date_set_parse(Handle, native_value);
+ GLib.Marshaller.Free (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time(IntPtr raw, int time_);
+
+ [Obsolete]
+ public int Time {
+ set {
+ g_date_set_time(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time_t(IntPtr raw, IntPtr timet);
+
+ public long TimeT {
+ set {
+ g_date_set_time_t(Handle, new IntPtr (value));
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_set_time_val(IntPtr raw, IntPtr value);
+
+ public GLib.TimeVal TimeVal {
+ set {
+ IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
+ g_date_set_time_val(Handle, native_value);
+ value = GLib.TimeVal.New (native_value);
+ Marshal.FreeHGlobal (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_days(IntPtr raw, uint n_days);
+
+ public void SubtractDays(uint n_days) {
+ g_date_subtract_days(Handle, n_days);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_months(IntPtr raw, uint n_months);
+
+ public void SubtractMonths(uint n_months) {
+ g_date_subtract_months(Handle, n_months);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_subtract_years(IntPtr raw, uint n_years);
+
+ public void SubtractYears(uint n_years) {
+ g_date_subtract_years(Handle, n_years);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_to_struct_tm(IntPtr raw, IntPtr tm);
+
+ public void ToStructTm(IntPtr tm) {
+ g_date_to_struct_tm(Handle, tm);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid(IntPtr raw);
+
+ public bool Valid() {
+ bool raw_ret = g_date_valid(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_days_in_month(int month, ushort year);
+
+ public static byte GetDaysInMonth(int month, ushort year) {
+ byte raw_ret = g_date_get_days_in_month(month, year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_monday_weeks_in_year(ushort year);
+
+ public static byte GetMondayWeeksInYear(ushort year) {
+ byte raw_ret = g_date_get_monday_weeks_in_year(year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern byte g_date_get_sunday_weeks_in_year(ushort year);
+
+ public static byte GetSundayWeeksInYear(ushort year) {
+ byte raw_ret = g_date_get_sunday_weeks_in_year(year);
+ byte ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_is_leap_year(ushort year);
+
+ public static bool IsLeapYear(ushort year) {
+ bool raw_ret = g_date_is_leap_year(year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern UIntPtr g_date_strftime(IntPtr s, UIntPtr slen, IntPtr format, IntPtr date);
+
+ public static ulong Strftime(string s, string format, GLib.Date date) {
+ IntPtr native_s = GLib.Marshaller.StringToPtrGStrdup (s);
+ IntPtr native_format = GLib.Marshaller.StringToPtrGStrdup (format);
+ UIntPtr raw_ret = g_date_strftime(native_s, new UIntPtr ((ulong) System.Text.Encoding.UTF8.GetByteCount (s)), native_format, date == null ? IntPtr.Zero : date.Handle);
+ ulong ret = (ulong) raw_ret;
+ GLib.Marshaller.Free (native_s);
+ GLib.Marshaller.Free (native_format);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_day(byte day);
+
+ public static bool ValidDay(byte day) {
+ bool raw_ret = g_date_valid_day(day);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_dmy(byte day, int month, ushort year);
+
+ public static bool ValidDmy(byte day, int month, ushort year) {
+ bool raw_ret = g_date_valid_dmy(day, month, year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_julian(uint julian_date);
+
+ public static bool ValidJulian(uint julian_date) {
+ bool raw_ret = g_date_valid_julian(julian_date);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_month(int month);
+
+ public static bool ValidMonth(int month) {
+ bool raw_ret = g_date_valid_month(month);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_weekday(int weekday);
+
+ public static bool ValidWeekday(int weekday) {
+ bool raw_ret = g_date_valid_weekday(weekday);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_valid_year(ushort year);
+
+ public static bool ValidYear(ushort year) {
+ bool raw_ret = g_date_valid_year(year);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ public Date(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new();
+
+ public Date ()
+ {
+ Raw = g_date_new();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new_dmy(byte day, int month, ushort year);
+
+ public Date (byte day, int month, ushort year)
+ {
+ Raw = g_date_new_dmy(day, month, year);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_new_julian(uint julian_day);
+
+ public Date (uint julian_day)
+ {
+ Raw = g_date_new_julian(julian_day);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_free(IntPtr raw);
+
+ protected override void Free (IntPtr raw)
+ {
+ g_date_free (raw);
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_date_free (handle);
+ return false;
+ }
+ }
+
+ ~Date ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
Added: glib/DateTime.cs
===================================================================
@@ -0,0 +1,512 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class DateTime : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_date_time_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add(IntPtr raw, long timespan);
+
+ public GLib.DateTime Add(long timespan) {
+ IntPtr raw_ret = g_date_time_add(Handle, timespan);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_days(IntPtr raw, int days);
+
+ public GLib.DateTime AddDays(int days) {
+ IntPtr raw_ret = g_date_time_add_days(Handle, days);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_full(IntPtr raw, int years, int months, int days, int hours, int minutes, double seconds);
+
+ public GLib.DateTime AddFull(int years, int months, int days, int hours, int minutes, double seconds) {
+ IntPtr raw_ret = g_date_time_add_full(Handle, years, months, days, hours, minutes, seconds);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_hours(IntPtr raw, int hours);
+
+ public GLib.DateTime AddHours(int hours) {
+ IntPtr raw_ret = g_date_time_add_hours(Handle, hours);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_minutes(IntPtr raw, int minutes);
+
+ public GLib.DateTime AddMinutes(int minutes) {
+ IntPtr raw_ret = g_date_time_add_minutes(Handle, minutes);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_months(IntPtr raw, int months);
+
+ public GLib.DateTime AddMonths(int months) {
+ IntPtr raw_ret = g_date_time_add_months(Handle, months);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_seconds(IntPtr raw, double seconds);
+
+ public GLib.DateTime AddSeconds(double seconds) {
+ IntPtr raw_ret = g_date_time_add_seconds(Handle, seconds);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_weeks(IntPtr raw, int weeks);
+
+ public GLib.DateTime AddWeeks(int weeks) {
+ IntPtr raw_ret = g_date_time_add_weeks(Handle, weeks);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_add_years(IntPtr raw, int years);
+
+ public GLib.DateTime AddYears(int years) {
+ IntPtr raw_ret = g_date_time_add_years(Handle, years);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_difference(IntPtr raw, IntPtr begin);
+
+ public long Difference(GLib.DateTime begin) {
+ long raw_ret = g_date_time_difference(Handle, begin == null ? IntPtr.Zero : begin.Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_format(IntPtr raw, IntPtr format);
+
+ public string Format(string format) {
+ IntPtr native_format = GLib.Marshaller.StringToPtrGStrdup (format);
+ IntPtr raw_ret = g_date_time_format(Handle, native_format);
+ string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
+ GLib.Marshaller.Free (native_format);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_month(IntPtr raw);
+
+ public int DayOfMonth {
+ get {
+ int raw_ret = g_date_time_get_day_of_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_week(IntPtr raw);
+
+ public int DayOfWeek {
+ get {
+ int raw_ret = g_date_time_get_day_of_week(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_day_of_year(IntPtr raw);
+
+ public int DayOfYear {
+ get {
+ int raw_ret = g_date_time_get_day_of_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_hour(IntPtr raw);
+
+ public int Hour {
+ get {
+ int raw_ret = g_date_time_get_hour(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_microsecond(IntPtr raw);
+
+ public int Microsecond {
+ get {
+ int raw_ret = g_date_time_get_microsecond(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_minute(IntPtr raw);
+
+ public int Minute {
+ get {
+ int raw_ret = g_date_time_get_minute(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_month(IntPtr raw);
+
+ public int Month {
+ get {
+ int raw_ret = g_date_time_get_month(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_second(IntPtr raw);
+
+ public int Second {
+ get {
+ int raw_ret = g_date_time_get_second(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern double g_date_time_get_seconds(IntPtr raw);
+
+ public double Seconds {
+ get {
+ double raw_ret = g_date_time_get_seconds(Handle);
+ double ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_get_timezone_abbreviation(IntPtr raw);
+
+ public string TimezoneAbbreviation {
+ get {
+ IntPtr raw_ret = g_date_time_get_timezone_abbreviation(Handle);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_get_utc_offset(IntPtr raw);
+
+ public long UtcOffset {
+ get {
+ long raw_ret = g_date_time_get_utc_offset(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_week_numbering_year(IntPtr raw);
+
+ public int WeekNumberingYear {
+ get {
+ int raw_ret = g_date_time_get_week_numbering_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_week_of_year(IntPtr raw);
+
+ public int WeekOfYear {
+ get {
+ int raw_ret = g_date_time_get_week_of_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_get_year(IntPtr raw);
+
+ public int Year {
+ get {
+ int raw_ret = g_date_time_get_year(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_time_get_ymd(IntPtr raw, out int year, out int month, out int day);
+
+ public void GetYmd(out int year, out int month, out int day) {
+ g_date_time_get_ymd(Handle, out year, out month, out day);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_is_daylight_savings(IntPtr raw);
+
+ public bool IsDaylightSavings {
+ get {
+ bool raw_ret = g_date_time_is_daylight_savings(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_local(IntPtr raw);
+
+ public GLib.DateTime ToLocal() {
+ IntPtr raw_ret = g_date_time_to_local(Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_to_timeval(IntPtr raw, IntPtr tv);
+
+ public bool ToTimeval(GLib.TimeVal tv) {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ bool raw_ret = g_date_time_to_timeval(Handle, native_tv);
+ bool ret = raw_ret;
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_timezone(IntPtr raw, IntPtr tz);
+
+ public GLib.DateTime ToTimezone(GLib.TimeZone tz) {
+ IntPtr raw_ret = g_date_time_to_timezone(Handle, tz == null ? IntPtr.Zero : tz.Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_date_time_to_unix(IntPtr raw);
+
+ public long ToUnix() {
+ long raw_ret = g_date_time_to_unix(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_to_utc(IntPtr raw);
+
+ public GLib.DateTime ToUtc() {
+ IntPtr raw_ret = g_date_time_to_utc(Handle);
+ GLib.DateTime ret = raw_ret == IntPtr.Zero ? null : (GLib.DateTime) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.DateTime), true);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_date_time_compare(IntPtr dt1, IntPtr dt2);
+
+ public static int Compare(IntPtr dt1, IntPtr dt2) {
+ int raw_ret = g_date_time_compare(dt1, dt2);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_date_time_equal(IntPtr dt1, IntPtr dt2);
+
+ public static bool Equal(IntPtr dt1, IntPtr dt2) {
+ bool raw_ret = g_date_time_equal(dt1, dt2);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_date_time_hash(IntPtr datetime);
+
+ public static uint Hash(IntPtr datetime) {
+ uint raw_ret = g_date_time_hash(datetime);
+ uint ret = raw_ret;
+ return ret;
+ }
+
+ public DateTime(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new(IntPtr tz, int year, int month, int day, int hour, int minute, double seconds);
+
+ public DateTime (GLib.TimeZone tz, int year, int month, int day, int hour, int minute, double seconds)
+ {
+ Raw = g_date_time_new(tz == null ? IntPtr.Zero : tz.Handle, year, month, day, hour, minute, seconds);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_timeval_local(IntPtr tv);
+
+ public DateTime (GLib.TimeVal tv)
+ {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ Raw = g_date_time_new_from_timeval_local(native_tv);
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_timeval_utc(IntPtr tv);
+
+ public static DateTime NewFromTimevalUtc(GLib.TimeVal tv)
+ {
+ IntPtr native_tv = GLib.Marshaller.StructureToPtrAlloc (tv);
+ DateTime result = new DateTime (g_date_time_new_from_timeval_utc(native_tv));
+ tv = GLib.TimeVal.New (native_tv);
+ Marshal.FreeHGlobal (native_tv);
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_unix_local(long t);
+
+ public DateTime (long t)
+ {
+ Raw = g_date_time_new_from_unix_local(t);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_from_unix_utc(long t);
+
+ public static DateTime NewFromUnixUtc(long t)
+ {
+ DateTime result = new DateTime (g_date_time_new_from_unix_utc(t));
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_local(int year, int month, int day, int hour, int minute, double seconds);
+
+ public DateTime (int year, int month, int day, int hour, int minute, double seconds)
+ {
+ Raw = g_date_time_new_local(year, month, day, hour, minute, seconds);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now(IntPtr tz);
+
+ public DateTime (GLib.TimeZone tz)
+ {
+ Raw = g_date_time_new_now(tz == null ? IntPtr.Zero : tz.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now_local();
+
+ public DateTime ()
+ {
+ Raw = g_date_time_new_now_local();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_now_utc();
+
+ public static DateTime NewNowUtc()
+ {
+ DateTime result = new DateTime (g_date_time_new_now_utc());
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_new_utc(int year, int month, int day, int hour, int minute, double seconds);
+
+ public static DateTime NewUtc(int year, int month, int day, int hour, int minute, double seconds)
+ {
+ DateTime result = new DateTime (g_date_time_new_utc(year, month, day, hour, minute, seconds));
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_date_time_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_date_time_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_date_time_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_date_time_unref (raw);
+ Owned = false;
+ }
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_date_time_unref (handle);
+ return false;
+ }
+ }
+
+ ~DateTime ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
Added: glib/GLibSharp.SourceDummyMarshalNative.cs
===================================================================
@@ -0,0 +1,92 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLibSharp {
+
+ using System;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+ internal delegate void SourceDummyMarshalNative();
+
+ internal class SourceDummyMarshalInvoker {
+
+ SourceDummyMarshalNative native_cb;
+ IntPtr __data;
+ GLib.DestroyNotify __notify;
+
+ ~SourceDummyMarshalInvoker ()
+ {
+ if (__notify == null)
+ return;
+ __notify (__data);
+ }
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data) : this (native_cb, data, null) {}
+
+ internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data, GLib.DestroyNotify notify)
+ {
+ this.native_cb = native_cb;
+ __data = data;
+ __notify = notify;
+ }
+
+ internal GLib.SourceDummyMarshal Handler {
+ get {
+ return new GLib.SourceDummyMarshal(InvokeNative);
+ }
+ }
+
+ void InvokeNative ()
+ {
+ native_cb ();
+ }
+ }
+
+ internal class SourceDummyMarshalWrapper {
+
+ public void NativeCallback ()
+ {
+ try {
+ managed ();
+ if (release_on_call)
+ gch.Free ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ }
+ }
+
+ bool release_on_call = false;
+ GCHandle gch;
+
+ public void PersistUntilCalled ()
+ {
+ release_on_call = true;
+ gch = GCHandle.Alloc (this);
+ }
+
+ internal SourceDummyMarshalNative NativeDelegate;
+ GLib.SourceDummyMarshal managed;
+
+ public SourceDummyMarshalWrapper (GLib.SourceDummyMarshal managed)
+ {
+ this.managed = managed;
+ if (managed != null)
+ NativeDelegate = new SourceDummyMarshalNative (NativeCallback);
+ }
+
+ public static GLib.SourceDummyMarshal GetManagedDelegate (SourceDummyMarshalNative native)
+ {
+ if (native == null)
+ return null;
+ SourceDummyMarshalWrapper wrapper = (SourceDummyMarshalWrapper) native.Target;
+ if (wrapper == null)
+ return null;
+ return wrapper.managed;
+ }
+ }
+#endregion
+}
Added: glib/GLibSharp.SourceFuncNative.cs
===================================================================
@@ -0,0 +1,95 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLibSharp {
+
+ using System;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+ internal delegate bool SourceFuncNative(IntPtr user_data);
+
+ internal class SourceFuncInvoker {
+
+ SourceFuncNative native_cb;
+ IntPtr __data;
+ GLib.DestroyNotify __notify;
+
+ ~SourceFuncInvoker ()
+ {
+ if (__notify == null)
+ return;
+ __notify (__data);
+ }
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}
+
+ internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data, GLib.DestroyNotify notify)
+ {
+ this.native_cb = native_cb;
+ __data = data;
+ __notify = notify;
+ }
+
+ internal GLib.SourceFunc Handler {
+ get {
+ return new GLib.SourceFunc(InvokeNative);
+ }
+ }
+
+ bool InvokeNative (IntPtr user_data)
+ {
+ bool __result = native_cb (__data);
+ return __result;
+ }
+ }
+
+ internal class SourceFuncWrapper {
+
+ public bool NativeCallback (IntPtr user_data)
+ {
+ try {
+ bool __ret = managed (user_data);
+ if (release_on_call)
+ gch.Free ();
+ return __ret;
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ return false;
+ }
+ }
+
+ bool release_on_call = false;
+ GCHandle gch;
+
+ public void PersistUntilCalled ()
+ {
+ release_on_call = true;
+ gch = GCHandle.Alloc (this);
+ }
+
+ internal SourceFuncNative NativeDelegate;
+ GLib.SourceFunc managed;
+
+ public SourceFuncWrapper (GLib.SourceFunc managed)
+ {
+ this.managed = managed;
+ if (managed != null)
+ NativeDelegate = new SourceFuncNative (NativeCallback);
+ }
+
+ public static GLib.SourceFunc GetManagedDelegate (SourceFuncNative native)
+ {
+ if (native == null)
+ return null;
+ SourceFuncWrapper wrapper = (SourceFuncWrapper) native.Target;
+ if (wrapper == null)
+ return null;
+ return wrapper.managed;
+ }
+ }
+#endregion
+}
Modified: glib/MainContext.cs
===================================================================
@@ -38,13 +38,13 @@ public MainContext ()
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_ref (IntPtr raw);
- internal MainContext (IntPtr raw)
+ public MainContext (IntPtr raw)
{
handle = raw;
g_main_context_ref (handle);
}
- internal IntPtr Handle {
+ public IntPtr Handle {
get {
return handle;
}
Modified: glib/Makefile.am
===================================================================
@@ -19,9 +19,19 @@ POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
references =
+# TODO: auto-generate at compile time the following classes:
+# Cond, Date, DateTime, Mutex, PollFD, RecMutex, (half)Source,
+# SourceCallbackFuncs, SourceDummyMarshal, SourceFunc,
+# SourceFuncNative, SourceFuncs, TimeVal, TimeZone
+# (to do that, we need to fill missing pieces in glib's
+# gobject-introspection metadata upstream)
+
sources = \
Argv.cs \
ConnectBeforeAttribute.cs \
+ Cond.cs \
+ Date.cs \
+ DateTime.cs \
DefaultSignalHandlerAttribute.cs \
DestroyNotify.cs \
ExceptionManager.cs \
@@ -48,23 +58,34 @@ sources = \
Markup.cs \
Marshaller.cs \
MissingIntPtrCtorException.cs \
+ Mutex.cs \
NotifyHandler.cs \
Object.cs \
ObjectManager.cs \
Opaque.cs \
ParamSpec.cs \
+ PollFD.cs \
Priority.cs \
PropertyAttribute.cs \
PtrArray.cs \
+ RecMutex.cs \
Signal.cs \
SignalArgs.cs \
SignalAttribute.cs \
SignalClosure.cs \
SList.cs \
Source.cs \
+ SourceFunc.cs \
+ SourceFuncs.cs \
+ SourceDummyMarshal.cs \
+ GLibSharp.SourceFuncNative.cs \
+ GLibSharp.SourceDummyMarshalNative.cs \
+ SourceCallbackFuncs.cs \
Spawn.cs \
Thread.cs \
Timeout.cs \
+ TimeVal.cs \
+ TimeZone.cs \
ToggleRef.cs \
TypeFundamentals.cs \
TypeInitializerAttribute.cs \
Modified: glib/Marshaller.cs
===================================================================
@@ -170,7 +170,7 @@ public static IntPtr StringToFilenamePtr (string str)
return ret.Replace ("%", "%%");
}
- internal static IntPtr StringArrayToStrvPtr (string[] strs)
+ public static IntPtr StringArrayToStrvPtr (string[] strs)
{
IntPtr[] ptrs = StringArrayToNullTermPointer (strs);
IntPtr ret = g_malloc (new UIntPtr ((ulong) (ptrs.Length * IntPtr.Size)));
@@ -178,6 +178,11 @@ internal static IntPtr StringArrayToStrvPtr (string[] strs)
return ret;
}
+ public static IntPtr StringArrayToNullTermStrvPointer (string[] strs)
+ {
+ return StringArrayToStrvPtr (strs);
+ }
+
public static IntPtr[] StringArrayToNullTermPointer (string[] strs)
{
if (strs == null)
@@ -343,15 +348,15 @@ public static string[] ArrayPtrToArgv (IntPtr array, int argc)
return unmarshal_32 (array, argc);
}
- static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 0);
- static int utc_offset = (int) (TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds;
+ static System.DateTime local_epoch = new System.DateTime (1970, 1, 1, 0, 0, 0);
+ static int utc_offset = (int) (System.TimeZone.CurrentTimeZone.GetUtcOffset (System.DateTime.Now)).TotalSeconds;
- public static IntPtr DateTimeTotime_t (DateTime time)
+ public static IntPtr DateTimeTotime_t (System.DateTime time)
{
return new IntPtr (((long)time.Subtract (local_epoch).TotalSeconds) - utc_offset);
}
- public static DateTime time_tToDateTime (IntPtr time_t)
+ public static System.DateTime time_tToDateTime (IntPtr time_t)
{
return local_epoch.AddSeconds (time_t.ToInt64 () + utc_offset);
}
@@ -458,6 +463,39 @@ public static Array ListToArray (ListBase list, System.Type type)
return result;
}
+
+ public static T[] StructArrayFromNullTerminatedIntPtr<T> (IntPtr array)
+ {
+ var res = new List<T> ();
+ IntPtr current = array;
+ T currentStruct = default(T);
+
+ while (current != IntPtr.Zero) {
+ Marshal.PtrToStructure (current, currentStruct);
+ res.Add (currentStruct);
+ current = (IntPtr) ((long)current + Marshal.SizeOf (typeof (T)));
+ }
+
+ return res.ToArray ();
+ }
+
+ public static IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray)
+ {
+ int intPtrSize = Marshal.SizeOf (typeof (IntPtr));
+ IntPtr mem = Marshal.AllocHGlobal ((InputArray.Length + 1) * intPtrSize);
+
+ for (int i = 0; i < InputArray.Length; i++) {
+ IntPtr structPtr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (T)));
+ Marshal.StructureToPtr (InputArray[i], structPtr, false);
+ // jump to next pointer
+ Marshal.WriteIntPtr (mem, structPtr);
+ mem = (IntPtr) ((long)mem + intPtrSize);
+ }
+ // null terminate
+ Marshal.WriteIntPtr (mem, IntPtr.Zero);
+
+ return mem;
+ }
}
}
Added: glib/Mutex.cs
===================================================================
@@ -0,0 +1,55 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class Mutex : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_clear(IntPtr raw);
+
+ public void Clear() {
+ g_mutex_clear(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_init(IntPtr raw);
+
+ public void Init() {
+ g_mutex_init(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_lock(IntPtr raw);
+
+ public void Lock() {
+ g_mutex_lock(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_mutex_trylock(IntPtr raw);
+
+ public bool Trylock() {
+ bool raw_ret = g_mutex_trylock(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_mutex_unlock(IntPtr raw);
+
+ public void Unlock() {
+ g_mutex_unlock(Handle);
+ }
+
+ public Mutex(IntPtr raw) : base(raw) {}
+
+#endregion
+ }
+}
Added: glib/PollFD.cs
===================================================================
@@ -0,0 +1,67 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct PollFD : IEquatable<PollFD> {
+
+ public int Fd;
+ public ushort Events;
+ public ushort Revents;
+
+ public static GLib.PollFD Zero = new GLib.PollFD ();
+
+ public static GLib.PollFD New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.PollFD.Zero;
+ return (GLib.PollFD) Marshal.PtrToStructure (raw, typeof (GLib.PollFD));
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_pollfd_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_pollfd_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ public bool Equals (PollFD other)
+ {
+ return true && Fd.Equals (other.Fd) && Events.Equals (other.Events) && Revents.Equals (other.Revents);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is PollFD && Equals ((PollFD) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ Fd.GetHashCode () ^ Events.GetHashCode () ^ Revents.GetHashCode ();
+ }
+
+ public static explicit operator GLib.Value (GLib.PollFD boxed)
+ {
+ GLib.Value val = GLib.Value.Empty;
+ val.Init (GLib.PollFD.GType);
+ val.Val = boxed;
+ return val;
+ }
+
+ public static explicit operator GLib.PollFD (GLib.Value val)
+ {
+ return (GLib.PollFD) val.Val;
+ }
+#endregion
+ }
+}
Added: glib/RecMutex.cs
===================================================================
@@ -0,0 +1,55 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class RecMutex : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_clear(IntPtr raw);
+
+ public void Clear() {
+ g_rec_mutex_clear(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_init(IntPtr raw);
+
+ public void Init() {
+ g_rec_mutex_init(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_lock(IntPtr raw);
+
+ public void Lock() {
+ g_rec_mutex_lock(Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_rec_mutex_trylock(IntPtr raw);
+
+ public bool Trylock() {
+ bool raw_ret = g_rec_mutex_trylock(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_rec_mutex_unlock(IntPtr raw);
+
+ public void Unlock() {
+ g_rec_mutex_unlock(Handle);
+ }
+
+ public RecMutex(IntPtr raw) : base(raw) {}
+
+#endregion
+ }
+}
Modified: glib/Source.cs
===================================================================
@@ -43,10 +43,11 @@ internal void Remove ()
proxy_handler = null;
}
}
-
- public class Source {
+
+ public partial class Source : GLib.Opaque {
+
private Source () {}
-
+
internal static Hashtable source_handlers = new Hashtable ();
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
@@ -58,5 +59,343 @@ public static bool Remove (uint tag)
source_handlers.Remove (tag);
return g_source_remove (tag);
}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_context(IntPtr raw);
+
+ public GLib.MainContext Context {
+ get {
+ IntPtr raw_ret = g_source_get_context(Handle);
+ GLib.MainContext ret = raw_ret == IntPtr.Zero ? null : new MainContext (raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_source_get_priority(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_priority(IntPtr raw, int priority);
+
+ public int Priority {
+ get {
+ int raw_ret = g_source_get_priority(Handle);
+ int ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_priority(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_name(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_name(IntPtr raw, IntPtr name);
+
+ public string Name {
+ get {
+ IntPtr raw_ret = g_source_get_name(Handle);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+ set {
+ IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
+ g_source_set_name(Handle, native_value);
+ GLib.Marshaller.Free (native_value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_source_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_add_child_source(IntPtr raw, IntPtr child_source);
+
+ public void AddChildSource(GLib.Source child_source) {
+ g_source_add_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_add_poll(IntPtr raw, IntPtr fd);
+
+ public void AddPoll(GLib.PollFD fd) {
+ IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
+ g_source_add_poll(Handle, native_fd);
+ fd = GLib.PollFD.New (native_fd);
+ Marshal.FreeHGlobal (native_fd);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_source_attach(IntPtr raw, IntPtr context);
+
+ public uint Attach(GLib.MainContext context) {
+ uint raw_ret = g_source_attach(Handle, context == null ? IntPtr.Zero : context.Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+
+ uint Attach() {
+ return Attach (null);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_get_can_recurse(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_can_recurse(IntPtr raw, bool can_recurse);
+
+ public bool CanRecurse {
+ get {
+ bool raw_ret = g_source_get_can_recurse(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_can_recurse(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_get_current_time(IntPtr raw, IntPtr timeval);
+
+ [Obsolete]
+ public void GetCurrentTime(GLib.TimeVal timeval) {
+ IntPtr native_timeval = GLib.Marshaller.StructureToPtrAlloc (timeval);
+ g_source_get_current_time(Handle, native_timeval);
+ timeval = GLib.TimeVal.New (native_timeval);
+ Marshal.FreeHGlobal (native_timeval);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern uint g_source_get_id(IntPtr raw);
+
+ public uint Id {
+ get {
+ uint raw_ret = g_source_get_id(Handle);
+ uint ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_source_get_ready_time(IntPtr raw);
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_ready_time(IntPtr raw, long ready_time);
+
+ public long ReadyTime {
+ get {
+ long raw_ret = g_source_get_ready_time(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ set {
+ g_source_set_ready_time(Handle, value);
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern long g_source_get_time(IntPtr raw);
+
+ public long Time {
+ get {
+ long raw_ret = g_source_get_time(Handle);
+ long ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_is_destroyed(IntPtr raw);
+
+ public bool IsDestroyed {
+ get {
+ bool raw_ret = g_source_is_destroyed(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_modify_unix_fd(IntPtr raw, IntPtr tag, int new_events);
+
+ public void ModifyUnixFd(IntPtr tag, GLib.IOCondition new_events) {
+ g_source_modify_unix_fd(Handle, tag, (int) new_events);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_source_query_unix_fd(IntPtr raw, IntPtr tag);
+
+ public GLib.IOCondition QueryUnixFd(IntPtr tag) {
+ int raw_ret = g_source_query_unix_fd(Handle, tag);
+ GLib.IOCondition ret = (GLib.IOCondition) raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_child_source(IntPtr raw, IntPtr child_source);
+
+ public void RemoveChildSource(GLib.Source child_source) {
+ g_source_remove_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_poll(IntPtr raw, IntPtr fd);
+
+ public void RemovePoll(GLib.PollFD fd) {
+ IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
+ g_source_remove_poll(Handle, native_fd);
+ fd = GLib.PollFD.New (native_fd);
+ Marshal.FreeHGlobal (native_fd);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_remove_unix_fd(IntPtr raw, IntPtr tag);
+
+ public void RemoveUnixFd(IntPtr tag) {
+ g_source_remove_unix_fd(Handle, tag);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_callback_indirect(IntPtr raw, IntPtr callback_data, IntPtr callback_funcs);
+
+ public void SetCallbackIndirect(IntPtr callback_data, GLib.SourceCallbackFuncs callback_funcs) {
+ IntPtr native_callback_funcs = GLib.Marshaller.StructureToPtrAlloc (callback_funcs);
+ g_source_set_callback_indirect(Handle, callback_data, native_callback_funcs);
+ callback_funcs = GLib.SourceCallbackFuncs.New (native_callback_funcs);
+ Marshal.FreeHGlobal (native_callback_funcs);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_funcs(IntPtr raw, IntPtr value);
+
+ public GLib.SourceFuncs Funcs {
+ set {
+ IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
+ g_source_set_funcs(Handle, native_value);
+ value = GLib.SourceFuncs.New (native_value);
+ Marshal.FreeHGlobal (native_value);
+ }
+ }
+
+ /*
+ * commented out because there is already a custom implementation for Remove
+ *
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove(uint tag);
+
+ public static bool Remove(uint tag) {
+ bool raw_ret = g_source_remove(tag);
+ bool ret = raw_ret;
+ return ret;
+ }
+ */
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove_by_funcs_user_data(IntPtr funcs, IntPtr user_data);
+
+ public static bool RemoveByFuncsUserData(GLib.SourceFuncs funcs, IntPtr user_data) {
+ IntPtr native_funcs = GLib.Marshaller.StructureToPtrAlloc (funcs);
+ bool raw_ret = g_source_remove_by_funcs_user_data(native_funcs, user_data);
+ bool ret = raw_ret;
+ funcs = GLib.SourceFuncs.New (native_funcs);
+ Marshal.FreeHGlobal (native_funcs);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_source_remove_by_user_data(IntPtr user_data);
+
+ public static bool RemoveByUserData(IntPtr user_data) {
+ bool raw_ret = g_source_remove_by_user_data(user_data);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_set_name_by_id(uint tag, IntPtr name);
+
+ public static void SetNameById(uint tag, string name) {
+ IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
+ g_source_set_name_by_id(tag, native_name);
+ GLib.Marshaller.Free (native_name);
+ }
+
+ public Source(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_new(IntPtr source_funcs, uint struct_size);
+
+ public Source (GLib.SourceFuncs source_funcs, uint struct_size)
+ {
+ IntPtr native_source_funcs = GLib.Marshaller.StructureToPtrAlloc (source_funcs);
+ Raw = g_source_new(native_source_funcs, struct_size);
+ source_funcs = GLib.SourceFuncs.New (native_source_funcs);
+ Marshal.FreeHGlobal (native_source_funcs);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_source_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_source_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_source_unref (raw);
+ Owned = false;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_source_destroy(IntPtr raw);
+
+ protected override void Free (IntPtr raw)
+ {
+ g_source_destroy (raw);
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_source_destroy (handle);
+ return false;
+ }
+ }
+
+ ~Source ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
}
-}
+
+}
\ No newline at end of file
Added: glib/SourceCallbackFuncs.cs
===================================================================
@@ -0,0 +1,44 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct SourceCallbackFuncs : IEquatable<SourceCallbackFuncs> {
+
+
+ public static GLib.SourceCallbackFuncs Zero = new GLib.SourceCallbackFuncs ();
+
+ public static GLib.SourceCallbackFuncs New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.SourceCallbackFuncs.Zero;
+ return (GLib.SourceCallbackFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceCallbackFuncs));
+ }
+
+ public bool Equals (SourceCallbackFuncs other)
+ {
+ return true;
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is SourceCallbackFuncs && Equals ((SourceCallbackFuncs) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Added: glib/SourceDummyMarshal.cs
===================================================================
@@ -0,0 +1,10 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+
+ public delegate void SourceDummyMarshal();
+
+}
Added: glib/SourceFunc.cs
===================================================================
@@ -0,0 +1,10 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+
+ public delegate bool SourceFunc(IntPtr user_data);
+
+}
Added: glib/SourceFuncs.cs
===================================================================
@@ -0,0 +1,46 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct SourceFuncs : IEquatable<SourceFuncs> {
+
+ internal GLibSharp.SourceFuncNative closure_callback;
+ internal GLibSharp.SourceDummyMarshalNative closure_marshal;
+
+ public static GLib.SourceFuncs Zero = new GLib.SourceFuncs ();
+
+ public static GLib.SourceFuncs New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.SourceFuncs.Zero;
+ return (GLib.SourceFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceFuncs));
+ }
+
+ public bool Equals (SourceFuncs other)
+ {
+ return true && closure_callback.Equals (other.closure_callback) && closure_callback.Equals (other.closure_callback);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is SourceFuncs && Equals ((SourceFuncs) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ closure_marshal.GetHashCode () ^ closure_marshal.GetHashCode ();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Added: glib/TimeVal.cs
===================================================================
@@ -0,0 +1,105 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ [StructLayout(LayoutKind.Sequential)]
+ public partial struct TimeVal : IEquatable<TimeVal> {
+
+ private IntPtr tv_sec;
+ public long TvSec {
+ get {
+ return (long) tv_sec;
+ }
+ set {
+ tv_sec = new IntPtr (value);
+ }
+ }
+ private IntPtr tv_usec;
+ public long TvUsec {
+ get {
+ return (long) tv_usec;
+ }
+ set {
+ tv_usec = new IntPtr (value);
+ }
+ }
+
+ public static GLib.TimeVal Zero = new GLib.TimeVal ();
+
+ public static GLib.TimeVal New(IntPtr raw) {
+ if (raw == IntPtr.Zero)
+ return GLib.TimeVal.Zero;
+ return (GLib.TimeVal) Marshal.PtrToStructure (raw, typeof (GLib.TimeVal));
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_time_val_add(IntPtr raw, IntPtr microseconds);
+
+ public void Add(long microseconds) {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ g_time_val_add(this_as_native, new IntPtr (microseconds));
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_val_to_iso8601(IntPtr raw);
+
+ public string ToIso8601() {
+ IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
+ System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
+ IntPtr raw_ret = g_time_val_to_iso8601(this_as_native);
+ string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
+ ReadNative (this_as_native, ref this);
+ System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_time_val_from_iso8601(IntPtr iso_date, IntPtr time_);
+
+ public static bool FromIso8601(string iso_date, out GLib.TimeVal time_) {
+ IntPtr native_iso_date = GLib.Marshaller.StringToPtrGStrdup (iso_date);
+ IntPtr native_time_ = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (GLib.TimeVal)));
+ bool raw_ret = g_time_val_from_iso8601(native_iso_date, native_time_);
+ bool ret = raw_ret;
+ GLib.Marshaller.Free (native_iso_date);
+ time_ = GLib.TimeVal.New (native_time_);
+ Marshal.FreeHGlobal (native_time_);
+ return ret;
+ }
+
+ static void ReadNative (IntPtr native, ref GLib.TimeVal target)
+ {
+ target = New (native);
+ }
+
+ public bool Equals (TimeVal other)
+ {
+ return true && TvSec.Equals (other.TvSec) && TvUsec.Equals (other.TvUsec);
+ }
+
+ public override bool Equals (object other)
+ {
+ return other is TimeVal && Equals ((TimeVal) other);
+ }
+
+ public override int GetHashCode ()
+ {
+ return this.GetType().FullName.GetHashCode() ^ TvSec.GetHashCode () ^ TvUsec.GetHashCode ();
+ }
+
+ private static GLib.GType GType {
+ get { return GLib.GType.Pointer; }
+ }
+#endregion
+ }
+}
Added: glib/TimeZone.cs
===================================================================
@@ -0,0 +1,146 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+namespace GLib {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public partial class TimeZone : GLib.Opaque {
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_get_type();
+
+ public static GLib.GType GType {
+ get {
+ IntPtr raw_ret = g_time_zone_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_adjust_time(IntPtr raw, int type, long time_);
+
+ public int AdjustTime(int type, long time_) {
+ int raw_ret = g_time_zone_adjust_time(Handle, type, time_);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_find_interval(IntPtr raw, int type, long time_);
+
+ public int FindInterval(int type, long time_) {
+ int raw_ret = g_time_zone_find_interval(Handle, type, time_);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_get_abbreviation(IntPtr raw, int interval);
+
+ public string GetAbbreviation(int interval) {
+ IntPtr raw_ret = g_time_zone_get_abbreviation(Handle, interval);
+ string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern int g_time_zone_get_offset(IntPtr raw, int interval);
+
+ public int GetOffset(int interval) {
+ int raw_ret = g_time_zone_get_offset(Handle, interval);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern bool g_time_zone_is_dst(IntPtr raw, int interval);
+
+ public bool IsDst(int interval) {
+ bool raw_ret = g_time_zone_is_dst(Handle, interval);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ public TimeZone(IntPtr raw) : base(raw) {}
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new(IntPtr identifier);
+
+ public TimeZone (string identifier)
+ {
+ IntPtr native_identifier = GLib.Marshaller.StringToPtrGStrdup (identifier);
+ Raw = g_time_zone_new(native_identifier);
+ GLib.Marshaller.Free (native_identifier);
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new_local();
+
+ public TimeZone ()
+ {
+ Raw = g_time_zone_new_local();
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_new_utc();
+
+ public static TimeZone NewUtc()
+ {
+ TimeZone result = new TimeZone (g_time_zone_new_utc());
+ return result;
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr g_time_zone_ref(IntPtr raw);
+
+ protected override void Ref (IntPtr raw)
+ {
+ if (!Owned) {
+ g_time_zone_ref (raw);
+ Owned = true;
+ }
+ }
+
+ [DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
+ static extern void g_time_zone_unref(IntPtr raw);
+
+ protected override void Unref (IntPtr raw)
+ {
+ if (Owned) {
+ g_time_zone_unref (raw);
+ Owned = false;
+ }
+ }
+
+ class FinalizerInfo {
+ IntPtr handle;
+
+ public FinalizerInfo (IntPtr handle)
+ {
+ this.handle = handle;
+ }
+
+ public bool Handler ()
+ {
+ g_time_zone_unref (handle);
+ return false;
+ }
+ }
+
+ ~TimeZone ()
+ {
+ if (!Owned)
+ return;
+ FinalizerInfo info = new FinalizerInfo (Handle);
+ GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
+ }
+
+#endregion
+ }
+}
\ No newline at end of file
Modified: glib/Value.cs
===================================================================
@@ -421,10 +421,14 @@ object ToBoxed ()
return (GLib.Opaque) this;
MethodInfo mi = t.GetMethod ("New", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
- if (mi == null)
- return Marshal.PtrToStructure (boxed_ptr, t);
- else
+ if (mi != null)
return mi.Invoke (null, new object[] {boxed_ptr});
+
+ ConstructorInfo ci = t.GetConstructor (new Type[] { typeof(IntPtr) });
+ if (ci != null)
+ return ci.Invoke (new object[] { boxed_ptr });
+
+ return Marshal.PtrToStructure (boxed_ptr, t);
}
public object Val
@@ -548,8 +552,15 @@ public object Val
internal void Update (object val)
{
- if (GType.Is (type, GType.Boxed) && !(val is IWrapper))
- Marshal.StructureToPtr (val, g_value_get_boxed (ref this), false);
+ Type t = GType.LookupType (type);
+ if (GType.Is (type, GType.Boxed) && !(val is IWrapper)) {
+ MethodInfo mi = val.GetType ().GetMethod ("Update", BindingFlags.NonPublic | BindingFlags.Instance);
+ IntPtr boxed_ptr = g_value_get_boxed (ref this);
+ if (mi == null)
+ Marshal.StructureToPtr (val, boxed_ptr, false);
+ else
+ mi.Invoke (val, null);
+ }
}
bool HoldsFlags {
Modified: glib/glib.csproj
===================================================================
@@ -87,8 +87,15 @@
<Compile Include="Variant.cs" />
<Compile Include="VariantType.cs" />
<Compile Include="GLibSynchronizationContext.cs" />
+ <Compile Include="Mutex.cs" />
+ <Compile Include="RecMutex.cs" />
+ <Compile Include="Cond.cs" />
+ <Compile Include="Date.cs" />
+ <Compile Include="DateTime.cs" />
+ <Compile Include="TimeVal.cs" />
+ <Compile Include="TimeZone.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Core" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
Modified: parser/gapi-fixup.cs
===================================================================
@@ -1,8 +1,11 @@
// gapi-fixup.cs - xml alteration engine.
//
-// Author: Mike Kestner <[email protected]>
+// Authors:
+// Mike Kestner <[email protected]>
+// Stephan Sundermann <[email protected]>
//
// Copyright (c) 2003 Mike Kestner
+// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@@ -92,6 +95,26 @@ public static int Main (string[] args)
XPathNavigator meta_nav = meta_doc.CreateNavigator ();
XPathNavigator api_nav = api_doc.CreateNavigator ();
+ XPathNodeIterator copy_iter = meta_nav.Select ("/metadata/copy-node");
+ while (copy_iter.MoveNext ()) {
+ string path = copy_iter.Current.GetAttribute ("path", String.Empty);
+ XPathExpression expr = api_nav.Compile (path);
+ string parent = copy_iter.Current.Value;
+ XPathNodeIterator parent_iter = api_nav.Select (parent);
+ bool matched = false;
+ while (parent_iter.MoveNext ()) {
+ XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
+ XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
+ while (path_iter.MoveNext ()) {
+ XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
+ parent_node.AppendChild (node.Clone ());
+ }
+ matched = true;
+ }
+ if (!matched)
+ Console.WriteLine ("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
+ }
+
XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");
while (rmv_iter.MoveNext ()) {
string path = rmv_iter.Current.GetAttribute ("path", "");
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches