[Rcpp-commits] r3795 - in pkg/Rcpp: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 9 05:19:48 CEST 2012


Author: edd
Date: 2012-10-09 05:19:47 +0200 (Tue, 09 Oct 2012)
New Revision: 3795

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/src/exceptions.cpp
Log:
additonal PROTECT layer on parsing exception messages before returning errors to R


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-07 22:12:12 UTC (rev 3794)
+++ pkg/Rcpp/ChangeLog	2012-10-09 03:19:47 UTC (rev 3795)
@@ -1,3 +1,8 @@
+2012-10-08  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/exceptions.cpp: Additional PROTECT for parsing exception
+	messages before returning them to R
+
 2012-10-07  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/unitTests/runit.Date.R: Added a few more tests
@@ -4,12 +9,12 @@
 
 2012-10-06  Dirk Eddelbuettel  <edd at debian.org>
 
-	* inst/include/Rcpp/Date.h (Rcpp): Dates are now represented as
-	doubles, also added accessor functions for double and retained int
+	* inst/include/Rcpp/Date.h: Dates are now represented as doubles,
+	also added accessor functions for double and retained int
 
-	* src/Date.cpp (Rcpp): Convert from SEXP to double, added constructor
-	from double and added checks for 'finite' representation before
-	converting to 'struct tm' adding support for NA, NaN and Inf
+	* src/Date.cpp: Convert from SEXP to double, added constructor from
+	double and added checks for 'finite' representation before converting
+	to 'struct tm' adding support for NA, NaN and Inf
 
 	* src/DateVector.cpp: Instantiate Date types as double
 

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2012-10-07 22:12:12 UTC (rev 3794)
+++ pkg/Rcpp/DESCRIPTION	2012-10-09 03:19:47 UTC (rev 3795)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.9.14.2
+Version: 0.9.14.3
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Douglas Bates and John Chambers

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2012-10-07 22:12:12 UTC (rev 3794)
+++ pkg/Rcpp/inst/NEWS.Rd	2012-10-09 03:19:47 UTC (rev 3795)
@@ -11,7 +11,10 @@
     \item The \code{Date} and \code{Datetime} types now correctly
     handles \code{NA}, \code{NaN} and \code{Inf} representation; the
     \code{Date} type switched to an internal representation via \code{double}
-    \item Added \code{Date} and \code{Datetime} unit tests for the new features
+    \item Added \code{Date} and \code{Datetime} unit tests for the new
+    features
+    \item An additional \code{PROTECT} was added for parsing exception
+    messages before returning them to R, following a report by Ben North
   }
 }
 

Modified: pkg/Rcpp/src/exceptions.cpp
===================================================================
--- pkg/Rcpp/src/exceptions.cpp	2012-10-07 22:12:12 UTC (rev 3794)
+++ pkg/Rcpp/src/exceptions.cpp	2012-10-09 03:19:47 UTC (rev 3795)
@@ -2,7 +2,7 @@
 //
 // exceptions.cpp: R/C++ interface class library -- exception handling
 //
-// Copyright (C) 2009 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2009 - 2012  Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -22,41 +22,41 @@
 #include <Rcpp.h>
 
 namespace Rcpp{
-	exception::exception( const char* message_, const char* file, int line) : message(message_){
-		rcpp_set_stack_trace( stack_trace(file,line) ) ;
-	}
-	exception::~exception() throw(){}
+    exception::exception( const char* message_, const char* file, int line) : message(message_){
+	rcpp_set_stack_trace( stack_trace(file,line) ) ;
+    }
+    exception::~exception() throw(){}
 
-#define RCPP_EXCEPTION_WHAT(__CLASS__) \
-const char* __CLASS__::what() const throw(){ return message.c_str(); }
+#define RCPP_EXCEPTION_WHAT(__CLASS__)					\
+    const char* __CLASS__::what() const throw(){ return message.c_str(); }
 
-RCPP_EXCEPTION_WHAT(exception)
+    RCPP_EXCEPTION_WHAT(exception)
 
-RCPP_EXCEPTION_WHAT(not_compatible)
-RCPP_EXCEPTION_WHAT(S4_creation_error)
-RCPP_EXCEPTION_WHAT(reference_creation_error)
-RCPP_EXCEPTION_WHAT(no_such_binding)
-RCPP_EXCEPTION_WHAT(binding_not_found)
-RCPP_EXCEPTION_WHAT(binding_is_locked)
-RCPP_EXCEPTION_WHAT(no_such_namespace)
-RCPP_EXCEPTION_WHAT(eval_error)
+    RCPP_EXCEPTION_WHAT(not_compatible)
+    RCPP_EXCEPTION_WHAT(S4_creation_error)
+    RCPP_EXCEPTION_WHAT(reference_creation_error)
+    RCPP_EXCEPTION_WHAT(no_such_binding)
+    RCPP_EXCEPTION_WHAT(binding_not_found)
+    RCPP_EXCEPTION_WHAT(binding_is_locked)
+    RCPP_EXCEPTION_WHAT(no_such_namespace)
+    RCPP_EXCEPTION_WHAT(eval_error)
 
 #undef RCPP_EXCEPTION_WHAT
 
-#define RCPP_SIMPLE_EXCEPTION_WHAT(__CLASS__,__MESSAGE__)  \
+#define RCPP_SIMPLE_EXCEPTION_WHAT(__CLASS__,__MESSAGE__)		\
 const char* __CLASS__::what() const throw(){ return __MESSAGE__ ; }
 
-RCPP_SIMPLE_EXCEPTION_WHAT(not_a_matrix, "not a matrix" )
-RCPP_SIMPLE_EXCEPTION_WHAT(index_out_of_bounds, "index out of bounds" )
-RCPP_SIMPLE_EXCEPTION_WHAT(parse_error, "parse error") 
-RCPP_SIMPLE_EXCEPTION_WHAT(not_s4, "not an S4 object" )
-RCPP_SIMPLE_EXCEPTION_WHAT(not_reference, "not a reference S4 object" )
-RCPP_SIMPLE_EXCEPTION_WHAT(not_initialized, "C++ object not initialized" )
-RCPP_SIMPLE_EXCEPTION_WHAT(no_such_slot, "no such slot" )
-RCPP_SIMPLE_EXCEPTION_WHAT(no_such_field, "no such field" )
-RCPP_SIMPLE_EXCEPTION_WHAT(not_a_closure, "not a closure" )
-RCPP_SIMPLE_EXCEPTION_WHAT(no_such_function, "no such function" )
-RCPP_SIMPLE_EXCEPTION_WHAT(unevaluated_promise, "promise not yet evaluated" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(not_a_matrix, "not a matrix" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(index_out_of_bounds, "index out of bounds" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(parse_error, "parse error") 
+    RCPP_SIMPLE_EXCEPTION_WHAT(not_s4, "not an S4 object" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(not_reference, "not a reference S4 object" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(not_initialized, "C++ object not initialized" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(no_such_slot, "no such slot" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(no_such_field, "no such field" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(not_a_closure, "not a closure" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(no_such_function, "no such function" )
+    RCPP_SIMPLE_EXCEPTION_WHAT(unevaluated_promise, "promise not yet evaluated" )
 
 #undef RCPP_SIMPLE_EXCEPTION_WHAT
 }
@@ -86,17 +86,17 @@
 #include <cxxabi.h>
 
 std::string demangle( const std::string& name ){
-	std::string real_class ;
-	int status =-1 ;
-	char *dem = 0;
-	dem = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
-	if( status == 0 ){
-		real_class = dem ;
-		free(dem);
-	} else {
-		real_class = name ;
-	}
-	return real_class ;
+    std::string real_class ;
+    int status =-1 ;
+    char *dem = 0;
+    dem = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
+    if( status == 0 ){
+	real_class = dem ;
+	free(dem);
+    } else {
+	real_class = name ;
+    }
+    return real_class ;
 }
 
 /* much inspired from the __verbose_terminate_handler of the GCC */
@@ -138,60 +138,50 @@
     }
     
     SEXP cppExceptSym = Rf_install("cpp_exception"); 	// cannot cause a gc() once in symbol table
-    Rf_eval( 
-	    Rf_lang3( 
-		cppExceptSym,
-		     Rf_mkString(exception_what.c_str()), 
-		     has_exception_class ? Rf_mkString(exception_class.c_str()) : R_NilValue), 
-		R_FindNamespace(Rf_mkString("Rcpp"))
-	     ) ; 
+    SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
+					  Rf_mkString(exception_what.c_str()), 
+					  has_exception_class ? Rf_mkString(exception_class.c_str()) : R_NilValue)); 
+    Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); // Should not return
+    UNPROTECT(1);    // in case someone replaces the definition of "cpp_exception" such that it does return
 }
 void forward_exception_to_r( const std::exception& ex){
-	std::string exception_class ;
+    std::string exception_class ;
     std::string exception_what  = ex.what();
-   	const char *name = typeid(ex).name() ;
-   	// now we need to demangle "name"
-   	{
-		int status = -1;
-		char *dem = 0;
-		dem = abi::__cxa_demangle(name, 0, 0, &status);
-		if( status == 0){
-			exception_class = dem ; /* great we can use the demangled name */
-			free(dem);
-		} else{
-			exception_class = name ; /* just using the mangled name */
-		}
+    const char *name = typeid(ex).name() ;
+    // now we need to demangle "name"
+    {
+	int status = -1;
+	char *dem = 0;
+	dem = abi::__cxa_demangle(name, 0, 0, &status);
+	if( status == 0){
+	    exception_class = dem ; /* great we can use the demangled name */
+	    free(dem);
+	} else{
+	    exception_class = name ; /* just using the mangled name */
 	}
-	SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
-	Rf_eval( 
-	    Rf_lang3( 
-		cppExceptSym,
-		     Rf_mkString(exception_what.c_str()), 
-		     Rf_mkString(exception_class.c_str())
-		), R_FindNamespace(Rf_mkString("Rcpp"))
-	) ; 
+    }
+    SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
+    SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
+					  Rf_mkString(exception_what.c_str()), 
+					  Rf_mkString(exception_class.c_str())));
+    Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); // Should not return
+    UNPROTECT(1);    // in case someone replaces the definition of "cpp_exception" such that it does return
 }
 #else
 void forward_uncaught_exceptions_to_r(){
-	SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
-	Rf_eval( 
-	    Rf_lang3( 
-		cppExceptSym,
-		     Rf_mkString("exception : we don't know how to get the exception message with your compiler, patches welcome"), 
-		     R_NilValue), 
-		R_FindNamespace(Rf_mkString("Rcpp"))
-	     ) ; 
+    SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
+    SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
+					  Rf_mkString("exception : we don't know how to get the exception"
+						      "message with your compiler, patches welcome"), 
+					  R_NilValue)); 
+    Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); 	 // Should not return 
+    UNPROTECT(1);    // in case someone replaces the definition of "cpp_exception" such that it does return
 }
 void forward_exception_to_r( const std::exception& ex){
-	SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
-	Rf_eval( 
-	    Rf_lang3( 
-		cppExceptSym,
-		     Rf_mkString(ex.what()), 
-		     R_NilValue), 
-		R_FindNamespace(Rf_mkString("Rcpp"))
-	     ) ; 
-	
+    SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() once in symbol table
+    SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym, Rf_mkString(ex.what()), R_NilValue)); 
+    Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); 	 // Should not return
+    UNPROTECT(1);    // in case someone replaces the definition of "cpp_exception" such that it does return
 }
 std::string demangle( const std::string& name ){
 	return name ;	



More information about the Rcpp-commits mailing list