2008-04-04 Mike Kestner <mkestner@novell.com>

* atk/Atk.metadata: markup all the Ref* methods to indicate owned refs.
	* generator/ReturnValue.cs: Add owned object ToNative handling.
	* generator/VirtualMethod.cs: Split ToNative call from managed method
	invocation to avoid duplicate calls in null checking scenarios.
	* glib/Object.cs: add OwnedHandle property for use by language binding
	code which needs to pass owned refs to native methods.

svn path=/trunk/gtk-sharp/; revision=99849
This commit is contained in:
Mike Kestner 2008-04-04 16:10:08 +00:00
parent 1a64851790
commit bdeb30bbad
5 changed files with 24 additions and 3 deletions

View file

@ -1,3 +1,12 @@
2008-04-04 Mike Kestner <mkestner@novell.com>
* atk/Atk.metadata: markup all the Ref* methods to indicate owned refs.
* generator/ReturnValue.cs: Add owned object ToNative handling.
* generator/VirtualMethod.cs: Split ToNative call from managed method
invocation to avoid duplicate calls in null checking scenarios.
* glib/Object.cs: add OwnedHandle property for use by language binding
code which needs to pass owned refs to native methods.
2008-04-04 Mike Kestner <mkestner@novell.com> 2008-04-04 Mike Kestner <mkestner@novell.com>
* atk/Object.custom: take out a ref on the return value of * atk/Object.custom: take out a ref on the return value of

View file

@ -1,5 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<metadata> <metadata>
<attr path="/api/namespace/interface[@cname='AtkComponent']/*[@name='RefAccessibleAtPoint']/return-type" name="owned">true</attr>
<attr path="/api/namespace/interface[@cname='AtkDocument']/method[@name='GetAttributes']/return-type" name="element_type">AtkAttribute*</attr> <attr path="/api/namespace/interface[@cname='AtkDocument']/method[@name='GetAttributes']/return-type" name="element_type">AtkAttribute*</attr>
<attr path="/api/namespace/interface[@cname='AtkDocument']/method[@name='GetDocument']" name="name">GetTheDocument</attr> <attr path="/api/namespace/interface[@cname='AtkDocument']/method[@name='GetDocument']" name="name">GetTheDocument</attr>
<attr path="/api/namespace/interface[@cname='AtkDocument']/virtual_method[@name='GetDocument']" name="name">GetTheDocument</attr> <attr path="/api/namespace/interface[@cname='AtkDocument']/virtual_method[@name='GetDocument']" name="name">GetTheDocument</attr>
@ -10,6 +11,9 @@
<attr path="/api/namespace/interface[@cname='AtkDocument']/virtual_method[@name='SetDocumentAttribute']" name="name">SetAttributeValue</attr> <attr path="/api/namespace/interface[@cname='AtkDocument']/virtual_method[@name='SetDocumentAttribute']" name="name">SetAttributeValue</attr>
<attr path="/api/namespace/interface[@cname='AtkEditableText']/method[@name='InsertText']/*/*[@name='position']" name="pass_as">ref</attr> <attr path="/api/namespace/interface[@cname='AtkEditableText']/method[@name='InsertText']/*/*[@name='position']" name="pass_as">ref</attr>
<attr path="/api/namespace/interface[@cname='AtkEditableText']/virtual_method[@name='InsertText']/*/*[@name='position']" name="pass_as">ref</attr> <attr path="/api/namespace/interface[@cname='AtkEditableText']/virtual_method[@name='InsertText']/*/*[@name='position']" name="pass_as">ref</attr>
<attr path="/api/namespace/interface[@cname='AtkImplementor']/*[@name='RefAccessible']/return-type" name="owned">true</attr>
<attr path="/api/namespace/interface[@cname='AtkSelection']/*[@name='RefSelection']/return-type" name="owned">true</attr>
<attr path="/api/namespace/interface[@cname='AtkTable']/*[@name='RefAt']/return-type" name="owned">true</attr>
<attr path="/api/namespace/interface[@cname='AtkValue']/*[@name='GetCurrentValue']/*/*[@name='value']" name="pass_as">out</attr> <attr path="/api/namespace/interface[@cname='AtkValue']/*[@name='GetCurrentValue']/*/*[@name='value']" name="pass_as">out</attr>
<attr path="/api/namespace/class[@cname='AtkState_']" name="name">StateManager</attr> <attr path="/api/namespace/class[@cname='AtkState_']" name="name">StateManager</attr>
<attr path="/api/namespace/object[@cname='AtkObject']/method[@name='GetAttributes']/return-type" name="element_type">AtkAttribute*</attr> <attr path="/api/namespace/object[@cname='AtkObject']/method[@name='GetAttributes']/return-type" name="element_type">AtkAttribute*</attr>

View file

@ -148,6 +148,8 @@ namespace GtkSharp.Generation {
if (IGen is IManualMarshaler) if (IGen is IManualMarshaler)
return (IGen as IManualMarshaler).AllocNative (var); return (IGen as IManualMarshaler).AllocNative (var);
else if (IGen is ObjectGen && owned)
return var + " == null ? IntPtr.Zero : " + var + ".OwnedHandle";
else else
return IGen.ToNativeReturn (var); return IGen.ToNativeReturn (var);
} }

View file

@ -97,11 +97,11 @@ namespace GtkSharp.Generation {
} else } else
sw.WriteLine ("\t\t\t\t" + call_string + ";"); sw.WriteLine ("\t\t\t\t" + call_string + ";");
} else } else
sw.WriteLine ("\t\t\t\t" + retval.ToNativeType + " __result = " + retval.ToNative (call_string) + ";"); sw.WriteLine ("\t\t\t\t" + retval.CSType + " __result = " + call_string + ";");
bool fatal = parms.HasOutParam || !retval.IsVoid; bool fatal = parms.HasOutParam || !retval.IsVoid;
sw.Write (call.Finish ("\t\t\t\t")); sw.Write (call.Finish ("\t\t\t\t"));
if (!retval.IsVoid) if (!retval.IsVoid)
sw.WriteLine ("\t\t\t\treturn __result;"); sw.WriteLine ("\t\t\t\treturn " + retval.ToNative ("__result") + ";");
sw.WriteLine ("\t\t\t} catch (Exception e) {"); sw.WriteLine ("\t\t\t} catch (Exception e) {");
sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");"); sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");

View file

@ -94,7 +94,7 @@ namespace GLib {
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_object_ref (IntPtr raw); static extern IntPtr g_object_ref (IntPtr raw);
public static Object GetObject(IntPtr o, bool owned_ref) public static Object GetObject(IntPtr o, bool owned_ref)
{ {
@ -342,6 +342,12 @@ namespace GLib {
} }
} }
public IntPtr OwnedHandle {
get {
return g_object_ref (handle);
}
}
Hashtable before_signals; Hashtable before_signals;
[Obsolete ("Replaced by GLib.Signal marshaling mechanism.")] [Obsolete ("Replaced by GLib.Signal marshaling mechanism.")]
protected Hashtable BeforeSignals { protected Hashtable BeforeSignals {