[Rcpp-commits] r1526 - pkg/Rcpp/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jun 13 20:00:11 CEST 2010
Author: edd
Date: 2010-06-13 20:00:11 +0200 (Sun, 13 Jun 2010)
New Revision: 1526
Modified:
pkg/Rcpp/src/RcppDate.cpp
pkg/Rcpp/src/RcppDatetime.cpp
Log:
added some sanity checking to constructors from SEXP
Modified: pkg/Rcpp/src/RcppDate.cpp
===================================================================
--- pkg/Rcpp/src/RcppDate.cpp 2010-06-12 17:53:27 UTC (rev 1525)
+++ pkg/Rcpp/src/RcppDate.cpp 2010-06-13 18:00:11 UTC (rev 1526)
@@ -46,7 +46,11 @@
}
RcppDate::RcppDate(SEXP dt) {
- jdn = Rcpp::as<int>(dt) + Jan1970Offset;
+ if (Rf_length(dt) != 1) {
+ throw std::range_error("RcppDate: expect one argument in SEXP constructor");
+ }
+ //jdn = Rcpp::as<int>(dt) + Jan1970Offset;
+ jdn = INTEGER(dt)[0] + Jan1970Offset;
jdn2mdy();
}
Modified: pkg/Rcpp/src/RcppDatetime.cpp
===================================================================
--- pkg/Rcpp/src/RcppDatetime.cpp 2010-06-12 17:53:27 UTC (rev 1525)
+++ pkg/Rcpp/src/RcppDatetime.cpp 2010-06-13 18:00:11 UTC (rev 1526)
@@ -35,6 +35,9 @@
}
RcppDatetime::RcppDatetime(SEXP ds) {
+ if (Rf_length(ds) != 1) {
+ throw std::range_error("RcppDatetime: expect one argument in SEXP constructor");
+ }
m_d = REAL(ds)[0];
m_parsed = false;
m_us = 0;
More information about the Rcpp-commits
mailing list