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

Arno Rehn kde at arnorehn.de
Wed Apr 25 15:24:35 UTC 2007


SVN commit 657958 by arnorehn:

* Special cased QVector<QRgb> when marshalling.
* Fixed two more memory leaks.
* Removed all the instances of delegates in SmokeMarshallers.cs. In C# 2.0
  we can directly specify a method, we don't need an instance of a correspondending
  delegate anymore.

CCMAIL: kde-bindings at kde.org



 M  +8 -0      ChangeLog  
 M  +58 -69    src/SmokeMarshallers.cs  
 M  +72 -1     src/handlers.cpp  
 M  +1 -0      src/qyoto.h  


--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #657957:657958
@@ -1,3 +1,11 @@
+2007-04-25  Arno Rehn  <arno at arnorehn.de>
+
+	* Special cased QVector<QRgb> when marshalling.
+	* Fixed two more memory leaks.
+	* Removed all the instances of delegates in SmokeMarshallers.cs. In C# 2.0
+	  we can directly specify a method, we don't need an instance of a correspondending
+	  delegate anymore.
+
 2007-04-16  Richard Dale  <rdale at foton.es>
 
 	* Added a QyotoHash() method for deriving a hash value from the c++
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #657957:657958
@@ -55,8 +55,14 @@
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern void AddIntToQList(IntPtr ptr, int i);
 		
+		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+		public static extern IntPtr ConstructQListQRgb();
 		
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+		public static extern void AddUIntToQListQRgb(IntPtr ptr, uint i);
+		
+		
+		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern IntPtr ConstructQMap(int type);
 		
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -140,6 +146,9 @@
 		public static extern IntPtr InstallListIntToQListInt(GetIntPtr callback);
 
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+		public static extern IntPtr InstallListUIntToQListQRgb(GetIntPtr callback);
+
+		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern void InstallAddIntPtrToList(SetIntPtr callback);
 
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -156,6 +165,9 @@
 
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern void InstallDictionaryToQMap(DictToMap callback);
+
+		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+		public static extern void InstallAddUIntToListUInt(AddUInt callback);
 #endregion
 		
 #region delegates
@@ -174,6 +186,7 @@
 		public delegate IntPtr OverridenMethodFn(IntPtr instance, string method);
 		public delegate void InvokeMethodFn(IntPtr instance, IntPtr method, IntPtr args);
 		public delegate void AddInt(IntPtr obj, int i);
+		public delegate void AddUInt(IntPtr obj, uint i);
 		public delegate void AddIntObject(IntPtr hash, int key, IntPtr val);
 		public delegate IntPtr DictToMap(IntPtr ptr, int type);
 		public delegate IntPtr ConstructDict(string type1, string type2);
@@ -520,6 +533,20 @@
 			return QList;
 		}
 
+		public static IntPtr ListUIntToQListQRgb(IntPtr ptr) {
+			List<uint> il = (List<uint>) ((GCHandle) ptr).Target;
+			IntPtr QList = ConstructQListQRgb();
+			foreach (uint i in il) {
+				AddUIntToQListQRgb(QList, i);
+			}
+			return QList;
+		}
+
+		public static void AddUIntToListUInt(IntPtr ptr, uint i) {
+			List<uint> il = (List<uint>) ((GCHandle) ptr).Target;
+			il.Add(i);
+		}
+
 		public static IntPtr ListToPointerList(IntPtr ptr) {
 			object l = ((GCHandle) ptr).Target;
 			// convert the list to an array via reflection. this is probably the easiest way
@@ -623,84 +650,46 @@
 #endregion
 		
 #region Setup
-		static private FromIntPtr freeGCHandle = new FromIntPtr(FreeGCHandle);
-
-		static private GetIntPtr getSmokeObject = new GetIntPtr(GetSmokeObject);
-		static private SetIntPtr setSmokeObject = new SetIntPtr(SetSmokeObject);
-		
-		static private MapPointerFn mapPointer = new MapPointerFn(MapPointer);
-		static private FromIntPtr unmapPointer = new FromIntPtr(UnmapPointer);
-		static private GetInstanceFn getInstance = new GetInstanceFn(GetInstance);
-		
-		static private GetIntPtr intPtrToCharStarStar = new GetIntPtr(IntPtrToCharStarStar);
-		static private GetStringFromIntPtr intPtrToString = new GetStringFromIntPtr(IntPtrToString);
-		static private GetIntPtrFromString intPtrFromString = new GetIntPtrFromString(IntPtrFromString);
-		static private GetIntPtr intPtrToQString = new GetIntPtr(IntPtrToQString);
-		static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
-		static private GetIntPtr stringBuilderToQString = new GetIntPtr(StringBuilderToQString);
-		static private SetIntPtrFromCharStar stringBuilderFromQString = new SetIntPtrFromCharStar(StringBuilderFromQString);
-		
-		static private GetIntPtr stringListToQStringList = new GetIntPtr(StringListToQStringList);
-		static private GetIntPtr listToPointerList = new GetIntPtr(ListToPointerList);
-		static private GetIntPtr listIntToQListInt = new GetIntPtr(ListIntToQListInt);
-		
-		static private DictToMap dictionaryToQMap = new DictToMap(DictionaryToQMap);
-		
-		static private CreateListFn constructList = new CreateListFn(ConstructList);
-		static private SetIntPtr addIntPtrToList = new SetIntPtr(AddIntPtrToList);
-		static private AddInt addIntToListInt = new AddInt(AddIntToListInt);
-		
-		static private ConstructDict constructDictionary = new ConstructDict(ConstructDictionary);
-		static private InvokeMethodFn addObjectObjectToDictionary = new InvokeMethodFn(AddObjectObjectToDictionary);
-		static private AddIntObject addIntObjectToDictionary = new AddIntObject(AddIntObjectToDictionary);
-		
-		static private OverridenMethodFn overridenMethod = new OverridenMethodFn(SmokeInvocation.OverridenMethod);
-		static private InvokeMethodFn invokeMethod = new InvokeMethodFn(SmokeInvocation.InvokeMethod);
-
-		static private CreateInstanceFn createInstance = new CreateInstanceFn(CreateInstance);
-		static private InvokeCustomSlotFn invokeCustomSlot = new InvokeCustomSlotFn(SmokeInvocation.InvokeCustomSlot);
-		
-		static private OverridenMethodFn getProperty = new OverridenMethodFn(GetProperty);
-		static private SetPropertyFn setProperty = new SetPropertyFn(SetProperty);
-		
 		public static void SetUp() {
-			InstallFreeGCHandle(freeGCHandle);
+			InstallFreeGCHandle(FreeGCHandle);
 
-			InstallGetSmokeObject(getSmokeObject);
-			InstallSetSmokeObject(setSmokeObject);
+			InstallGetSmokeObject(GetSmokeObject);
+			InstallSetSmokeObject(SetSmokeObject);
 			
-			InstallMapPointer(mapPointer);
-			InstallUnmapPointer(unmapPointer);
-			InstallGetInstance(getInstance);
+			InstallMapPointer(MapPointer);
+			InstallUnmapPointer(UnmapPointer);
+			InstallGetInstance(GetInstance);
 
-			InstallIntPtrToCharStarStar(intPtrToCharStarStar);
-			InstallIntPtrToCharStar(intPtrToString);
-			InstallIntPtrFromCharStar(intPtrFromString);
-			InstallIntPtrToQString(intPtrToQString);
-			InstallIntPtrFromQString(intPtrFromQString);
-			InstallStringBuilderToQString(stringBuilderToQString);
-			InstallStringBuilderFromQString(stringBuilderFromQString);
-			InstallConstructList(constructList);
-			InstallStringListToQStringList(stringListToQStringList);
-			InstallListToPointerList(listToPointerList);
-			InstallListIntToQListInt(listIntToQListInt);
-			InstallAddIntPtrToList(addIntPtrToList);
-			InstallAddIntToListInt(addIntToListInt);
+			InstallIntPtrToCharStarStar(IntPtrToCharStarStar);
+			InstallIntPtrToCharStar(IntPtrToString);
+			InstallIntPtrFromCharStar(IntPtrFromString);
+			InstallIntPtrToQString(IntPtrToQString);
+			InstallIntPtrFromQString(IntPtrFromQString);
+			InstallStringBuilderToQString(StringBuilderToQString);
+			InstallStringBuilderFromQString(StringBuilderFromQString);
+			InstallConstructList(ConstructList);
+			InstallStringListToQStringList(StringListToQStringList);
+			InstallListToPointerList(ListToPointerList);
+			InstallListIntToQListInt(ListIntToQListInt);
+			InstallListUIntToQListQRgb(ListUIntToQListQRgb);
+			InstallAddIntPtrToList(AddIntPtrToList);
+			InstallAddIntToListInt(AddIntToListInt);
+			InstallAddUIntToListUInt(AddUIntToListUInt);
 
-			InstallConstructDictionary(constructDictionary);
-			InstallAddObjectObjectToDictionary(addObjectObjectToDictionary);
-			InstallAddIntObjectToDictionary(addIntObjectToDictionary);
+			InstallConstructDictionary(ConstructDictionary);
+			InstallAddObjectObjectToDictionary(AddObjectObjectToDictionary);
+			InstallAddIntObjectToDictionary(AddIntObjectToDictionary);
 			
-			InstallDictionaryToQMap(dictionaryToQMap);
+			InstallDictionaryToQMap(DictionaryToQMap);
 
-			InstallOverridenMethod(overridenMethod);
-			InstallInvokeMethod(invokeMethod);
+			InstallOverridenMethod(SmokeInvocation.OverridenMethod);
+			InstallInvokeMethod(SmokeInvocation.InvokeMethod);
 
-			InstallCreateInstance(createInstance);
-			InstallInvokeCustomSlot(invokeCustomSlot);
+			InstallCreateInstance(CreateInstance);
+			InstallInvokeCustomSlot(SmokeInvocation.InvokeCustomSlot);
 			
-			InstallGetProperty(getProperty);
-			InstallSetProperty(setProperty);
+			InstallGetProperty(GetProperty);
+			InstallSetProperty(SetProperty);
 		}
 #endregion
 
--- trunk/KDE/kdebindings/csharp/qyoto/src/handlers.cpp #657957:657958
@@ -77,9 +77,11 @@
 static GetIntPtr StringListToQStringList;
 static GetIntPtr ListToPointerList;
 static GetIntPtr ListIntToQListInt;
+static GetIntPtr ListUIntToQListQRgb;
 static CreateListFn ConstructList;
 static SetIntPtr AddIntPtrToList;
 static AddInt AddIntToListInt;
+static AddUInt AddUIntToListUInt;
 static ConstructDict ConstructDictionary;
 static InvokeMethodFn AddObjectObjectToDictionary;
 static AddIntObject AddIntObjectToDictionary;
@@ -170,6 +172,16 @@
 	DictionaryToQMap = callback;
 }
 
+void InstallListUIntToQListQRgb(GetIntPtr callback)
+{
+	ListUIntToQListQRgb = callback;
+}
+
+void InstallAddUIntToListUInt(AddUInt callback)
+{
+	AddUIntToListUInt = callback;
+}
+
 void* ConstructPointerList()
 {
 	void * list = (void*) new QList<void*>;
@@ -226,6 +238,17 @@
 	map->insert(QString(str), *variant);
 }
 
+void* ConstructQListQRgb()
+{
+	return (void*) new QList<QRgb>;
+}
+
+void AddUIntToQListQRgb(void* ptr, uint i)
+{
+	QList<QRgb>* list = (QList<QRgb>*) ptr;
+	list->append(i);
+}
+
 };
 
 extern bool isDerivedFromByName(Smoke *smoke, const char *className, const char *baseClassName);
@@ -1339,6 +1362,7 @@
 					obj = (*CreateInstance)(resolve_classname(o->smoke, o->classId, o->ptr), o);
 				}
 				(*AddIntPtrToList)(al, obj);
+				(*FreeGCHandle)(obj);
 			}
 
 			m->var().s_voidp = al;
@@ -1483,6 +1507,7 @@
 				}
 
 				(*AddIntPtrToList)(al, obj);
+				(*FreeGCHandle)(obj);
 			}
 
 			m->var().s_voidp = al;
@@ -1502,7 +1527,53 @@
 	}
 }
 
+void marshall_QRgbVector(Marshall *m)
+{
+	switch(m->action()) {
+		case Marshall::FromObject:
+		{
+			QList<QRgb>* cpplist = (QList<QRgb>*) (*ListUIntToQListQRgb)(m->var().s_voidp);
+			m->item().s_voidp = cpplist;
+			m->next();
+			
+			(*FreeGCHandle)(m->var().s_voidp);
 
+			if (m->cleanup()) {
+				delete cpplist;
+			}
+		}
+		break;
+      
+		case Marshall::ToObject:
+		{
+			QList<QRgb> *valuelist = (QList<QRgb>*) m->item().s_voidp;
+			if (valuelist == 0) {
+				break;
+			}
+
+			void * al = (*ConstructList)("System.UInt32");
+
+			for (int i=0; i < valuelist->size() ; ++i) {
+				(*AddUIntToListUInt)(al, valuelist->at(i));
+			}
+
+			m->var().s_voidp = al;
+			m->next();
+
+			if (m->cleanup()) {
+				delete valuelist;
+			}
+			
+
+		}
+		break;
+      
+		default:
+			m->unsupported();
+		break;
+	}
+}
+
 #define DEF_VALUELIST_MARSHALLER(ListIdent,ItemList,Item) namespace { char ListIdent##STR[] = #Item; };  \
         Marshall::HandlerFn marshall_##ListIdent = marshall_ValueListItem<Item,ItemList,ListIdent##STR>;
 
@@ -1519,7 +1590,7 @@
 DEF_VALUELIST_MARSHALLER( QTextBlockList, QList<QTextBlock>, QTextBlock )
 
 DEF_VALUELIST_MARSHALLER( QColorVector, QVector<QColor>, QColor )
-DEF_VALUELIST_MARSHALLER( QRgbVector, QVector<QRgb>, QRgb )
+// DEF_VALUELIST_MARSHALLER( QRgbVector, QVector<QRgb>, QRgb )
 DEF_VALUELIST_MARSHALLER( QVariantVector, QVector<QVariant>, QVariant )
 DEF_VALUELIST_MARSHALLER( QTextFormatVector, QVector<QTextFormat>, QTextFormat )
 DEF_VALUELIST_MARSHALLER( QTextLengthVector, QVector<QTextLength>, QTextLength )
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.h #657957:657958
@@ -73,6 +73,7 @@
 typedef void * (*GetInstanceFn)(void *, bool);
 typedef void (*InvokeCustomSlotFn)(void *, const char*, void *, void *);
 typedef void (*AddInt)(void *, int);
+typedef void (*AddUInt)(void *, uint);
 typedef void (*AddIntObject)(void *, int, void *);
 typedef void * (*DictToMap)(void *, int);
 typedef void * (*ConstructDict)(const char*, const char*);



More information about the Kde-bindings mailing list