From 3eefa37272a3bc10be70e736b4e5ff82351b7826 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 30 May 2013 23:55:19 +0200 Subject: [PATCH 01/44] 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. --- generator/MethodBody.cs | 21 +++++++++++++++------ generator/Parameter.cs | 24 ++++++++++++++++++++++++ generator/Parameters.cs | 8 ++++++++ generator/Parser.cs | 2 +- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/generator/MethodBody.cs b/generator/MethodBody.cs index 1afb636f2..1575f9315 100644 --- a/generator/MethodBody.cs +++ b/generator/MethodBody.cs @@ -101,17 +101,26 @@ namespace GtkSharp.Generation { 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; diff --git a/generator/Parameter.cs b/generator/Parameter.cs index 2196f4bc4..1344ea102 100644 --- a/generator/Parameter.cs +++ b/generator/Parameter.cs @@ -236,6 +236,30 @@ namespace GtkSharp.Generation { } } + 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; diff --git a/generator/Parameters.cs b/generator/Parameters.cs index ad31a1b1c..b35b0658c 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -80,6 +80,14 @@ namespace GtkSharp.Generation { 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) diff --git a/generator/Parser.cs b/generator/Parser.cs index c9052d230..6b92b0aaf 100644 --- a/generator/Parser.cs +++ b/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) { From 4b470cadbb42536633f12eb8dfb107ff8d247c95 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 31 May 2013 00:21:59 +0200 Subject: [PATCH 02/44] generator: Added GThread type --- generator/SymbolTable.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 4ace94446..1e8066aca 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -126,6 +126,7 @@ namespace GtkSharp.Generation { 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})")); From c14277f391b138c91661ea00c9f3e69612f6f8b0 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 31 May 2013 00:55:50 +0200 Subject: [PATCH 03/44] generator: GThread type should be SimpleGen --- generator/SymbolTable.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 1e8066aca..cd199bb8f 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -126,13 +126,14 @@ namespace GtkSharp.Generation { 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")); From 115659f46b2ee3b592121c806515f59f5592838d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 31 May 2013 19:38:35 +0200 Subject: [PATCH 04/44] generator: fixed Equals/GetHashCode for no fields or padding Fixed Equals/GetHashCode methods when struct has no fields, or field is padding. --- generator/StructBase.cs | 14 +++++++++----- generator/StructField.cs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 63ace754e..4c8833c69 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -115,12 +115,16 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { } } 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)"); diff --git a/generator/StructField.cs b/generator/StructField.cs index 7b62cabd0..ac885038e 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -89,7 +89,7 @@ namespace GtkSharp.Generation { } } - bool IsPadding { + public bool IsPadding { get { return (CName.StartsWith ("dummy") || CName.StartsWith ("padding")); } From 94da3fb2abdf8d6f840704cb568e787011967a13 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 16:27:47 +0200 Subject: [PATCH 05/44] generator: faster Equals implementation --- generator/StructBase.cs | 44 +++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 4c8833c69..6fc7bcde5 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -1,8 +1,11 @@ // GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class. // -// Author: Mike Kestner +// Authors: +// Mike Kestner +// Stephan Sundermann // // 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 @@ namespace GtkSharp.Generation { { 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 @@ namespace GtkSharp.Generation { 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 (); From 8d4ec22ef2ec442648e146e8f6957a9855c7aa25 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 17:46:19 +0200 Subject: [PATCH 06/44] 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. --- generator/Parameters.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/generator/Parameters.cs b/generator/Parameters.cs index b35b0658c..c2c50dbd6 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -49,6 +49,18 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { if (p.IsCount) return true; - if (p.CType == "GError**") + if (p.CType == "GError**" && Throws) return true; if (HasCB || HideData) { @@ -212,7 +224,7 @@ namespace GtkSharp.Generation { } } } - } 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 @@ namespace GtkSharp.Generation { 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; + } + } } } From b5806d2a1b351092380352f1550ed9db2b809851 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 17:54:29 +0200 Subject: [PATCH 07/44] generator: fixed string[] return types --- generator/ReturnValue.cs | 2 +- glib/Marshaller.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index 40d139f7e..4d70d123a 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -160,7 +160,7 @@ namespace GtkSharp.Generation { 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); diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index d28d57e9b..49ec19086 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -170,7 +170,7 @@ namespace GLib { 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 @@ namespace GLib { return ret; } + public static IntPtr StringArrayToNullTermStrvPointer (string[] strs) + { + return StringArrayToStrvPtr (strs); + } + public static IntPtr[] StringArrayToNullTermPointer (string[] strs) { if (strs == null) From c53147c1c4decc8bb97274c911a352d228e4bee6 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 18:45:42 +0200 Subject: [PATCH 08/44] 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. --- generator/ClassBase.cs | 21 +++++++++++++ generator/ClassGen.cs | 3 +- generator/Constant.cs | 64 ++++++++++++++++++++++++++++++++++++++ generator/Makefile.am | 1 + generator/ObjectGen.cs | 3 +- generator/OpaqueGen.cs | 3 +- generator/generator.csproj | 1 + 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 generator/Constant.cs diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 8c77764c6..57e277044 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -34,6 +34,7 @@ namespace GtkSharp.Generation { private IDictionary props = new Dictionary (); private IDictionary fields = new Dictionary (); private IDictionary methods = new Dictionary (); + private IDictionary constants = new Dictionary(); protected IList interfaces = new List(); protected IList managed_interfaces = new List(); protected IList ctors = new List(); @@ -108,6 +109,11 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { case "implements": case "constructor": case "disabledefaultconstructor": + case "constant": return true; default: @@ -221,6 +236,12 @@ namespace GtkSharp.Generation { 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) { diff --git a/generator/ClassGen.cs b/generator/ClassGen.cs index f0cf6a33f..f6ef5b958 100644 --- a/generator/ClassGen.cs +++ b/generator/ClassGen.cs @@ -77,9 +77,10 @@ namespace GtkSharp.Generation { sw.WriteLine (" {"); sw.WriteLine (); + GenConstants (gen_info); GenProperties (gen_info, null); GenMethods (gen_info, null, null); - + sw.WriteLine ("#endregion"); sw.WriteLine ("\t}"); diff --git a/generator/Constant.cs b/generator/Constant.cs new file mode 100644 index 000000000..c8a06ca14 --- /dev/null +++ b/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); + } + } +} diff --git a/generator/Makefile.am b/generator/Makefile.am index dfd24c401..2fc3aabe7 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -19,6 +19,7 @@ sources = \ CodeGenerator.cs \ ConstFilenameGen.cs \ ConstStringGen.cs \ + Constant.cs \ Ctor.cs \ DefaultSignalHandler.cs \ EnumGen.cs \ diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 774a797da..05ea12ca1 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -195,9 +195,10 @@ namespace GtkSharp.Generation { 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 (); foreach (Method m in Methods.Values) { diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index 5b71ea742..7cef60587 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -79,7 +79,8 @@ namespace GtkSharp.Generation { sw.WriteLine (" {"); sw.WriteLine (); - + + GenConstants (gen_info); GenFields (gen_info); GenMethods (gen_info, null, null); GenCtors (gen_info); diff --git a/generator/generator.csproj b/generator/generator.csproj index 415779754..41ccce2e6 100644 --- a/generator/generator.csproj +++ b/generator/generator.csproj @@ -91,6 +91,7 @@ + From edde96c5bec6956bcd5f45edd92c283c7b326724 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 18:46:44 +0200 Subject: [PATCH 09/44] generator: fixed writeable and readable detection --- generator/FieldBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 7e18bbb36..353c6c553 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -42,13 +42,13 @@ namespace GtkSharp.Generation { 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"); } } From f6219b97e07d1652e16b296b40d2a449e4f8a59c Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 5 Jun 2013 19:26:33 +0200 Subject: [PATCH 10/44] generator: Added count param detection for return values --- generator/CallbackGen.cs | 2 ++ generator/ReturnValue.cs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index fde76684c..a63dab813 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -56,6 +56,8 @@ namespace GtkSharp.Generation { if (!String.IsNullOrEmpty (retval.CountParameterName)) retval.CountParameter = parms.GetCountParameter (retval.CountParameterName); + if (retval.CountParameterIndex >= 0) + retval.CountParameter = parms[retval.CountParameterIndex]; return valid; } diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index 4d70d123a..7e4e6ec18 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -32,6 +32,7 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { get { return array_length_param; } } + public int CountParameterIndex { + get { return array_length_param_index; } + } + public string CType { get { return ctype; From c5909d32fb2b61244cf2b63f826978ce421e8e95 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 11 Jun 2013 09:42:58 +0200 Subject: [PATCH 11/44] generator: fixed string array return type for virtual_methods --- generator/ReturnValue.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index 7e4e6ec18..9815d0764 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -133,7 +133,9 @@ namespace GtkSharp.Generation { 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; } } From dc4e7f30b9ba6ebe2457d26fd6efbb1aec812629 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 17 Jun 2013 11:56:09 +0200 Subject: [PATCH 12/44] generator: Added long long conversion --- generator/SymbolTable.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index cd199bb8f..e4cca25d7 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -69,6 +69,7 @@ namespace GtkSharp.Generation { 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")); From fd2fb44f99f2f36d4d8c5e0253bbb644f933699e Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 18:55:34 +0200 Subject: [PATCH 13/44] generator: readable&writable attribs to be backwards compat --- generator/FieldBase.cs | 4 ++++ generator/Parameters.cs | 9 +-------- generator/Parser.cs | 6 ++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 353c6c553..053e98aa9 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -42,12 +42,16 @@ namespace GtkSharp.Generation { 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"); } } diff --git a/generator/Parameters.cs b/generator/Parameters.cs index c2c50dbd6..2ea48d260 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -53,7 +53,7 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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; - } - } } } diff --git a/generator/Parser.cs b/generator/Parser.cs index 6b92b0aaf..b7bfa5f98 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -187,6 +187,12 @@ namespace GtkSharp.Generation { 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"); From 747a4ad871d86103134c5b63d2ecd64298cbfb9d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 8 Oct 2013 20:22:16 +0200 Subject: [PATCH 14/44] generator: Added conversion for unions Also removed all assumptions for parameters when ParserVersion >= 3 --- generator/Makefile.am | 1 + generator/Parameters.cs | 31 ++++++++++++++++--------------- generator/Parser.cs | 3 +++ generator/StructBase.cs | 16 +++++++++++++--- generator/StructField.cs | 4 ++-- generator/SymbolTable.cs | 7 +++++++ generator/UnionGen.cs | 18 ++++++++++++++++++ generator/generator.csproj | 1 + 8 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 generator/UnionGen.cs diff --git a/generator/Makefile.am b/generator/Makefile.am index 2fc3aabe7..a45405357 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -64,6 +64,7 @@ sources = \ StructField.cs \ StructGen.cs \ SymbolTable.cs \ + UnionGen.cs \ VirtualMethod.cs \ VMSignature.cs \ XmlElementExtensions.cs diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 2ea48d260..ae953ab7e 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -93,23 +93,23 @@ namespace GtkSharp.Generation { 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; - else if (param.DestroyNotify == idx) + 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 (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 @@ namespace GtkSharp.Generation { 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; diff --git a/generator/Parser.cs b/generator/Parser.cs index b7bfa5f98..0974d5908 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -171,6 +171,9 @@ namespace GtkSharp.Generation { 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)); diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 6fc7bcde5..9288fc3a4 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -110,6 +110,12 @@ namespace GtkSharp.Generation { } } + public virtual bool Union { + get { + return false; + } + } + protected void GenEqualsAndHash (StreamWriter sw) { int bitfields = 0; @@ -172,12 +178,13 @@ namespace GtkSharp.Generation { { 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 @@ namespace GtkSharp.Generation { 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 (); diff --git a/generator/StructField.cs b/generator/StructField.cs index ac885038e..e0ba545d4 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -80,7 +80,7 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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") { diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index e4cca25d7..823494a97 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -292,6 +292,13 @@ namespace GtkSharp.Generation { return false; } + + public bool IsUnion (string c_type) + { + if (this[c_type] is UnionGen) + return true; + return false; + } public bool IsEnum(string c_type) { diff --git a/generator/UnionGen.cs b/generator/UnionGen.cs new file mode 100644 index 000000000..15589b262 --- /dev/null +++ b/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; + } + } + } +} diff --git a/generator/generator.csproj b/generator/generator.csproj index 41ccce2e6..1d19e62ae 100644 --- a/generator/generator.csproj +++ b/generator/generator.csproj @@ -92,6 +92,7 @@ + From 112e2b9598140070a2972117260b5be3e5b814b9 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 13:09:34 +0200 Subject: [PATCH 15/44] generator,glib: Added Mutex, RecMutex, Cond types Bind these types manually and added generator support for them. --- generator/SymbolTable.cs | 3 ++ glib/Cond.cs | 70 +++++++++++++++++++++++++ glib/Makefile.am | 3 ++ glib/Mutex.cs | 110 +++++++++++++++++++++++++++++++++++++++ glib/RecMutex.cs | 57 ++++++++++++++++++++ glib/glib.csproj | 3 ++ 6 files changed, 246 insertions(+) create mode 100644 glib/Cond.cs create mode 100644 glib/Mutex.cs create mode 100644 glib/RecMutex.cs diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 823494a97..d490a02d4 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -127,6 +127,9 @@ namespace GtkSharp.Generation { 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})")); diff --git a/glib/Cond.cs b/glib/Cond.cs new file mode 100644 index 000000000..ee7c2e100 --- /dev/null +++ b/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 + } +} diff --git a/glib/Makefile.am b/glib/Makefile.am index b23c11ad6..c73edaf87 100644 --- a/glib/Makefile.am +++ b/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 \ diff --git a/glib/Mutex.cs b/glib/Mutex.cs new file mode 100644 index 000000000..9a6d2e6db --- /dev/null +++ b/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 { + + [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 + } +} diff --git a/glib/RecMutex.cs b/glib/RecMutex.cs new file mode 100644 index 000000000..a1e3bdbc5 --- /dev/null +++ b/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 + } +} diff --git a/glib/glib.csproj b/glib/glib.csproj index 0f7bf4384..7e3f086ab 100644 --- a/glib/glib.csproj +++ b/glib/glib.csproj @@ -87,6 +87,9 @@ + + + From d01be26f0ccb231abeb8899db872ece5e9805505 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 1 Jul 2013 19:26:14 +0200 Subject: [PATCH 16/44] generator: added defaultconstructoraccess attrib --- generator/ObjectGen.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 05ea12ca1..d514353e4 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -261,8 +261,9 @@ namespace GtkSharp.Generation { { 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)"); From 29a900e51ef02c390c6f622c86e515b1b5ff4133 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 13:40:56 +0200 Subject: [PATCH 17/44] 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. --- generator/FieldBase.cs | 6 +- generator/Makefile.am | 1 + generator/NativeStructGen.cs | 232 +++++++++++++++++++++++++++++++++++ generator/ObjectField.cs | 2 +- generator/Parser.cs | 3 + generator/StructField.cs | 10 ++ generator/generator.csproj | 3 +- glib/Value.cs | 21 +++- 8 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 generator/NativeStructGen.cs diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 053e98aa9..8e927d601 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -40,7 +40,7 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { } } - 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 @@ namespace GtkSharp.Generation { protected abstract string DefaultAccess { get; } - protected string Access { + internal string Access { get { return elem.HasAttribute ("access") ? elem.GetAttribute ("access") : DefaultAccess; } diff --git a/generator/Makefile.am b/generator/Makefile.am index a45405357..ffea9f0a0 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -43,6 +43,7 @@ sources = \ MethodBase.cs \ MethodBody.cs \ Method.cs \ + NativeStructGen.cs \ ObjectField.cs \ ObjectBase.cs \ ObjectGen.cs \ diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs new file mode 100644 index 000000000..b4cb06d46 --- /dev/null +++ b/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 fields = new List (); + 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 ();"); + } + } +} + diff --git a/generator/ObjectField.cs b/generator/ObjectField.cs index f0edd1a5e..2b004a6ff 100644 --- a/generator/ObjectField.cs +++ b/generator/ObjectField.cs @@ -32,7 +32,7 @@ namespace GtkSharp.Generation { ctype = "const-" + CType; } - protected override bool Writable { + internal override bool Writable { get { return elem.GetAttributeAsBoolean ("writeable"); } diff --git a/generator/Parser.cs b/generator/Parser.cs index 0974d5908..0d96e59fd 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -140,6 +140,7 @@ namespace GtkSharp.Generation { continue; bool is_opaque = elem.GetAttributeAsBoolean ("opaque"); + bool is_native_struct = elem.GetAttributeAsBoolean ("native"); switch (def.Name) { case "alias": @@ -177,6 +178,8 @@ namespace GtkSharp.Generation { 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)); } diff --git a/generator/StructField.cs b/generator/StructField.cs index e0ba545d4..d60273cb0 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -70,6 +70,13 @@ namespace GtkSharp.Generation { } } + bool visible = false; + internal bool Visible { + get { + return visible; + } + } + public string EqualityName { get { SymbolTable table = SymbolTable.Table; @@ -127,6 +134,8 @@ namespace GtkSharp.Generation { if (Hidden) return; + visible = Access != "private"; + StreamWriter sw = gen_info.Writer; SymbolTable table = SymbolTable.Table; @@ -158,6 +167,7 @@ namespace GtkSharp.Generation { } } 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); diff --git a/generator/generator.csproj b/generator/generator.csproj index 1d19e62ae..681863983 100644 --- a/generator/generator.csproj +++ b/generator/generator.csproj @@ -93,6 +93,7 @@ + @@ -102,4 +103,4 @@ - \ No newline at end of file + diff --git a/glib/Value.cs b/glib/Value.cs index deb7deb3e..1c89cc37d 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -421,10 +421,14 @@ namespace GLib { 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 @@ namespace GLib { 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 { From 33fd293b8479aa4da3528d4562cb64ba45aa60ac Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 11 Jul 2013 12:58:05 +0200 Subject: [PATCH 18/44] generator: null check for handle (NativeStructGen) Check Handle against IntPtr.Zero before marshalling. --- generator/NativeStructGen.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index b4cb06d46..3379e350a 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -126,7 +126,8 @@ namespace GtkSharp.Generation 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 (); } From 388a2fe65993311d4b4d4ba1903cfc26468b588a Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 15:31:10 +0200 Subject: [PATCH 19/44] generator: added handling of optional parameters --- generator/Method.cs | 11 +++++++++++ generator/Parameter.cs | 6 ++++++ generator/Parameters.cs | 8 ++++++++ generator/Signature.cs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/generator/Method.cs b/generator/Method.cs index 59711bfe6..14cb56a6f 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -207,6 +207,14 @@ namespace GtkSharp.Generation { } } + 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 @@ namespace GtkSharp.Generation { } else gen_info.Writer.WriteLine(); + + if (Parameters.HasOptional && !(is_get || is_set)) + GenerateOverloads (gen_info.Writer); gen_info.Writer.WriteLine(); diff --git a/generator/Parameter.cs b/generator/Parameter.cs index 1344ea102..31d2063f0 100644 --- a/generator/Parameter.cs +++ b/generator/Parameter.cs @@ -90,6 +90,12 @@ namespace GtkSharp.Generation { } } + internal bool IsOptional { + get { + return elem.GetAttributeAsBoolean ("allow-none"); + } + } + bool is_count; bool is_count_set; public bool IsCount { diff --git a/generator/Parameters.cs b/generator/Parameters.cs index ae953ab7e..067fd8801 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -142,6 +142,11 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { return false; } + if (p.IsOptional && p.PassAs == String.Empty) + has_optional = true; + IGeneratable gen = p.Generatable; if (p.IsArray) { diff --git a/generator/Signature.cs b/generator/Signature.cs index 80808ddd3..9c2683ce7 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -118,6 +118,44 @@ namespace GtkSharp.Generation { 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); + } } } From 972e6257fcde57865197d27bcaac802f7b103c64 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 17 Jul 2013 17:07:20 +0200 Subject: [PATCH 20/44] generator: removed wrong glue code for structs --- generator/FieldBase.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 8e927d601..f42e52eb1 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -176,13 +176,8 @@ namespace GtkSharp.Generation { } 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 @@ namespace GtkSharp.Generation { } 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}"); } From 949c538fe39c34969d70d0bbb69057a7e34b1a54 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 17 Jul 2013 17:15:52 +0200 Subject: [PATCH 21/44] generator: IntPtr.Zero for optional IntPtr params IntPtr.Zero should be passed for optional IntPtr params instead of null --- generator/Signature.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/generator/Signature.cs b/generator/Signature.cs index 9c2683ce7..156480003 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -148,8 +148,14 @@ namespace GtkSharp.Generation { 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; } From ddd241915129a4f8ab4849219a6872b1187d94ff Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 17 Jul 2013 18:43:45 +0200 Subject: [PATCH 22/44] generator: fix optional parameters again --- generator/Signature.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/Signature.cs b/generator/Signature.cs index 156480003..9f64ae3b8 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -150,7 +150,7 @@ namespace GtkSharp.Generation { 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 From 55ab3ab284856ea6498ce595e4528661311747e8 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 18 Jul 2013 17:05:58 +0200 Subject: [PATCH 23/44] generator: fixed glue code for callbacks --- generator/CallbackGen.cs | 8 ++++++++ generator/FieldBase.cs | 24 +++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index a63dab813..319fe5be1 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -70,6 +70,14 @@ namespace GtkSharp.Generation { } } + public string WrapperName { + get { + if (!valid) + return String.Empty; + return NS + "Sharp." + Name + "Wrapper"; + } + } + public override string MarshalType { get { if (valid) diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index f42e52eb1..b2985ac97 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -156,6 +156,7 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { } 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 @@ namespace GtkSharp.Generation { } 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}"); } From aaa41cd0953b5fb1f38b10b586a4f33dec178bef Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 18:04:47 +0200 Subject: [PATCH 24/44] fixup: added copy-node metadata tag --- parser/gapi-fixup.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/parser/gapi-fixup.cs b/parser/gapi-fixup.cs index 67a9d82bb..9203fb30a 100644 --- a/parser/gapi-fixup.cs +++ b/parser/gapi-fixup.cs @@ -1,8 +1,11 @@ // gapi-fixup.cs - xml alteration engine. // -// Author: Mike Kestner +// Authors: +// Mike Kestner +// Stephan Sundermann // // 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 @@ namespace GtkSharp.Parsing { 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: matched no nodes", path); + } + XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node"); while (rmv_iter.MoveNext ()) { string path = rmv_iter.Current.GetAttribute ("path", ""); From 9abde602ecc3f20500d86c3c05fa6f98be214fa1 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 18:30:10 +0200 Subject: [PATCH 25/44] 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 --- generator/SymbolTable.cs | 3 +- glib/Cond.cs | 2 - glib/Date.cs | 478 ++++++++++++++++++++++++++++++++++++ glib/DateTime.cs | 512 +++++++++++++++++++++++++++++++++++++++ glib/Makefile.am | 7 + glib/Marshaller.cs | 8 +- glib/Mutex.cs | 2 - glib/RecMutex.cs | 2 - glib/TimeVal.cs | 105 ++++++++ glib/TimeZone.cs | 146 +++++++++++ glib/glib.csproj | 6 +- 11 files changed, 1259 insertions(+), 12 deletions(-) create mode 100644 glib/Date.cs create mode 100644 glib/DateTime.cs create mode 100644 glib/TimeVal.cs create mode 100644 glib/TimeZone.cs diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index d490a02d4..408125e3f 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -130,6 +130,8 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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")); diff --git a/glib/Cond.cs b/glib/Cond.cs index ee7c2e100..aa589a900 100644 --- a/glib/Cond.cs +++ b/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; diff --git a/glib/Date.cs b/glib/Date.cs new file mode 100644 index 000000000..b7c81d917 --- /dev/null +++ b/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 + } +} diff --git a/glib/DateTime.cs b/glib/DateTime.cs new file mode 100644 index 000000000..f1b8dbfca --- /dev/null +++ b/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 + } +} diff --git a/glib/Makefile.am b/glib/Makefile.am index c73edaf87..6484b0d9b 100644 --- a/glib/Makefile.am +++ b/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 \ diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index 49ec19086..e08792ddb 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -348,15 +348,15 @@ namespace GLib { 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); } diff --git a/glib/Mutex.cs b/glib/Mutex.cs index 9a6d2e6db..fdd675d80 100644 --- a/glib/Mutex.cs +++ b/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; diff --git a/glib/RecMutex.cs b/glib/RecMutex.cs index a1e3bdbc5..b6d50a717 100644 --- a/glib/RecMutex.cs +++ b/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; diff --git a/glib/TimeVal.cs b/glib/TimeVal.cs new file mode 100644 index 000000000..a439433b4 --- /dev/null +++ b/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 { + + 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 + } +} diff --git a/glib/TimeZone.cs b/glib/TimeZone.cs new file mode 100644 index 000000000..90dfd8ce0 --- /dev/null +++ b/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 diff --git a/glib/glib.csproj b/glib/glib.csproj index 7e3f086ab..4a9612cd0 100644 --- a/glib/glib.csproj +++ b/glib/glib.csproj @@ -90,8 +90,12 @@ + + + + - \ No newline at end of file + From 8b101d552541675a925c1f36bc68357a20bb0c65 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 18:44:04 +0200 Subject: [PATCH 26/44] 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. --- glib/Cond.cs | 10 ++------ glib/Makefile.am | 2 ++ glib/Mutex.cs | 67 +++++------------------------------------------- 3 files changed, 11 insertions(+), 68 deletions(-) diff --git a/glib/Cond.cs b/glib/Cond.cs index aa589a900..2ff9afeed 100644 --- a/glib/Cond.cs +++ b/glib/Cond.cs @@ -43,21 +43,15 @@ namespace GLib { 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; } diff --git a/glib/Makefile.am b/glib/Makefile.am index 6484b0d9b..dd880e5ea 100644 --- a/glib/Makefile.am +++ b/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 \ diff --git a/glib/Mutex.cs b/glib/Mutex.cs index fdd675d80..de74d5f2c 100644 --- a/glib/Mutex.cs +++ b/glib/Mutex.cs @@ -9,66 +9,35 @@ namespace GLib { using System.Runtime.InteropServices; #region Autogenerated code - [StructLayout(LayoutKind.Explicit)] - public partial struct Mutex : IEquatable { - - [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 @@ namespace GLib { 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); + g_mutex_unlock(Handle); } - 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 (); - } + public Mutex(IntPtr raw) : base(raw) {} #endregion } From e031a4ff18996d8a108bd98081cd175a8f966f38 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 18:51:38 +0200 Subject: [PATCH 27/44] generator: auto escape string constants --- generator/Constant.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/generator/Constant.cs b/generator/Constant.cs index c8a06ca14..2b197d782 100644 --- a/generator/Constant.cs +++ b/generator/Constant.cs @@ -58,7 +58,13 @@ namespace GtkSharp.Generation { 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); } } } From 139479036b64fade6c1f680119373b3ccc3b9c00 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 29 Jul 2013 18:38:06 +0200 Subject: [PATCH 28/44] generator: do not generate methods without (C)Name --- generator/Method.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/generator/Method.cs b/generator/Method.cs index 14cb56a6f..76078d65b 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -84,6 +84,11 @@ namespace GtkSharp.Generation { 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); From 6ab620d6891a90004d9be96235ef741ed6ab1f58 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 19:41:21 +0200 Subject: [PATCH 29/44] 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. --- generator/SymbolTable.cs | 2 + glib/GLibSharp.SourceDummyMarshalNative.cs | 92 ++++++ glib/GLibSharp.SourceFuncNative.cs | 95 ++++++ glib/Makefile.am | 11 +- glib/PollFD.cs | 67 ++++ glib/Source.cs | 347 ++++++++++++++++++++- glib/SourceCallbackFuncs.cs | 44 +++ glib/SourceDummyMarshal.cs | 10 + glib/SourceFunc.cs | 10 + glib/SourceFuncs.cs | 46 +++ 10 files changed, 719 insertions(+), 5 deletions(-) create mode 100644 glib/GLibSharp.SourceDummyMarshalNative.cs create mode 100644 glib/GLibSharp.SourceFuncNative.cs create mode 100644 glib/PollFD.cs create mode 100644 glib/SourceCallbackFuncs.cs create mode 100644 glib/SourceDummyMarshal.cs create mode 100644 glib/SourceFunc.cs create mode 100644 glib/SourceFuncs.cs diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 408125e3f..039a63025 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -132,6 +132,8 @@ namespace GtkSharp.Generation { 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})")); diff --git a/glib/GLibSharp.SourceDummyMarshalNative.cs b/glib/GLibSharp.SourceDummyMarshalNative.cs new file mode 100644 index 000000000..3a491b841 --- /dev/null +++ b/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 +} diff --git a/glib/GLibSharp.SourceFuncNative.cs b/glib/GLibSharp.SourceFuncNative.cs new file mode 100644 index 000000000..de915f5a7 --- /dev/null +++ b/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 +} diff --git a/glib/Makefile.am b/glib/Makefile.am index dd880e5ea..aedada623 100644 --- a/glib/Makefile.am +++ b/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 \ diff --git a/glib/PollFD.cs b/glib/PollFD.cs new file mode 100644 index 000000000..aa2821428 --- /dev/null +++ b/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 { + + 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 + } +} diff --git a/glib/Source.cs b/glib/Source.cs index 0e5b01b8f..28ef406e0 100644 --- a/glib/Source.cs +++ b/glib/Source.cs @@ -43,10 +43,11 @@ namespace GLib { 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 @@ namespace GLib { 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 diff --git a/glib/SourceCallbackFuncs.cs b/glib/SourceCallbackFuncs.cs new file mode 100644 index 000000000..c1f72a30b --- /dev/null +++ b/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 { + + + 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 + } +} diff --git a/glib/SourceDummyMarshal.cs b/glib/SourceDummyMarshal.cs new file mode 100644 index 000000000..df9f7307f --- /dev/null +++ b/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(); + +} diff --git a/glib/SourceFunc.cs b/glib/SourceFunc.cs new file mode 100644 index 000000000..3a4b2b6ed --- /dev/null +++ b/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); + +} diff --git a/glib/SourceFuncs.cs b/glib/SourceFuncs.cs new file mode 100644 index 000000000..4fc603f8d --- /dev/null +++ b/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 { + + 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 + } +} From b868b80deef1a510bce2fe47ef5220ad2d9a8a14 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 19:44:50 +0200 Subject: [PATCH 30/44] 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 --- generator/SymbolTable.cs | 1 + glib/MainContext.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 039a63025..520024ce6 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -133,6 +133,7 @@ namespace GtkSharp.Generation { 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})")); diff --git a/glib/MainContext.cs b/glib/MainContext.cs index e46fa7847..2144aff59 100644 --- a/glib/MainContext.cs +++ b/glib/MainContext.cs @@ -38,13 +38,13 @@ namespace GLib { [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; } From f958b2247b44de88d5574da7121833e348bc9286 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 7 Aug 2013 23:36:38 +0200 Subject: [PATCH 31/44] generator: include api files from XML --- generator/Parser.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generator/Parser.cs b/generator/Parser.cs index 0d96e59fd..907de9860 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -111,6 +111,10 @@ namespace GtkSharp.Generation { 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; From 5eea00f70500e120e4c8028d61bff3d347092c68 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 20:00:14 +0200 Subject: [PATCH 32/44] generator: new --gapidir flag to search for xml files --- generator/CodeGenerator.cs | 7 +++++-- generator/Parser.cs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/generator/CodeGenerator.cs b/generator/CodeGenerator.cs index bbd9830b3..187cca62b 100644 --- a/generator/CodeGenerator.cs +++ b/generator/CodeGenerator.cs @@ -34,6 +34,7 @@ namespace GtkSharp.Generation { bool show_help = false; string dir = ""; string assembly_name = ""; + string gapidir = ""; string glue_filename = ""; string glue_includes = ""; string gluelib_name = ""; @@ -54,6 +55,8 @@ namespace GtkSharp.Generation { (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 @@ namespace GtkSharp.Generation { 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); } diff --git a/generator/Parser.cs b/generator/Parser.cs index 907de9860..f206fdd00 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -77,6 +77,11 @@ namespace GtkSharp.Generation { } 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) @@ -112,7 +117,18 @@ namespace GtkSharp.Generation { 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": From c3f7b8e32b4e0d687a601829f39416407c341212 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 12 Aug 2013 10:50:13 +0200 Subject: [PATCH 33/44] generator: fixed optional array parameters --- generator/Signature.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generator/Signature.cs b/generator/Signature.cs index 9f64ae3b8..3b14127d3 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -149,7 +149,9 @@ namespace GtkSharp.Generation { 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"; From 5f271e04fa71875805694cfeb0cdc6d2137956d0 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Mon, 12 Aug 2013 11:17:09 +0200 Subject: [PATCH 34/44] 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. --- generator/FieldBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index b2985ac97..1c2a30c9a 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -32,6 +32,8 @@ namespace GtkSharp.Generation { { log.Member = Name; if (!Ignored && !Hidden && CSType == "") { + if (Name == "Priv") + return false; log.Warn ("field has unknown type: " + CType); Statistics.ThrottledCount++; return false; From 2152f4626eb0e30a6132cd50fdd58d00bed9cdea Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Tue, 13 Aug 2013 14:39:59 +0200 Subject: [PATCH 35/44] generator: use default value for optional generation --- generator/Signature.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/generator/Signature.cs b/generator/Signature.cs index 3b14127d3..c63ba75b0 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -149,14 +149,7 @@ namespace GtkSharp.Generation { 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; From 53312d5fc075af4189b65d12238c5f142415ccb4 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 14 Aug 2013 13:16:40 +0200 Subject: [PATCH 36/44] generator: fixed optional array parameters --- generator/Signature.cs | 5 ++++- generator/StructField.cs | 18 +++++++++++++++++- glib/Marshaller.cs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/generator/Signature.cs b/generator/Signature.cs index c63ba75b0..c2f942ac3 100644 --- a/generator/Signature.cs +++ b/generator/Signature.cs @@ -149,7 +149,10 @@ namespace GtkSharp.Generation { 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; diff --git a/generator/StructField.cs b/generator/StructField.cs index d60273cb0..58ccf1f11 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -58,6 +58,10 @@ namespace GtkSharp.Generation { } } + bool IsNullTermArray { + get { return elem.GetAttributeAsBoolean ("null_term_array"); } + } + public new string CSType { get { string type = base.CSType; @@ -143,9 +147,21 @@ namespace GtkSharp.Generation { 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) { diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index e08792ddb..ff38caba7 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -463,6 +463,39 @@ namespace GLib { return result; } + + public static T[] StructArrayFromNullTerminatedIntPtr (IntPtr array) + { + var res = new List (); + 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[] 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; + } } } From 31e2c02e94fc009518eed4454764ed73da4373a2 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Oct 2013 20:37:18 +0200 Subject: [PATCH 37/44] generator: public accessor in method overloads --- generator/Method.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/Method.cs b/generator/Method.cs index 76078d65b..784951074 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -215,7 +215,7 @@ namespace GtkSharp.Generation { 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}"); } From 0f79e9af06edd1d20de2c7dafc2c61e98369fc9d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 28 Aug 2013 14:54:17 +0200 Subject: [PATCH 38/44] 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. --- generator/NativeStructGen.cs | 46 ++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index 3379e350a..e6bd689db 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -10,13 +10,9 @@ namespace GtkSharp.Generation public class NativeStructGen : HandleBase { IList fields = new List (); - 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 @@ namespace GtkSharp.Generation 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 @@ namespace GtkSharp.Generation 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 @@ namespace GtkSharp.Generation 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 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation { 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 @@ namespace GtkSharp.Generation public override void Prepare (StreamWriter sw, string indent) { - sw.WriteLine (indent + "Update ();"); + sw.WriteLine (indent + "NativeStruct native = Native;"); } } } From edc339baf51653f7599bb499475dc75a4616806f Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 28 Aug 2013 15:01:02 +0200 Subject: [PATCH 39/44] generator: redundant method in NativeStructGen --- generator/NativeStructGen.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index e6bd689db..09d7767fe 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -219,11 +219,6 @@ namespace GtkSharp.Generation sw.WriteLine (); } - - public override void Prepare (StreamWriter sw, string indent) - { - sw.WriteLine (indent + "NativeStruct native = Native;"); - } } } From c5b04cb70e3d8279a4fb622e6b6c38138c2a393e Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 29 Aug 2013 16:14:28 +0200 Subject: [PATCH 40/44] generator: fixed native struct parent --- generator/NativeStructGen.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index 09d7767fe..00bf25c16 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -78,7 +78,7 @@ namespace GtkSharp.Generation 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 @@ namespace GtkSharp.Generation 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); } From f6fef3a402bbfe82d11aadb12edf621d38f842c1 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 29 Aug 2013 16:16:42 +0200 Subject: [PATCH 41/44] generator: fixed NativeStructGen's formatting --- generator/NativeStructGen.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index 00bf25c16..2871d5063 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -132,10 +132,11 @@ namespace GtkSharp.Generation 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); } From 21c9c9ff8c46b933de67287f645e21d639865f95 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 29 Aug 2013 16:26:54 +0200 Subject: [PATCH 42/44] generator: remove bitfields from Equals/GetHashCode --- generator/NativeStructGen.cs | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index 2871d5063..8f4b6562c 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -176,32 +176,18 @@ namespace GtkSharp.Generation 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}"); From 50f07d17adb7dc6fd5e48410ae8d2b32599113f8 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 29 Aug 2013 16:47:34 +0200 Subject: [PATCH 43/44] generator: removed redundant allocation --- generator/NativeStructGen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index 8f4b6562c..f605d4e83 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -156,7 +156,7 @@ namespace GtkSharp.Generation 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}"); From 587f0f56e76567ba58c18909fc72f8aa4748c52f Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 6 Sep 2013 13:21:20 +0200 Subject: [PATCH 44/44] generator: NativeStructGen needs to be partial --- generator/NativeStructGen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/NativeStructGen.cs b/generator/NativeStructGen.cs index f605d4e83..f75ea0306 100644 --- a/generator/NativeStructGen.cs +++ b/generator/NativeStructGen.cs @@ -105,7 +105,7 @@ namespace GtkSharp.Generation 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"); }