diff --git a/ChangeLog b/ChangeLog index abe312f2a..e23a21520 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-08-13 Mike Kestner + + * generator/ByRefGen.cs : implement IManualMarshaler. + * generator/Parameter.cs : use StructParameter for ByRefGen. + 2007-08-13 Mike Kestner * generator/*.cs : switch to IntPtr marshaling for struct types diff --git a/generator/ByRefGen.cs b/generator/ByRefGen.cs index a60d7ea82..2cb3fab18 100644 --- a/generator/ByRefGen.cs +++ b/generator/ByRefGen.cs @@ -24,36 +24,39 @@ namespace GtkSharp.Generation { using System; - public class ByRefGen : SimpleBase { + public class ByRefGen : SimpleBase, IManualMarshaler { public ByRefGen (string ctype, string type) : base (ctype, type) {} public override string MarshalType { get { - return "ref " + QualifiedName; - } - } - - public override string MarshalReturnType { - get { - return QualifiedName; - } - } - - public override string ToNativeReturnType { - get { - return QualifiedName; + return "IntPtr"; } } public override string CallByName (string var_name) { - return "ref " + var_name; + return "native_" + var_name; } - public override string ToNativeReturn(string var) + public string AllocNative () { - return var; + return "Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + QualifiedName + ")))"; + } + + public string AllocNative (string var_name) + { + return "GLib.Marshaller.StructureToPtrAlloc (" + var_name + ")"; + } + + public override string FromNative (string var_name) + { + return String.Format ("({0}) Marshal.PtrToStructure ({1}, typeof ({0}))", QualifiedName, var_name); + } + + public string ReleaseNative (string var_name) + { + return "GLib.Marshaller.Free (" + var_name + ")"; } } } diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 5d961fb27..fd560a8aa 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -240,7 +240,7 @@ namespace GtkSharp.Generation { if (PassAs != "out") result += " = " + (gen as IManualMarshaler).AllocNative (CallName); return new string [] { result + ";" }; - } else if (PassAs == "out" && CSType != MarshalType && !(gen is StructBase || gen is ByRefGen)) + } else if (PassAs == "out" && CSType != MarshalType) return new string [] { gen.MarshalType + " native_" + CallName + ";" }; return new string [0]; @@ -256,7 +256,7 @@ namespace GtkSharp.Generation { return SymbolTable.Table.CallByName (CType, CallName + "_wrapper"); else if (PassAs != String.Empty) { call_parm = PassAs + " "; - if (CSType != MarshalType && !(gen is ByRefGen)) + if (CSType != MarshalType) call_parm += "native_"; call_parm += CallName; } else if (gen is IManualMarshaler) @@ -279,7 +279,7 @@ namespace GtkSharp.Generation { if (PassAs != "out") result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";"; return result; - } else if (PassAs != String.Empty && MarshalType != CSType && !(gen is StructBase || gen is ByRefGen)) + } else if (PassAs != String.Empty && MarshalType != CSType) return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" }; return new string [0]; } @@ -630,7 +630,7 @@ namespace GtkSharp.Generation { } } else if (p.CType == "GError**") p = new ErrorParameter (parm); - else if (gen is StructBase) { + else if (gen is StructBase || gen is ByRefGen) { p = new StructParameter (parm); } else if (gen is CallbackGen) { has_cb = true;