[Rprotobuf-commits] r662 - in pkg: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 31 04:05:29 CET 2013


Author: murray
Date: 2013-12-31 04:05:26 +0100 (Tue, 31 Dec 2013)
New Revision: 662

Modified:
   pkg/ChangeLog
   pkg/src/DescriptorPoolLookup.cpp
   pkg/src/rprotobuf.cpp
Log:
Rf_error -> Rcpp::error and wrap a function in the needed BEGIN_RCPP /
END_RCPP boilerplate.  This update is tested by an existing unit test
that does checkException("/invalid/file").



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-12-31 02:45:32 UTC (rev 661)
+++ pkg/ChangeLog	2013-12-31 03:05:26 UTC (rev 662)
@@ -7,7 +7,8 @@
 	  repeated fields.
 	* src/wrapper_Message.cpp (rprotobuf): Remove Rf_error in favor of
 	  Rcpp_error so that we throw an exception and unwind the stack to
-	  deallocate objects before jumping to R' serror.
+	  deallocate objects before jumping to R's error.
+	* src/DescriptorPoolLookup.cpp (rprotobuf): Idem.
 	* R/size.R: Correct an incorrect method name that prevented size<-
 	  from working.
 	* man/size.Rd: Document the behavior of size<-

Modified: pkg/src/DescriptorPoolLookup.cpp
===================================================================
--- pkg/src/DescriptorPoolLookup.cpp	2013-12-31 02:45:32 UTC (rev 661)
+++ pkg/src/DescriptorPoolLookup.cpp	2013-12-31 03:05:26 UTC (rev 662)
@@ -36,13 +36,21 @@
 GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, &error_collector);
 GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory(importer.pool());
 
+/**
+ * Add descriptors from a proto file to the descriptor pool.
+ *
+ * @param files A character vector of .proto files to import.
+ * @param dirs A character vector of directories to import from.
+ * @throws Rcpp::exception if a file can't be loaded (uncaught).
+ */
 void DescriptorPoolLookup::importProtoFiles(SEXP files, SEXP dirs) {
     source_tree.addDirectories(dirs);
     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)));
+            string message = "Could not load proto file '" + CHAR(STRING_ELT(files, j)) + "'\n";
+            Rcpp_error(message.c_str());
             continue;
         }
         int ntypes = file_desc->message_type_count();

Modified: pkg/src/rprotobuf.cpp
===================================================================
--- pkg/src/rprotobuf.cpp	2013-12-31 02:45:32 UTC (rev 661)
+++ pkg/src/rprotobuf.cpp	2013-12-31 03:05:26 UTC (rev 662)
@@ -48,8 +48,10 @@
  * @param file proto file name
  */
 SEXP readProtoFiles(SEXP file, SEXP dirs) {
+    BEGIN_RCPP
     DescriptorPoolLookup::importProtoFiles(file, dirs);
     return R_NilValue;
+    END_RCPP
 }
 
 /**



More information about the Rprotobuf-commits mailing list