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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Dec 17 12:19:39 UTC 2010


Revision: 3261
          http://rkward.svn.sourceforge.net/rkward/?rev=3261&view=rev
Author:   tfry
Date:     2010-12-17 12:19:39 +0000 (Fri, 17 Dec 2010)

Log Message:
-----------
Make the basics of the new backend work on Windows. No output visible from 'system', yet.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/CMakeLists.txt
    trunk/rkward/rkward/rbackend/rkfrontendtransmitter.cpp
    trunk/rkward/rkward/rbackend/rkrbackend.cpp
    trunk/rkward/rkward/rbackend/rkrbackendprotocol_backend.cpp
    trunk/rkward/rkward/rbackend/rksignalsupport.cpp
    trunk/rkward/rkward/rbackend/rktransmitter.cpp
    trunk/rkward/rkward/rbackend/rktransmitter.h

Modified: trunk/rkward/rkward/rbackend/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/rbackend/CMakeLists.txt	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/CMakeLists.txt	2010-12-17 12:19:39 UTC (rev 3261)
@@ -6,7 +6,7 @@
 
 ADD_SUBDIRECTORY( rpackages )
 
-INCLUDE_DIRECTORIES( ${R_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
+INCLUDE_DIRECTORIES( ${R_INCLUDEDIR} ${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 
 SET (
 	rbackend_shared_SRCS

Modified: trunk/rkward/rkward/rbackend/rkfrontendtransmitter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkfrontendtransmitter.cpp	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rkfrontendtransmitter.cpp	2010-12-17 12:19:39 UTC (rev 3261)
@@ -71,6 +71,9 @@
 	if (!backend->canReadLine ()) backend->waitForReadyRead ();
 	token = QString::fromLocal8Bit (backend->readLine ());
 	token.chop (1);
+#ifdef Q_WS_WIN
+	token.chop (1);	// '\r', I suppose...
+#endif
 
 	connect (backend, SIGNAL (readyReadStandardOutput ()), this, SLOT (newProcessOutput ()));
 	if (backend->bytesAvailable ()) newProcessOutput ();

Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp	2010-12-17 12:19:39 UTC (rev 3261)
@@ -17,6 +17,17 @@
 
 #include "rkrbackend.h"
 
+#ifdef Q_WS_WIN
+#	include <windows.h>
+#	include <winsock2.h>
+#	undef ERROR 	// clashes with R
+#	define Win32	// needed for R includes
+#else
+#	include <dlfcn.h>
+#	include <sys/resource.h>
+#	include <sys/types.h>
+#endif
+
 // statics
 RKRBackend *RKRBackend::this_pointer = 0;
 RKRBackend::RKReplStatus RKRBackend::repl_status = { QByteArray (), 0, true, 0, 0, RKRBackend::RKReplStatus::NoUserCommand, 0, false, false };
@@ -43,14 +54,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
-#ifdef Q_WS_WIN
-#	include <winsock.h>
-#	undef ERROR	// windows define clashes with R define
-#else
-#include <dlfcn.h>
-#include <sys/resource.h>
-#include <sys/types.h>
-#endif
 
 extern "C" {
 #define R_INTERFACE_PTRS 1
@@ -65,11 +68,6 @@
 #define IS_UTF8(x) (Rf_getCharCE(x) == CE_UTF8)
 #define IS_LATIN1(x) (Rf_getCharCE(x) == CE_LATIN1)
 
-#ifdef Q_WS_WIN
-	// needed for R includes
-#	define Win32
-#endif
-
 #include <Rdefines.h>
 #include <R_ext/Rdynload.h>
 #include <R_ext/eventloop.h>
@@ -78,13 +76,19 @@
 #include <Rinternals.h>
 #include <R_ext/Parse.h>
 #include <Rembedded.h>
-#include <Rinterface.h>
 
 #ifdef Q_WS_WIN
 #	include <R_ext/RStartup.h>
 #	include <R_ext/Utils.h>
 
 	structRstart RK_R_Params;
+
+	// why oh why isn't Rinterface.h available on Windows?
+	LibExtern void* R_GlobalContext;
+	LibExtern uintptr_t R_CStackLimit;
+	LibExtern void R_SaveGlobalEnvToFile(char*);
+#else
+#	include <Rinterface.h>
 #endif
 
 void RK_scheduleIntr () {
@@ -389,7 +393,7 @@
 		}
 		filename = dir.absoluteFilePath (filename);
 
-		if (R_DirtyImage) R_SaveGlobalEnvToFile (filename.toLocal8Bit ());
+		if (R_DirtyImage) R_SaveGlobalEnvToFile (filename.toLocal8Bit ().data ());
 		qDebug ("Created emergency save file in %s", qPrintable (filename));
 	}
 
@@ -607,7 +611,7 @@
 }
 
 #ifdef Q_WS_WIN
-void RThread::setupCallbacks () {
+void RKRBackend::setupCallbacks () {
 	RK_TRACE (RBACKEND);
 
 	R_setStartTime();
@@ -632,7 +636,7 @@
 	RK_R_Params.R_Interactive = (Rboolean) 1;
 }
 
-void RThread::connectCallbacks () {
+void RKRBackend::connectCallbacks () {
 	RK_TRACE (RBACKEND);
 	R_SetParams(&RK_R_Params);
 }

Modified: trunk/rkward/rkward/rbackend/rkrbackendprotocol_backend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackendprotocol_backend.cpp	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rkrbackendprotocol_backend.cpp	2010-12-17 12:19:39 UTC (rev 3261)
@@ -71,7 +71,9 @@
 
 		void run () {
 			RK_TRACE (RBACKEND);
+#	ifndef Q_WS_WIN
 			RKRBackendProtocolBackend::instance ()->r_thread_id = currentThreadId ();
+#	endif
 			RKRBackend::this_pointer->run ();
 		}
 
@@ -160,7 +162,9 @@
 	RKRBackendThread::instance->start ();
 #else
 	r_thread = QThread::currentThread ();	// R thread == main thread
+#	ifndef Q_WS_WIN
 	r_thread_id = QThread::currentThreadId ();
+#	endif
 #endif
 	data_dir = storage_dir;
 }

Modified: trunk/rkward/rkward/rbackend/rksignalsupport.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rksignalsupport.cpp	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rksignalsupport.cpp	2010-12-17 12:19:39 UTC (rev 3261)
@@ -164,9 +164,11 @@
 	RK_ASSERT (!RKSignalSupportPrivate::r_sigint_handler);
 	RKSignalSupportPrivate::new_sigint_handler = handler;
 	RKSignalSupportPrivate::r_sigint_handler = signal (SIGINT, &RKSignalSupportPrivate::internal_sigint_handler);
+#ifndef Q_WS_WIN
 	// default action in R: save and quit. We use these as a proxy for SIGINT, instead.
 	signal (SIGUSR1, &RKSignalSupportPrivate::internal_sigint_handler);
 	signal (SIGUSR2, &RKSignalSupportPrivate::internal_sigint_handler);
+#endif
 }
 
 void RKSignalSupport::callOldSigIntHandler () {

Modified: trunk/rkward/rkward/rbackend/rktransmitter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rktransmitter.cpp	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rktransmitter.cpp	2010-12-17 12:19:39 UTC (rev 3261)
@@ -203,6 +203,7 @@
 	RK_ASSERT (_instance == 0);	// NOTE: Although there are two instances of an abstract transmitter in an RKWard session, these live in different processes.
 	_instance = this;
 	connection = 0;
+	fetching_transmission = false;
 
 	moveToThread (this);
 }
@@ -221,6 +222,7 @@
 	}
 
 	QByteArray buffer = RKRBackendSerializer::serialize (*request);
+	RK_DO (qDebug ("Transmitting request of length %s", QString::number (buffer.length ()).toLocal8Bit ().data ()), RBACKEND, DL_DEBUG);
 	connection->write (QString::number (buffer.length ()).toLocal8Bit () + "\n");
 	connection->write (buffer);
 }
@@ -245,12 +247,15 @@
 		return;
 	}
 
+	if (fetching_transmission) return;	// apparently, on Windows, readyRead() *does* get emitted from waitForReadyRead. Avoid recursion.
+
 	if (!connection->canReadLine ()) return;
+	fetching_transmission = true;
 
 	QString line = QString::fromLocal8Bit (connection->readLine ());
 	bool ok;
 	int expected_length = line.toInt (&ok);
-	if (!ok) handleTransmissionError ("Protocol header error. Last connection error was: " + connection->errorString ());
+	if (!ok) handleTransmissionError ("Protocol header error. Last connection error was: " + connection->errorString ()+ "; header was: " + line);
 
 	QByteArray receive_buffer;
 	while (receive_buffer.length () < expected_length) {
@@ -264,6 +269,7 @@
 			}
 		}
 	}
+	fetching_transmission = false;
 
 	requestReceived (RKRBackendSerializer::unserialize (receive_buffer));
 

Modified: trunk/rkward/rkward/rbackend/rktransmitter.h
===================================================================
--- trunk/rkward/rkward/rbackend/rktransmitter.h	2010-12-17 07:06:37 UTC (rev 3260)
+++ trunk/rkward/rkward/rbackend/rktransmitter.h	2010-12-17 12:19:39 UTC (rev 3261)
@@ -66,7 +66,8 @@
 	void fetchTransmission ();
 	void disconnected ();
 private:
-static RKAbstractTransmitter* _instance;
+	static RKAbstractTransmitter* _instance;
+	bool fetching_transmission;
 };
 
 #endif


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