2003-10-13 Mike Kestner <mkestner@ximian.com>

* gdk/Gdk.metadata : mark an array param on PixbufDestroyNotify
	* gdk/gdk-api.xml : regenerated
	* generator/CallbackGen.cs : Handle out params in callback sigs
	and ditch the object[] args handling for typed args.
	* generator/Parameters.cs : more proactive PassAs logic.  We now
	default all simple pointer types (uint*, int*, double*, etc...)
	to out params unless they are marked otherwise in the XML with a
	pass_as tag or an array tag.  [Fixes #32104]

svn path=/trunk/gtk-sharp/; revision=18993
This commit is contained in:
Mike Kestner 2003-10-13 21:53:40 +00:00
parent f314da0c9f
commit bdc5c7071f
5 changed files with 43 additions and 17 deletions

View file

@ -1,3 +1,14 @@
2003-10-13 Mike Kestner <mkestner@ximian.com>
* gdk/Gdk.metadata : mark an array param on PixbufDestroyNotify
* gdk/gdk-api.xml : regenerated
* generator/CallbackGen.cs : Handle out params in callback sigs
and ditch the object[] args handling for typed args.
* generator/Parameters.cs : more proactive PassAs logic. We now
default all simple pointer types (uint*, int*, double*, etc...)
to out params unless they are marked otherwise in the XML with a
pass_as tag or an array tag. [Fixes #32104]
2003-10-13 Mike Kestner <mkestner@ximian.com>
* gnome/Gnome.metadata : new xpath metadata rules

View file

@ -6,6 +6,7 @@
<attr path="//boxed[@cname='GdkColor']/method[@name='Parse']/return-type" name="type">gboolean</attr>
<attr path="//boxed[@cname='GdkColor']/method[@name='Parse']/*/*[@type='GdkColor*']" name="pass_as">ref</attr>
<attr path="//boxed[@cname='GdkCursor']" name="opaque">1</attr>
<attr path="//callback[@cname='GdkPixbufDestroyNotify']/*/*[@type='guchar*']" name="array">1</attr>
<attr path="//class[@cname='GdkEvent_']" name="name">EventHelper</attr>
<attr path="//class[@cname='GdkPango_']" name="name">PangoHelper</attr>
<attr path="//class[@cname='GdkPixbuf_']" name="hidden">1</attr>

View file

@ -3612,7 +3612,7 @@
<callback name="PixbufDestroyNotify" cname="GdkPixbufDestroyNotify">
<return-type type="void" />
<parameters>
<parameter type="guchar*" name="pixels" />
<parameter type="guchar*" name="pixels" array="1" />
<parameter type="gpointer" name="data" />
</parameters>
</callback>

View file

@ -104,12 +104,11 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\t{");
int count = (parms != null) ? parms.Count : 0;
if (count > 0)
sw.WriteLine ("\t\t\tobject[] _args = new object[{0}];", count);
int idx = 0;
bool need_sep = false;
bool need_ref_owned = true;
string call_str = "";
string cleanup_str = "";
for (int i = 0; i < count; i++)
{
string parm_name = parms[i].Name;
@ -122,22 +121,27 @@ namespace GtkSharp.Generation {
continue;
string cstype = parms[i].CSType;
// FIXME: Too much code copy/pasted here. Refactor?
ClassBase parm_wrapper = table.GetClassGen (ctype);
if (need_ref_owned && parm_wrapper != null && ((parm_wrapper is ObjectGen) || (parm_wrapper is InterfaceGen))) {
need_ref_owned = false;
sw.WriteLine("\t\t\tbool ref_owned = false;");
}
sw.WriteLine("\t\t\t_args[" + idx + "] = " + table.FromNative (ctype, parm_name) + ";");
sw.Write("\t\t\t" + cstype + " _arg" + idx);
if (parms[i].PassAs == "out") {
sw.WriteLine(";");
cleanup_str += "\t\t\t" + parm_name + " = " + table.CallByName (ctype, "_arg" + idx) + ";\n";
} else
sw.WriteLine(" = " + table.FromNative (ctype, parm_name) + ";");
if ((parm_wrapper != null && ((parm_wrapper is OpaqueGen))) || table.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\tif (_args[" + idx + "] == null)");
sw.WriteLine("\t\t\t\t_args[{0}] = new {1}({2});", idx, cstype, parm_name);
sw.WriteLine("\t\t\tif (_arg" + idx + " == null)");
sw.WriteLine("\t\t\t\t_arg{0} = new {1}({2});", idx, cstype, parm_name);
}
if (need_sep)
call_str += ", ";
else
need_sep = true;
call_str += String.Format ("({0}) _args[{1}]", cstype, idx);
call_str += String.Format ("{0} _arg{1}", parms[i].PassAs, idx);
idx++;
}
@ -154,9 +158,11 @@ namespace GtkSharp.Generation {
sw.WriteLine ("return (int) {0};", invoke);
else
sw.WriteLine ("return ({0}) {1};", m_ret, table.ToNativeReturn (rettype, invoke));
}
else
} else
sw.WriteLine (invoke + ";");
if (cleanup_str != "")
sw.Write (cleanup_str);
sw.WriteLine ("\t\t}");
sw.WriteLine ();

View file

@ -119,7 +119,16 @@ namespace GtkSharp.Generation {
public string PassAs {
get {
return elem.GetAttribute ("pass_as");
if (elem.HasAttribute ("pass_as"))
return elem.GetAttribute ("pass_as");
if (IsArray)
return "";
if (Generatable is SimpleGen && !(Generatable is ConstStringGen) && CType.EndsWith ("*") && !CSType.EndsWith ("IntPtr"))
return "out";
return "";
}
}
@ -283,7 +292,10 @@ namespace GtkSharp.Generation {
need_sep = true;
}
if (this [i].PassAs != "") {
if (type == "GError**") {
call_string += "out ";
import_sig += "out ";
} else if (this [i].PassAs != "" && !IsVarArgs) {
signature += this [i].PassAs + " ";
// We only need to do this for value types
if (type != "GError**" && m_type != "IntPtr" && m_type != "System.IntPtr")
@ -298,12 +310,8 @@ namespace GtkSharp.Generation {
call_parm = this [i].PassAs + " " + call_parm.Replace (".Handle", "_handle");
import_sig += this [i].PassAs + " ";
}
} else if (type == "GError**") {
call_string += "out ";
import_sig += "out ";
}
if (IsVarArgs && i == (Count - 2) && VAType == "length_param") {
call_string += this [Count - 1].Name + ".Length";
} else {