Skip to content

Commit d238645

Browse files
Merge pull request #53 from RcppCore/headeronly
Making Rcpp header only. closes #36
2 parents 820e15b + e2e7877 commit d238645

File tree

152 files changed

+6011
-6735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+6011
-6735
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inst/lib
2+

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ env:
2727
global:
2828
- R_BUILD_ARGS="--no-build-vignettes --no-manual"
2929
- R_CHECK_ARGS="--no-build-vignettes --no-manual --as-cran"
30+
- RunAllRcppTests="yes"
31+
3032
# See the travis docs for more information:
3133
# http://about.travis-ci.org/docs/user/build-configuration/#The-Build-Matrix
3234

R/Rcpp.package.skeleton.R

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,7 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
134134
dir.create( src )
135135
}
136136
skeleton <- system.file( "skeleton", package = "Rcpp" )
137-
Makevars <- file.path( src, "Makevars" )
138-
if( !file.exists( Makevars ) ){
139-
file.copy( file.path( skeleton, "Makevars" ), Makevars )
140-
message( " >> added Makevars file with Rcpp settings" )
141-
}
142-
143-
Makevars.win <- file.path( src, "Makevars.win" )
144-
if( !file.exists( Makevars.win ) ){
145-
file.copy( file.path( skeleton, "Makevars.win" ), Makevars.win )
146-
message( " >> added Makevars.win file with Rcpp settings" )
147-
}
148-
137+
149138
if ( length(cpp_files) > 0L ) {
150139
for (file in cpp_files) {
151140
file.copy(file, src)

R/RcppLdpath.R

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
1+
# Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
22
#
33
# This file is part of Rcpp.
44
#
@@ -20,22 +20,10 @@ Rcpp.system.file <- function(...){
2020
tools::file_path_as_absolute( base::system.file( ..., package = "Rcpp" ) )
2121
}
2222

23-
## identifies if the default linking on the platform should be static
24-
## or dynamic. Currently only linux uses dynamic linking by default
25-
## although it works fine on mac osx as well
26-
staticLinking <- function() {
27-
! grepl( "^linux", R.version$os )
28-
}
29-
3023
## Use R's internal knowledge of path settings to find the lib/ directory
3124
## plus optinally an arch-specific directory on system building multi-arch
3225
RcppLdPath <- function() {
33-
if (nzchar(.Platform$r_arch)) { ## eg amd64, ia64, mips
34-
path <- Rcpp.system.file("lib",.Platform$r_arch)
35-
} else {
36-
path <- Rcpp.system.file("lib")
37-
}
38-
path
26+
""
3927
}
4028

4129
## Provide linker flags -- i.e. -L/path/to/libRcpp -- as well as an
@@ -45,34 +33,15 @@ RcppLdPath <- function() {
4533
## Updated Jan 2010: We now default to static linking but allow the use
4634
## of rpath on Linux if static==FALSE has been chosen
4735
## Note that this is probably being called from LdFlags()
48-
RcppLdFlags <- function(static=staticLinking()) {
49-
rcppdir <- RcppLdPath()
50-
if (static) { # static is default on Windows and OS X
51-
flags <- paste(rcppdir, "/libRcpp.a", sep="")
52-
if (.Platform$OS.type=="windows") {
53-
flags <- asBuildPath(flags)
54-
}
55-
} else { # else for dynamic linking
56-
flags <- paste("-L", rcppdir, " -lRcpp", sep="") # baseline setting
57-
if ((.Platform$OS.type == "unix") && # on Linux, we can use rpath to encode path
58-
(length(grep("^linux",R.version$os)))) {
59-
flags <- paste(flags, " -Wl,-rpath,", rcppdir, sep="")
60-
}
61-
}
62-
invisible(flags)
63-
}
36+
## Updated Nov 2013: We no longer build a library. This should be deprecated.
37+
RcppLdFlags <- function() { "" }
6438

6539
# indicates if Rcpp was compiled with GCC >= 4.3
6640
canUseCXX0X <- function() .Call( "canUseCXX0X", PACKAGE = "Rcpp" )
6741

6842
## Provide compiler flags -- i.e. -I/path/to/Rcpp.h
6943
RcppCxxFlags <- function(cxx0x=FALSE) {
70-
# path <- RcppLdPath()
71-
path <- Rcpp.system.file( "include" )
72-
if (.Platform$OS.type=="windows") {
73-
path <- asBuildPath(path)
74-
}
75-
paste("-I", path, if( cxx0x && canUseCXX0X() ) " -std=c++0x" else "", sep="")
44+
""
7645
}
7746

7847
## Shorter names, and call cat() directly
@@ -81,8 +50,8 @@ CxxFlags <- function(cxx0x=FALSE) {
8150
cat(RcppCxxFlags(cxx0x=cxx0x))
8251
}
8352
## LdFlags defaults to static linking on the non-Linux platforms Windows and OS X
84-
LdFlags <- function(static=staticLinking()) {
85-
cat(RcppLdFlags(static=static))
53+
LdFlags <- function() {
54+
cat(RcppLdFlags())
8655
}
8756

8857
# capabilities

R/inline.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2009 - 2011 Dirk Eddelbuettel and Romain Francois
1+
# Copyright (C) 2009 - 2013 Dirk Eddelbuettel and Romain Francois
22
#
33
# This file is part of Rcpp.
44
#
@@ -21,8 +21,8 @@ Rcpp.plugin.maker <- function(
2121
LinkingTo = unique( c( package, "Rcpp" ) ),
2222
Depends = unique( c( package, "Rcpp" ) ),
2323
libs = "",
24-
Makevars = readLines( system.file("skeleton", "Makevars" , package = package ) ) ,
25-
Makevars.win = readLines( system.file("skeleton", "Makevars.win", package = package ) ),
24+
Makevars = NULL ,
25+
Makevars.win = NULL,
2626
package = "Rcpp"
2727
){
2828
function( ... ){
@@ -41,17 +41,18 @@ includes <- sprintf( "%s
4141
using namespace Rcpp;
4242
", include.before, include.after )
4343

44-
list(
45-
env = list( PKG_LIBS = paste( libs, Rcpp::RcppLdFlags() ) ),
44+
out <- list(
45+
env = list( PKG_LIBS = libs ),
4646
includes = includes,
4747
LinkingTo = LinkingTo ,
4848
body = function( x ){
4949
sprintf( "BEGIN_RCPP\n%s\nEND_RCPP", x )
5050
},
51-
Depends = Depends,
52-
Makevars = Makevars,
53-
Makevars.win = Makevars.win
51+
Depends = Depends
5452
)
53+
if( !is.null(Makevars ) ) out$Makevars <- Makevars
54+
if( !is.null(Makevars.win ) ) out$Makevars.win <- Makevars.win
55+
out
5556
}
5657
}
5758

R/unit.tests.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ test <- function( output = if( file.exists( "/tmp" ) ) "/tmp" else getwd() ){
2727
system( cmd )
2828
}
2929

30-
compile_unit_tests <- function( definitions, includes = "", cxxargs = "" ){
31-
signatures <- lapply(definitions, "[[", 1L)
32-
bodies <- lapply(definitions, "[[", 2L)
33-
cxxfunction <- get( "cxxfunction", asNamespace("inline" ) )
34-
fun <- cxxfunction( signatures, bodies, plugin = "Rcpp",
35-
includes = sprintf( "using namespace std;\n%s", paste( includes, collapse = "\n") ),
36-
cxxargs = cxxargs
37-
)
38-
fun
39-
}
40-
4130
unit_test_setup <- function(file, packages = NULL) {
4231
function(){
4332
if( !is.null(packages) ){

inst/include/Rcpp.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,28 @@
2626
/* it is important that this comes first */
2727
#include <RcppCommon.h>
2828

29-
/* new api */
30-
#include <Rcpp/exceptions.h>
31-
3229
#include <Rcpp/RObject.h>
3330

34-
#include <Rcpp/Promise.h>
3531
#include <Rcpp/S4.h>
3632
#include <Rcpp/Reference.h>
3733
#include <Rcpp/clone.h>
3834
#include <Rcpp/grow.h>
3935
#include <Rcpp/Dimension.h>
4036
#include <Rcpp/Environment.h>
41-
#include <Rcpp/Evaluator.h>
4237

4338
#include <Rcpp/Vector.h>
4439
#include <Rcpp/sugar/nona/nona.h>
4540
#include <Rcpp/Fast.h>
4641
#include <Rcpp/Extractor.h>
42+
#include <Rcpp/Promise.h>
4743

4844
#include <Rcpp/XPtr.h>
4945
#include <Rcpp/Symbol.h>
46+
#include <Rcpp/DottedPairImpl.h>
47+
#include <Rcpp/Function.h>
5048
#include <Rcpp/Language.h>
5149
#include <Rcpp/DottedPair.h>
5250
#include <Rcpp/Pairlist.h>
53-
#include <Rcpp/Function.h>
5451
#include <Rcpp/WeakReference.h>
5552
#include <Rcpp/StringTransformer.h>
5653
#include <Rcpp/Formula.h>

inst/include/Rcpp/Benchmark/Timer.h

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Timer.h: Rcpp R/C++ interface class library -- Rcpp benchmark utility
44
//
5-
// Copyright (C) 2012 JJ Allaire, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2013 JJ Allaire, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -29,25 +29,109 @@
2929
#define R_NO_REMAP
3030
#include <Rinternals.h>
3131

32+
#if defined(_WIN32)
33+
#define WIN32_LEAN_AND_MEAN
34+
#include <windows.h>
35+
#elif defined(__APPLE__)
36+
#include <mach/mach_time.h>
37+
#elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__)
38+
#include <time.h>
39+
#elif defined(sun) || defined(__sun) || defined(_AIX)
40+
#include <sys/time.h>
41+
#else /* Unsupported OS */
42+
#error "Rcpp::Timer not supported by your OS."
43+
#endif
44+
3245
namespace Rcpp{
3346

3447
typedef uint64_t nanotime_t;
35-
nanotime_t get_nanotime(void);
48+
49+
#if defined(_WIN32)
50+
51+
inline nanotime_t get_nanotime(void) {
52+
LARGE_INTEGER time_var, frequency;
53+
QueryPerformanceCounter(&time_var);
54+
QueryPerformanceFrequency(&frequency);
55+
56+
/* Convert to nanoseconds */
57+
return 1.0e9 * time_var.QuadPart / frequency.QuadPart;
58+
}
59+
60+
#elif defined(__APPLE__)
61+
62+
inline nanotime_t get_nanotime(void) {
63+
nanotime_t time;
64+
mach_timebase_info_data_t info;
65+
66+
time = mach_absolute_time();
67+
mach_timebase_info(&info);
68+
69+
/* Convert to nanoseconds */
70+
return time * (info.numer / info.denom);
71+
}
72+
73+
#elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__)
74+
75+
static const nanotime_t nanoseconds_in_second = static_cast<nanotime_t>(1000000000.0);
76+
77+
inline nanotime_t get_nanotime(void) {
78+
struct timespec time_var;
79+
80+
/* Possible other values we could have used are CLOCK_MONOTONIC,
81+
* which is takes longer to retrieve and CLOCK_PROCESS_CPUTIME_ID
82+
* which, if I understand it correctly, would require the R
83+
* process to be bound to one core.
84+
*/
85+
clock_gettime(CLOCK_REALTIME, &time_var);
86+
87+
nanotime_t sec = time_var.tv_sec;
88+
nanotime_t nsec = time_var.tv_nsec;
89+
90+
/* Combine both values to one nanoseconds value */
91+
return (nanoseconds_in_second * sec) + nsec;
92+
}
93+
94+
#elif defined(sun) || defined(__sun) || defined(_AIX)
95+
96+
/* short an sweet! */
97+
inline nanotime_t get_nanotime(void) {
98+
return gethrtime();
99+
}
100+
101+
#endif
102+
36103

37104
class Timer {
38105
public:
39-
Timer() ;
106+
Timer() : data(), start_time( get_nanotime() ){}
40107

41-
void step( const std::string& ) ;
108+
void step( const std::string& name){
109+
nanotime_t now = get_nanotime() ;
110+
data.push_back( std::make_pair( name, now - start_time ) ) ;
111+
start_time = get_nanotime() ;
112+
}
42113

43-
operator SEXP() const ;
114+
operator SEXP() const {
115+
NumericVector out( data.begin(), data.end(), get_second ) ;
116+
CharacterVector names( data.begin(), data.end(), get_first ) ;
117+
out.attr( "names" ) = names ;
118+
return out ;
119+
}
44120

45-
private:
46-
typedef std::pair<std::string,nanotime_t> Step;
47-
typedef std::vector<Step> Steps;
48-
49-
Steps data ;
50-
nanotime_t start_time ;
121+
private:
122+
123+
inline std::string get_first( const std::pair<std::string,nanotime_t>& pair ){
124+
return pair.first ;
125+
}
126+
inline double get_second( const std::pair<std::string,nanotime_t>& pair ){
127+
return static_cast<double>(pair.second) ;
128+
}
129+
130+
typedef std::pair<std::string,nanotime_t> Step;
131+
typedef std::vector<Step> Steps;
132+
133+
Steps data ;
134+
nanotime_t start_time ;
51135

52136
} ;
53137

0 commit comments

Comments
 (0)