[rkward-cvs] SF.net SVN: rkward:[3397] trunk/rkward/rkward/rbackend/rkrbackend.cpp

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Jan 27 14:13:23 UTC 2011


Revision: 3397
          http://rkward.svn.sourceforge.net/rkward/?rev=3397&view=rev
Author:   tfry
Date:     2011-01-27 14:13:23 +0000 (Thu, 27 Jan 2011)

Log Message:
-----------
Better recursion prevention during cleanup.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rkrbackend.cpp

Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-01-27 11:49:39 UTC (rev 3396)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-01-27 14:13:23 UTC (rev 3397)
@@ -367,6 +367,8 @@
 	Q_UNUSED (RunLast);		// R_dot_Last is called while "running" the QuitCommand
 
 	if (RKRBackend::this_pointer->killed == RKRBackend::AlreadyDead) return;	// Nothing to clean up
+	if (!RKRBackend::this_pointer->r_running) return;			// prevent recursion (if an error occurs, here, we get jumped to the console repl, again!)
+	RKRBackend::this_pointer->r_running = false;
 
 	// we could be in a signal handler, and the stack base may have changed.
 	uintptr_t old_lim = R_CStackLimit;
@@ -374,20 +376,6 @@
 
 	if ((status != 0) && (RKRBackend::this_pointer->killed != RKRBackend::ExitNow)) RKRBackend::this_pointer->killed = RKRBackend::EmergencySaveThenExit;
 
-	if (saveact != SA_SUICIDE) {
-		if (!RKRBackend::this_pointer->isKilled ()) {
-			RBackendRequest request (true, RBackendRequest::BackendExit);
-			request.params["message"] = QVariant (i18n ("The R engine has shut down with status: %1").arg (status));
-			RKRBackend::this_pointer->handleRequest (&request);
-		}
-
-		Rf_KillAllDevices ();
-		R_RunExitFinalizers ();
-		R_CleanTempDir ();
-	}
-
-	RKRBackend::this_pointer->r_running = false;	// To signify we have finished everything else and are now trying to create an emergency save (if applicable)
-
 	if (RKRBackend::this_pointer->killed == RKRBackend::EmergencySaveThenExit) {
 		QString filename;
 		QDir dir (RKRBackendProtocolBackend::dataDir ());
@@ -403,6 +391,18 @@
 		qDebug ("Created emergency save file in %s", qPrintable (filename));
 	}
 
+	if (saveact != SA_SUICIDE) {
+		if (!RKRBackend::this_pointer->isKilled ()) {
+			RBackendRequest request (true, RBackendRequest::BackendExit);
+			request.params["message"] = QVariant (i18n ("The R engine has shut down with status: %1").arg (status));
+			RKRBackend::this_pointer->handleRequest (&request);
+		}
+
+		Rf_KillAllDevices ();
+		R_RunExitFinalizers ();
+		R_CleanTempDir ();
+	}
+
 	RKRBackend::this_pointer->killed = RKRBackend::AlreadyDead;	// just in case
 
 	R_CStackLimit = old_lim;	// well, it should not matter any longer, but...


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list