[rkward-cvs] SF.net SVN: rkward:[3396] trunk/rkward/rkward/rbackend

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Jan 27 11:49:39 UTC 2011


Revision: 3396
          http://rkward.svn.sourceforge.net/rkward/?rev=3396&view=rev
Author:   tfry
Date:     2011-01-27 11:49:39 +0000 (Thu, 27 Jan 2011)

Log Message:
-----------
Change exit strategy once more to ensure that .Last is run while the frontend is still alive. Not tested on Windows, yet.

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

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2011-01-26 19:59:41 UTC (rev 3395)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2011-01-27 11:49:39 UTC (rev 3396)
@@ -243,8 +243,6 @@
 				command_logfile.write ("\n");
 			}
 		}
-
-		if (command->type () & RCommand::QuitCommand) backend_dead = true;
 	}
 
 	command_request->command = proxy;
@@ -722,6 +720,7 @@
 			na_real = request->params["na_real"].toDouble ();
 			na_int = request->params["na_int"].toInt ();
 	} else if (type == RBackendRequest::BackendExit) {
+		if (request->params.value ("regular", QVariant (false)).toBool ()) backend_dead = true;		// regular exit via QuitCommand
 		if (!backend_dead) {
 			backend_dead = true;
 			QString message = request->params["message"].toString ();

Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-01-26 19:59:41 UTC (rev 3395)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-01-27 11:49:39 UTC (rev 3396)
@@ -2,7 +2,7 @@
                           rkrbackend  -  description
                              -------------------
     begin                : Sun Jul 25 2004
-    copyright            : (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -212,6 +212,12 @@
 			if (RKRBackend::repl_status.user_command_status == RKRBackend::RKReplStatus::NoUserCommand) {
 				RCommandProxy *command = RKRBackend::this_pointer->fetchNextCommand ();
 				if (!command) {
+#ifdef Q_OS_WINDOWS
+					// Can't easily override R_CleanUp on Windows, so we're calling it manually, here, then force exit
+					if (RKRBackend::this_pointer->killed == RKRBackend::ExitNow) RCleanUp (SA_NOSAVE, 0, 0);
+					else RCleanUp (SA_SUICIDE, 1, 0);
+					exit (0);
+#endif
 					return 0;	// jumps out of the event loop!
 				}
 
@@ -358,6 +364,7 @@
 
 void RCleanUp (SA_TYPE saveact, int status, int RunLast) {
 	RK_TRACE (RBACKEND);
+	Q_UNUSED (RunLast);		// R_dot_Last is called while "running" the QuitCommand
 
 	if (RKRBackend::this_pointer->killed == RKRBackend::AlreadyDead) return;	// Nothing to clean up
 
@@ -374,8 +381,7 @@
 			RKRBackend::this_pointer->handleRequest (&request);
 		}
 
-		if (RunLast) R_dot_Last ();
-
+		Rf_KillAllDevices ();
 		R_RunExitFinalizers ();
 		R_CleanTempDir ();
 	}
@@ -631,7 +637,8 @@
 	RK_R_Params.Busy = RBusy;
 
 	// TODO: callback mechanism(s) for ChosseFile, ShowFiles, EditFiles
-	// TODO: also for RSuicide / RCleanup? (Less important, obviously, since those should not be triggered, in normal operation).
+	// TODO: also for RSuicide (Less important, obviously, since this should not be triggered, in normal operation).
+	// NOTE: For RCleanUp see RReadConsole RCleanup? 
 
 	RK_R_Params.R_Quiet = (Rboolean) 0;
 	RK_R_Params.R_Interactive = (Rboolean) 1;
@@ -1058,6 +1065,10 @@
 	if (ctype & RCommand::DirectToOutput) runDirectCommand (".rk.capture.messages()");
 
 	if (ctype & RCommand::QuitCommand) {
+		R_dot_Last ();		// should run while communication with frontend is still possible
+		RBackendRequest req (true, RBackendRequest::BackendExit);
+		req.params["regular"] = QVariant (true);
+		handleRequest (&req);
 		killed = ExitNow;
 	} else if (!(ctype & RCommand::EmptyCommand)) {
 		repl_status.eval_depth++;


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