[Rcpp-commits] r426 - in pkg: inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 22 15:51:11 CET 2010


Author: romain
Date: 2010-01-22 15:51:11 +0100 (Fri, 22 Jan 2010)
New Revision: 426

Modified:
   pkg/inst/ChangeLog
   pkg/src/Environment.cpp
Log:
use Evaluator instead of R_TopLevelExec

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-22 14:43:35 UTC (rev 425)
+++ pkg/inst/ChangeLog	2010-01-22 14:51:11 UTC (rev 426)
@@ -11,6 +11,8 @@
 
 	* src/*cpp: make sure foo.cpp only include Rcpp/foo.h
 
+	* src/Environment.cpp: use Evaluator instead of R_ToplevelExec
+
 2010-01-21  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION: Release 0.7.3

Modified: pkg/src/Environment.cpp
===================================================================
--- pkg/src/Environment.cpp	2010-01-22 14:43:35 UTC (rev 425)
+++ pkg/src/Environment.cpp	2010-01-22 14:51:11 UTC (rev 426)
@@ -23,14 +23,6 @@
 
 namespace Rcpp {
 
-struct safeFindNamespace_s {
-    SEXP sym, val ;
-};
-static void safeFindNamespace(void *data) {
-    struct safeFindNamespace_s *s = (struct safeFindNamespace_s*) data;
-    s->val = R_FindNamespace(s->sym);
-}
-
     Environment::Environment( SEXP x = R_GlobalEnv) throw(not_compatible) : RObject::RObject(x){
     	if( ! Rf_isEnvironment(x) ) {
     		/* not an environment, but maybe convertible to one using 
@@ -197,12 +189,14 @@
     }
     
     Environment Environment::namespace_env(const std::string& package) throw(no_such_namespace) {
-    	struct safeFindNamespace_s s;
-    	s.sym = Rf_mkString( package.c_str() ) ;
-    	if( !s.sym || s.sym == R_NilValue || !R_ToplevelExec(safeFindNamespace, (void*) &s) ){
-    		throw no_such_namespace(package) ;
+    	
+    	SEXP env = R_NilValue ;
+    	try{
+    		env = Evaluator::run( Rf_lang2(Rf_install("getNamespace"), Rf_mkString(package.c_str()) ) ) ;
+    	} catch( const Evaluator::eval_error& ex){
+    		throw no_such_namespace( package  ) ; 
     	}
-    	return s.val ;
+    	return Environment( env ) ;
     }
     
     Environment Environment::parent() const throw() {



More information about the Rcpp-commits mailing list