[Rprotobuf-commits] r541 - in pkg: . R inst/unitTests vignettes/RProtoBuf-quickref

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 14 03:47:26 CET 2013


Author: murray
Date: 2013-11-14 03:47:25 +0100 (Thu, 14 Nov 2013)
New Revision: 541

Modified:
   pkg/ChangeLog
   pkg/R/extensions.R
   pkg/inst/unitTests/runit.extensions.R
   pkg/vignettes/RProtoBuf-quickref/RProtoBuf-quickref.Rnw
Log:
Raise an R stop() error rather than crashing with a CHECK failure in
C++ code when the user attempts to get an extension of the wrong type.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-11-14 01:47:29 UTC (rev 540)
+++ pkg/ChangeLog	2013-11-14 02:47:25 UTC (rev 541)
@@ -1,3 +1,10 @@
+2013-11-13  Murray Stokely  <murray at FreeBSD.org>
+
+	* R/extensions.R: Give a user friendly error message if someone tries
+	  to set an extension to a message of the wrong type instead of
+	  causing a C++ check failure that terminates your R session.
+	* inst/unitTests/runit.extensions.R (test.extension): Add test.
+
 2013-10-23  Murray Stokely  <murray at FreeBSD.org>
 
 	* src/lookup.cpp (rprotobuf): Remove stop() error in object table

Modified: pkg/R/extensions.R
===================================================================
--- pkg/R/extensions.R	2013-11-14 01:47:29 UTC (rev 540)
+++ pkg/R/extensions.R	2013-11-14 02:47:25 UTC (rev 541)
@@ -43,6 +43,14 @@
 	if (!is_extension(field)) {
 		stop(paste(name(field), "is not an extension FieldDescriptor."))
 	}
+	# This check causes a CHECK failure in the C++ code, so give
+	# a more user-friendly error here.
+	if (containing_type(field)@type != object at type) {
+		stop(paste("Field", name(field),
+			   "does not match message type (",
+			   containing_type(field)@type, "!=",
+			   object at type, ")"))
+	}
         .Call( "getExtension", object at pointer, field,
               PACKAGE = "RProtoBuf" )
 } )

Modified: pkg/inst/unitTests/runit.extensions.R
===================================================================
--- pkg/inst/unitTests/runit.extensions.R	2013-11-14 01:47:29 UTC (rev 540)
+++ pkg/inst/unitTests/runit.extensions.R	2013-11-14 02:47:25 UTC (rev 541)
@@ -75,4 +75,8 @@
     ## Check that we do something sensible if invalid field descriptors are passed
     checkException(test$getExtension(protobuf_unittest.TestAllExtensions))
     checkException(test$setExtension(protobuf_unittest.TestAllExtensions, 3))
+
+    ## Check that we don't CHECK fail in C++, but instead give a reasonable
+    ## error message if incorrect extensions types are provided.
+    checkException(test$getExtension(protobuf_unittest.my_extension_string))
 }

Modified: pkg/vignettes/RProtoBuf-quickref/RProtoBuf-quickref.Rnw
===================================================================
--- pkg/vignettes/RProtoBuf-quickref/RProtoBuf-quickref.Rnw	2013-11-14 01:47:29 UTC (rev 540)
+++ pkg/vignettes/RProtoBuf-quickref/RProtoBuf-quickref.Rnw	2013-11-14 02:47:25 UTC (rev 541)
@@ -1,6 +1,7 @@
 \documentclass[10pt,twocolumn,a4paper]{article}
 %\VignetteIndexEntry{RProtoBuf-quickref}
 
+
 \setlength{\hoffset}{-0.8in}
 \setlength{\voffset}{-0.8in}
 



More information about the Rprotobuf-commits mailing list