[Kde-bindings] KDE/kdebindings/csharp

Arno Rehn kde at arnorehn.de
Wed Jul 30 23:49:59 UTC 2008


SVN commit 839859 by arnorehn:

* If a custom subclass of one of the binding's classes is destroyed, try to
  call the Dispose() method of it. This might be useful since finalizers are
  usually called much to late by the GC for doing a proper cleanup.
* Remove the manual Dispose() calls from the KWrite example.

CCMAIL: kde-bindings at kde.org



 M  +1 -12     ktexteditor/examples/kwrite/kwritemain.cs  
 M  +6 -0      qyoto/ChangeLog  
 M  +17 -0     qyoto/src/SmokeMarshallers.cs  
 M  +1 -0      qyoto/src/qyoto.h  
 M  +7 -0      qyoto/src/qyotoshared.cpp  
 M  +2 -0      qyoto/src/qyotosmokebinding.cpp  


--- trunk/KDE/kdebindings/csharp/ktexteditor/examples/kwrite/kwritemain.cs #839858:839859
@@ -114,11 +114,7 @@
         Show();
     }
 
-    private bool isDisposed = false;
-
     public new void Dispose() {
-        if (isDisposed) return;
-        isDisposed = true;
         winList.Remove(this);
 
         if (m_view.Document().Views().Count == 1) {
@@ -129,10 +125,6 @@
         KGlobal.Config().Sync();
     }
 
-    ~KWrite() {
-        Dispose();
-    }
-
     private void SetupActions() {
         ActionCollection().AddAction(KStandardAction.StandardAction.Close, "file_close", this, SLOT("SlotFlush()"))
             .WhatsThis = KDE.I18n("Use this to close the current document");
@@ -225,14 +217,11 @@
 
     // is closing the window wanted by user?
     protected override bool QueryClose() {
-        if (m_view.Document().Views().Count > 1) {
-            Dispose();
+        if (m_view.Document().Views().Count > 1)
             return true;
-        }
 
         if (m_view.Document().QueryClose()) {
             WriteConfig();
-            Dispose();
             return true;
         }
 
--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #839858:839859
@@ -1,3 +1,9 @@
+2008-07-31  Arno Rehn  <arno at arnorehn.de>
+
+	* If a custom subclass of one of the binding's classes is destroyed, try to
+	  call the Dispose() method of it. This might be useful since finalizers are
+	  usually called much to late by the GC for doing a proper cleanup.
+
 2008-07-28  Arno Rehn  <arno at arnorehn.de>
 
 	* Various fixes for the signal->delegate connection stuff.
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #839858:839859
@@ -207,6 +207,9 @@
 		
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern void InstallCreateGenericPointer(CreateInstanceFn callback);
+
+		[DllImport("libqyotoshared", CharSet=CharSet.Ansi)]
+		public static extern void InstallTryDispose(FromIntPtr callback);
 #endregion
 		
 #region delegates
@@ -810,6 +813,18 @@
 			object o = Activator.CreateInstance(t, new object[] { ptr });
 			return (IntPtr) GCHandle.Alloc(o);
 		}
+		
+		public static void TryDispose(IntPtr obj) {
+			object o = ((GCHandle) obj).Target;
+			if (IsSmokeClass(o.GetType())) return;
+			try {
+				((IDisposable) o).Dispose();
+			} catch (Exception e) {
+#if DEBUG
+				Console.WriteLine("Disposing {0} failed, reason: {1}", obj, e);
+#endif
+			}
+		}
 #endregion
 		
 #region Setup
@@ -861,6 +876,8 @@
 			
 			InstallGenericPointerGetIntPtr(GenericPointerGetIntPtr);
 			InstallCreateGenericPointer(CreateGenericPointer);
+			
+			InstallTryDispose(TryDispose);
 		}
 #endregion
 
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.h #839858:839859
@@ -127,6 +127,7 @@
 extern Q_DECL_EXPORT SetPropertyFn SetProperty;
 
 extern Q_DECL_EXPORT SetIntPtr InvokeDelegate;
+extern Q_DECL_EXPORT FromIntPtr TryDispose;
 
 extern "C" {
 extern Q_DECL_EXPORT QMetaObject* parent_meta_object(void* obj);
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyotoshared.cpp #839858:839859
@@ -43,6 +43,7 @@
 SetPropertyFn SetProperty;
 
 SetIntPtr InvokeDelegate;
+FromIntPtr TryDispose;
 
 void
 smokeStackToQtStack(Smoke::Stack stack, void ** o, int start, int end, QList<MocArgument*> args)
@@ -324,6 +325,12 @@
 {
 
 Q_DECL_EXPORT void
+InstallTryDispose(FromIntPtr callback)
+{
+	TryDispose = callback;
+}
+
+Q_DECL_EXPORT void
 InstallInvokeDelegate(SetIntPtr callback)
 {
 	InvokeDelegate = callback;
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyotosmokebinding.cpp #839858:839859
@@ -40,6 +40,8 @@
 		fflush(stdout);
 	}
 
+	(*TryDispose)(obj);
+
 	if (o == 0 || o->ptr == 0) {
 		(*FreeGCHandle)(obj);
 		return;



More information about the Kde-bindings mailing list