[Kde-bindings] KDE/kdebindings/csharp/qyoto

Richard Dale Richard_Dale at tipitina.demon.co.uk
Mon Jul 20 16:21:16 UTC 2009


SVN commit 999938 by rdale:

* Make SmokeMarshallers.GetInstance() lock the pointerMap and fix bug 
  caused by trying to access 'IsAlive' on a null weakRef. This caused the 
  colliding mice example to crash on startup. Thanks to meebey from Debian
  for the fixes, and to pusling for telling me about them.

CCMAIL: kde-bindings at kde.org


 M  +6 -0      ChangeLog  
 M  +42 -40    src/SmokeMarshallers.cs  


--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #999937:999938
@@ -1,3 +1,9 @@
+2009-07-20  Richard Dale  <richard.j.dale at gmail.com>
+	* Make SmokeMarshallers.GetInstance() lock the pointerMap and fix bug 
+	  caused by trying to access 'IsAlive' on a null weakRef. This caused the 
+	  colliding mice example to crash on startup. Thanks to meebey from Debian
+	  for the fixes, and to pusling for telling me about them.
+
 2009-05-10  Arno Rehn  <arno at arnorehn.de>
 	* Add a QPair marshaller. We still need a List<QPair<...>> one.
 	* Fix some memory leaks.
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #999937:999938
@@ -432,63 +432,65 @@
 		public static IntPtr GetInstance(IntPtr ptr, bool allInstances) {
 			WeakReference weakRef;
 			object strongRef;
-			if (!pointerMap.TryGetValue(ptr, out weakRef)) {
+			lock (pointerMap) {
+				if (!pointerMap.TryGetValue(ptr, out weakRef)) {
 #if DEBUG
-				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
-						&& QDebug.debugLevel >= DebugLevel.Extensive ) 
-				{
-					Console.WriteLine("GetInstance() pointerMap[0x{0:x8}] == null", (int) ptr);
+					if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
+							&& QDebug.debugLevel >= DebugLevel.Extensive ) 
+					{
+						Console.WriteLine("GetInstance() pointerMap[0x{0:x8}] == null", (int) ptr);
+					}
+#endif
+					return IntPtr.Zero;
 				}
-#endif
-				return IntPtr.Zero;
-			}
 
-			if (weakRef.IsAlive) {
+				if (weakRef != null && weakRef.IsAlive) {
 #if DEBUG
-				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
-						&& QDebug.debugLevel >= DebugLevel.Extensive ) 
-				{
-					Console.WriteLine("GetInstance() weakRef.IsAlive 0x{0:x8} -> {1}", (int) ptr, weakRef.Target);
-				}
+					if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
+							&& QDebug.debugLevel >= DebugLevel.Extensive ) 
+					{
+						Console.WriteLine("GetInstance() weakRef.IsAlive 0x{0:x8} -> {1}", (int) ptr, weakRef.Target);
+					}
 #endif
-				if (!allInstances && IsSmokeClass(weakRef.Target.GetType())) {
-					return IntPtr.Zero;
-				} 
+					if (!allInstances && IsSmokeClass(weakRef.Target.GetType())) {
+						return IntPtr.Zero;
+					} 
 
 #if DEBUG
-				GCHandle instanceHandle = DebugGCHandle.Alloc(weakRef.Target);
+					GCHandle instanceHandle = DebugGCHandle.Alloc(weakRef.Target);
 #else
-				GCHandle instanceHandle = GCHandle.Alloc(weakRef.Target);
+					GCHandle instanceHandle = GCHandle.Alloc(weakRef.Target);
 #endif
-				return (IntPtr) instanceHandle;
-			} else if (Environment.HasShutdownStarted && globalReferenceMap.TryGetValue(ptr, out strongRef)) {
+					return (IntPtr) instanceHandle;
+				} else if (Environment.HasShutdownStarted && globalReferenceMap.TryGetValue(ptr, out strongRef)) {
 #if DEBUG
-				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
-						&& QDebug.debugLevel >= DebugLevel.Extensive ) 
-				{
-					Console.WriteLine("GetInstance() strongRef 0x{0:x8} -> {1}", (int) ptr, strongRef);
-				}
+					if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
+							&& QDebug.debugLevel >= DebugLevel.Extensive ) 
+					{
+						Console.WriteLine("GetInstance() strongRef 0x{0:x8} -> {1}", (int) ptr, strongRef);
+					}
 #endif
-				if (!allInstances && IsSmokeClass(strongRef.GetType())) {
-					return IntPtr.Zero;
-				} 
+					if (!allInstances && IsSmokeClass(strongRef.GetType())) {
+						return IntPtr.Zero;
+					} 
 
 #if DEBUG
-				GCHandle instanceHandle = DebugGCHandle.Alloc(strongRef);
+					GCHandle instanceHandle = DebugGCHandle.Alloc(strongRef);
 #else
-				GCHandle instanceHandle = GCHandle.Alloc(strongRef);
+					GCHandle instanceHandle = GCHandle.Alloc(strongRef);
 #endif
-				return (IntPtr) instanceHandle;
-			} else {
+					return (IntPtr) instanceHandle;
+				} else {
 #if DEBUG
-				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
-						&& QDebug.debugLevel >= DebugLevel.Extensive ) 
-				{
-					Console.WriteLine("GetInstance() weakRef dead ptr: 0x{0:x8}", (int) ptr);
+					if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
+							&& QDebug.debugLevel >= DebugLevel.Extensive ) 
+					{
+						Console.WriteLine("GetInstance() weakRef dead ptr: 0x{0:x8}", (int) ptr);
+					}
+#endif
+					pointerMap.Remove(ptr);
+					return IntPtr.Zero;
 				}
-#endif
-				pointerMap.Remove(ptr);
-				return IntPtr.Zero;
 			}
 		}
 



More information about the Kde-bindings mailing list