Skip to content

Commit 17ef95e

Browse files
committed
Merge pull request #351 from RcppCore/bugfix/unique-modules-names
address issue #350 by renaming Modules
2 parents d9a448a + 49944cf commit 17ef95e

File tree

17 files changed

+170
-150
lines changed

17 files changed

+170
-150
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: 69 additions & 72 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,73 +70,73 @@ class World {
7070
std::string msg;
7171
};
7272

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

77-
class Num{
77+
class ModuleNum{
7878
public:
79-
Num() : x(0.0), y(0) {} ;
79+
ModuleNum() : 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

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

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

99-
class Randomizer {
99+
class ModuleRandomizer {
100100
public:
101101

102102
// Randomizer() : min(0), max(1) {}
103-
Randomizer(double min_, double max_) : min(min_), max(max_) {}
103+
ModuleRandomizer(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

114-
RCPP_EXPOSED_CLASS(Test)
115-
class Test{
114+
RCPP_EXPOSED_CLASS(ModuleTest)
115+
class ModuleTest {
116116
public:
117-
double value ;
118-
Test(double v) : value(v) {}
117+
double value;
118+
ModuleTest(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+
ModuleTest(const ModuleTest& other);
123+
ModuleTest& operator=(const ModuleTest&);
124+
};
125125

126-
double Test_get_x_const_ref(const Test& x) {
127-
return x.value ;
126+
double Test_get_x_const_ref(const ModuleTest& x) {
127+
return x.value;
128128
}
129-
double Test_get_x_ref(Test& x) {
129+
double Test_get_x_ref(ModuleTest& x) {
130130
return x.value;
131131
}
132-
double Test_get_x_const_pointer(const Test* x) {
133-
return x->value ;
132+
double Test_get_x_const_pointer(const ModuleTest* x) {
133+
return x->value;
134134
}
135-
double Test_get_x_pointer(Test* x) {
136-
return x->value ;
135+
double Test_get_x_pointer(ModuleTest* x) {
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,43 +145,41 @@ 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

151-
class_<Test>("Test")
151+
class_<ModuleTest>("ModuleTest")
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

166-
class_<Num>("Num")
164+
class_<ModuleNum>("ModuleNum")
167165
.constructor()
168166

169167
// read and write property
170-
.property("x", &Num::getX, &Num::setX)
168+
.property("x", &ModuleNum::getX, &ModuleNum::setX)
171169

172170
// read-only property
173-
.property("y", &Num::getY)
171+
.property("y", &ModuleNum::getY)
174172
;
175173

176-
class_<Number>("Number")
174+
class_<ModuleNumber>("ModuleNumber")
177175

178176
.constructor()
179177

180178
// read and write data member
181-
.field("x", &Number::x)
179+
.field("x", &ModuleNumber::x)
182180

183181
// read only data member
184-
.field_readonly("y", &Number::y)
182+
.field_readonly("y", &ModuleNumber::y)
185183
;
186184

187185
function("Test_get_x_const_ref", Test_get_x_const_ref);
@@ -190,32 +188,31 @@ RCPP_MODULE(yada) {
190188
function("Test_get_x_pointer", Test_get_x_pointer);
191189

192190

193-
class_<Randomizer>("Randomizer")
191+
class_<ModuleRandomizer>("ModuleRandomizer")
194192
// No default: .default_constructor()
195193
.constructor<double,double>()
196194

197-
.method("get" , &Randomizer::get)
195+
.method("get" , &ModuleRandomizer::get)
198196
;
199197
}
200198

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

206204
// [[Rcpp::export]]
207-
double attr_Test_get_x_ref(Test& x) {
205+
double attr_Test_get_x_ref(ModuleTest& x) {
208206
return x.value;
209207
}
210208

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

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

221-

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

0 commit comments

Comments
 (0)