* generator/Parameters.cs (AllowComplexRefs): new property for
whether or not to allow "complex" ref/out args. (Validate): update for that * generator/Signal.cs: set AllowComplexRefs false on the params. (Validate): fix the messages (GenCallback, GenEventHandler): properly handle ref/out args, by manually pointerifying them (except for boxed args, which are already pointers). * glib/Marshaller.cs (StructureToPtrAlloc): Rename from PtrToStructureAlloc, since it wraps Marshal.StructureToPtr. svn path=/trunk/gtk-sharp/; revision=46773
This commit is contained in:
parent
a0912263e2
commit
635ed16db4
5 changed files with 73 additions and 26 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2005-06-30 Dan Winship <danw@novell.com>
|
||||||
|
|
||||||
|
* generator/Parameters.cs (AllowComplexRefs): new property for
|
||||||
|
whether or not to allow "complex" ref/out args.
|
||||||
|
(Validate): update for that
|
||||||
|
|
||||||
|
* generator/Signal.cs: set AllowComplexRefs false on the params.
|
||||||
|
(Validate): fix the messages
|
||||||
|
(GenCallback, GenEventHandler): properly handle ref/out args, by
|
||||||
|
manually pointerifying them (except for boxed args, which are
|
||||||
|
already pointers).
|
||||||
|
|
||||||
|
* glib/Marshaller.cs (StructureToPtrAlloc): Rename from
|
||||||
|
PtrToStructureAlloc, since it wraps Marshal.StructureToPtr.
|
||||||
|
|
||||||
2005-06-28 Mike Kestner <mkestner@novell.com>
|
2005-06-28 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* gtk/ComboBox.custom : add ctor (string[]).
|
* gtk/ComboBox.custom : add ctor (string[]).
|
||||||
|
|
|
@ -223,8 +223,8 @@
|
||||||
<since version="Gtk# 2.4" />
|
<since version="Gtk# 2.4" />
|
||||||
</Docs>
|
</Docs>
|
||||||
</Member>
|
</Member>
|
||||||
<Member MemberName="PtrToStructureAlloc">
|
<Member MemberName="StructureToPtrAlloc">
|
||||||
<MemberSignature Language="C#" Value="public static IntPtr PtrToStructureAlloc (object o);" />
|
<MemberSignature Language="C#" Value="public static IntPtr StructureToPtrAlloc (object o);" />
|
||||||
<MemberType>Method</MemberType>
|
<MemberType>Method</MemberType>
|
||||||
<ReturnValue>
|
<ReturnValue>
|
||||||
<ReturnType>System.IntPtr</ReturnType>
|
<ReturnType>System.IntPtr</ReturnType>
|
||||||
|
@ -233,10 +233,10 @@
|
||||||
<Parameter Name="o" Type="System.Object" />
|
<Parameter Name="o" Type="System.Object" />
|
||||||
</Parameters>
|
</Parameters>
|
||||||
<Docs>
|
<Docs>
|
||||||
<summary>To be added</summary>
|
<param name="o">the structure to marshal</param>
|
||||||
<param name="o">a <see cref="T:System.Object" /></param>
|
<summary>Marshals a structure to newly-allocated memory.</summary>
|
||||||
<returns>a <see cref="T:System.IntPtr" /></returns>
|
<returns>a pointer to the newly-allocated memory</returns>
|
||||||
<remarks>To be added</remarks>
|
<remarks>This is like <see cref="M:System.Runtime.InteropServices.Marshal.StructureToPtr" /> except that it allocates the memory for the unmanaged copy itself. You should free the memory with <see cref="M:System.Runtime.InteropServices.Marshal.FreeHGlobal" /> when you are done with it.</remarks>
|
||||||
<since version="Gtk# 2.4" />
|
<since version="Gtk# 2.4" />
|
||||||
</Docs>
|
</Docs>
|
||||||
</Member>
|
</Member>
|
||||||
|
|
|
@ -310,6 +310,12 @@ namespace GtkSharp.Generation {
|
||||||
set { is_static = value; }
|
set { is_static = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool allow_complex_refs;
|
||||||
|
public bool AllowComplexRefs {
|
||||||
|
get { return allow_complex_refs; }
|
||||||
|
set { allow_complex_refs = value; }
|
||||||
|
}
|
||||||
|
|
||||||
bool cleared = false;
|
bool cleared = false;
|
||||||
void Clear ()
|
void Clear ()
|
||||||
{
|
{
|
||||||
|
@ -344,6 +350,14 @@ namespace GtkSharp.Generation {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p.PassAs != "" && !allow_complex_refs) {
|
||||||
|
if (!(p.Generatable is BoxedGen) &&
|
||||||
|
!(p.Generatable is SimpleGen)) {
|
||||||
|
Console.Write("Complex " + p.PassAs + " param " + p.Name + " ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (p.Generatable is CallbackGen) {
|
if (p.Generatable is CallbackGen) {
|
||||||
has_cb = true;
|
has_cb = true;
|
||||||
if (i == Count - 3 &&
|
if (i == Count - 3 &&
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace GtkSharp.Generation {
|
||||||
name = elem.GetAttribute ("name");
|
name = elem.GetAttribute ("name");
|
||||||
retval = new ReturnValue (elem ["return-type"]);
|
retval = new ReturnValue (elem ["return-type"]);
|
||||||
parms = new Parameters (elem["parameters"]);
|
parms = new Parameters (elem["parameters"]);
|
||||||
|
parms.AllowComplexRefs = false;
|
||||||
this.container_type = container_type;
|
this.container_type = container_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,16 +57,16 @@ namespace GtkSharp.Generation {
|
||||||
public bool Validate ()
|
public bool Validate ()
|
||||||
{
|
{
|
||||||
if (Name == "") {
|
if (Name == "") {
|
||||||
Console.Write ("bad signal " + Name);
|
Console.Write ("Nameless signal ");
|
||||||
Statistics.ThrottledCount++;
|
Statistics.ThrottledCount++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parms.Validate ())
|
if (!parms.Validate () || !retval.Validate ()) {
|
||||||
return false;
|
Console.Write (" in signal " + Name + " ");
|
||||||
|
Statistics.ThrottledCount++;
|
||||||
if (!retval.Validate ())
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -208,9 +209,8 @@ namespace GtkSharp.Generation {
|
||||||
for (int idx = 1; idx < parms.Count; idx++) {
|
for (int idx = 1; idx < parms.Count; idx++) {
|
||||||
Parameter p = parms [idx];
|
Parameter p = parms [idx];
|
||||||
IGeneratable igen = p.Generatable;
|
IGeneratable igen = p.Generatable;
|
||||||
if (p.PassAs == "out")
|
if (p.PassAs != "out") {
|
||||||
finish += "\t\t\targ" + idx + " = " + igen.ToNativeReturn ("((" + p.CSType + ")args.Args[" + (idx - 1) + "])") + ";\n";
|
if (igen is ManualGen) {
|
||||||
else if (igen is ManualGen) {
|
|
||||||
sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx);
|
sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx);
|
||||||
sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1);
|
sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1);
|
||||||
sw.WriteLine("\t\t\telse {");
|
sw.WriteLine("\t\t\telse {");
|
||||||
|
@ -219,6 +219,9 @@ namespace GtkSharp.Generation {
|
||||||
} else
|
} else
|
||||||
sw.WriteLine("\t\t\targs.Args[" + (idx - 1) + "] = " + igen.FromNative ("arg" + idx) + ";");
|
sw.WriteLine("\t\t\targs.Args[" + (idx - 1) + "] = " + igen.FromNative ("arg" + idx) + ";");
|
||||||
}
|
}
|
||||||
|
if (p.PassAs != "")
|
||||||
|
finish += "\t\t\targ" + idx + " = " + igen.ToNativeReturn ("((" + p.CSType + ")args.Args[" + (idx - 1) + "])") + ";\n";
|
||||||
|
}
|
||||||
sw.WriteLine("\t\t\t{0} handler = ({0}) sig.Handler;", EventHandlerQualifiedName);
|
sw.WriteLine("\t\t\t{0} handler = ({0}) sig.Handler;", EventHandlerQualifiedName);
|
||||||
sw.WriteLine("\t\t\thandler (GLib.Object.GetObject (arg0), args);");
|
sw.WriteLine("\t\t\thandler (GLib.Object.GetObject (arg0), args);");
|
||||||
sw.WriteLine (finish);
|
sw.WriteLine (finish);
|
||||||
|
@ -299,13 +302,28 @@ namespace GtkSharp.Generation {
|
||||||
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
|
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
|
||||||
string cleanup = "";
|
string cleanup = "";
|
||||||
for (int i = 1; i < parms.Count; i++) {
|
for (int i = 1; i < parms.Count; i++) {
|
||||||
if (parms [i].PassAs == "out") {
|
Parameter p = parms [i];
|
||||||
sw.WriteLine ("\t\t\tvals [" + i + "] = GLib.Value.Empty;");
|
if (p.PassAs != "") {
|
||||||
cleanup += "\t\t\t" + parms [i].Name + " = (" + parms [i].CSType + ") vals [" + i + "];\n";
|
if (SymbolTable.Table.IsBoxed (p.CType)) {
|
||||||
} else if (parms [i].IsLength && parms [i - 1].IsString)
|
if (p.PassAs == "ref")
|
||||||
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + ");");
|
||||||
|
else
|
||||||
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value ((GLib.GType)typeof (" + p.CSType + "));");
|
||||||
|
cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
|
||||||
|
} else {
|
||||||
|
if (p.PassAs == "ref")
|
||||||
|
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc ((" + p.CSType + ") " + p.Name + ");");
|
||||||
|
else
|
||||||
|
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.CSType + ")));");
|
||||||
|
|
||||||
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + "_ptr);");
|
||||||
|
cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.CSType + "));\n";
|
||||||
|
cleanup += "\t\t\tMarshal.FreeHGlobal (" + p.Name + "_ptr);\n";
|
||||||
|
}
|
||||||
|
} else if (p.IsLength && parms [i - 1].IsString)
|
||||||
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + parms [i-1].Name + ".Length);");
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + parms [i-1].Name + ".Length);");
|
||||||
else
|
else
|
||||||
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + parms [i].Name + ");");
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + ");");
|
||||||
|
|
||||||
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + i + "]);");
|
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + i + "]);");
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ namespace GLib {
|
||||||
return glibsharp_utf16_to_unichar ((ushort) c);
|
return glibsharp_utf16_to_unichar ((ushort) c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntPtr PtrToStructureAlloc (object o)
|
public static IntPtr StructureToPtrAlloc (object o)
|
||||||
{
|
{
|
||||||
IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf (o));
|
IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf (o));
|
||||||
Marshal.StructureToPtr (o, result, false);
|
Marshal.StructureToPtr (o, result, false);
|
||||||
|
|
Loading…
Reference in a new issue