[Rcpp-devel] ColDatum constructors memory safety
Dirk Eddelbuettel
edd at debian.org
Fri Mar 19 04:03:32 CET 2010
Note to self, no more coding when tired...
On 18 March 2010 at 21:49, Dirk Eddelbuettel wrote:
| So I became a little more ambitious and made the runit file a fuller test of
| ColDatum and RcppFrame (both of the old API):
|
| test.ColDatum.vector <- function() {
| src <- 'std::vector<ColDatum> colDatumVector(3);
| colDatumVector[0].setDoubleValue(1.23);
| colDatumVector[1].setIntValue(42);
| colDatumVector[2].setLogicalValue(0);
| std::vector<std::string> names;
| names.push_back("A");
| names.push_back("B");
| names.push_back("C");
| RcppFrame fr(names);
| fr.addRow(colDatumVector);
| RcppResultSet rs;
| rs.add("data.frame", fr);
| return R_NilValue;';
| funx <- cfunction(signature(), src, Rcpp=TRUE)
| checkEquals(funx(), NULL, msg = "RcppColDatum.vector")
| }
That had an extra return R_NilValue; in there we didn't want. I fixed that and renamed it:
R> library(RUnit)
R> library(inline)
R> test.RcppFrame <- function() {
+ src <- 'std::vector<ColDatum> colDatumVector(3);
+ colDatumVector[0].setDoubleValue(1.23);
+ colDatumVector[1].setIntValue(42);
+ colDatumVector[2].setLogicalValue(0);
+ std::vector<std::string> names;
+ names.push_back("A");
+ names.push_back("B");
+ names.push_back("C");
+ RcppFrame fr(names);
+ fr.addRow(colDatumVector);
+ RcppResultSet rs;
+ rs.add("data.frame", fr);
+ return rs.getReturnList();';
+ funx <- cfunction(signature(), src, Rcpp=TRUE)
+ dframe <- data.frame(funx()[[1]]) ## needs a data.frame() call on first list elem
+ checkEquals(dframe, data.frame(A=1.23, B=42, C=FALSE), msg = "RcppColDatum.vector")
+ }
R> test.RcppFrame()
Loading required package: Rcpp
[1] TRUE
R>
Now -- this works fine __with or without your patch__ so at this point, I am
still not sure what error your patch is fixing. Can you help me out?
Many thanks, Dirk
--
Registration is open for the 2nd International conference R / Finance 2010
See http://www.RinFinance.com for details, and see you in Chicago in April!
More information about the Rcpp-devel
mailing list