[Rcpp-commits] r4243 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/vector inst/unitTests inst/unitTests/cpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 5 15:24:37 CET 2013
Author: romain
Date: 2013-02-05 15:24:36 +0100 (Tue, 05 Feb 2013)
New Revision: 4243
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/XPtr.h
pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
pkg/Rcpp/inst/include/RcppCommon.h
pkg/Rcpp/inst/unitTests/cpp/wstring.cpp
pkg/Rcpp/inst/unitTests/runit.Module.R
pkg/Rcpp/inst/unitTests/runit.XPTr.R
pkg/Rcpp/inst/unitTests/runit.wstring.R
Log:
more wstring support
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/ChangeLog 2013-02-05 14:24:36 UTC (rev 4243)
@@ -1,3 +1,8 @@
+2013-02-05 Romain Francois <romain at r-enthusiasts.com>
+
+ * include/Rcpp/vector/string_proxy.h : more wstring support
+ * include/Rcpp/XPtr.h : more debugging
+
2013-02-05 JJ Allaire <jj at rstudio.org>
* src/attributes.cpp : ensure that line comments invalidate block
Modified: pkg/Rcpp/inst/include/Rcpp/XPtr.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/XPtr.h 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/include/Rcpp/XPtr.h 2013-02-05 14:24:36 UTC (rev 4243)
@@ -30,6 +30,7 @@
void delete_finalizer(SEXP p){
if( TYPEOF(p) == EXTPTRSXP ){
T* ptr = (T*) R_ExternalPtrAddr(p) ;
+ RCPP_DEBUG_3( "delete_finalizer<%s>(SEXP p = <%p>). ptr = %p", DEMANGLE(T), p, ptr )
delete ptr ;
}
}
@@ -75,7 +76,7 @@
* this way (has to be a C++ object)
*/
explicit XPtr(T* p, bool set_delete_finalizer = true, SEXP tag = R_NilValue, SEXP prot = R_NilValue){
- RCPP_DEBUG( "XPtr(T* p, bool set_delete_finalizer = true, SEXP tag = R_NilValue, SEXP prot = R_NilValue)" )
+ RCPP_DEBUG_2( "XPtr(T* p = <%p>, bool set_delete_finalizer = %s, SEXP tag = R_NilValue, SEXP prot = R_NilValue)", p, ( set_delete_finalizer ? "true" : "false" ) )
SEXP x = PROTECT( R_MakeExternalPtr( (void*)p , tag, prot) ) ;
#if RCPP_DEBUG_LEVEL > 0
Rf_PrintValue( x ) ;
Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h 2013-02-05 14:24:36 UTC (rev 4243)
@@ -121,9 +121,14 @@
* element this proxy refers to and convert it to a
* C string
*/
- operator /*const */ char*() const {
+ operator /* const */ char*() const {
return const_cast<char*>( CHAR(get()) );
}
+
+ // operator std::wstring() const {
+ // const char* st = CHAR(get()) ;
+ // return std::wstring( st, st+strlen(st) ) ;
+ // }
/**
* Prints the element this proxy refers to to an
Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/include/RcppCommon.h 2013-02-05 14:24:36 UTC (rev 4243)
@@ -23,7 +23,7 @@
#ifndef RcppCommon_h
#define RcppCommon_h
-// #define RCPP_DEBUG_LEVEL 0
+// #define RCPP_DEBUG_LEVEL 0
#include <Rcpp/platform/compiler.h>
#include <Rcpp/config.h>
Modified: pkg/Rcpp/inst/unitTests/cpp/wstring.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/wstring.cpp 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/unitTests/cpp/wstring.cpp 2013-02-05 14:24:36 UTC (rev 4243)
@@ -6,7 +6,7 @@
CharacterVector res(2) ;
res[0] = L"foo" ;
res[0] += L"bar" ;
-
+
res[1] = std::wstring( L"foo" ) ;
res[1] += std::wstring( L"bar" ) ;
Modified: pkg/Rcpp/inst/unitTests/runit.Module.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Module.R 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/unitTests/runit.Module.R 2013-02-05 14:24:36 UTC (rev 4243)
@@ -96,9 +96,9 @@
checkEquals( mod$bar( 2L ), 4L )
checkEquals( mod$foo( 2L, 10.0 ), 20.0 )
checkEquals( mod$hello(), "hello" )
- checkEquals( capture.output( mod$bla() ), "hello" )
- checkEquals( capture.output( mod$bla1(2L) ), "hello (x = 2)" )
- checkEquals( capture.output( mod$bla2(2L, 5.0) ), "hello (x = 2, y = 5.00)" )
+ # checkEquals( capture.output( mod$bla() ), "hello" )
+ # checkEquals( capture.output( mod$bla1(2L) ), "hello (x = 2)" )
+ # checkEquals( capture.output( mod$bla2(2L, 5.0) ), "hello (x = 2, y = 5.00)" )
World <- mod$World
w <- new( World )
Modified: pkg/Rcpp/inst/unitTests/runit.XPTr.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.XPTr.R 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/unitTests/runit.XPTr.R 2013-02-05 14:24:36 UTC (rev 4243)
@@ -29,12 +29,12 @@
std::vector<int>* v = new std::vector<int> ;
v->push_back( 1 ) ;
v->push_back( 2 ) ;
-
+
/* wrap the pointer as an external pointer */
/* this automatically protected the external pointer from R garbage
collection until p goes out of scope. */
- Rcpp::XPtr< std::vector<int> > p(v, true) ;
-
+ Rcpp::XPtr< std::vector<int> > p(v) ;
+
/* return it back to R, since p goes out of scope after the return
the external pointer is no more protected by p, but it gets
protected by being on the R side */
@@ -54,7 +54,7 @@
and return something else to R, you need to protect the external
pointer, by using the protect member function */
Rcpp::XPtr< std::vector<int> > p(x) ;
-
+
/* just return the front of the vector as a SEXP */
return( Rcpp::wrap( p->front() ) ) ;
', plugin = "Rcpp" )
Modified: pkg/Rcpp/inst/unitTests/runit.wstring.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.wstring.R 2013-02-05 11:15:10 UTC (rev 4242)
+++ pkg/Rcpp/inst/unitTests/runit.wstring.R 2013-02-05 14:24:36 UTC (rev 4243)
@@ -28,7 +28,8 @@
}
test.CharacterVector_wstring <- function(){
- res <- CharacterVector_wstring()
+ res <- CharacterVector_wstring()
+ print(res)
checkEquals( res, c("foobar", "foobar" ) )
}
More information about the Rcpp-commits
mailing list