From 08b43fbd7647067c6ff6d59b6310b08360e2ff8e Mon Sep 17 00:00:00 2001 From: Christian Hoff Date: Thu, 13 Aug 2009 14:46:33 +0000 Subject: [PATCH] 2009-08-13 Christian Hoff * generator/IGeneratable.cs: Remove MarshalReturnType, ToNativeReturnType, FromNativeReturn and ToNativeReturn as they never returned something else than MarshalType, FromNative/AllocNative and CallByName, respectively. * generator/Signal.cs: Use AllocNative for IManualMarshalers. svn path=/trunk/gtk-sharp/; revision=139849 --- ChangeLog | 7 +++++++ generator/ConstStringGen.cs | 5 ----- generator/FieldBase.cs | 17 ++++++++++------- generator/GenBase.cs | 28 +++------------------------- generator/HandleBase.cs | 10 ---------- generator/IGeneratable.cs | 14 -------------- generator/ManagedCallString.cs | 4 +++- generator/ReturnValue.cs | 8 ++++---- generator/Signal.cs | 8 +++++--- generator/SimpleBase.cs | 22 ---------------------- generator/StructField.cs | 2 +- generator/SymbolTable.cs | 32 -------------------------------- 12 files changed, 33 insertions(+), 124 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c6689ee5..21f834bd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-08-13 Christian Hoff + + * generator/IGeneratable.cs: Remove MarshalReturnType, ToNativeReturnType, + FromNativeReturn and ToNativeReturn as they never returned something else + than MarshalType, FromNative/AllocNative and CallByName, respectively. + * generator/Signal.cs: Use AllocNative for IManualMarshalers. + 2009-08-12 Christian Hoff * configure.in.in: Detect GDK backend. diff --git a/generator/ConstStringGen.cs b/generator/ConstStringGen.cs index 70f882ef2..72fc8870e 100644 --- a/generator/ConstStringGen.cs +++ b/generator/ConstStringGen.cs @@ -40,11 +40,6 @@ namespace GtkSharp.Generation { return "GLib.Marshaller.Utf8PtrToString (" + var + ")"; } - public override string ToNativeReturn (string var) - { - return "GLib.Marshaller.StringToPtrGStrdup (" + var + ")"; - } - public string AllocNative (string managed_var) { return "GLib.Marshaller.StringToPtrGStrdup (" + managed_var + ")"; diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 3fc07a83b..91a764464 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -115,7 +115,7 @@ namespace GtkSharp.Generation { if (getterName != null) { sw.WriteLine (indent + "[DllImport (\"{0}\")]", gen_info.GluelibName); sw.WriteLine (indent + "extern static {0} {1} ({2} raw);", - table.GetMarshalReturnType (CType), getterName, + table.GetMarshalType (CType), getterName, container_type.MarshalType); } @@ -164,7 +164,7 @@ namespace GtkSharp.Generation { } else if (getterName != null) { sw.WriteLine (indent + "\tget {"); container_type.Prepare (sw, indent + "\t\t"); - sw.WriteLine (indent + "\t\t" + CSType + " result = " + table.FromNativeReturn (ctype, getterName + " (" + container_type.CallByName () + ")") + ";"); + sw.WriteLine (indent + "\t\t" + CSType + " result = " + table.FromNative (ctype, getterName + " (" + container_type.CallByName () + ")") + ";"); container_type.Finish (sw, indent + "\t\t"); sw.WriteLine (indent + "\t\treturn result;"); sw.WriteLine (indent + "\t}"); @@ -175,13 +175,16 @@ namespace GtkSharp.Generation { 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.GetMarshalReturnType (CType) + "* raw_ptr = (" + table.GetMarshalReturnType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");"); - sw.WriteLine (indent + "\t\t\treturn " + table.FromNativeReturn (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}"); } + IGeneratable gen = table [CType]; + string to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative ("value") : gen.CallByName ("value"); + if (Setter != null) { sw.Write (indent + "\tset "); Setter.GenerateBody (gen_info, container_type, "\t"); @@ -189,7 +192,7 @@ namespace GtkSharp.Generation { } else if (setterName != null) { sw.WriteLine (indent + "\tset {"); container_type.Prepare (sw, indent + "\t\t"); - sw.WriteLine (indent + "\t\t" + setterName + " (" + container_type.CallByName () + ", " + table.CallByName (ctype, "value") + ");"); + sw.WriteLine (indent + "\t\t" + setterName + " (" + container_type.CallByName () + ", " + to_native + ");"); container_type.Finish (sw, indent + "\t\t"); sw.WriteLine (indent + "\t}"); } else if (Writable && offsetName != null) { @@ -199,8 +202,8 @@ namespace GtkSharp.Generation { 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.GetMarshalReturnType (CType) + "* raw_ptr = (" + table.GetMarshalReturnType (CType) + "*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");"); - sw.WriteLine (indent + "\t\t\t*raw_ptr = " + table.ToNativeReturn (ctype, "value") + ";"); + 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}"); diff --git a/generator/GenBase.cs b/generator/GenBase.cs index ed68c5c30..1e4011ce0 100644 --- a/generator/GenBase.cs +++ b/generator/GenBase.cs @@ -72,12 +72,6 @@ namespace GtkSharp.Generation { } } - public virtual string MarshalReturnType { - get { - return MarshalType; - } - } - public abstract string MarshalType { get; } public string Name { @@ -100,16 +94,10 @@ namespace GtkSharp.Generation { } } - public virtual string ToNativeReturnType { - get { - return MarshalType; - } - } - protected void AppendCustom (StreamWriter sw, string custom_dir) - { - AppendCustom (sw, custom_dir, Name); - } + { + AppendCustom (sw, custom_dir, Name); + } protected void AppendCustom (StreamWriter sw, string custom_dir, string type_name) { @@ -130,16 +118,6 @@ namespace GtkSharp.Generation { public abstract string FromNative (string var); - public virtual string FromNativeReturn (string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn (string var) - { - return CallByName (var); - } - public abstract bool Validate (); public void Generate () diff --git a/generator/HandleBase.cs b/generator/HandleBase.cs index 08f7805a3..70ab8e7ac 100644 --- a/generator/HandleBase.cs +++ b/generator/HandleBase.cs @@ -58,16 +58,6 @@ namespace GtkSharp.Generation { return FromNative (var, false); } - public string FromNativeReturn (string var, bool owned) - { - return FromNative (var, owned); - } - - public override string FromNativeReturn (string var) - { - return FromNativeReturn (var, false); - } - public void WriteAccessors (StreamWriter sw, string indent, string var) { sw.WriteLine (indent + "get {"); diff --git a/generator/IGeneratable.cs b/generator/IGeneratable.cs index 1608fd7cd..3fd532c6a 100644 --- a/generator/IGeneratable.cs +++ b/generator/IGeneratable.cs @@ -37,14 +37,6 @@ namespace GtkSharp.Generation { // signature when passing this generatable to unmanaged code string MarshalType {get;} - // The type to use as the return type in an import signature when - // receiving this generatable back from unmanaged code - string MarshalReturnType {get;} - - // The type to use in a managed callback signature when returning this - // generatable to unmanaged code - string ToNativeReturnType {get;} - // The value returned by callbacks that are interrupted prematurely // by managed exceptions or other conditions where an appropriate // value can't be otherwise obtained. @@ -56,12 +48,6 @@ namespace GtkSharp.Generation { // Generates an expression to convert var from MarshalType string FromNative (string var); - // Generates an expression to convert var from MarshalReturnType - string FromNativeReturn (string var); - - // Generates an expression to convert var to ToNativeReturnType - string ToNativeReturn (string var); - bool Validate (); void Generate (); diff --git a/generator/ManagedCallString.cs b/generator/ManagedCallString.cs index 766f636f9..f4387449e 100644 --- a/generator/ManagedCallString.cs +++ b/generator/ManagedCallString.cs @@ -141,8 +141,10 @@ namespace GtkSharp.Generation { continue; else if (igen is StructBase || igen is ByRefGen) ret += indent + String.Format ("if ({0} != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (my{0}, {0}, false);\n", p.Name); + else if (igen is IManualMarshaler) + ret += String.Format ("{0}{1} = {2};", indent, p.Name, (igen as IManualMarshaler).AllocNative ("my" + p.Name)); else - ret += indent + p.Name + " = " + igen.ToNativeReturn ("my" + p.Name) + ";\n"; + ret += indent + p.Name + " = " + igen.CallByName ("my" + p.Name) + ";\n"; } return ret; diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index bbf0c2905..05d4e7f99 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -102,7 +102,7 @@ namespace GtkSharp.Generation { return String.Empty; else if (is_null_term) return "IntPtr"; - return IGen.MarshalReturnType + (is_array ? "[]" : String.Empty); + return IGen.MarshalType + (is_array ? "[]" : String.Empty); } } @@ -110,7 +110,7 @@ namespace GtkSharp.Generation { get { if (IGen == null) return String.Empty; - return IGen.ToNativeReturnType + (is_array || is_null_term ? "[]" : String.Empty); + return IGen.MarshalType + (is_array || is_null_term ? "[]" : String.Empty); } } @@ -130,7 +130,7 @@ namespace GtkSharp.Generation { else if (is_null_term) return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false"); else - return IGen.FromNativeReturn (var); + return IGen.FromNative (var); } public string ToNative (string var) @@ -151,7 +151,7 @@ namespace GtkSharp.Generation { else if (IGen is OpaqueGen && owned) return var + " == null ? IntPtr.Zero : " + var + ".OwnedCopy"; else - return IGen.ToNativeReturn (var); + return IGen.CallByName (var); } public bool Validate () diff --git a/generator/Signal.cs b/generator/Signal.cs index a3be2772e..bd6937b0b 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -178,10 +178,12 @@ namespace GtkSharp.Generation { } else sw.WriteLine("\t\t\t\targs.Args[" + idx + "] = " + p.FromNative ("arg" + idx) + ";"); } - if (igen is StructBase && p.PassAs == "ref") + if ((igen is StructBase || igen is ByRefGen) && p.PassAs != "") finish += "\t\t\t\tif (arg" + idx + " != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (args.Args[" + idx + "], arg" + idx + ", false);\n"; + else if (igen is IManualMarshaler && p.PassAs != "") + finish += String.Format ("\t\t\t\targ{0} = {1};\n", idx, (igen as IManualMarshaler).AllocNative ("args.Args[" + idx + "]")); else if (p.PassAs != "") - finish += "\t\t\t\targ" + idx + " = " + igen.ToNativeReturn ("((" + p.CSType + ")args.Args[" + idx + "])") + ";\n"; + finish += "\t\t\t\targ" + idx + " = " + igen.CallByName ("((" + p.CSType + ")args.Args[" + idx + "])") + ";\n"; } return finish; } @@ -198,7 +200,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t\t\tif (args.RetVal == null)"); sw.WriteLine ("\t\t\t\t\treturn false;"); } - sw.WriteLine("\t\t\t\treturn " + SymbolTable.Table.ToNativeReturn (retval.CType, "((" + retval.CSType + ")args.RetVal)") + ";"); + sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative (String.Format ("(({0}) args.RetVal)", retval.CSType))); } sw.WriteLine("\t\t\t} catch (Exception) {"); sw.WriteLine ("\t\t\t\tException ex = new Exception (\"args.RetVal or 'out' property unset or set to incorrect type in " + EventHandlerQualifiedName + " callback\");"); diff --git a/generator/SimpleBase.cs b/generator/SimpleBase.cs index 38bfbe36b..0a6f2b8fa 100644 --- a/generator/SimpleBase.cs +++ b/generator/SimpleBase.cs @@ -66,24 +66,12 @@ namespace GtkSharp.Generation { } } - public virtual string MarshalReturnType { - get { - return MarshalType; - } - } - public virtual string DefaultValue { get { return default_value; } } - public virtual string ToNativeReturnType { - get { - return MarshalType; - } - } - public virtual string CallByName (string var) { return var; @@ -93,16 +81,6 @@ namespace GtkSharp.Generation { { return var; } - - public virtual string FromNativeReturn(string var) - { - return FromNative (var); - } - - public virtual string ToNativeReturn(string var) - { - return CallByName (var); - } public bool Validate () { diff --git a/generator/StructField.cs b/generator/StructField.cs index 58f92d494..50389a75b 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -134,7 +134,7 @@ namespace GtkSharp.Generation { sw.WriteLine (); if (Access != "private") { sw.WriteLine (indent + Access + " " + wrapped + " " + wrapped_name + " {"); - sw.WriteLine (indent + "\tget { return " + table.FromNativeReturn (CType, Name) + "; }"); + sw.WriteLine (indent + "\tget { return " + table.FromNative (CType, Name) + "; }"); sw.WriteLine (indent + "}"); } } else if (IsPointer && CSType != "string") { diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 4fc0a8711..6fcebbce3 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -213,22 +213,6 @@ namespace GtkSharp.Generation { return types [type]; } - public string FromNativeReturn(string c_type, string val) - { - IGeneratable gen = this[c_type]; - if (gen == null) - return ""; - return gen.FromNativeReturn (val); - } - - public string ToNativeReturn(string c_type, string val) - { - IGeneratable gen = this[c_type]; - if (gen == null) - return ""; - return gen.ToNativeReturn (val); - } - public string FromNative(string c_type, string val) { IGeneratable gen = this[c_type]; @@ -253,22 +237,6 @@ namespace GtkSharp.Generation { return gen.Name; } - public string GetMarshalReturnType(string c_type) - { - IGeneratable gen = this[c_type]; - if (gen == null) - return ""; - return gen.MarshalReturnType; - } - - public string GetToNativeReturnType(string c_type) - { - IGeneratable gen = this[c_type]; - if (gen == null) - return ""; - return gen.ToNativeReturnType; - } - public string GetMarshalType(string c_type) { IGeneratable gen = this[c_type];