[Gtk-sharp-list] Gtk# refcount problem
Martin Baulig
martin@gnome.org
15 Sep 2002 17:01:34 +0200
--=-=-=
Hi,
there's a problem with the new refcounting code in gtk#:
Currently, ObjectManager.CreateObject() may create several managed GLib.Object's for the
same underlying GObject. Since the GLib.Object's calls g_object_unref() when it's
disposed, CreateObject() must g_object_ref() the GObject.
Here's a patch:
--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=diff
? api/generated-stamp
? parser/gapi_format_xml
Index: glib/ObjectManager.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/glib/ObjectManager.cs,v
retrieving revision 1.5
diff -u -u -r1.5 ObjectManager.cs
--- glib/ObjectManager.cs 20 Aug 2002 19:56:17 -0000 1.5
+++ glib/ObjectManager.cs 15 Sep 2002 15:02:18 -0000
@@ -30,7 +30,9 @@
Type t = Type.GetType (mangled);
if (t == null)
return null;
- return (GLib.Object) Activator.CreateInstance (t, new object[] {raw});
+ GLib.Object retval = (GLib.Object) Activator.CreateInstance (t, new object[] {raw});
+ retval.Ref ();
+ return retval;
}
public static void RegisterType (string native_name, string managed_name, string assembly)
Index: gnome/Modules.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/gnome/Modules.cs,v
retrieving revision 1.2
diff -u -u -r1.2 Modules.cs
--- gnome/Modules.cs 30 Jul 2002 23:02:11 -0000 1.2
+++ gnome/Modules.cs 15 Sep 2002 15:02:19 -0000
@@ -3,7 +3,7 @@
using System;
using System.Runtime.InteropServices;
- class Modules
+ public class Modules
{
[DllImport("libgnome-2.so.0")]
static extern System.IntPtr libgnome_module_info_get ();
Index: sample/CanvasExample.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/sample/CanvasExample.cs,v
retrieving revision 1.2
diff -u -u -r1.2 CanvasExample.cs
--- sample/CanvasExample.cs 6 Aug 2002 05:42:57 -0000 1.2
+++ sample/CanvasExample.cs 15 Sep 2002 15:02:19 -0000
@@ -115,6 +115,7 @@
sa.RetVal = true;
return;
}
+ break;
case EventType.TwoButtonPress:
ChangeItemColor (item);
sa.RetVal = true;
Index: sample/Scribble.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/sample/Scribble.cs,v
retrieving revision 1.2
diff -u -u -r1.2 Scribble.cs
--- sample/Scribble.cs 4 Aug 2002 04:23:13 -0000 1.2
+++ sample/Scribble.cs 15 Sep 2002 15:02:19 -0000
@@ -30,10 +30,10 @@
darea.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEvent);
darea.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEvent);
darea.Events = (int)EventMask.ExposureMask |
- EventMask.LeaveNotifyMask |
- EventMask.ButtonPressMask |
- EventMask.PointerMotionMask |
- EventMask.PointerMotionHintMask;
+ (int)EventMask.LeaveNotifyMask |
+ (int)EventMask.ButtonPressMask |
+ (int)EventMask.PointerMotionMask |
+ (int)EventMask.PointerMotionHintMask;
win.ShowAll ();
Application.Run ();
--=-=-=
--
Martin Baulig
martin@gnome.org
--=-=-=--