[Rcpp-commits] r276 - in pkg: R inst src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 5 10:06:54 CET 2010


Author: romain
Date: 2010-01-05 10:06:53 +0100 (Tue, 05 Jan 2010)
New Revision: 276

Modified:
   pkg/R/RcppLdpath.R
   pkg/R/zzz.R
   pkg/inst/ChangeLog
   pkg/src/Rcpp/Function.h
   pkg/src/Rcpp/Language.h
   pkg/src/Rcpp/Named.h
   pkg/src/Rcpp/Pairlist.h
   pkg/src/Rcpp/pairlist.h
   pkg/src/RcppCommon.cpp
   pkg/src/RcppCommon.h
Log:
improve conditional compiling logic

Modified: pkg/R/RcppLdpath.R
===================================================================
--- pkg/R/RcppLdpath.R	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/R/RcppLdpath.R	2010-01-05 09:06:53 UTC (rev 276)
@@ -37,3 +37,6 @@
 CxxFlags <- function() cat(RcppCxxFlags())
 LdFlags <- function() cat(RcppLdFlags())
 
+# capabilities
+RcppCapabilities <- capabilities <- function() .Call("capabilities", PACKAGE = "Rcpp")
+

Modified: pkg/R/zzz.R
===================================================================
--- pkg/R/zzz.R	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/R/zzz.R	2010-01-05 09:06:53 UTC (rev 276)
@@ -1,4 +1,4 @@
-# Copyright (C)        2009 Romain Francois
+# Copyright (C) 2009- 2010	Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/inst/ChangeLog	2010-01-05 09:06:53 UTC (rev 276)
@@ -1,3 +1,17 @@
+2010-01-05  Romain Francois <francoisromain at free.fr>
+
+	* src/RcppCommon.h: improve the conditional compiling logic
+	with macros HAS_VARIADIC_TEMPLATES and HAS_INIT_LISTS instead
+	of CXX0X. This ensures the package can be compiled with 
+	older GCC, with lower functionality
+
+	* src/RcppCommon.{h,cpp}: added a capabilities function that 
+	can be used to bring the result of the two above macros to R
+
+	* R/RcppLdPaths.R: added unexported function RcppCapabilities
+	to call the internal capabilities. capabilities is an alias
+	to RcppCapabilities so that we can call Rcpp::capabilities()
+
 2010-01-04  Romain Francois <francoisromain at free.fr>
 
 	* src/Rcpp/Function.h: new class Rcpp::Function to manage functions

Modified: pkg/src/Rcpp/Function.h
===================================================================
--- pkg/src/Rcpp/Function.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/Rcpp/Function.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -68,7 +68,7 @@
 	 *        a wrap function that takes this type as its parameter
 	 *
 	 */
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 template<typename... Args> 
 	SEXP operator()( const Args&... args) {
 		Evaluator evaluator( Rf_lcons( m_sexp, pairlist(args...) ) ) ; 

Modified: pkg/src/Rcpp/Language.h
===================================================================
--- pkg/src/Rcpp/Language.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/Rcpp/Language.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -99,7 +99,7 @@
 	 * 0.0 is wrapped as a numeric vector using wrap( const& double )
 	 * ...
 	 */
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 template<typename... Args> 
 	Language( const std::string& symbol, const Args&... args) : RObject() {
 		/* TODO: should we first allocate and protect the list  ?*/

Modified: pkg/src/Rcpp/Named.h
===================================================================
--- pkg/src/Rcpp/Named.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/Rcpp/Named.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -48,7 +48,7 @@
 	 */
 	Named( const std::string& tag ) : object(R_NilValue), tag(tag){} ;
 	
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 	template<typename T>
 	Named( const std::string& tag, const T& value ) : object(R_NilValue), tag(tag) {
 		object = wrap( value ) ;

Modified: pkg/src/Rcpp/Pairlist.h
===================================================================
--- pkg/src/Rcpp/Pairlist.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/Rcpp/Pairlist.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -72,7 +72,7 @@
 	 * will create the same pair list as
 	 * > pairlist( 10L, "foobar", "rnorm" )
 	 */
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 template<typename... Args> 
 	Pairlist( const Args&... args) : RObject() {
 		/* TODO: should we first allocate and protect the list  ?*/

Modified: pkg/src/Rcpp/pairlist.h
===================================================================
--- pkg/src/Rcpp/pairlist.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/Rcpp/pairlist.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -29,7 +29,7 @@
 namespace Rcpp{
 	/* recursive packing of the arguments into a list, 
 	  use first as the CAR and build the CDR from the remaining args recursively */
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 	SEXP pairlist() ;
 	template<typename T, typename... Args>
 	SEXP pairlist( const T& first, const Args&... args ){

Modified: pkg/src/RcppCommon.cpp
===================================================================
--- pkg/src/RcppCommon.cpp	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/RcppCommon.cpp	2010-01-05 09:06:53 UTC (rev 276)
@@ -42,7 +42,7 @@
 
 SEXP test_variadic() {
 	SEXP res = PROTECT( Rf_allocVector(INTSXP, 5) ) ; 
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 	INTEGER(res)[0] = variadic_length() ; 
 	INTEGER(res)[1] = variadic_length(1) ;
 	INTEGER(res)[2] = variadic_length(1, 3.3) ;
@@ -60,17 +60,39 @@
 }
 
 SEXP canUseCXX0X(){
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 	return Rf_ScalarLogical( TRUE ) ;
 #else
 	return Rf_ScalarLogical( FALSE ) ;
 #endif
 }
 
+SEXP capabilities(){
+	SEXP cap = PROTECT( Rf_allocVector( LGLSXP, 2) ) ;
+	SEXP names = PROTECT( Rf_allocVector( STRSXP, 2 ) ) ;
+#ifdef HAS_VARIADIC_TEMPLATES
+	LOGICAL(cap)[0] = TRUE ;
+#else
+	LOGICAL(cap)[0] = FALSE ;
+#endif
+#ifdef HAS_INIT_LISTS
+	LOGICAL(cap)[1] = TRUE ;
+#else
+	LOGICAL(cap)[1] = FALSE ;
+#endif
+	
+	SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates") ) ;
+	SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists") ) ;
+	Rf_setAttrib( cap, R_NamesSymbol, names ) ;
+	UNPROTECT(2) ;
+	return cap ;
+}
+
+
 /* this is mainly here so that variadic template errors show up 
    at compile time */
 SEXP test_named(){
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 	return Rcpp::Language( "foobar", Rcpp::Named("foo", 2 ), 2, Rcpp::Named("bar", 10) ) ;
 #else
 	return R_NilValue ;

Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h	2010-01-04 22:51:53 UTC (rev 275)
+++ pkg/src/RcppCommon.h	2010-01-05 09:06:53 UTC (rev 276)
@@ -24,9 +24,15 @@
 #ifndef RcppCommon_h
 #define RcppCommon_h
 
-// TODO: need to bring this from the configure step
-//       but I have no idea how to do it
-#define CXX0X
+#ifdef __GNUC__
+	#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+	#if GCC_VERSION >= 40300
+		#define HAS_VARIADIC_TEMPLATES
+	#endif
+	#if GCC_VERSION >= 40400
+		#define HAS_INIT_LISTS
+	#endif
+#endif
 
 #include <exception>
 #include <iostream>
@@ -66,7 +72,7 @@
 RcppExport SEXP initUncaughtExceptionHandler() ; 
 
 /* just testing variadic templates */
-#ifdef CXX0X
+#ifdef HAS_VARIADIC_TEMPLATES
 template<typename... Args>
 int variadic_length( const Args&... args) { return sizeof...(Args) ; }
 #endif
@@ -74,5 +80,6 @@
 RcppExport SEXP test_variadic() ; 
 RcppExport SEXP canUseCXX0X() ;
 RcppExport SEXP test_named() ;
+RcppExport SEXP capabilities() ;
 
 #endif



More information about the Rcpp-commits mailing list