From e3a26238b6ddf7890e5c928536143ae353b874d9 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 31 Mar 2005 16:31:31 +0000 Subject: [PATCH] 2005-03-31 Mike Kestner * glib/ManagedValue.cs : add null/NULL guarding to Copy, Free, WrapObject, and ObjectForWrapper. [Fixes #74197] svn path=/trunk/gtk-sharp/; revision=42434 --- ChangeLog | 5 +++++ glib/ManagedValue.cs | 8 ++++++++ sample/ManagedTreeViewDemo.cs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 094ef8cb5..e1aa673ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-03-31 Mike Kestner + + * glib/ManagedValue.cs : add null/NULL guarding to Copy, Free, + WrapObject, and ObjectForWrapper. [Fixes #74197] + 2005-03-30 Jeroen Zwartepoorte * parser/gapi2xml.pl : parse gst type macros. diff --git a/glib/ManagedValue.cs b/glib/ManagedValue.cs index 1f5d2d98a..5923524d6 100644 --- a/glib/ManagedValue.cs +++ b/glib/ManagedValue.cs @@ -56,23 +56,31 @@ namespace GLib { static IntPtr Copy (IntPtr ptr) { + if (ptr == IntPtr.Zero) + return ptr; GCHandle gch = (GCHandle) ptr; return (IntPtr) GCHandle.Alloc (gch.Target); } static void Free (IntPtr ptr) { + if (ptr == IntPtr.Zero) + return; GCHandle gch = (GCHandle) ptr; gch.Free (); } public static IntPtr WrapObject (object obj) { + if (obj == null) + return IntPtr.Zero; return (IntPtr) GCHandle.Alloc (obj); } public static object ObjectForWrapper (IntPtr ptr) { + if (ptr == IntPtr.Zero) + return null; return ((GCHandle)ptr).Target; } } diff --git a/sample/ManagedTreeViewDemo.cs b/sample/ManagedTreeViewDemo.cs index cd53b4036..ef06e4061 100644 --- a/sample/ManagedTreeViewDemo.cs +++ b/sample/ManagedTreeViewDemo.cs @@ -24,7 +24,7 @@ namespace GtkSamples { private static void PopulateStore () { store = new ListStore (typeof (Pair)); - string[] combs = {"foo", "bar", "baz", "quux"}; + string[] combs = {null, "foo", "bar", "baz"}; foreach (string a in combs) { foreach (string b in combs) { store.AppendValues (new Pair (a, b));