diff --git a/ChangeLog b/ChangeLog index f224e53e3..3031a84e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-04-04 Mike Kestner + + * 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 * atk/Object.custom: take out a ref on the return value of diff --git a/atk/Atk.metadata b/atk/Atk.metadata index 984832084..459df33a0 100644 --- a/atk/Atk.metadata +++ b/atk/Atk.metadata @@ -1,5 +1,6 @@ + true AtkAttribute* GetTheDocument GetTheDocument @@ -10,6 +11,9 @@ SetAttributeValue ref ref + true + true + true out StateManager AtkAttribute* diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index d6548cbda..1636004f6 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -148,6 +148,8 @@ namespace GtkSharp.Generation { if (IGen is IManualMarshaler) return (IGen as IManualMarshaler).AllocNative (var); + else if (IGen is ObjectGen && owned) + return var + " == null ? IntPtr.Zero : " + var + ".OwnedHandle"; else return IGen.ToNativeReturn (var); } diff --git a/generator/VirtualMethod.cs b/generator/VirtualMethod.cs index 23aa27937..79911012f 100644 --- a/generator/VirtualMethod.cs +++ b/generator/VirtualMethod.cs @@ -97,11 +97,11 @@ namespace GtkSharp.Generation { } else sw.WriteLine ("\t\t\t\t" + call_string + ";"); } 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; sw.Write (call.Finish ("\t\t\t\t")); 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\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");"); diff --git a/glib/Object.cs b/glib/Object.cs index 98128f1e3..b7a096d33 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -94,7 +94,7 @@ namespace GLib { } [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) { @@ -342,6 +342,12 @@ namespace GLib { } } + public IntPtr OwnedHandle { + get { + return g_object_ref (handle); + } + } + Hashtable before_signals; [Obsolete ("Replaced by GLib.Signal marshaling mechanism.")] protected Hashtable BeforeSignals {