[Rcpp-commits] r1109 - in pkg/Rcpp: . R inst/include/Rcpp inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 22 12:29:10 CEST 2010
Author: romain
Date: 2010-04-22 12:29:09 +0200 (Thu, 22 Apr 2010)
New Revision: 1109
Modified:
pkg/Rcpp/DESCRIPTION
pkg/Rcpp/NAMESPACE
pkg/Rcpp/NEWS
pkg/Rcpp/R/cppfunction.R
pkg/Rcpp/R/zzz.R
pkg/Rcpp/inst/include/Rcpp/Environment.h
pkg/Rcpp/inst/include/Rcpp/Evaluator.h
pkg/Rcpp/inst/include/Rcpp/Function.h
pkg/Rcpp/inst/include/Rcpp/Promise.h
pkg/Rcpp/inst/include/Rcpp/RObject.h
pkg/Rcpp/inst/include/Rcpp/exceptions.h
pkg/Rcpp/inst/unitTests/runit.environments.R
pkg/Rcpp/src/Environment.cpp
pkg/Rcpp/src/Evaluator.cpp
pkg/Rcpp/src/Function.cpp
pkg/Rcpp/src/Promise.cpp
Log:
moving exceptions out of classes
Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/DESCRIPTION 2010-04-22 10:29:09 UTC (rev 1109)
@@ -46,8 +46,10 @@
.
Several examples are included, and over 220 unit tests provide addtional
usage examples.
-Depends: R (>= 2.10.0)
-Suggests: inline (>= 0.3.4), RUnit
+Depends: R (>= 2.10.0), inline (>= 0.3.4)
+Suggests: RUnit
SystemRequirements: GNU make
URL: http://dirk.eddelbuettel.com/code/rcpp.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp
License: GPL (>= 2)
+BugReports: http://r-forge.r-project.org/tracker/?atid=637&group_id=155&func=browse
+
Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/NAMESPACE 2010-04-22 10:29:09 UTC (rev 1109)
@@ -5,3 +5,5 @@
importFrom( utils, capture.output )
+importFrom( inline, cfunction )
+
Modified: pkg/Rcpp/NEWS
===================================================================
--- pkg/Rcpp/NEWS 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/NEWS 2010-04-22 10:29:09 UTC (rev 1109)
@@ -1,20 +1,48 @@
0.7.13
+ o All Rcpp headers have been moved to the inst/include directory,
+ allowing use of LinkingTo: Rcpp. But the Makevars and Makevars.win
+ are still need to link against the user library.
+
+ o Automatic exception forwarding has been withdrawn because of portability
+ issues (it did not work on windows). Exception forwarding is still possible
+ but is now based on explicit code of the form:
+
+ try{
+ // user code
+ } catch( std::exception& __ex__){
+ forward_exception_to_r( __ex___ ) ;
+ }
+
+ Alternatively, the macro BEGIN_RCPP and END_RCPP can use used to enclose
+ code so that it captures exceptions and forward them to R.
+
+ BEGIN_RCPP
+ // user code
+ END_RCPP
+
+ o Rcpp now depends on inline (>= 0.3.4)
+
+ o new R function "cppfunction" that invokes cfunction from inline with
+ focus on Rcpp usage (enforcing .Call, adding the Rcpp namespace, set up
+ exception forwarding). cppfunction uses BEGIN_RCPP and END_RCPP macros
+ to enclose the user code
+
o new class Rcpp::Formula to help building formulae in C++
o Rcpp.package.skeleton gains an argument "example_code" and can now be
- used with an empty list, so that only the skeleton is generated
+ used with an empty list, so that only the skeleton is generated. It has also
+ been reworked to show how to use LinkingTo: Rcpp
o wrap now supports containers of the following types: long, long double,
unsigned long, short and unsigned short which are silently converted
to the most acceptable R type.
- o All Rcpp headers have been moved to the inst/include directory,
- allowing use of LinkingTo: Rcpp. But the Makevars and Makevars.win
- are still need to link against the user library.
-
o Revert to not double-quote protecting the path on Windows as this
breaks backticks expansion used n Makevars.win etc
+
+ o Exceptions classes have been moved out of Rcpp classes, e.g. Rcpp::RObject::not_a_matrix
+ is now Rcpp::not_a_matrix
0.7.12 2010-04-16
Modified: pkg/Rcpp/R/cppfunction.R
===================================================================
--- pkg/Rcpp/R/cppfunction.R 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/R/cppfunction.R 2010-04-22 10:29:09 UTC (rev 1109)
@@ -16,38 +16,12 @@
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
NAMESPACE <- environment()
-HAVEINLINE <- FALSE
-cfunction <- function(...) stop( "inline not available" )
-init.inline <- function(){
- unlockBinding( "HAVEINLINE", NAMESPACE )
- unlockBinding( "cfunction", NAMESPACE )
- assignInNamespace( "HAVEINLINE", TRUE, NAMESPACE )
- assignInNamespace( "cfunction" , get( "cfunction", asNamespace( "inline" )), NAMESPACE )
- lockBinding( "HAVEINLINE", NAMESPACE )
- lockBinding( "cfunction", NAMESPACE )
-}
-
cppfunction <- function (sig = character(), body = character(), includes = character(),
otherdefs = character(), verbose = FALSE,
cppargs = character(), cxxargs = character(), libargs = character(),
namespace = TRUE, forward.exceptions = TRUE ){
- ok <- HAVEINLINE
- if( !ok){
- if( "package:inline" %in% search() ){
- ok <- TRUE
- } else{
- ok <- tryCatch( {
- require( "inline", character.only = TRUE, quietly = TRUE )
- TRUE
- } , error = function(e) FALSE )
- }
- if( ! ok ){
- stop( "package inline is not available" )
- }
- init.inline()
- }
if( isTRUE( namespace ) ){
includes <- c( includes, "using namespace Rcpp;" )
}
Modified: pkg/Rcpp/R/zzz.R
===================================================================
--- pkg/Rcpp/R/zzz.R 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/R/zzz.R 2010-04-22 10:29:09 UTC (rev 1109)
@@ -15,9 +15,5 @@
# You should have received a copy of the GNU General Public License
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
-.onLoad <- function(libname, pkgname){
- if( "package:inline" %in% search() ){
- init.inline()
- }
-}
+.onLoad <- function(libname, pkgname){}
Modified: pkg/Rcpp/inst/include/Rcpp/Environment.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Environment.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/Environment.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -34,88 +34,8 @@
class Environment: public RObject{
public:
-
- class not_found : public std::exception{
- public:
- not_found( const std::string& binding ) ;
- virtual ~not_found() throw() ;
- virtual const char* what() const throw();
- private:
- std::string binding ;
- } ;
-
- /**
- * Exception thrown when attempting to assign a value to a binding
- * that is locked
- */
- class binding_is_locked: public std::exception{
- public:
- /**
- * @param binding name of the binding
- */
- binding_is_locked( const std::string& binding) ;
- virtual ~binding_is_locked() throw() ;
-
- /**
- * The message: binding is locked : '{binding}'
- */
- virtual const char* what() const throw() ;
-
- private:
- std::string message ;
- } ;
/**
- * Exception thrown when attempting to get a namespace that does
- * not exist
- */
- class no_such_namespace: public std::exception{
- public:
- /**
- * @param package name of the package
- */
- no_such_namespace( const std::string& package) ;
-
- virtual ~no_such_namespace() throw() ;
-
- /**
- * The message: no such namespace : '{package}'
- */
- virtual const char* what() const throw() ;
-
-
- private:
- std::string message ;
- } ;
-
- /**
- * Exception thrown when attempting to get an environment from a
- * name
- */
- class no_such_env: public std::exception{
- public:
- /**
- * @param name name of the environment, e.g "package:Rcpp"
- */
- no_such_env( const std::string& name) ;
-
- /**
- * @paral pos search path position where there is no environment
- */
- no_such_env(int pos) ;
- virtual ~no_such_env() throw() ;
-
- /**
- * The message: no such environment : '{name}'
- */
- virtual const char* what() const throw() ;
-
-
- private:
- std::string message ;
- } ;
-
- /**
* proxy class to allow read and write access to a binding in
* an environment
*/
@@ -312,7 +232,7 @@
* @param name name of the object
*
*/
- SEXP find( const std::string& name) const ;
+ SEXP find( const std::string& name) const throw(binding_not_found) ;
/**
* Indicates if an object called name exists in the
Modified: pkg/Rcpp/inst/include/Rcpp/Evaluator.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Evaluator.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/Evaluator.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -23,23 +23,13 @@
#define Rcpp_Evaluator_h
#include <RcppCommon.h>
-
#include <Rcpp/Environment.h>
namespace Rcpp{
class Evaluator{
public:
-
- class eval_error : public std::exception{
- public:
- eval_error( const std::string& message ) throw() ;
- virtual ~eval_error() throw() ;
- virtual const char* what() const throw() ;
- private:
- std::string message ;
- } ;
-
+
static SEXP run(SEXP expr) throw(eval_error) ;
static SEXP run(SEXP expr, SEXP env) throw(eval_error) ;
};
Modified: pkg/Rcpp/inst/include/Rcpp/Function.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Function.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/Function.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -36,28 +36,6 @@
public:
/**
- * thrown when attempting to get/set the environment of
- * a function that is a not a closure (CLOSXP)
- */
- class not_a_closure : public std::exception{
- public:
- not_a_closure() throw() {} ;
- virtual ~not_a_closure() throw() {} ;
- virtual const char* what() const throw() ;
- } ;
-
- /**
- * thrown when attempting to find a function that
- * does not exist.
- */
- class no_such_function : public std::exception{
- public:
- no_such_function() throw(){};
- virtual ~no_such_function() throw(){}
- virtual const char* what() const throw() ;
- } ;
-
- /**
* Attempts to convert the SEXP to a pair list
*
* @throw not_compatible if the SEXP could not be converted
Modified: pkg/Rcpp/inst/include/Rcpp/Promise.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Promise.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/Promise.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -32,13 +32,6 @@
class Promise : public RObject {
public:
- class unevaluated_promise : public std::exception{
- public:
- unevaluated_promise() throw(){};
- virtual ~unevaluated_promise() throw(){} ;
- virtual const char* what() const throw() ;
- } ;
-
Promise( SEXP x) throw(not_compatible) ;
Promise( const Promise& other) ;
Modified: pkg/Rcpp/inst/include/Rcpp/RObject.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/RObject.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/RObject.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -266,15 +266,6 @@
};
-class exception : public std::exception {
- public:
- exception(const char* message_, const char* file, int line ) ;
- virtual ~exception() throw() ;
- virtual const char* what() const throw() { return message.c_str() ; };
- private:
- std::string message ;
-} ;
-
} // namespace Rcpp
#endif
Modified: pkg/Rcpp/inst/include/Rcpp/exceptions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/exceptions.h 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/include/Rcpp/exceptions.h 2010-04-22 10:29:09 UTC (rev 1109)
@@ -24,6 +24,26 @@
namespace Rcpp{
+class exception : public std::exception {
+ public:
+ exception(const char* message_, const char* file, int line ) ;
+ virtual ~exception() throw() ;
+ virtual const char* what() const throw() { return message.c_str() ; };
+ private:
+ std::string message ;
+} ;
+
+class no_such_env : public std::exception{
+public:
+ no_such_env( const std::string& name ) throw() : message( std::string("no such environment: '") + name + "'" ){} ;
+ no_such_env( int pos ) throw() : message( "no environment in given position ") {} ;
+ virtual ~no_such_env() throw(){} ;
+ virtual const char* what() const throw(){ return message.c_str() ; } ;
+private:
+ std::string message ;
+} ;
+
+
#define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__) \
class __CLASS__ : public std::exception{ \
public: \
@@ -47,11 +67,20 @@
RCPP_SIMPLE_EXCEPTION_CLASS(parse_error, "parse error")
RCPP_SIMPLE_EXCEPTION_CLASS(not_s4, "not an S4 object" )
RCPP_SIMPLE_EXCEPTION_CLASS(no_such_slot, "no such slot" )
+RCPP_SIMPLE_EXCEPTION_CLASS(not_a_closure, "not a closure" )
+RCPP_SIMPLE_EXCEPTION_CLASS(no_such_function, "no such function" )
+RCPP_SIMPLE_EXCEPTION_CLASS(unevaluated_promise, "promise not yet evaluated" )
+
RCPP_EXCEPTION_CLASS(not_compatible, message )
RCPP_EXCEPTION_CLASS(S4_creation_error, std::string("error creating object of S4 class : ") + message )
RCPP_EXCEPTION_CLASS(no_such_binding, std::string("no such binding : '") + message + "'" )
+RCPP_EXCEPTION_CLASS(binding_not_found, std::string("binding not found: '") + message + "'" )
+RCPP_EXCEPTION_CLASS(binding_is_locked, std::string("binding is locked: '") + message + "'" )
+RCPP_EXCEPTION_CLASS(no_such_namespace, std::string("no such namespace: '") + message + "'" )
+RCPP_EXCEPTION_CLASS(eval_error, message )
+
#undef RCPP_EXCEPTION_CLASS
#undef RCPP_SIMPLE_EXCEPTION_CLASS
Modified: pkg/Rcpp/inst/unitTests/runit.environments.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.environments.R 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/inst/unitTests/runit.environments.R 2010-04-22 10:29:09 UTC (rev 1109)
@@ -92,24 +92,11 @@
lockBinding( "a", e )
checkTrue(
- tryCatch( { funx(e, "a", letters ) ; FALSE}, "Rcpp::Environment::binding_is_locked" = function(e) TRUE ),
+ tryCatch( { funx(e, "a", letters ) ; FALSE}, "Rcpp::binding_is_locked" = function(e) TRUE ),
msg = "cannot assign to locked binding (catch exception)" )
}
-## test.environment.assign.templated <- function(){
-##
-## funx <- cppfunction(signature(x="environment", name = "character", object = "ANY" ), '
-## Environment env(x) ;
-## std::string st = as<std::string>(name) ;
-## return wrap( env.assign(st, object) ) ;
-## ' )
-##
-## e <- new.env( )
-##
-##
-## }
-
test.environment.isLocked <- function(){
funx <- cppfunction(signature(x="environment" ), '
Environment env(x) ;
@@ -250,7 +237,7 @@
return Environment::namespace_env(st); ' )
checkEquals( funx("Rcpp"), asNamespace("Rcpp"), msg = "REnvironment::base_namespace" )
checkTrue(
- tryCatch( { funx("----" ) ; FALSE}, "Rcpp::Environment::no_such_namespace" = function(e) TRUE ),
+ tryCatch( { funx("----" ) ; FALSE}, "Rcpp::no_such_namespace" = function(e) TRUE ),
msg = "Environment::namespace_env(no namespace) -> exception)" )
}
Modified: pkg/Rcpp/src/Environment.cpp
===================================================================
--- pkg/Rcpp/src/Environment.cpp 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/src/Environment.cpp 2010-04-22 10:29:09 UTC (rev 1109)
@@ -23,15 +23,7 @@
namespace Rcpp {
- Environment::not_found::not_found(const std::string& binding_) : binding(binding_){}
- Environment::not_found::~not_found() throw(){}
- const char* Environment::not_found::what() const throw(){
- std::string message( "not found : " ) ;
- message += binding ;
- return message.c_str() ;
- }
-
- Environment::Environment() : RObject(R_NilValue){}
+ Environment::Environment() : RObject(R_NilValue){}
Environment::Environment( SEXP x = R_GlobalEnv) throw(not_compatible) : RObject(x){
if( ! Rf_isEnvironment(x) ) {
@@ -40,7 +32,7 @@
SEXP res ;
try{
res = Evaluator::run( Rf_lang2(Rf_install("as.environment"), x ) ) ;
- } catch( const Evaluator::eval_error& ex){
+ } catch( const eval_error& ex){
throw not_compatible( "cannot convert to environment" ) ;
}
setSEXP( res ) ;
@@ -58,7 +50,7 @@
try{
res = Evaluator::run(
Rf_lang2( Rf_install("as.environment"), Rf_mkString(name.c_str()) ) ) ;
- } catch( const Evaluator::eval_error& ex){
+ } catch( const eval_error& ex){
throw no_such_env(name) ;
}
setSEXP( res ) ;
@@ -69,7 +61,7 @@
SEXP res ;
try{
res = Evaluator::run( Rf_lang2( Rf_install("as.environment"), Rf_ScalarInteger(pos) ) ) ;
- } catch( const Evaluator::eval_error& ex){
+ } catch( const eval_error& ex){
throw no_such_env(pos) ;
}
setSEXP( res ) ;
@@ -106,19 +98,19 @@
if( res == R_UnboundValue ) return R_NilValue ;
/* We need to evaluate if it is a promise */
- if( TYPEOF(res) == PROMSXP){
+ if( TYPEOF(res) == PROMSXP){
res = Rf_eval( res, m_sexp ) ;
}
return res ;
}
- SEXP Environment::find( const std::string& name) const {
+ SEXP Environment::find( const std::string& name) const throw(binding_not_found) {
SEXP res = Rf_findVar( Rf_install(name.c_str()), m_sexp ) ;
- if( res == R_UnboundValue ) throw not_found(name) ;
+ if( res == R_UnboundValue ) throw binding_not_found(name) ;
/* We need to evaluate if it is a promise */
- if( TYPEOF(res) == PROMSXP){
+ if( TYPEOF(res) == PROMSXP){
res = Rf_eval( res, m_sexp ) ;
}
return res ;
@@ -215,7 +207,7 @@
SEXP env = R_NilValue ;
try{
env = Evaluator::run( Rf_lang2(Rf_install("getNamespace"), Rf_mkString(package.c_str()) ) ) ;
- } catch( const Evaluator::eval_error& ex){
+ } catch( const eval_error& ex){
throw no_such_namespace( package ) ;
}
return Environment( env ) ;
@@ -225,32 +217,6 @@
return Environment( ENCLOS(m_sexp) ) ;
}
- /* exceptions */
- Environment::binding_is_locked::binding_is_locked(const std::string& binding) :
- message("binding is locked : '" + binding + "'" ) {}
- const char* Environment::binding_is_locked::what() const throw(){
- return message.c_str() ;
- }
- Environment::binding_is_locked::~binding_is_locked() throw() {}
-
- Environment::no_such_namespace::no_such_namespace(const std::string& package) :
- message("no such namespace : '" + package + "'" ) {}
- const char* Environment::no_such_namespace::what() const throw(){
- return message.c_str() ;
- }
- Environment::no_such_namespace::~no_such_namespace() throw() {}
-
- Environment::no_such_env::no_such_env(const std::string& name) :
- message("no environment called : '" + name + "'" ) {}
- Environment::no_such_env::no_such_env(int pos) :
- message("no environment in the given position" ) {}
- const char* Environment::no_such_env::what() const throw(){
- return message.c_str() ;
- }
- Environment::no_such_env::~no_such_env() throw() {}
-
-
-
Environment::Binding::Binding( Environment& env_, const std::string& name_):
env(env_), name(name_){}
Modified: pkg/Rcpp/src/Evaluator.cpp
===================================================================
--- pkg/Rcpp/src/Evaluator.cpp 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/src/Evaluator.cpp 2010-04-22 10:29:09 UTC (rev 1109)
@@ -23,11 +23,6 @@
namespace Rcpp {
- Evaluator::eval_error::eval_error( const std::string& message) throw() :
- message(message){}
- Evaluator::eval_error::~eval_error( ) throw(){}
- const char* Evaluator::eval_error::what() const throw(){ return message.c_str() ; }
-
SEXP Evaluator::run(SEXP expr, SEXP env) throw(eval_error) {
SEXP call = PROTECT( Rf_lang3( Rf_install("rcpp_tryCatch") , expr, env ) ) ;
@@ -63,7 +58,7 @@
SEXP res = R_NilValue ;
try{
res = Evaluator::run( Rf_lcons( Rf_install(fun), Rf_cons(x, R_NilValue) ) ) ;
- } catch( Evaluator::eval_error& e){
+ } catch( eval_error& e){
throw ::Rcpp::not_compatible( std::string("could not convert using R function : ") + fun ) ;
}
return res;
Modified: pkg/Rcpp/src/Function.cpp
===================================================================
--- pkg/Rcpp/src/Function.cpp 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/src/Function.cpp 2010-04-22 10:29:09 UTC (rev 1109)
@@ -23,13 +23,6 @@
namespace Rcpp {
- const char* Function::not_a_closure::what() const throw(){
- return "not a closure" ;
- }
- const char* Function::no_such_function::what() const throw(){
- return "no such function" ;
- }
-
Function::Function( SEXP x = R_NilValue ) throw(not_compatible) : RObject( ){
switch( TYPEOF(x) ){
case CLOSXP:
Modified: pkg/Rcpp/src/Promise.cpp
===================================================================
--- pkg/Rcpp/src/Promise.cpp 2010-04-22 09:15:20 UTC (rev 1108)
+++ pkg/Rcpp/src/Promise.cpp 2010-04-22 10:29:09 UTC (rev 1109)
@@ -23,10 +23,6 @@
namespace Rcpp {
- const char* Promise::unevaluated_promise::what() const throw() {
- return "promise not yet evaluated" ;
- }
-
Promise::Promise(SEXP x) throw(not_compatible) : RObject(){
if( TYPEOF(x) == PROMSXP ){
setSEXP( x ) ;
More information about the Rcpp-commits
mailing list