[Rcpp-commits] r3030 - in pkg/Rcpp: . inst inst/include/Rcpp/internal inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 24 18:18:19 CEST 2011


Author: edd
Date: 2011-05-24 18:18:18 +0200 (Tue, 24 May 2011)
New Revision: 3030

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/unitTests/runit.wrap.R
Log:
wrap() no longer dies over const char* arguments that are NULL (which we can blame on Rf_mkString() anyway)


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-05-17 01:17:41 UTC (rev 3029)
+++ pkg/Rcpp/ChangeLog	2011-05-24 16:18:18 UTC (rev 3030)
@@ -1,3 +1,9 @@
+2011-05-24  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/include/Rcpp/internal/wrap.h: For arguments of type const char *,
+	wrap now checks for NULL arguments before calling Rf_mkString()
+	* unitTests/runit.wrap.R: Added unit test for this
+
 2011-05-14  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw: Corrected an error in STL

Modified: pkg/Rcpp/inst/NEWS
===================================================================
--- pkg/Rcpp/inst/NEWS	2011-05-17 01:17:41 UTC (rev 3029)
+++ pkg/Rcpp/inst/NEWS	2011-05-24 16:18:18 UTC (rev 3030)
@@ -7,6 +7,8 @@
 
     o   Minor correction and extension to STL documentation in Rcpp-quickref
 
+    o   wrap() is now resilient to NULL pointers passed as in const char * 
+
 0.9.4   2011-04-12
 
     o   New R function "loadRcppModules" to load Rcpp modules automatically

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2011-05-17 01:17:41 UTC (rev 3029)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2011-05-24 16:18:18 UTC (rev 3030)
@@ -3,7 +3,7 @@
 //
 // wrap.h: Rcpp R/C++ interface class library -- wrap implementations
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2011  Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -778,6 +778,9 @@
 
 // special case - FIXME : this is not template specializations of wrap<>
 inline SEXP wrap(const char* const v ){ 
+    if (v == NULL)
+	return R_NilValue;
+    else
 	return Rf_mkString(v) ;
 }
 

Modified: pkg/Rcpp/inst/unitTests/runit.wrap.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.wrap.R	2011-05-17 01:17:41 UTC (rev 3029)
+++ pkg/Rcpp/inst/unitTests/runit.wrap.R	2011-05-24 16:18:18 UTC (rev 3030)
@@ -1,6 +1,6 @@
 #!/usr/bin/r -t
 #
-# Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010 - 2011  Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -120,6 +120,17 @@
   	            std::vector<int> c ; c.push_back(1) ; c.push_back(2) ; c.push_back(2) ; c.push_back(2) ;
   	            m.insert( _pair("c",  c) );
   	            return wrap(m);')
+
+                  ,"null_const_char"=list(
+                   signature(),
+                   'const char *p = NULL;
+  	            return wrap(p);')
+
+                   ,"nonnull_const_char"=list(
+                   signature(),
+                   'const char *p = "foo";
+  	            return wrap(p);')
+
                   )
 
 
@@ -274,7 +285,19 @@
 		msg = "wrap( multimap<string,vector<int>>) " )
 }
 
+test.null.const.char <- function() {
+    fun <- .rcpp.wrap$null_const_char
+    checkEquals(fun(),
+                NULL,
+                msg = "null const char*")
+}
 
+test.nonnull.const.char <- function() {
+    fun <- .rcpp.wrap$nonnull_const_char
+    checkEquals(fun(),
+                "foo",
+                msg = "null const char*")
+}
 
 ## tr1::unordered_map
 if (Rcpp:::capabilities()[["tr1 unordered maps"]]) {



More information about the Rcpp-commits mailing list