[Rcpp-devel] Missing PROTECT()s in forward_exception_to_r()?

Dirk Eddelbuettel edd at debian.org
Tue Oct 9 01:47:54 CEST 2012


Or rather this version without a typo:

	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. 

	// Do this in case somehow someone replaces the definition of
	// "cpp_exception" such that it does return:
	UNPROTECT(1);

It passes checks here, but so did the previous versions -- and when I do a
simple test with gctorture() :

   library(inline)
   f <- rcpp(signature(aa="ANY"), body='Rcpp::NumericVector a(aa); return a;')
   gctorture(TRUE)
   print(f(1:4))
   f(LETTERS[1:4])			# will trigger exception

I get this before the patch

   edd at max:~$  R --slave -e 'source("/tmp/tryEx.r")'
   [1] 1 2 3 4
   Error in f(LETTERS[1:4]) : /usr/local/lib/R/site-library/Rcpp/R/Rcpp.rdb
   Calls: source ... withVisible -> eval -> eval -> f -> <Anonymous> -> <Anonymous>
   Execution halted
   edd at max:~$ 

which seems like what you described where as after installing Rcpp with the
change above, we get 

   edd at max:~/svn/rcpp/pkg$ R --slave -e 'source("/tmp/tryEx.r")'
   [1] 1 2 3 4
   Error in f(LETTERS[1:4]) : not compatible with REALSXP
   Calls: source ... withVisible -> eval -> eval -> f -> <Anonymous> -> cpp_exception
   Execution halted
   edd at max:~/svn/rcpp/pkg$ 

which is what we get without gctorture() -- so the PROTECT seems to help.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list