[Rprotobuf-commits] r407 - patches pkg pkg/R pkg/inst pkg/inst/unitTests pkg/man pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 11 03:35:27 CET 2011


Author: edd
Date: 2011-01-11 03:35:26 +0100 (Tue, 11 Jan 2011)
New Revision: 407

Added:
   patches/patch_by_Murray_rprotobuf_r406.diff
Modified:
   pkg/ChangeLog
   pkg/R/internals.R
   pkg/inst/NEWS
   pkg/inst/unitTests/runit.golden.message.R
   pkg/man/readProtoFiles.Rd
   pkg/src/DescriptorPoolLookup.cpp
Log:
new patch by Murray with 
 - more graceful error handling, 
 - support import patterns other than .proto$, 
 - and add simple repeated field unit test
patch itself added too
ChangeLog and NEWS updated
one minor tweak to Rd file doubly escaping backslashes


Added: patches/patch_by_Murray_rprotobuf_r406.diff
===================================================================
--- patches/patch_by_Murray_rprotobuf_r406.diff	                        (rev 0)
+++ patches/patch_by_Murray_rprotobuf_r406.diff	2011-01-11 02:35:26 UTC (rev 407)
@@ -0,0 +1,77 @@
+Index: pkg/R/internals.R
+===================================================================
+--- pkg/R/internals.R	(revision 406)
++++ pkg/R/internals.R	(working copy)
+@@ -11,8 +11,9 @@
+ #' @return invisible(NULL)
+ readProtoFiles <- function( 
+ 	files, 
+-	dir, 
+-	package = "RProtoBuf"
++	dir,
++	package = "RProtoBuf",
++	pattern = "\\.proto$"
+ 	){
+ 	
+ 	if( missing( files ) ){
+@@ -26,7 +27,7 @@
+ 				}
+ 			}
+ 		}
+-		files <- list.files( dir, pattern = "\\.proto$", full.names = TRUE ) 
++		files <- list.files( dir, pattern = pattern, full.names = TRUE ) 
+ 	} else {
+ 		if( !is.character( files )  ){
+ 			stop( "'file' should be a character vector" )
+Index: pkg/src/DescriptorPoolLookup.cpp
+===================================================================
+--- pkg/src/DescriptorPoolLookup.cpp	(revision 406)
++++ pkg/src/DescriptorPoolLookup.cpp	(working copy)
+@@ -26,6 +26,11 @@
+ 		int n = LENGTH(files) ;
+ 		for( int j=0; j < n; j++ ){
+ 			const GPB::FileDescriptor* file_desc = importer.Import( CHAR(STRING_ELT(files, j)) );
++			if (!file_desc) {
++				Rf_error("Could not load proto file '%s'\n",
++					 CHAR(STRING_ELT(files, j)));
++				continue;
++			}
+ 		    int ntypes = file_desc->message_type_count() ;
+ 		    for( int i=0; i<ntypes; i++){
+ 		    	const GPB::Descriptor* desc = file_desc->message_type( i ) ;
+Index: pkg/man/readProtoFiles.Rd
+===================================================================
+--- pkg/man/readProtoFiles.Rd	(revision 406)
++++ pkg/man/readProtoFiles.Rd	(working copy)
+@@ -9,7 +9,7 @@
+ message type names.
+ }
+ \usage{
+-readProtoFiles(files, dir, package = "RProtoBuf")
++readProtoFiles(files, dir, package = "RProtoBuf", pattern = "\\.proto$")
+ }
+ \arguments{
+   \item{files}{Proto files}
+@@ -19,6 +19,7 @@
+   \item{package}{R package name. If \code{files} and \code{dir} are
+   missing, "proto" files in the "proto" directory of the 
+   package tree are imported.}
++  \item{pattern}{A filename pattern to match proto files.}
+ }
+ \value{
+ \code{NULL}, invisibly. 
+Index: pkg/inst/unitTests/runit.golden.message.R
+===================================================================
+--- pkg/inst/unitTests/runit.golden.message.R	(revision 406)
++++ pkg/inst/unitTests/runit.golden.message.R	(working copy)
+@@ -55,4 +55,9 @@
+ 	
+ }
+ 
+-
++# Early versions of RProtoBuf did not support repeated messages properly.
++test.repeatedFields <- function(){
++	test <- new(protobuf_unittest.TestAllTypes)
++	test$add("repeated_int32", c(1:5))
++	checkEquals(test$repeated_int32, c(1:5))
++}

Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/ChangeLog	2011-01-11 02:35:26 UTC (rev 407)
@@ -1,3 +1,12 @@
+2011-01-10  Dirk Eddelbuettel  <edd at debian.org>
+
+	* Applied another patch by Murray Stokely providing:
+	   - R/internals.R: generalise readProtoFiles() adding 'pattern' arg
+	   - man/readProtoFiles.Rd: documenting new 'pattern' argument
+	   - src/DescriptorPoolLookup.cpp: enhanced error message
+	   - inst/unitTests/runit.golden.message.R: new unit test for
+	   repeated fields fixed (which was issue addressed earlier)
+
 2011-01-07  Dirk Eddelbuettel  <edd at debian.org>
 
 	* Applied patch by Murray Stokely providing all the following:

Modified: pkg/R/internals.R
===================================================================
--- pkg/R/internals.R	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/R/internals.R	2011-01-11 02:35:26 UTC (rev 407)
@@ -11,8 +11,9 @@
 #' @return invisible(NULL)
 readProtoFiles <- function( 
 	files, 
-	dir, 
-	package = "RProtoBuf"
+	dir,
+	package = "RProtoBuf",
+	pattern = "\\.proto$"
 	){
 	
 	if( missing( files ) ){
@@ -26,7 +27,7 @@
 				}
 			}
 		}
-		files <- list.files( dir, pattern = "\\.proto$", full.names = TRUE ) 
+		files <- list.files( dir, pattern = pattern, full.names = TRUE ) 
 	} else {
 		if( !is.character( files )  ){
 			stop( "'file' should be a character vector" )

Modified: pkg/inst/NEWS
===================================================================
--- pkg/inst/NEWS	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/inst/NEWS	2011-01-11 02:35:26 UTC (rev 407)
@@ -1,10 +1,13 @@
-0.2.2   2011-0107 
+0.2.2   2011-01-xx 
 
-   o 	Applied patch by Murray Stokely which 
-         - corrects a typo preventing some functions from being called, 
-         - adds bounds checking in call to google protobuf library, 
-         - adds a new name method 
-         - adds a tiny unit test 
+   o 	Applied two patches by Murray Stokely which 
+         - correct a typo preventing some functions from being called, 
+         - add bounds checking in call to google protobuf library, 
+         - add a new name method 
+         - add a tiny unit test 
+	 - add more graceful error handling
+	 - add support for import patterns other than .proto$, 
+	 - add simple repeated field unit test
 
 0.2.1   2010-10-18
 

Modified: pkg/inst/unitTests/runit.golden.message.R
===================================================================
--- pkg/inst/unitTests/runit.golden.message.R	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/inst/unitTests/runit.golden.message.R	2011-01-11 02:35:26 UTC (rev 407)
@@ -55,4 +55,9 @@
 	
 }
 
-
+# Early versions of RProtoBuf did not support repeated messages properly.
+test.repeatedFields <- function(){
+	test <- new(protobuf_unittest.TestAllTypes)
+	test$add("repeated_int32", c(1:5))
+	checkEquals(test$repeated_int32, c(1:5))
+}

Modified: pkg/man/readProtoFiles.Rd
===================================================================
--- pkg/man/readProtoFiles.Rd	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/man/readProtoFiles.Rd	2011-01-11 02:35:26 UTC (rev 407)
@@ -9,7 +9,7 @@
 message type names.
 }
 \usage{
-readProtoFiles(files, dir, package = "RProtoBuf")
+readProtoFiles(files, dir, package = "RProtoBuf", pattern = "\\\\.proto$")
 }
 \arguments{
   \item{files}{Proto files}
@@ -19,6 +19,7 @@
   \item{package}{R package name. If \code{files} and \code{dir} are
   missing, "proto" files in the "proto" directory of the 
   package tree are imported.}
+  \item{pattern}{A filename pattern to match proto files.}
 }
 \value{
 \code{NULL}, invisibly. 

Modified: pkg/src/DescriptorPoolLookup.cpp
===================================================================
--- pkg/src/DescriptorPoolLookup.cpp	2011-01-08 02:38:47 UTC (rev 406)
+++ pkg/src/DescriptorPoolLookup.cpp	2011-01-11 02:35:26 UTC (rev 407)
@@ -26,6 +26,11 @@
 		int n = LENGTH(files) ;
 		for( int j=0; j < n; j++ ){
 			const GPB::FileDescriptor* file_desc = importer.Import( CHAR(STRING_ELT(files, j)) );
+			if (!file_desc) {
+				Rf_error("Could not load proto file '%s'\n",
+					 CHAR(STRING_ELT(files, j)));
+				continue;
+			}
 		    int ntypes = file_desc->message_type_count() ;
 		    for( int i=0; i<ntypes; i++){
 		    	const GPB::Descriptor* desc = file_desc->message_type( i ) ;



More information about the Rprotobuf-commits mailing list