[Rcpp-commits] r4126 - in pkg/Rcpp: . R inst/include inst/include/Rcpp inst/include/Rcpp/platform src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 10 12:52:54 CET 2012


Author: romain
Date: 2012-12-10 12:52:53 +0100 (Mon, 10 Dec 2012)
New Revision: 4126

Added:
   pkg/Rcpp/inst/include/Rcpp/platform/
   pkg/Rcpp/inst/include/Rcpp/platform/compiler.h
   pkg/Rcpp/src/internal.h
Removed:
   pkg/Rcpp/src/RcppCommon.cpp
   pkg/Rcpp/src/coerce.cpp
   pkg/Rcpp/src/debugging.cpp
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/R/RcppLdpath.R
   pkg/Rcpp/inst/include/Rcpp/config.h
   pkg/Rcpp/inst/include/RcppCommon.h
   pkg/Rcpp/src/Rcpp_init.c
   pkg/Rcpp/src/api.cpp
Log:
start to move things out of Rcpp.h

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/ChangeLog	2012-12-10 11:52:53 UTC (rev 4126)
@@ -1,7 +1,12 @@
 2012-12-10 Romain Francois <romain at r-enthusiasts.com>
 
-        * src/api.cpp: import r_cast.cpp content
-
+        * src/api.cpp: import r_cast.cpp, coerce.cpp, RcppCommon.cpp
+        and debugging.cpp content
+        * include/platform/compiler.h: put here compiler specific deduction things
+        * src/internal.h: new header to host function declarations for 
+        routines that are not exported into Rcpp.h (capabilities, ...)
+        * src/Rcpp_init.c: export capabilities (renamed rcpp_capabilities)
+        
 2012-12-09 Romain Francois <romain at r-enthusiasts.com>
 
         * src/api.cpp: merge many .cpp files here to reduce compile time

Modified: pkg/Rcpp/R/RcppLdpath.R
===================================================================
--- pkg/Rcpp/R/RcppLdpath.R	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/R/RcppLdpath.R	2012-12-10 11:52:53 UTC (rev 4126)
@@ -1,3 +1,19 @@
+# Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+#
+# This file is part of Rcpp.
+#
+# Rcpp is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Rcpp is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
 ## make sure system.file returns an absolute path
 Rcpp.system.file <- function(...){
@@ -70,7 +86,7 @@
 }
 
 # capabilities
-RcppCapabilities <- capabilities <- function() .Call("capabilities", PACKAGE = "Rcpp")
+RcppCapabilities <- capabilities <- function() .Call( rcpp_capabilities )
 
 # compile, load and call the cxx0x.c script to identify whether
 # the compiler is GCC >= 4.3

Modified: pkg/Rcpp/inst/include/Rcpp/config.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/config.h	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/inst/include/Rcpp/config.h	2012-12-10 11:52:53 UTC (rev 4126)
@@ -22,18 +22,6 @@
 #ifndef RCPP__CONFIG_H
 #define RCPP__CONFIG_H
 
-#ifdef __GNUC__
-  // from http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems#MacOS
-  #ifdef __APPLE__ 
-    #include <Availability.h>
-    #ifndef __MAC_10_8
-        #define RCPP_HAS_DEMANGLING
-    #endif
-  #else
-      #define RCPP_HAS_DEMANGLING
-  #endif
-#endif
-
 #define Rcpp_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))
 
 // 0.10.1.02 for devel version

Added: pkg/Rcpp/inst/include/Rcpp/platform/compiler.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/platform/compiler.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/platform/compiler.h	2012-12-10 11:52:53 UTC (rev 4126)
@@ -0,0 +1,194 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// compiler.h: Rcpp R/C++ interface class library -- check compiler
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__platform__compiler_h
+#define Rcpp__platform__compiler_h
+
+#undef GOOD_COMPILER_FOR_RCPP
+#ifdef __GNUC__
+#define GOOD_COMPILER_FOR_RCPP
+#endif
+#ifdef __SUNPRO_CC
+#define GOOD_COMPILER_FOR_RCPP
+#endif
+#ifdef __clang__
+#define GOOD_COMPILER_FOR_RCPP
+#endif
+#ifdef __INTEL_COMPILER
+#define GOOD_COMPILER_FOR_RCPP
+#endif
+
+#ifndef GOOD_COMPILER_FOR_RCPP
+# error "This compiler is not supported"
+#endif
+        
+#ifdef __GNUC__
+    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+    // g++ 4.5 does not seem to like some of the fast indexing
+    #if GCC_VERSION >= 40500
+        #define IS_GCC_450_OR_LATER
+    #endif
+    // g++ 4.6 switches from exception_defines.h to bits/exception_defines.h
+    #if GCC_VERSION < 40600
+        #define IS_EARLIER_THAN_GCC_460
+    #endif
+    #if GCC_VERSION >= 40600
+        #define IS_GCC_460_OR_LATER
+    #endif
+#endif
+
+// Check C++0x features
+#if defined(__INTEL_COMPILER)
+    #if __cplusplus >= 201103L
+        #define HAS_CXX0X_FLAG
+        #if __INTEL_COMPILER >= 1210
+            // #define HAS_VARIADIC_TEMPLATES
+        #endif
+        #if __INTEL_COMPILER >= 1100
+            #define HAS_STATIC_ASSERT
+        #endif
+    #endif
+#elif defined(__clang__)
+    #if __cplusplus >= 201103L
+        #define HAS_CXX0X_FLAG
+        #if __has_feature(cxx_variadic_templates)
+            // #define HAS_VARIADIC_TEMPLATES
+        #endif
+        #if __has_feature(cxx_static_assert)
+            #define HAS_STATIC_ASSERT
+        #endif
+    #endif
+#elif defined(__GNUC__)
+    #ifdef __GXX_EXPERIMENTAL_CXX0X__
+        // #define HAS_CXX0X_FLAG
+        #if GCC_VERSION >= 40300
+            // #define HAS_VARIADIC_TEMPLATES
+            #define HAS_STATIC_ASSERT
+        #endif
+    #endif
+#endif
+
+// Check C++0x headers
+#include <cmath>
+#if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
+    #if defined(__GLIBCXX__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
+        #if __GLIBCXX__ >= 20090421 // GCC 4.4.0
+            #define HAS_CXX0X_UNORDERED_MAP
+            #define HAS_CXX0X_UNORDERED_SET
+            #define HAS_CXX0X_INITIALIZER_LIST
+        #endif
+    #endif
+#elif defined(__clang__)
+    #if __cplusplus >= 201103L
+        #if __has_include(<unordered_map>)
+            #define HAS_CXX0X_UNORDERED_MAP
+        #endif
+        #if __has_include(<unordered_set>)
+            #define HAS_CXX0X_UNORDERED_SET
+        #endif
+        #if __has_include(<initializer_list>)
+            #define HAS_CXX0X_INITIALIZER_LIST
+        #endif
+    #endif
+#endif
+
+// Check TR1 Headers
+#if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
+    #if defined(__GLIBCXX__)
+        #if __GLIBCXX__ >= 20070719 // GCC 4.2.1
+            #define HAS_TR1_UNORDERED_MAP
+            #define HAS_TR1_UNORDERED_SET
+        #endif
+    #endif
+#elif defined(__clang__)
+    #if __cplusplus >= 201103L
+        #if __has_include(<tr1/unordered_map>)
+            #define HAS_TR1_UNORDERED_MAP
+        #endif
+        #if __has_include(<tr1/unordered_set>)
+            #define HAS_TR1_UNORDERED_SET
+        #endif
+    #endif
+#endif
+
+#if defined(HAS_TR1_UNORDERED_MAP) && defined(HAS_TR1_UNORDERED_SET)
+#define HAS_TR1
+#endif
+     
+// Conditionally include headers
+#ifdef HAS_CXX0X_INITIALIZER_LIST
+#include <initializer_list>
+#endif
+
+#ifdef HAS_CXX0X_FLAG
+    #if defined(HAS_CXX0X_UNORDERED_MAP)
+        #include <unordered_map>
+        #define RCPP_UNORDERED_MAP std::unordered_map
+    #else
+        #include <map>
+        #define RCPP_UNORDERED_MAP std::map
+    #endif
+    #if defined(HAS_CXX0X_UNORDERED_SET)
+        #include <unordered_set>
+        #define RCPP_UNORDERED_SET std::unordered_set
+    #else
+        #include <set>
+        #define RCPP_UNORDERED_SET std::set
+    #endif
+#else
+    #if defined(HAS_TR1_UNORDERED_MAP)
+        #include <tr1/unordered_map>
+        #define RCPP_UNORDERED_MAP std::tr1::unordered_map
+    #else
+        #include <map>
+        #define RCPP_UNORDERED_MAP std::map
+    #endif
+    #if defined(HAS_TR1_UNORDERED_SET)
+        #include <tr1/unordered_set>
+        #define RCPP_UNORDERED_SET std::tr1::unordered_set
+    #else
+        #include <set>
+        #define RCPP_UNORDERED_SET std::set
+    #endif
+#endif
+
+#ifdef __GNUC__
+  #ifdef __APPLE__ 
+    #include <Availability.h>
+    #ifndef __MAC_10_8
+        #define RCPP_HAS_DEMANGLING
+    #endif
+  #else
+      #define RCPP_HAS_DEMANGLING
+  #endif
+#endif
+
+#ifdef __GNUC__
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#ifdef LONG_LONG_MAX
+    __extension__ typedef long long int rcpp_long_long_type;
+    __extension__ typedef unsigned long long int rcpp_ulong_long_type;
+    #define RCPP_HAS_LONG_LONG_TYPES
+#endif
+#endif
+#endif
+
+#endif

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2012-12-10 11:52:53 UTC (rev 4126)
@@ -23,24 +23,8 @@
 #ifndef RcppCommon_h
 #define RcppCommon_h
 
-#undef GOOD_COMPILER_FOR_RCPP
-#ifdef __GNUC__
-#define GOOD_COMPILER_FOR_RCPP
-#endif
-#ifdef __SUNPRO_CC
-#define GOOD_COMPILER_FOR_RCPP
-#endif
-#ifdef __clang__
-#define GOOD_COMPILER_FOR_RCPP
-#endif
-#ifdef __INTEL_COMPILER
-#define GOOD_COMPILER_FOR_RCPP
-#endif
+#include <Rcpp/platform/compiler.h>
 
-#ifndef GOOD_COMPILER_FOR_RCPP
-# error "This compiler is not supported"
-#endif
-
 #include <Rcpp/config.h>
 #include <Rcpp/macros/unroll.h>
 
@@ -66,99 +50,6 @@
 
 #include <Rcpp/module/macros.h>
 
-#ifdef __GNUC__
-    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
-    // g++ 4.5 does not seem to like some of the fast indexing
-    #if GCC_VERSION >= 40500
-        #define IS_GCC_450_OR_LATER
-    #endif
-    // g++ 4.6 switches from exception_defines.h to bits/exception_defines.h
-    #if GCC_VERSION < 40600
-        #define IS_EARLIER_THAN_GCC_460
-    #endif
-    #if GCC_VERSION >= 40600
-        #define IS_GCC_460_OR_LATER
-    #endif
-#endif
-
-// Check C++0x features
-#if defined(__INTEL_COMPILER)
-    #if __cplusplus >= 201103L
-        #define HAS_CXX0X_FLAG
-        #if __INTEL_COMPILER >= 1210
-            // #define HAS_VARIADIC_TEMPLATES
-        #endif
-        #if __INTEL_COMPILER >= 1100
-            #define HAS_STATIC_ASSERT
-        #endif
-    #endif
-#elif defined(__clang__)
-    #if __cplusplus >= 201103L
-        #define HAS_CXX0X_FLAG
-        #if __has_feature(cxx_variadic_templates)
-            // #define HAS_VARIADIC_TEMPLATES
-        #endif
-        #if __has_feature(cxx_static_assert)
-            #define HAS_STATIC_ASSERT
-        #endif
-    #endif
-#elif defined(__GNUC__)
-    #ifdef __GXX_EXPERIMENTAL_CXX0X__
-        // #define HAS_CXX0X_FLAG
-        #if GCC_VERSION >= 40300
-            // #define HAS_VARIADIC_TEMPLATES
-            #define HAS_STATIC_ASSERT
-        #endif
-    #endif
-#endif
-
-// Check C++0x headers
-#include <cmath>
-#if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
-    #if defined(__GLIBCXX__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
-        #if __GLIBCXX__ >= 20090421 // GCC 4.4.0
-            #define HAS_CXX0X_UNORDERED_MAP
-            #define HAS_CXX0X_UNORDERED_SET
-            #define HAS_CXX0X_INITIALIZER_LIST
-        #endif
-    #endif
-#elif defined(__clang__)
-    #if __cplusplus >= 201103L
-        #if __has_include(<unordered_map>)
-            #define HAS_CXX0X_UNORDERED_MAP
-        #endif
-        #if __has_include(<unordered_set>)
-            #define HAS_CXX0X_UNORDERED_SET
-        #endif
-        #if __has_include(<initializer_list>)
-            #define HAS_CXX0X_INITIALIZER_LIST
-        #endif
-    #endif
-#endif
-
-// Check TR1 Headers
-#if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
-    #if defined(__GLIBCXX__)
-        #if __GLIBCXX__ >= 20070719 // GCC 4.2.1
-            #define HAS_TR1_UNORDERED_MAP
-            #define HAS_TR1_UNORDERED_SET
-        #endif
-    #endif
-#elif defined(__clang__)
-    #if __cplusplus >= 201103L
-        #if __has_include(<tr1/unordered_map>)
-            #define HAS_TR1_UNORDERED_MAP
-        #endif
-        #if __has_include(<tr1/unordered_set>)
-            #define HAS_TR1_UNORDERED_SET
-        #endif
-    #endif
-#endif
-
-#if defined(HAS_TR1_UNORDERED_MAP) && defined(HAS_TR1_UNORDERED_SET)
-#define HAS_TR1
-#endif
-
 #include <iterator>
 #include <exception>
 #include <iostream>
@@ -178,43 +69,6 @@
 #include <typeinfo>
 #include <Rcpp/sprintf.h>
 
-// Conditionally include headers
-#ifdef HAS_CXX0X_INITIALIZER_LIST
-#include <initializer_list>
-#endif
-
-#ifdef HAS_CXX0X_FLAG
-    #if defined(HAS_CXX0X_UNORDERED_MAP)
-        #include <unordered_map>
-        #define RCPP_UNORDERED_MAP std::unordered_map
-    #else
-        #include <map>
-        #define RCPP_UNORDERED_MAP std::map
-    #endif
-    #if defined(HAS_CXX0X_UNORDERED_SET)
-        #include <unordered_set>
-        #define RCPP_UNORDERED_SET std::unordered_set
-    #else
-        #include <set>
-        #define RCPP_UNORDERED_SET std::set
-    #endif
-#else
-    #if defined(HAS_TR1_UNORDERED_MAP)
-        #include <tr1/unordered_map>
-        #define RCPP_UNORDERED_MAP std::tr1::unordered_map
-    #else
-        #include <map>
-        #define RCPP_UNORDERED_MAP std::map
-    #endif
-    #if defined(HAS_TR1_UNORDERED_SET)
-        #include <tr1/unordered_set>
-        #define RCPP_UNORDERED_SET std::tr1::unordered_set
-    #else
-        #include <set>
-        #define RCPP_UNORDERED_SET std::set
-    #endif
-#endif
-
 // include R headers, but set R_NO_REMAP and access everything via Rf_ prefixes
 #define R_NO_REMAP
 #include <R.h>
@@ -241,32 +95,6 @@
 
 RcppExport void init_Rcpp_routines(DllInfo*) ;
 
-namespace Rcpp{
-    namespace internal{
-        template <typename T> int rcpp_call_test(T t){
-            return T::r_type::value ;
-        }
-        int rcpp_call_test_(SEXP) ;
-    }
-}
-
-extern "C" SEXP rcpp_call_test(SEXP x) ;
-
-/* just testing variadic templates */
-#ifdef HAS_VARIADIC_TEMPLATES
-template<typename... Args>
-int variadic_length( const Args&... args) { return sizeof...(Args) ; }
-#endif
-
-#ifdef HAS_VARIADIC_TEMPLATES
-RcppExport inline SEXP canUseCXX0X(){ return Rf_ScalarLogical( TRUE ); }
-#else
-RcppExport inline SEXP canUseCXX0X(){ return Rf_ScalarLogical( FALSE ); }
-#endif
-
-
-RcppExport SEXP capabilities() ;
-
 const char * sexp_to_name(int sexp_type); 
 
 #include <Rcpp/exceptions.h>
@@ -295,20 +123,6 @@
 	  inline void stop(const std::string& message) { throw Rcpp::exception(message.c_str()); }
 } // namespace Rcpp
 
-#if RCPP_DEBUG_LEVEL > 0
-    #include <typeinfo>
-#endif
-
-#ifdef __GNUC__
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-#ifdef LONG_LONG_MAX
-    __extension__ typedef long long int rcpp_long_long_type;
-    __extension__ typedef unsigned long long int rcpp_ulong_long_type;
-    #define RCPP_HAS_LONG_LONG_TYPES
-#endif
-#endif
-#endif
-
 namespace Rcpp{
     template <typename T> class object ;
     class String ;

Deleted: pkg/Rcpp/src/RcppCommon.cpp
===================================================================
--- pkg/Rcpp/src/RcppCommon.cpp	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/src/RcppCommon.cpp	2012-12-10 11:52:53 UTC (rev 4126)
@@ -1,222 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// RcppCommon.cpp: R/C++ interface class library -- common functions
-//
-// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
-// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
-//
-// This file is part of Rcpp.
-//
-// Rcpp is free software: you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// (at your option) any later version.
-//
-// Rcpp is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
-
-#include <Rcpp.h>
-#include <cstring>
-#include <stdio.h>
-
-void logTxtFunction(const char* file, const int line, const char* expression) {
-    Rprintf("%s:%d %s\n", file, line, expression);
-}
-
-SEXP capabilities(){
-	SEXP cap = PROTECT( Rf_allocVector( LGLSXP, 8) ) ;
-	SEXP names = PROTECT( Rf_allocVector( STRSXP, 8 ) ) ;
-#ifdef HAS_VARIADIC_TEMPLATES
-	LOGICAL(cap)[0] = TRUE ;
-#else
-	LOGICAL(cap)[0] = FALSE ;
-#endif
-#ifdef HAS_CXX0X_INITIALIZER_LIST
-	LOGICAL(cap)[1] = TRUE ;
-#else
-	LOGICAL(cap)[1] = FALSE ;
-#endif
-	/* exceptions are allways supported */
-	LOGICAL(cap)[2] = TRUE ;
-
-#ifdef HAS_TR1_UNORDERED_MAP
-	LOGICAL(cap)[3] = TRUE ;
-#else
-	LOGICAL(cap)[3] = FALSE ;
-#endif
-
-#ifdef HAS_TR1_UNORDERED_SET
-	LOGICAL(cap)[4] = TRUE ;
-#else
-	LOGICAL(cap)[4] = FALSE ;
-#endif
-
-	LOGICAL(cap)[5] = TRUE ;
-
-#ifdef RCPP_HAS_DEMANGLING
-	LOGICAL(cap)[6] = TRUE ;
-#else
-	LOGICAL(cap)[6] = FALSE ;
-#endif
-
-	LOGICAL(cap)[7] = FALSE ;
-
-	SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates") ) ;
-	SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists") ) ;
-	SET_STRING_ELT(names, 2, Rf_mkChar("exception handling") ) ;
-	SET_STRING_ELT(names, 3, Rf_mkChar("tr1 unordered maps") ) ;
-	SET_STRING_ELT(names, 4, Rf_mkChar("tr1 unordered sets") ) ;
-	SET_STRING_ELT(names, 5, Rf_mkChar("Rcpp modules") ) ;
-	SET_STRING_ELT(names, 6, Rf_mkChar("demangling") ) ;
-	SET_STRING_ELT(names, 7, Rf_mkChar("classic api") ) ;
-	Rf_setAttrib( cap, R_NamesSymbol, names ) ;
-	UNPROTECT(2) ;
-	return cap ;
-}
-
-const char * sexp_to_name(int sexp_type) {
-    switch (sexp_type) {
-    case NILSXP:	return "NILSXP";
-    case SYMSXP:	return "SYMSXP";
-    case RAWSXP:	return "RAWSXP";
-    case LISTSXP:	return "LISTSXP";
-    case CLOSXP:	return "CLOSXP";
-    case ENVSXP:	return "ENVSXP";
-    case PROMSXP:	return "PROMSXP";
-    case LANGSXP:	return "LANGSXP";
-    case SPECIALSXP:	return "SPECIALSXP";
-    case BUILTINSXP:	return "BUILTINSXP";
-    case CHARSXP:	return "CHARSXP";
-    case LGLSXP:	return "LGLSXP";
-    case INTSXP:	return "INTSXP";
-    case REALSXP:	return "REALSXP";
-    case CPLXSXP:	return "CPLXSXP";
-    case STRSXP:	return "STRSXP";
-    case DOTSXP:	return "DOTSXP";
-    case ANYSXP:	return "ANYSXP";
-    case VECSXP:	return "VECSXP";
-    case EXPRSXP:	return "EXPRSXP";
-    case BCODESXP:	return "BCODESXP";
-    case EXTPTRSXP:	return "EXTPTRSXP";
-    case WEAKREFSXP:	return "WEAKREFSXP";
-    case S4SXP:		return "S4SXP";
-    default:
-	return "<unknown>";
-    }
-}
-
-namespace Rcpp{
-namespace internal{
-
-	template<> int* r_vector_start<INTSXP>(SEXP x){ return INTEGER(x) ; }
-	template<> int* r_vector_start<LGLSXP>(SEXP x){ return LOGICAL(x) ; }
-	template<> double* r_vector_start<REALSXP>(SEXP x){ return REAL(x) ; }
-	template<> Rbyte* r_vector_start<RAWSXP>(SEXP x){ return RAW(x) ; }
-	template<> Rcomplex* r_vector_start<CPLXSXP>(SEXP x){ return COMPLEX(x) ; }
-	
-	template<> void r_init_vector<VECSXP>(SEXP x){}
-	template<> void r_init_vector<EXPRSXP>(SEXP x){}
-	template<> void r_init_vector<STRSXP>(SEXP x){}
-
-	template<> Rcomplex get_zero<CPLXSXP,Rcomplex>(){
-		Rcomplex x ;
-		x.r = 0.0 ;
-		x.i = 0.0 ;
-		return x ;
-	}
-
-	template<> Rcomplex caster<std::complex<double>, Rcomplex>( std::complex<double> from){
-		Rcomplex cx ;
-		cx.r = from.real() ; 
-		cx.i = from.imag() ;
-		return cx ;
-	}
-	template<> Rcomplex caster<std::complex<float>, Rcomplex>( std::complex<float> from){
-		Rcomplex cx ;
-		cx.r = static_cast<double>( from.real() ); 
-		cx.i = static_cast<double>( from.imag() );
-		return cx ;
-	}
-
-	template<> std::complex<double> caster<Rcomplex,std::complex<double> >( Rcomplex from){
-		return std::complex<double>(from.r, from.i ) ;
-	}
-	template<> std::complex<float> caster<Rcomplex,std::complex<float> >( Rcomplex from){
-		return std::complex<float>(static_cast<float>(from.r), static_cast<float>(from.i) ) ;
-	}
-
-	int rcpp_call_test_(SEXP x){
-		RCPP_RETURN_VECTOR( rcpp_call_test, x );
-	}
-	
-	SEXP convert_using_rfunction(SEXP x, const char* const fun) {
-        SEXP res = R_NilValue ;
-        try{
-            SEXP funSym = Rf_install(fun);
-            res = Evaluator::run( Rf_lang2( funSym, x ) ) ;
-        } catch( eval_error& e){
-            throw ::Rcpp::not_compatible( std::string("could not convert using R function : ") + fun  ) ;
-        }
-        return res;
-    }
-    
-    SEXP try_catch( SEXP expr, SEXP env ) {
-        return Evaluator::run(expr, env) ;
-    }
-    SEXP try_catch( SEXP expr ) {
-        return Evaluator::run(expr) ;
-    }
-    
-    SEXP eval_methods<EXPRSXP>::eval(){
-        SEXP xp = ( static_cast<ExpressionVector&>(*this) ).asSexp() ;
-        SEXP evalSym = Rf_install( "eval" );
-        return try_catch( Rf_lang2( evalSym, xp ) ) ;
-    }
-    
-    SEXP eval_methods<EXPRSXP>::eval( SEXP env ){
-        SEXP xp = ( static_cast<ExpressionVector&>(*this) ).asSexp() ;
-        SEXP evalSym = Rf_install( "eval" );
-        return try_catch( Rf_lang3( evalSym, xp, env ) ) ;
-    }
-	
-} // internal
-} // Rcpp
-
-SEXP rcpp_call_test(SEXP x){
-	return Rf_ScalarInteger( ::Rcpp::internal::rcpp_call_test_(x) ) ;
-}
-
-SEXP as_character_externalptr(SEXP xp){
-	char buffer[20] ;
-	sprintf( buffer, "%p", (void*)EXTPTR_PTR(xp) ) ;
-	return Rcpp::wrap( (const char*)buffer ) ;
-}
-
-SEXP exception_to_try_error( const std::exception& ex ){
-    return string_to_try_error(ex.what());
-}
-
-SEXP string_to_try_error( const std::string& str){
-
-    using namespace Rcpp;
-	
-    // form simple error condition based on a string
-    SEXP rcppNS = PROTECT(R_FindNamespace(Rf_mkString("Rcpp")));
-    SEXP simpleErrorExpr = PROTECT(::Rcpp_lcons(::Rf_install("simpleError"),
-                                            pairlist(str, R_NilValue)));
-    SEXP simpleError = PROTECT(Rf_eval(simpleErrorExpr, rcppNS));
-	
-    // create the try-error structure
-    SEXP structureExpr = PROTECT(::Rcpp_lcons(::Rf_install("structure"), 
-        pairlist(str, _["class"] = "try-error", _["condition"] = simpleError)));
-    SEXP tryError = PROTECT(Rf_eval(structureExpr, rcppNS));
-	
-    // unprotect and return
-    UNPROTECT(5);
-    return tryError;
-}

Modified: pkg/Rcpp/src/Rcpp_init.c
===================================================================
--- pkg/Rcpp/src/Rcpp_init.c	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/src/Rcpp_init.c	2012-12-10 11:52:53 UTC (rev 4126)
@@ -23,6 +23,7 @@
 #include <R_ext/Rdynload.h>
 
 #include <Rcpp/routines.h>
+#include "internal.h"
 
 // borrowed from Matrix
 #define CALLDEF(name, n)  {#name, (DL_FUNC) &name, n}
@@ -64,6 +65,10 @@
     CALLDEF(rcpp_set_stack_trace,1), 
     CALLDEF(rcpp_get_stack_trace,0),
     
+    // functions that are not defined in Rcpp.h
+    CALLDEF(rcpp_capabilities,0),
+    CALLDEF(rcpp_can_use_cxx0x,0),
+    CALLDEF(rcpp_call_test,1),
     {NULL, NULL, 0}
 }; 
 

Modified: pkg/Rcpp/src/api.cpp
===================================================================
--- pkg/Rcpp/src/api.cpp	2012-12-10 08:43:53 UTC (rev 4125)
+++ pkg/Rcpp/src/api.cpp	2012-12-10 11:52:53 UTC (rev 4126)
@@ -22,8 +22,11 @@
 
 #include <Rcpp.h>
 
+#include "internal.h" 
+
 // for R_ObjectTable
 #include <R_ext/Callbacks.h>
+#include <R_ext/PrtUtil.h>
 
 // {{{ Rcpp api classes
 namespace Rcpp {
@@ -141,7 +144,7 @@
 
     RObject::~RObject() {
         release() ;
-        logTxt("~RObject");
+        RCPP_DEBUG("~RObject")
     }
 
     std::vector<std::string> RObject::attributeNames() const {
@@ -848,7 +851,7 @@
     }
     
     Environment::~Environment(){
-        logTxt( "~Environment" ) ;
+        RCPP_DEBUG( "~Environment" )
     }
         
     SEXP Environment::ls( bool all = true) const {
@@ -1093,6 +1096,458 @@
 }
 // }}}
 
+// {{{ utilities (from RcppCommon.cpp)
+void logTxtFunction(const char* file, const int line, const char* expression) {
+    Rprintf("%s:%d %s\n", file, line, expression);
+}
+
+SEXP rcpp_can_use_cxx0x(){ 
+#ifdef HAS_VARIADIC_TEMPLATES
+    return Rf_ScalarLogical( TRUE );
+#else
+    return Rf_ScalarLogical( FALSE );
+#endif
+}
+
+SEXP rcpp_capabilities(){
+	SEXP cap = PROTECT( Rf_allocVector( LGLSXP, 8) ) ;
+	SEXP names = PROTECT( Rf_allocVector( STRSXP, 8 ) ) ;
+#ifdef HAS_VARIADIC_TEMPLATES
+	LOGICAL(cap)[0] = TRUE ;
+#else
+	LOGICAL(cap)[0] = FALSE ;
+#endif
+#ifdef HAS_CXX0X_INITIALIZER_LIST
+	LOGICAL(cap)[1] = TRUE ;
+#else
+	LOGICAL(cap)[1] = FALSE ;
+#endif
+	/* exceptions are always supported */
+	LOGICAL(cap)[2] = TRUE ;
+
+#ifdef HAS_TR1_UNORDERED_MAP
+	LOGICAL(cap)[3] = TRUE ;
+#else
+	LOGICAL(cap)[3] = FALSE ;
+#endif
+
+#ifdef HAS_TR1_UNORDERED_SET
+	LOGICAL(cap)[4] = TRUE ;
+#else
+	LOGICAL(cap)[4] = FALSE ;
+#endif
+
+	LOGICAL(cap)[5] = TRUE ;
+
+#ifdef RCPP_HAS_DEMANGLING
+	LOGICAL(cap)[6] = TRUE ;
+#else
+	LOGICAL(cap)[6] = FALSE ;
+#endif
+
+	LOGICAL(cap)[7] = FALSE ;
+
+	SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates") ) ;
+	SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists") ) ;
+	SET_STRING_ELT(names, 2, Rf_mkChar("exception handling") ) ;
+	SET_STRING_ELT(names, 3, Rf_mkChar("tr1 unordered maps") ) ;
+	SET_STRING_ELT(names, 4, Rf_mkChar("tr1 unordered sets") ) ;
+	SET_STRING_ELT(names, 5, Rf_mkChar("Rcpp modules") ) ;
+	SET_STRING_ELT(names, 6, Rf_mkChar("demangling") ) ;
+	SET_STRING_ELT(names, 7, Rf_mkChar("classic api") ) ;
+	Rf_setAttrib( cap, R_NamesSymbol, names ) ;
+	UNPROTECT(2) ;
+	return cap ;
+}
+
+const char * sexp_to_name(int sexp_type) {
+    switch (sexp_type) {
+    case NILSXP:	return "NILSXP";
+    case SYMSXP:	return "SYMSXP";
+    case RAWSXP:	return "RAWSXP";
+    case LISTSXP:	return "LISTSXP";
+    case CLOSXP:	return "CLOSXP";
+    case ENVSXP:	return "ENVSXP";
+    case PROMSXP:	return "PROMSXP";
+    case LANGSXP:	return "LANGSXP";
+    case SPECIALSXP:	return "SPECIALSXP";
+    case BUILTINSXP:	return "BUILTINSXP";
+    case CHARSXP:	return "CHARSXP";
+    case LGLSXP:	return "LGLSXP";
+    case INTSXP:	return "INTSXP";
+    case REALSXP:	return "REALSXP";
+    case CPLXSXP:	return "CPLXSXP";
+    case STRSXP:	return "STRSXP";
+    case DOTSXP:	return "DOTSXP";
+    case ANYSXP:	return "ANYSXP";
+    case VECSXP:	return "VECSXP";
+    case EXPRSXP:	return "EXPRSXP";
+    case BCODESXP:	return "BCODESXP";
+    case EXTPTRSXP:	return "EXTPTRSXP";
+    case WEAKREFSXP:	return "WEAKREFSXP";
+    case S4SXP:		return "S4SXP";
+    default:
+	return "<unknown>";
+    }
+}
+
+namespace Rcpp{
+namespace internal{
+
+	template<> int* r_vector_start<INTSXP>(SEXP x){ return INTEGER(x) ; }
+	template<> int* r_vector_start<LGLSXP>(SEXP x){ return LOGICAL(x) ; }
+	template<> double* r_vector_start<REALSXP>(SEXP x){ return REAL(x) ; }
+	template<> Rbyte* r_vector_start<RAWSXP>(SEXP x){ return RAW(x) ; }
+	template<> Rcomplex* r_vector_start<CPLXSXP>(SEXP x){ return COMPLEX(x) ; }
+	
+	template<> void r_init_vector<VECSXP>(SEXP x){}
+	template<> void r_init_vector<EXPRSXP>(SEXP x){}
+	template<> void r_init_vector<STRSXP>(SEXP x){}
+
+	template<> Rcomplex get_zero<CPLXSXP,Rcomplex>(){
+		Rcomplex x ;
+		x.r = 0.0 ;
+		x.i = 0.0 ;
+		return x ;
+	}
+
+	template<> Rcomplex caster<std::complex<double>, Rcomplex>( std::complex<double> from){
+		Rcomplex cx ;
+		cx.r = from.real() ; 
+		cx.i = from.imag() ;
+		return cx ;
+	}
+	template<> Rcomplex caster<std::complex<float>, Rcomplex>( std::complex<float> from){
+		Rcomplex cx ;
+		cx.r = static_cast<double>( from.real() ); 
+		cx.i = static_cast<double>( from.imag() );
+		return cx ;
+	}
+
+	template<> std::complex<double> caster<Rcomplex,std::complex<double> >( Rcomplex from){
+		return std::complex<double>(from.r, from.i ) ;
+	}
+	template<> std::complex<float> caster<Rcomplex,std::complex<float> >( Rcomplex from){
+		return std::complex<float>(static_cast<float>(from.r), static_cast<float>(from.i) ) ;
+	}
+
+	// TODO: move these two things in testing
+	template <typename T> int rcpp_call_test(T t){
+        return T::r_type::value ;
+    }
+    int rcpp_call_test_(SEXP x){
+		RCPP_RETURN_VECTOR( rcpp_call_test, x );
+	}
+	
+	SEXP convert_using_rfunction(SEXP x, const char* const fun) {
+        SEXP res = R_NilValue ;
+        try{
+            SEXP funSym = Rf_install(fun);
+            res = Evaluator::run( Rf_lang2( funSym, x ) ) ;
+        } catch( eval_error& e){
+            throw ::Rcpp::not_compatible( std::string("could not convert using R function : ") + fun  ) ;
+        }
+        return res;
+    }
+    
+    SEXP try_catch( SEXP expr, SEXP env ) {
+        return Evaluator::run(expr, env) ;
+    }
+    SEXP try_catch( SEXP expr ) {
+        return Evaluator::run(expr) ;
+    }
+    
+    SEXP eval_methods<EXPRSXP>::eval(){
+        SEXP xp = ( static_cast<ExpressionVector&>(*this) ).asSexp() ;
+        SEXP evalSym = Rf_install( "eval" );
+        return try_catch( Rf_lang2( evalSym, xp ) ) ;
+    }
+    
+    SEXP eval_methods<EXPRSXP>::eval( SEXP env ){
+        SEXP xp = ( static_cast<ExpressionVector&>(*this) ).asSexp() ;
+        SEXP evalSym = Rf_install( "eval" );
+        return try_catch( Rf_lang3( evalSym, xp, env ) ) ;
+    }
+	
+} // internal
+} // Rcpp
+
+SEXP rcpp_call_test(SEXP x){
+	return Rf_ScalarInteger( ::Rcpp::internal::rcpp_call_test_(x) ) ;
+}
+
+SEXP as_character_externalptr(SEXP xp){
+	char buffer[20] ;
+	sprintf( buffer, "%p", (void*)EXTPTR_PTR(xp) ) ;
+	return Rcpp::wrap( (const char*)buffer ) ;
+}
+
+SEXP exception_to_try_error( const std::exception& ex ){
+    return string_to_try_error(ex.what());
+}
+
+SEXP string_to_try_error( const std::string& str){
+
+    using namespace Rcpp;
+	
+    // form simple error condition based on a string
+    SEXP rcppNS = PROTECT(R_FindNamespace(Rf_mkString("Rcpp")));
+    SEXP simpleErrorExpr = PROTECT(::Rcpp_lcons(::Rf_install("simpleError"),
+                                            pairlist(str, R_NilValue)));
+    SEXP simpleError = PROTECT(Rf_eval(simpleErrorExpr, rcppNS));
+	
+    // create the try-error structure
+    SEXP structureExpr = PROTECT(::Rcpp_lcons(::Rf_install("structure"), 
+        pairlist(str, _["class"] = "try-error", _["condition"] = simpleError)));
+    SEXP tryError = PROTECT(Rf_eval(structureExpr, rcppNS));
+	
+    // unprotect and return
+    UNPROTECT(5);
+    return tryError;
+}
+
+const char* short_file_name(const char* file){
+    std::string f(file) ;
+    size_t index = f.find("/include/") ;
+    if( index != std::string::npos ){ f = f.substr( index + 9 ) ;}
+    return f.c_str() ;
+}
+
+#if defined(__GNUC__)
+#if defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__)
+// Simpler version for Windows and *BSD 
+SEXP stack_trace( const char* file, int line ){
+    Rcpp::List trace = Rcpp::List::create( 
+    	Rcpp::Named( "file"  ) = file, 
+    	Rcpp::Named( "line"  ) = line, 
+    	Rcpp::Named( "stack" ) = "C++ stack not available on this system" ) ;
+    trace.attr("class") = "Rcpp_stack_trace" ;
+    return trace ;
+}
+#else // ! (defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__)
+#include <execinfo.h>
+#include <cxxabi.h>
+
+static std::string demangler_one( const char* input){
+    static std::string buffer ;
+    buffer = input ;
+    buffer.resize( buffer.find_last_of( '+' ) - 1 ) ;
+    buffer.erase(
+        buffer.begin(), 
+        buffer.begin() + buffer.find_last_of( ' ' ) + 1
+    ) ;
+    return demangle( buffer) ;
+}
+
+/* inspired from http://tombarta.wordpress.com/2008/08/01/c-stack-traces-with-gcc/  */ 
+SEXP stack_trace( const char *file, int line) {
+    const size_t max_depth = 100;
+    size_t stack_depth;
+    void *stack_addrs[max_depth];
+    char **stack_strings;
+
+    stack_depth = backtrace(stack_addrs, max_depth);
+    stack_strings = backtrace_symbols(stack_addrs, stack_depth);
+
+    std::string current_line ;
+    
+    Rcpp::CharacterVector res( stack_depth - 1) ;
+    std::transform( 
+    	stack_strings + 1, stack_strings + stack_depth, 
+    	res.begin(), 
+    	demangler_one 
+    	) ;
+    free(stack_strings); // malloc()ed by backtrace_symbols
+    
+    Rcpp::List trace = Rcpp::List::create( 
+    	Rcpp::Named( "file"  ) = file, 
+    	Rcpp::Named( "line"  ) = line, 
+    	Rcpp::Named( "stack" ) = res ) ;
+    trace.attr("class") = "Rcpp_stack_trace" ;
+    return trace ;
+}
+#endif 
+#else /* !defined( __GNUC__ ) */
+SEXP stack_trace( const char *file, int line) {
+	return R_NilValue ;
+}
+#endif   
+// }}}
+
+// {{{ coercion
+
+namespace Rcpp{ 
+namespace internal{
+
+template <> int r_coerce<INTSXP,INTSXP>(int from) { return from ; }
+template <> int r_coerce<LGLSXP,LGLSXP>(int from) { return from ; }
+template <> double r_coerce<REALSXP,REALSXP>(double from) { return from ; }
+template <> Rcomplex r_coerce<CPLXSXP,CPLXSXP>(Rcomplex from) { return from ; }
+template <> Rbyte r_coerce<RAWSXP,RAWSXP>(Rbyte from) { return from ; }
+
+// -> INTSXP
+template <> int r_coerce<LGLSXP,INTSXP>(int from){
+	return (from==NA_LOGICAL) ? NA_INTEGER : from ;
+}
+template <> int r_coerce<REALSXP,INTSXP>(double from){
+	if (ISNAN(from)) return NA_INTEGER;
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcpp -r 4126


More information about the Rcpp-commits mailing list