[Rcpp-commits] r1054 - in pkg/Rcpp: R inst/include

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 15 16:07:36 CEST 2010


Author: romain
Date: 2010-04-15 16:07:36 +0200 (Thu, 15 Apr 2010)
New Revision: 1054

Modified:
   pkg/Rcpp/R/cppfunction.R
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
cppfunction wraps the function body in a try/catch/forward block

Modified: pkg/Rcpp/R/cppfunction.R
===================================================================
--- pkg/Rcpp/R/cppfunction.R	2010-04-15 10:55:56 UTC (rev 1053)
+++ pkg/Rcpp/R/cppfunction.R	2010-04-15 14:07:36 UTC (rev 1054)
@@ -33,7 +33,7 @@
     cppargs = character(), cxxargs = character(), libargs = character(), 
     .Cpp = TRUE, namespace = TRUE ){
 	
-    ok <- HAVEINLINE
+    ok <- HAVEINLINE                                                                                
 	if( !ok){
 		if( "package:inline" %in% search() ){
 			ok <- TRUE
@@ -51,15 +51,18 @@
 	if( isTRUE( namespace ) ){
 		includes <- c( includes, "using namespace Rcpp;" )
 	}
+	body <- sprintf( "try{ %s } catch( std::exception& __rcpp__ex__ ){ forward_exception_to_r( __rcpp__ex__ ) ; }", 
+		body                                                                                   
+	)
 	fx <- cfunction( sig = sig, body = body, includes = includes, 
 		otherdefs = otherdefs, language = "C++", convention = ".Call", 
 		Rcpp = TRUE, cppargs = cppargs, cxxargs = cxxargs, libargs = libargs, 
 		verbose = verbose )
-	if( isTRUE( .Cpp ) ){
-		# replace .Call by Rcpp::.Cpp
-		# this is somewhat heuristic, maybe we should search for .Call as opposed
-		# to assume it is in this position
-		body( fx at .Data )[[4]][[1]] <- call( "::", as.name("Rcpp"), as.name(".Cpp") )
-	}
+	# if( isTRUE( .Cpp ) ){
+	# 	# replace .Call by Rcpp::.Cpp
+	# 	# this is somewhat heuristic, maybe we should search for .Call as opposed
+	# 	# to assume it is in this position
+	# 	body( fx at .Data )[[4]][[1]] <- call( "::", as.name("Rcpp"), as.name(".Cpp") )
+	# }
 	fx
 }

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2010-04-15 10:55:56 UTC (rev 1053)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2010-04-15 14:07:36 UTC (rev 1054)
@@ -4,7 +4,7 @@
 //
 // Copyright (C) 2005 - 2006 Dominick Samperi
 // Copyright (C) 2008 - 2009 Dirk Eddelbuettel
-// Copyright (C)        2009 Romain Francois
+// Copyright (C) 2009 - 2010 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //



More information about the Rcpp-commits mailing list