[Rprotobuf-commits] r544 - in pkg: . inst inst/unitTests src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 15 00:47:22 CET 2013


Author: murray
Date: 2013-12-15 00:47:22 +0100 (Sun, 15 Dec 2013)
New Revision: 544

Modified:
   pkg/ChangeLog
   pkg/DESCRIPTION
   pkg/inst/NEWS.Rd
   pkg/inst/unitTests/runit.bytes.R
   pkg/src/mutators.cpp
Log:
Merge a fix I had made internally at Google over a year ago which
fixes the handling of repeated raw characters.  This problem was
reported on the protobuf list today.  Also add more tests, summarize
the recent changes into the NEWS.Rd file and update the version number
to 0.3.2 in anticipation of the next CRAN release.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-12-14 23:19:49 UTC (rev 543)
+++ pkg/ChangeLog	2013-12-14 23:47:22 UTC (rev 544)
@@ -1,5 +1,8 @@
 2013-12-14  Murray Stokely  <murray at FreeBSD.org>
 
+	* src/mutators.cpp (rprotobuf): Fix a bug which incorrectly
+	  prevented users from setting raw non-repeated fields under some
+	  circumstances.
 	* inst/unitTests/runit.bytes.R (test.all): Verify raw(10) can be
 	  set to required bytes fields to verify correct behavior for use
 	  case mentioned on rprotobuf-yada list.

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2013-12-14 23:19:49 UTC (rev 543)
+++ pkg/DESCRIPTION	2013-12-14 23:47:22 UTC (rev 544)
@@ -1,5 +1,5 @@
 Package: RProtoBuf
-Version: 0.3.1.1
+Version: 0.3.2
 Date: $Date$
 Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely
 Maintainer: Dirk Eddelbuettel <edd at debian.org>

Modified: pkg/inst/NEWS.Rd
===================================================================
--- pkg/inst/NEWS.Rd	2013-12-14 23:19:49 UTC (rev 543)
+++ pkg/inst/NEWS.Rd	2013-12-14 23:47:22 UTC (rev 544)
@@ -2,7 +2,20 @@
 \title{News for Package \pkg{RProtoBuf}}
 \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
 
-% TODO(edd): Update date and version number.
+\section{Changes in RProtoBuf version 0.3.2 (2013-12-15)}{
+  \itemize{
+    \item Fixed a bug that erroneously prevented users from setting raw
+    byte fields in protocol buffers under certain circumstances.
+    \item Give a user friendly error message when seting an extension to
+    a message of the wrong type instead of causing a C++ check failure
+    that terminates the Rsession.
+    \item Change object table lookup slightly to allow users to use the
+    '<<-' operator in code using RProtoBuf without hitting a stop() error
+    in the lookup routine.
+    \item Improve documentation and tests for all of the above.
+  }
+}
+
 \section{Changes in RProtoBuf version 0.3.1 (2013-09-13)}{
   \itemize{
     \item Added support for setting and getting 64-bit integer types as

Modified: pkg/inst/unitTests/runit.bytes.R
===================================================================
--- pkg/inst/unitTests/runit.bytes.R	2013-12-14 23:19:49 UTC (rev 543)
+++ pkg/inst/unitTests/runit.bytes.R	2013-12-14 23:47:22 UTC (rev 544)
@@ -9,6 +9,8 @@
 test.all <- function() {
     test <- new(TestBytes, req = "abc", rep = list(charToRaw("def"), raw(10)))
     checkEquals(rawToChar(test$req), "abc")
+    test$req <- charToRaw("abc")
+    checkEquals(rawToChar(test$req), "abc")
     checkEquals(rawToChar(test$opt), "hello world")
     checkEquals(test$rep, list(charToRaw("def"), raw(10)))
     test$rep[[3]]=charToRaw("ghi")

Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp	2013-12-14 23:19:49 UTC (rev 543)
+++ pkg/src/mutators.cpp	2013-12-14 23:47:22 UTC (rev 544)
@@ -401,31 +401,32 @@
 	}
 	// }}}
 
+	// {{{ preliminary checks
+	int value_size = Rf_isVector(value) ? LENGTH(value) : 1;
+	// if the R type is RAWSXP and the cpp type is string or bytes, 
+	// then value_size is actually one because the raw vector
+	// is converted to a string
+	int field_type = field_desc->type() ;
+	if( field_type == TYPE_STRING || field_type == TYPE_BYTES ){
+		if( TYPEOF(value) == RAWSXP ){
+			value_size = 1 ;
+		} else if( TYPEOF(value) == STRSXP ){
+			value_size = LENGTH(value);
+		} else if( TYPEOF(value) == S4SXP && Rf_inherits( value, "Message") ){
+			value_size = 1 ; /* we will store the message payload */
+		} else if( TYPEOF(value) == VECSXP && allAreMessages( value ) ){
+			value_size = LENGTH(value) ;
+		} else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){
+			value_size = LENGTH(value) ;
+		} else {
+			throwException( "cannot convert to string", "ConversionException" ) ;
+		}
+	}
+	// }}}
+
 	if( field_desc->is_repeated() ){
 		// {{{ repeated fields
 		
-		// {{{ preliminary checks
-		int value_size = Rf_isVector(value) ? LENGTH(value) : 1;
-		// if the R type is RAWSXP and the cpp type is string or bytes, 
-		// then value_size is actually one because the raw vector
-		// is converted to a string
-		int field_type = field_desc->type() ;
-		if( field_type == TYPE_STRING || field_type == TYPE_BYTES ){
-			if( TYPEOF(value) == RAWSXP ){
-				value_size = 1 ;
-            } else if( TYPEOF(value) == STRSXP ){
-                value_size = LENGTH(value);
-			} else if( TYPEOF(value) == S4SXP && Rf_inherits( value, "Message") ){
-				value_size = 1 ; /* we will store the message payload */
-			} else if( TYPEOF(value) == VECSXP && allAreMessages( value ) ){
-				value_size = LENGTH(value) ;
-			} else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){
-				value_size = LENGTH(value) ;
-			} else {
-				throwException( "cannot convert to string", "ConversionException" ) ;
-			}
-		}
-		// }}}
 		// The number of elements already in the repeated field.
 		int field_size = ref->FieldSize( *message, field_desc ) ;
 		
@@ -1011,7 +1012,7 @@
 		// }}}
 	} else {
 		// {{{ non repeated fields
-		if (Rf_isVector(value) && LENGTH(value) > 1) {
+		if (value_size > 1) {
 			throwException( "cannot set non-repeated field to vector of length > 1", "CastException" ) ;
 		}
 		switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){



More information about the Rprotobuf-commits mailing list