[rkward-cvs] [rkward] /: Fix freezes when using e.g. RK() from within Rcmdr. This was due to a request coming in without a running command (as seen by the frontend).

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sun Nov 30 12:52:17 UTC 2014


Git commit fb19efa6580a198a156b488bed78f641a1d22cba by Thomas Friedrichsmeier.
Committed on 30/11/2014 at 12:50.
Pushed by tfry into branch 'master'.

Fix freezes when using e.g. RK() from within Rcmdr. This was due to a request coming in without a running command (as seen by the frontend).

M  +1    -0    ChangeLog
M  +13   -1    rkward/rbackend/rinterface.cpp
M  +1    -0    rkward/rbackend/rinterface.h
M  +1    -1    rkward/rbackend/rkrbackend.cpp

http://commits.kde.org/rkward/fb19efa6580a198a156b488bed78f641a1d22cba

diff --git a/ChangeLog b/ChangeLog
index 0226b30..4dfc5c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Fixed: Freezes when using RKWard-functionality (such as the RK()-device) from tcl/tk (e.g. Rcmdr)
 - Allow opening RKWard's plugin files (with correct highlighting), and other text files
 - More robust control over placement of plugins within a menu
   - TODO: document, discuss
diff --git a/rkward/rbackend/rinterface.cpp b/rkward/rbackend/rinterface.cpp
index 77cb6bf..ce455b5 100644
--- a/rkward/rbackend/rinterface.cpp
+++ b/rkward/rbackend/rinterface.cpp
@@ -101,6 +101,7 @@ RInterface::RInterface () {
 	num_active_output_record_requests = 0;
 	previous_output_type = ROutput::NoOutput;
 	flush_timer_id = 0;
+	dummy_command_on_stack = 0;
 
 	// create a fake init command
 	RCommand *fake = new RCommand (i18n ("R Startup"), RCommand::App | RCommand::Sync | RCommand::ObjectListUpdate, i18n ("R Startup"), this, STARTUP_PHASE2_COMPLETE);
@@ -164,6 +165,15 @@ void RInterface::closeSubcommandChain (RCommand* parent_command) {
 		current_commands_with_subcommands.removeAll (parent_command);
 		doNextCommand (0);
 	}
+	if (parent_command && (parent_command == dummy_command_on_stack)) {
+		handleCommandOut (dummy_command_on_stack);
+		all_current_commands.removeAll (dummy_command_on_stack);
+		RCommandStack::pop (dummy_command_on_stack);
+		// TODO: I don't quite understand why the line below crashes (in RData::discardData()).
+		// However it's a tolerably slow mem-leak, by all means.
+//		delete dummy_command_on_stack;
+		dummy_command_on_stack = 0;
+	}
 }
 
 void RInterface::tryNextCommand () {
@@ -676,7 +686,9 @@ void RInterface::processHistoricalSubstackRequest (const QStringList &calllist)
 	if (!current_command) {
 		// This can happen for Tcl events. Create a dummy command on the stack to keep things looping.
 		current_command = new RCommand (QString (), RCommand::App | RCommand::EmptyCommand | RCommand::Sync);
-		issueCommand (current_command);
+		RCommandStack::issueCommand (current_command, 0);
+		all_current_commands.append (current_command);
+		dummy_command_on_stack = current_command;	// so we can get rid of it again, after it's sub-commands have finished
 	}
 	in_chain = openSubcommandChain (current_command);
 
diff --git a/rkward/rbackend/rinterface.h b/rkward/rbackend/rinterface.h
index 21abbf5..84a1845 100644
--- a/rkward/rbackend/rinterface.h
+++ b/rkward/rbackend/rinterface.h
@@ -126,6 +126,7 @@ private:
 	int num_active_output_record_requests;
 	ROutput::ROutputType previous_output_type;
 	QString recorded_output;
+	RCommand *dummy_command_on_stack;
 friend class RKRBackendProtocolFrontend;
 	bool backend_dead;
 	static double na_real;
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 3776295..2158eb1 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -1386,7 +1386,7 @@ void RKRBackend::run (const QString &locale_dir) {
 
 void RKRBackend::commandFinished (bool check_object_updates_needed) {
 	RK_TRACE (RBACKEND);
-	RK_DEBUG (RBACKEND, DL_DEBUG, "done running command");
+	RK_DEBUG (RBACKEND, DL_WARNING, "done running command %s", qPrintable (current_command->command));
 
 	{
 		QMutexLocker lock (&all_current_commands_mutex);




More information about the rkward-tracker mailing list