Skip to content

Commit aee3594

Browse files
committed
address issue #350 by renaming 'World' Modules
affects four different unit tests also very minor cleanups
1 parent d9a448a commit aee3594

File tree

16 files changed

+132
-111
lines changed

16 files changed

+132
-111
lines changed

ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2015-08-26 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/unitTests/testRcppClass/src/rcpp_module.cpp: Renamed Module
4+
'World' to 'RcppClassWorld' to avoid multiple modules with same name
5+
* inst/unitTests/testRcppClass/man/Rcpp_class_examples.Rd: Ditto
6+
* inst/unitTests/testRcppClass/R/load.R: Ditto
7+
* inst/unitTests/testRcppClass/NAMESPACE: Ditto
8+
* inst/unitTests/runit.Module.client.package.R: Re-enable test
9+
10+
* inst/unitTests/testRcppModule/src/rcpp_module.cpp: Renamed Module
11+
'World' to 'RcppModuleWorld' to avoid multiple modules with same name
12+
13+
* inst/unitTests/cpp/modref.cpp: Rename 'World' to 'ModRefWorld'
14+
* inst/unitTests/runit.modref.R (test.modRef): Ditto
15+
16+
* inst/unitTests/cpp/Module.cpp: Rename 'World' to 'ModuleWorld'
17+
* inst/unitTests/runit.Module.R (test.Module): Ditto
18+
119
2015-08-24 Dirk Eddelbuettel <[email protected]>
220

321
* vignettes/Rcpp.bib: Updated R / R Core references

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.12.0.2
4-
Date: 2015-08-17
3+
Version: 0.12.0.3
4+
Date: 2015-08-26
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey,
66
Qiang Kou, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
\item Correctly reset directory in case of no-rebuilding but Windows code
2020
(PR #335)
2121
}
22+
\item Changes in Rcpp Modules:
23+
\itemize{
24+
\item We no longer define multiple Modules objects named \code{World} in
25+
the unit tests with was seen to have a bad effect with R 3.2.2 or later.
26+
}
2227
}
2328
}
2429

inst/unitTests/cpp/Module.cpp

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// Module.cpp: Rcpp R/C++ interface class library -- module unit tests
55
//
6-
// Copyright (C) 2013 - 2014 Dirk Eddelbuettel and Romain Francois
6+
// Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
77
//
88
// This file is part of Rcpp.
99
//
@@ -22,45 +22,45 @@
2222

2323
#include <Rcpp.h>
2424

25-
using namespace Rcpp ;
25+
using namespace Rcpp;
2626

2727
std::string hello() {
28-
return "hello" ;
28+
return "hello";
2929
}
3030

3131
int bar(int x) {
32-
return x*2 ;
32+
return x*2;
3333
}
3434

3535
double foo(int x, double y) {
36-
return x * y ;
36+
return x * y;
3737
}
3838

3939
void bla() {
40-
Rprintf("hello\\n") ;
40+
Rprintf("hello\\n");
4141
}
4242

4343
void bla1(int x) {
44-
Rprintf("hello (x = %d)\\n", x) ;
44+
Rprintf("hello (x = %d)\\n", x);
4545
}
4646

4747
void bla2(int x, double y) {
48-
Rprintf("hello (x = %d, y = %5.2f)\\n", x, y) ;
48+
Rprintf("hello (x = %d, y = %5.2f)\\n", x, y);
4949
}
5050

5151
int test_reference(std::vector<double>& ref) {
52-
return ref.size() ;
52+
return ref.size();
5353
}
5454
int test_const_reference(const std::vector<double>& ref) {
55-
return ref.size() ;
55+
return ref.size();
5656
}
5757
int test_const(const std::vector<double> ref) {
58-
return ref.size() ;
58+
return ref.size();
5959
}
6060

61-
class World {
61+
class ModuleWorld {
6262
public:
63-
World() : msg("hello") {}
63+
ModuleWorld() : msg("hello") {}
6464
void set(std::string msg_) { this->msg = msg_; }
6565
void set_ref(std::string& msg_) { this->msg = msg_; }
6666
void set_const_ref(const std::string& msg_) { this->msg = msg_; }
@@ -70,30 +70,30 @@ class World {
7070
std::string msg;
7171
};
7272

73-
void clearWorld(World* w) {
73+
void clearWorld(ModuleWorld* w) {
7474
w->set("");
7575
}
7676

7777
class Num{
7878
public:
79-
Num() : x(0.0), y(0) {} ;
79+
Num() : x(0.0), y(0) {};
8080

81-
double getX() const { return x ; }
82-
void setX(double value) { x = value ; }
81+
double getX() const { return x; }
82+
void setX(double value) { x = value; }
8383

84-
int getY() { return y ; }
84+
int getY() { return y; }
8585

8686
private:
87-
double x ;
88-
int y ;
87+
double x;
88+
int y;
8989
};
9090

9191
class Number{
9292
public:
93-
Number() : x(0.0), y(0) {} ;
93+
Number() : x(0.0), y(0) {};
9494

95-
double x ;
96-
int y ;
95+
double x;
96+
int y;
9797
};
9898

9999
class Randomizer {
@@ -103,40 +103,40 @@ class Randomizer {
103103
Randomizer(double min_, double max_) : min(min_), max(max_) {}
104104

105105
NumericVector get(int n) {
106-
RNGScope scope ;
106+
RNGScope scope;
107107
return runif(n, min, max);
108108
}
109109

110110
private:
111-
double min, max ;
112-
} ;
111+
double min, max;
112+
};
113113

114114
RCPP_EXPOSED_CLASS(Test)
115115
class Test{
116116
public:
117-
double value ;
117+
double value;
118118
Test(double v) : value(v) {}
119119
private:
120120
// hiding those on purpose
121121
// we work by reference or pointers here. Not by copy.
122-
Test(const Test& other) ;
123-
Test& operator=(const Test&) ;
124-
} ;
122+
Test(const Test& other);
123+
Test& operator=(const Test&);
124+
};
125125

126126
double Test_get_x_const_ref(const Test& x) {
127-
return x.value ;
127+
return x.value;
128128
}
129129
double Test_get_x_ref(Test& x) {
130130
return x.value;
131131
}
132132
double Test_get_x_const_pointer(const Test* x) {
133-
return x->value ;
133+
return x->value;
134134
}
135135
double Test_get_x_pointer(Test* x) {
136-
return x->value ;
136+
return x->value;
137137
}
138138

139-
RCPP_MODULE(yada) {
139+
RCPP_MODULE(demoModule) {
140140
function("hello", &hello);
141141
function("bar" , &bar );
142142
function("foo" , &foo );
@@ -145,23 +145,21 @@ RCPP_MODULE(yada) {
145145
function("bla2" , &bla2 );
146146

147147
function("test_reference", test_reference);
148-
function("test_const_reference", test_const_reference) ;
149-
function("test_const", test_const) ;
148+
function("test_const_reference", test_const_reference);
149+
function("test_const", test_const);
150150

151151
class_<Test>("Test")
152152
.constructor<double>()
153153
;
154154

155-
class_<World>("World")
156-
155+
class_<ModuleWorld>("ModuleWorld")
157156
.constructor()
158-
159-
.method("greet", &World::greet)
160-
.method("set", &World::set)
161-
.method("set_ref", &World::set_ref)
162-
.method("set_const_ref", &World::set_const_ref)
157+
.method("greet", &ModuleWorld::greet)
158+
.method("set", &ModuleWorld::set)
159+
.method("set_ref", &ModuleWorld::set_ref)
160+
.method("set_const_ref", &ModuleWorld::set_const_ref)
163161
.method("clear", &clearWorld)
164-
;
162+
;
165163

166164
class_<Num>("Num")
167165
.constructor()
@@ -200,7 +198,7 @@ RCPP_MODULE(yada) {
200198

201199
// [[Rcpp::export]]
202200
double attr_Test_get_x_const_ref(const Test& x) {
203-
return x.value ;
201+
return x.value;
204202
}
205203

206204
// [[Rcpp::export]]
@@ -210,12 +208,12 @@ double attr_Test_get_x_ref(Test& x) {
210208

211209
// [[Rcpp::export]]
212210
double attr_Test_get_x_const_pointer(const Test* x) {
213-
return x->value ;
211+
return x->value;
214212
}
215213

216214
// [[Rcpp::export]]
217215
double attr_Test_get_x_pointer(Test* x) {
218-
return x->value ;
216+
return x->value;
219217
}
220218

221219

inst/unitTests/cpp/modref.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// modref.cpp: Rcpp R/C++ interface class library -- module unit tests
44
//
5-
// Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -22,9 +22,9 @@
2222
#include <Rcpp.h>
2323
using namespace Rcpp ;
2424

25-
class World {
25+
class ModRefWorld {
2626
public:
27-
World() : foo(1), msg("hello") {}
27+
ModRefWorld() : foo(1), msg("hello") {}
2828
void set(std::string msg_) { this->msg = msg_; }
2929
std::string greet() { return msg; }
3030

@@ -35,21 +35,21 @@ class World {
3535
std::string msg;
3636
};
3737

38-
void clearWorld( World* w ){
38+
void clearWorld( ModRefWorld* w ){
3939
w->set( "" );
4040
}
4141

42-
RCPP_MODULE(yada){
43-
class_<World>( "World" )
42+
RCPP_MODULE(modrefmodule){
43+
class_<ModRefWorld>( "ModRefWorld" )
4444
.default_constructor()
4545

46-
.method( "greet", &World::greet )
47-
.method( "set", &World::set )
46+
.method( "greet", &ModRefWorld::greet )
47+
.method( "set", &ModRefWorld::set )
4848
.method( "clear", &clearWorld )
4949

50-
.field( "foo", &World::foo )
51-
.field_readonly( "bar", &World::bar )
52-
;
50+
.field( "foo", &ModRefWorld::foo )
51+
.field_readonly( "bar", &ModRefWorld::bar )
52+
;
5353

5454
}
5555

inst/unitTests/runit.Module.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if( .runThisTest && Rcpp:::capabilities()[["Rcpp modules"]] ) {
3333
checkEquals( foo( 2L, 10.0 ), 20.0 )
3434
checkEquals( hello(), "hello" )
3535

36-
w <- new( World )
36+
w <- new( ModuleWorld )
3737
checkEquals( w$greet(), "hello" )
3838
w$set( "hello world" )
3939
checkEquals( w$greet(), "hello world" )

inst/unitTests/runit.Module.client.package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
.onWindows <- .Platform$OS.type == "windows"
3333

3434
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
35-
.runThisTest <- FALSE ## FIXME
3635

3736
if (.runThisTest && ! .badOSX && ! .onWindows) {
3837

inst/unitTests/runit.modref.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/r -t
22
#
3-
# Copyright (C) 2010 - 2014 John Chambers, Dirk Eddelbuettel and Romain Francois
3+
# Copyright (C) 2010 - 2015 John Chambers, Dirk Eddelbuettel and Romain Francois
44
#
55
# This file is part of Rcpp.
66
#
@@ -24,8 +24,8 @@ if (.runThisTest) {
2424
.setUp <- Rcpp:::unitTestSetup("modref.cpp")
2525

2626
test.modRef <- function() {
27-
ww = new(World)
28-
wg = World$new()
27+
ww <- new(ModRefWorld)
28+
wg <- ModRefWorld$new()
2929

3030
checkEquals(ww$greet(), wg$greet())
3131
wgg <- wg$greet()
@@ -36,7 +36,7 @@ if (.runThisTest) {
3636
checkEquals(ww$greet(), "Other")
3737
checkEquals(wg$greet(), wgg)
3838

39-
World$methods(twice = function() paste(greet(), greet()))
39+
ModRefWorld$methods(twice = function() paste(greet(), greet()))
4040

4141
checkEquals(ww$twice(), paste(ww$greet(), ww$greet()))
4242

inst/unitTests/testRcppClass/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import(Rcpp,methods)
44
export(genWorld, stdNumeric, rcpp_hello_world,
55
bar, foo, baz, baz1)
66

7-
exportClass(World, stdNumeric)#, NumEx)
7+
exportClass(RcppClassWorld, stdNumeric)#, NumEx)

inst/unitTests/testRcppClass/R/load.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
setRcppClass("World", module = "yada", fields = list(more = "character"),
1+
setRcppClass("RcppClassWorld", module = "RcppClassModule", fields = list(more = "character"),
22
methods = list(test = function(what) message("Testing: ", what, "; ", more)),
33
saveAs = "genWorld"
44
)
@@ -47,5 +47,7 @@ evalqOnLoad({
4747
## For R 2.15.1 and later this also works. Note that calling loadModule() triggers
4848
## a load action, so this does not have to be placed in .onLoad() or evalqOnLoad().
4949
loadModule("NumEx", TRUE)
50-
loadModule("yada", TRUE)
50+
loadModule("RcppClassModule", TRUE)
5151
loadModule("stdVector", TRUE)
52+
53+
loadModule("RcppClassModule", c("bar", baz = "bla", baz1 = "bla1", "foo"))

0 commit comments

Comments
 (0)