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

Arno Rehn kde at arnorehn.de
Tue Dec 16 17:58:44 UTC 2008


SVN commit 897728 by arnorehn:

* Make the pointerMap a Hashtable instead of a Dictionary - its implementation
  in Mono seems buggy. This should fix a crash reported by Eric Butler.
* Add FromArray() convenience method to Pointer<T>.

CCMAIL: kde-bindings at kde.org
CCMAIL: eric at extremeboredom.net
            


 M  +6 -0      ChangeLog  
 M  +6 -0      src/Qyoto.cs  
 M  +11 -5     src/SmokeMarshallers.cs  


--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #897727:897728
@@ -1,3 +1,9 @@
+2008-12-16  Arno Rehn  <arno at arnorehn.de>
+
+	* Make the pointerMap a Hashtable instead of a Dictionary - its implementation
+	  in Mono seems buggy. This should fix a crash reported by Eric Butler.
+	* Add FromArray() convenience method to Pointer<T>.
+
 2008-12-14  Arno Rehn  <arno at arnorehn.de>
 
 	* Don't use StackItem.s_long if we are on a 32 bit platform (i.e. a long isn't
--- trunk/KDE/kdebindings/csharp/qyoto/src/Qyoto.cs #897727:897728
@@ -212,6 +212,12 @@
 			}
 		}
 		
+		public void FromArray(T[] array) {
+			for (int i = 0; i < array.Length; i++) {
+				this[i] = array[i];
+			}
+		}
+		
 		public static implicit operator IntPtr (Pointer<T> rhs) {
 			return rhs.ToIntPtr();
 		}
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #897727:897728
@@ -329,7 +329,11 @@
 
 		// The key is an IntPtr corresponding to the address of the C++ instance,
 		// and the value is a WeakReference to the C# instance.
-		static private Dictionary<IntPtr, WeakReference> pointerMap = new Dictionary<IntPtr, WeakReference>(2179);
+		
+		// temporarily use a hashtable since Mono's Dictionary implementation seems buggy. And why do we fix the
+		// capacity to 2179?
+// 		static private Dictionary<IntPtr, WeakReference> pointerMap = new Dictionary<IntPtr, WeakReference>(2179);
+		static private Hashtable pointerMap = new Hashtable();
 
 		public static void AddGlobalRef(IntPtr instancePtr, IntPtr ptr) {
 			Object instance = ((GCHandle) instancePtr).Target;
@@ -399,7 +403,7 @@
 		// of a Qyoto class and therefore could have custom slots or overriden methods
 		public static IntPtr GetInstance(IntPtr ptr, bool allInstances) {
 			WeakReference weakRef;
-			if (!pointerMap.TryGetValue(ptr, out weakRef)) {
+			if (!pointerMap.ContainsKey(ptr)) {
 #if DEBUG
 				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
 						&& QDebug.debugLevel >= DebugLevel.Extensive ) 
@@ -407,9 +411,11 @@
 					Console.WriteLine("GetInstance() pointerMap[0x{0:x8}] == null", (int) ptr);
 				}
 #endif
-				return (IntPtr) 0;
+				return IntPtr.Zero;
 			}
 
+			weakRef = (WeakReference) pointerMap[ptr];
+
 			if (weakRef.IsAlive) {
 #if DEBUG
 				if (	(QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0
@@ -419,7 +425,7 @@
 				}
 #endif
 				if (!allInstances && IsSmokeClass(weakRef.Target.GetType())) {
-					return (IntPtr) 0;
+					return IntPtr.Zero;
 				} 
 
 #if DEBUG
@@ -437,7 +443,7 @@
 				}
 #endif
 				pointerMap.Remove(ptr);
-				return (IntPtr) 0;
+				return IntPtr.Zero;
 			}
 		}
 



More information about the Kde-bindings mailing list