[rkward-cvs] SF.net SVN: rkward: [2267] branches/KDE4_port/rkward/rbackend

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Nov 22 15:20:50 UTC 2007


Revision: 2267
          http://rkward.svn.sourceforge.net/rkward/?rev=2267&view=rev
Author:   tfry
Date:     2007-11-22 07:20:49 -0800 (Thu, 22 Nov 2007)

Log Message:
-----------
Move SIGSEGV handling closer to R initialization and into an own file / namespace

Modified Paths:
--------------
    branches/KDE4_port/rkward/rbackend/CMakeLists.txt
    branches/KDE4_port/rkward/rbackend/rembedinternal.cpp
    branches/KDE4_port/rkward/rbackend/rinterface.cpp

Added Paths:
-----------
    branches/KDE4_port/rkward/rbackend/rksignalsupport.cpp
    branches/KDE4_port/rkward/rbackend/rksignalsupport.h

Modified: branches/KDE4_port/rkward/rbackend/CMakeLists.txt
===================================================================
--- branches/KDE4_port/rkward/rbackend/CMakeLists.txt	2007-11-22 14:49:00 UTC (rev 2266)
+++ branches/KDE4_port/rkward/rbackend/CMakeLists.txt	2007-11-22 15:20:49 UTC (rev 2267)
@@ -17,6 +17,7 @@
 	rcommandstack.cpp
 	rdata.cpp
 	rkpthreadsupport.cpp
+	rksignalsupport.cpp
 	rklocalesupport.cpp
 )
 

Modified: branches/KDE4_port/rkward/rbackend/rembedinternal.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rembedinternal.cpp	2007-11-22 14:49:00 UTC (rev 2266)
+++ branches/KDE4_port/rkward/rbackend/rembedinternal.cpp	2007-11-22 15:20:49 UTC (rev 2267)
@@ -32,6 +32,7 @@
 
 #include "rklocalesupport.h"
 #include "rkpthreadsupport.h"
+#include "rksignalsupport.h"
 
 #include <dlfcn.h>
 #include <stdlib.h>
@@ -642,6 +643,8 @@
 bool REmbedInternal::startR (int argc, char** argv, bool stack_check) {
 	RK_TRACE (RBACKEND);
 
+	RKSignalSupport::saveDefaultSigSegvHandler ();
+
 	r_running = true;
 	bool ok = true;
 #ifdef R_2_3
@@ -684,6 +687,9 @@
 #ifdef R_2_6
 	R_LastvalueSymbol = Rf_install (".Last.value");
 #endif
+
+	RKSignalSupport::installSigSegvProxy ();
+
 	return ok;
 }
 

Modified: branches/KDE4_port/rkward/rbackend/rinterface.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rinterface.cpp	2007-11-22 14:49:00 UTC (rev 2266)
+++ branches/KDE4_port/rkward/rbackend/rinterface.cpp	2007-11-22 15:20:49 UTC (rev 2267)
@@ -52,36 +52,7 @@
 #include <qvalidator.h>
 
 #include <stdlib.h>
-#include <signal.h>
 
-#ifndef __sighandler_t
-typedef void (*__sighandler_t) (int);
-#endif
-__sighandler_t r_sigsegv_handler = 0;
-__sighandler_t default_sigsegv_handler = 0;
-
-void sigsegv_proxy (int signum) {
-	RK_ASSERT (signum == SIGSEGV);
-
-	// if we are not in the R thread, handling the signal in R does more harm than good.
-	if (RInterface::inRThread ()) {
-		if (r_sigsegv_handler) {
-			r_sigsegv_handler (signum);
-			return;
-		}
-	}
-
-	// this might be a Qt/KDE override
-	if (default_sigsegv_handler) {
-		default_sigsegv_handler (signum);
-		return;
-	}
-
-	signal(SIGSEGV,SIG_DFL);
-	raise(SIGSEGV);
-}
-
-
 // update output (for immediate output commands) at least this often (msecs):
 #define FLUSH_INTERVAL 100
 
@@ -164,7 +135,6 @@
 void RInterface::startThread () {
 	RK_TRACE (RBACKEND);
 
-	default_sigsegv_handler = signal (SIGSEGV, SIG_DFL);
 	r_thread->start ();
 }
 
@@ -231,7 +201,6 @@
 		r_thread->pauseOutput (false); // see above
 		processRCallbackRequest (static_cast<RCallbackArgs *> (ev->data ()));
 	} else if ((ev->etype () == RKRBackendEvent::RStarted)) {
-		r_sigsegv_handler = signal (SIGSEGV, &sigsegv_proxy);
 		r_thread->unlock (RThread::Startup);
 		RKWardMainWindow::discardStartupOptions ();
 	} else if ((ev->etype () == RKRBackendEvent::RStartupError)) {

Added: branches/KDE4_port/rkward/rbackend/rksignalsupport.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rksignalsupport.cpp	                        (rev 0)
+++ branches/KDE4_port/rkward/rbackend/rksignalsupport.cpp	2007-11-22 15:20:49 UTC (rev 2267)
@@ -0,0 +1,67 @@
+/***************************************************************************
+                          rksignalsupport  -  description
+                             -------------------
+    begin                : Thu Nov 22 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "rksignalsupport.h"
+
+#include <signal.h>
+
+#include "rinterface.h"
+
+#include "../debug.h"
+
+#ifndef __sighandler_t
+typedef void (*__sighandler_t) (int);
+#endif
+
+namespace RKSignalSupportPrivate {
+	__sighandler_t r_sigsegv_handler = 0;
+	__sighandler_t default_sigsegv_handler = 0;
+
+	void sigsegv_proxy (int signum) {
+		RK_ASSERT (signum == SIGSEGV);
+	
+		// if we are not in the R thread, handling the signal in R does more harm than good.
+		if (RInterface::inRThread ()) {
+			if (r_sigsegv_handler) {
+				r_sigsegv_handler (signum);
+				return;
+			}
+		}
+	
+		// this might be a Qt/KDE override
+		if (default_sigsegv_handler) {
+			default_sigsegv_handler (signum);
+			return;
+		}
+	
+		// do the default handling
+		signal (SIGSEGV, SIG_DFL);
+		raise (SIGSEGV);
+	}
+}
+
+void RKSignalSupport::saveDefaultSigSegvHandler () {
+	RK_TRACE (RBACKEND);
+
+	RKSignalSupportPrivate::default_sigsegv_handler = signal (SIGSEGV, SIG_DFL);
+}
+
+void RKSignalSupport::installSigSegvProxy () {
+	RK_TRACE (RBACKEND);
+
+	RKSignalSupportPrivate::r_sigsegv_handler = signal (SIGSEGV, &RKSignalSupportPrivate::sigsegv_proxy);
+}

Added: branches/KDE4_port/rkward/rbackend/rksignalsupport.h
===================================================================
--- branches/KDE4_port/rkward/rbackend/rksignalsupport.h	                        (rev 0)
+++ branches/KDE4_port/rkward/rbackend/rksignalsupport.h	2007-11-22 15:20:49 UTC (rev 2267)
@@ -0,0 +1,26 @@
+/***************************************************************************
+                          rksignalsupport  -  description
+                             -------------------
+    begin                : Thu Nov 22 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKSIGNALSUPPORT_H
+#define RKSIGNALSUPPORT_H
+
+namespace RKSignalSupport {
+	void saveDefaultSigSegvHandler ();
+	void installSigSegvProxy ();
+};
+
+#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