From noreply at r-forge.r-project.org Thu Aug 22 05:05:53 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 05:05:53 +0200 (CEST) Subject: [Rprotobuf-commits] r508 - in pkg: . R inst/unitTests man src Message-ID: <20130822030553.24444185576@r-forge.r-project.org> Author: murray Date: 2013-08-22 05:05:48 +0200 (Thu, 22 Aug 2013) New Revision: 508 Modified: pkg/ChangeLog pkg/R/00classes.R pkg/inst/unitTests/runit.extensions.R pkg/man/P.Rd pkg/src/rprotobuf.h pkg/src/wrapper_Message.cpp Log: Improve extensions support by: 1) Allowing one to find the FieldDescriptor for any extension with P(), even if it is in some weird nested location and not automatically imported. 2) Add a function for showing the number of extensions that are set in a given message, and use this to improve the show() output for messages. 3) Update tests and documentation. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/ChangeLog 2013-08-22 03:05:48 UTC (rev 508) @@ -1,3 +1,14 @@ +2013-08-21 Murray Stokely + + * man/P.Rd: Document behavior for extensions. + * inst/unitTests/runit.extensions.R (test.extension): Add another test. + * src/wrapper_Message.cpp (rprotobuf): Add function for returning + the number of extensions set in this message, to improve show() output. + * src/rprotobuf.cpp (rprotobuf): Add support for looking up + extensions by name and returning FieldDescriptors. + * R/00classes.R (P): Add support for returning extension + descriptors. + 2013-07-14 Dirk Eddelbuettel * inst/unitTests/runit.extensions.R (test.extension): Comment-out Modified: pkg/R/00classes.R =================================================================== --- pkg/R/00classes.R 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/R/00classes.R 2013-08-22 03:05:48 UTC (rev 508) @@ -119,7 +119,11 @@ desc <- .Call( "getProtobufDescriptor", type, PACKAGE = "RProtoBuf" ) if( is.null( desc ) ){ - stop( sprintf( "could not find descriptor for message type '%s' ", type ) ) + # See if it is an extension + desc <- .Call("getExtensionDescriptor", type, PACKAGE="RProtoBuf") + if (is.null(desc)) { + stop( sprintf( "could not find descriptor for message type '%s' ", type ) ) + } } desc } @@ -127,8 +131,13 @@ # {{{ show setMethod( "show", c( "Message" ), function(object){ - show( sprintf( "message of type '%s' with %d field%s set", object at type, - length(object), if (length(object) == 1) "" else "s" )) + tmp <- sprintf( "message of type '%s' with %d field%s set", object at type, + length(object), if (length(object) == 1) "" else "s" ) + nexts <- .Call("Message__num_extensions", object at pointer, PACKAGE="RProtoBuf") + if (nexts > 0) { + tmp <- paste(tmp, sprintf("and %d extension%s", nexts, if (nexts == 1) "" else "s")) + } + show(tmp) } ) setMethod( "show", c( "Descriptor" ), function(object){ show( sprintf( "descriptor for type '%s' ", object at type ) ) Modified: pkg/inst/unitTests/runit.extensions.R =================================================================== --- pkg/inst/unitTests/runit.extensions.R 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/inst/unitTests/runit.extensions.R 2013-08-22 03:05:48 UTC (rev 508) @@ -60,6 +60,13 @@ # TODO(edd): Commented out now # test$setExtension(protobuf_unittest.optional_nested_enum_extension, 9) + ## Test nested extensions + checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), + NULL) + test$setExtension(protobuf_unittest.TestNestedExtension.test, "Hello World") + checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), + "Hello World") + ## Test nested message extensions. tmp <- new( protobuf_unittest.TestAllTypes.NestedMessage ) tmp$bb <- 3 Modified: pkg/man/P.Rd =================================================================== --- pkg/man/P.Rd 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/man/P.Rd 2013-08-22 03:05:48 UTC (rev 508) @@ -9,14 +9,14 @@ P(type, file) } \arguments{ - \item{type}{Fully qualified type name of the protocol buffer} + \item{type}{Fully qualified type name of the protocol buffer or extension} \item{file}{optional proto file. If given, the definition contained in the file is first registered with the pool of message descriptors} } \value{ -An object of class \linkS4class{Descriptor}. -An error is generated otherwise. +An object of class \linkS4class{Descriptor} for message types or +\linkS4class{FieldDescriptor} for extensions. An error is generated otherwise. } \author{ Romain Francois Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/src/rprotobuf.h 2013-08-22 03:05:48 UTC (rev 508) @@ -120,6 +120,7 @@ RcppExport SEXP do_dollar_Descriptor( SEXP, SEXP ) ; RcppExport SEXP newProtoMessage( SEXP) ; RcppExport SEXP getProtobufDescriptor( SEXP ) ; +RcppExport SEXP getExtensionDescriptor( SEXP ) ; RcppExport SEXP readProtoFiles( SEXP, SEXP ); RcppExport Rboolean isMessage( SEXP, const char* ) ; RcppExport GPB::FieldDescriptor* getFieldDescriptor(GPB::Message*, SEXP) ; Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-07-15 03:02:53 UTC (rev 507) +++ pkg/src/wrapper_Message.cpp 2013-08-22 03:05:48 UTC (rev 508) @@ -224,6 +224,23 @@ return res ; } +/** + * The number of extensions the message has. + * + * @param xp external pointer to the Message + */ +RCPP_FUNCTION_1(int, METHOD(num_extensions), Rcpp::XPtr message){ + const GPB::Reflection * ref = message->GetReflection() ; + int nexts = 0; + vector fields; + ref->ListFields(*message, &fields); + for (int i = 0; i < fields.size(); i++) { + if (fields[i]->is_extension()) { + nexts++; + } + } + return nexts ; +} /** * Get the message descriptor of a Message From noreply at r-forge.r-project.org Thu Aug 22 05:10:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 05:10:50 +0200 (CEST) Subject: [Rprotobuf-commits] r509 - pkg/src Message-ID: <20130822031050.4C4A1185C04@r-forge.r-project.org> Author: murray Date: 2013-08-22 05:10:49 +0200 (Thu, 22 Aug 2013) New Revision: 509 Modified: pkg/src/rprotobuf.cpp Log: Add function missing from last CL to actually get the extension descriptor by name. Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-08-22 03:05:48 UTC (rev 508) +++ pkg/src/rprotobuf.cpp 2013-08-22 03:10:49 UTC (rev 509) @@ -83,7 +83,40 @@ return( S4_Descriptor( desc ) ) ; } + /** + * get the descriptor associated with an extension + * + * @param type message type + * + * @return an S4 object of class FieldDescriptor, or NULL if the type + * is unknown + */ +SEXP getExtensionDescriptor( SEXP type ){ +#ifdef RPB_DEBUG +Rprintf( "\n type = " ) ; +Rf_PrintValue( type ) ; +#endif + + const char * typeName = CHAR( STRING_ELT(type, 0 ) ) ; + + /* first try the generated pool */ + const GPB::DescriptorPool* pool = GPB::DescriptorPool::generated_pool() ; + const GPB::FieldDescriptor* desc = pool->FindExtensionByName( typeName ) ; + if( !desc ){ + /* then try the "runtime" pool" */ + pool = DescriptorPoolLookup::pool() ; + desc = pool->FindExtensionByName( typeName ) ; + if( !desc ){ + /* unlucky */ + return R_NilValue ; + } + } + + return( S4_FieldDescriptor( desc ) ) ; +} + +/** * make a new protobuf message * * @param descriptor a "Descriptor" R object @@ -233,4 +266,3 @@ } } // namespace rprotobuf - From noreply at r-forge.r-project.org Thu Aug 22 05:30:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 05:30:26 +0200 (CEST) Subject: [Rprotobuf-commits] r510 - in pkg: . inst/unitTests inst/unitTests/data Message-ID: <20130822033026.9F561185C04@r-forge.r-project.org> Author: murray Date: 2013-08-22 05:30:26 +0200 (Thu, 22 Aug 2013) New Revision: 510 Added: pkg/inst/unitTests/data/int64.ascii pkg/inst/unitTests/runit.int64.R Modified: pkg/ChangeLog Log: Add unit test (commented out) illustrating how RProtoBuf and Rcpp are broken with respect to 64-bit integers. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-22 03:10:49 UTC (rev 509) +++ pkg/ChangeLog 2013-08-22 03:30:26 UTC (rev 510) @@ -1,5 +1,8 @@ 2013-08-21 Murray Stokely + * inst/unitTests/runit.int64.R (test.int64): Add a test + illustrating how RProtoBuf is broken in handling 64-bit integers + (commented out for now). * man/P.Rd: Document behavior for extensions. * inst/unitTests/runit.extensions.R (test.extension): Add another test. * src/wrapper_Message.cpp (rprotobuf): Add function for returning Added: pkg/inst/unitTests/data/int64.ascii =================================================================== --- pkg/inst/unitTests/data/int64.ascii (rev 0) +++ pkg/inst/unitTests/data/int64.ascii 2013-08-22 03:30:26 UTC (rev 510) @@ -0,0 +1,2 @@ +repeated_int64: 9007199254740992 +repeated_int64: 9007199254740993 Added: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R (rev 0) +++ pkg/inst/unitTests/runit.int64.R 2013-08-22 03:30:26 UTC (rev 510) @@ -0,0 +1,31 @@ +# Copyright 2013 Google Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +test.int64 <- function() { + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } + + a <- protobuf_unittest.TestAllTypes$readASCII( + system.file("unitTests", "data", "int64.ascii", package="RProtoBuf")) + + # Uncomment when RProtoBuf / Rcpp are unbroken with respect to 64-bit ints. + # checkEquals(length(unique(a$repeated_int64)), 2) +} From noreply at r-forge.r-project.org Thu Aug 22 08:13:46 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 08:13:46 +0200 (CEST) Subject: [Rprotobuf-commits] r511 - in pkg: . R inst/unitTests Message-ID: <20130822061346.1296A1840BC@r-forge.r-project.org> Author: murray Date: 2013-08-22 08:13:45 +0200 (Thu, 22 Aug 2013) New Revision: 511 Modified: pkg/ChangeLog pkg/R/extensions.R pkg/inst/unitTests/runit.extensions.R Log: Add checks to ensure that a valid extension FieldDescriptor is used with getExtension and setExtension and add more tests. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-22 03:30:26 UTC (rev 510) +++ pkg/ChangeLog 2013-08-22 06:13:45 UTC (rev 511) @@ -1,10 +1,12 @@ 2013-08-21 Murray Stokely + * R/extensions.R: Add checks to ensure that a valid extension + FieldDescriptor is passed to getExtension and setExtension. * inst/unitTests/runit.int64.R (test.int64): Add a test illustrating how RProtoBuf is broken in handling 64-bit integers (commented out for now). * man/P.Rd: Document behavior for extensions. - * inst/unitTests/runit.extensions.R (test.extension): Add another test. + * inst/unitTests/runit.extensions.R (test.extension): Add more tests. * src/wrapper_Message.cpp (rprotobuf): Add function for returning the number of extensions set in this message, to improve show() output. * src/rprotobuf.cpp (rprotobuf): Add support for looking up Modified: pkg/R/extensions.R =================================================================== --- pkg/R/extensions.R 2013-08-22 03:30:26 UTC (rev 510) +++ pkg/R/extensions.R 2013-08-22 06:13:45 UTC (rev 511) @@ -21,10 +21,14 @@ } ) setMethod( "setExtension", "Message", function( object, field, values ){ - stopifnot(is_extension(field)) - - .Call( "setMessageField", object at pointer, field, values, - PACKAGE = "RProtoBuf" ) + if (!inherits(field, "FieldDescriptor")) { + stop("setExtension requires a FieldDescriptor") + } + if (!is_extension(field)) { + stop(paste(name(field), "is not an extension FieldDescriptor.")) + } + .Call( "setMessageField", object at pointer, field, values, + PACKAGE = "RProtoBuf" ) invisible( object ) } ) @@ -33,6 +37,12 @@ standardGeneric( "getExtension" ) } ) setMethod( "getExtension", "Message", function( object, field){ + if (!inherits(field, "FieldDescriptor")) { + stop("getExtension requires a FieldDescriptor") + } + if (!is_extension(field)) { + stop(paste(name(field), "is not an extension FieldDescriptor.")) + } .Call( "getExtension", object at pointer, field, PACKAGE = "RProtoBuf" ) } ) Modified: pkg/inst/unitTests/runit.extensions.R =================================================================== --- pkg/inst/unitTests/runit.extensions.R 2013-08-22 03:30:26 UTC (rev 510) +++ pkg/inst/unitTests/runit.extensions.R 2013-08-22 06:13:45 UTC (rev 511) @@ -26,6 +26,10 @@ checkTrue(inherits(protobuf_unittest.optional_uint32_extension, "FieldDescriptor")) + # Verify we can pull in other extensions with P() + checkTrue(inherits(P("protobuf_unittest.optional_uint32_extension"), + "FieldDescriptor")) + ## Test setting and getting singular extensions. test <- new(protobuf_unittest.TestAllExtensions) test$setExtension(protobuf_unittest.optional_int32_extension, @@ -45,6 +49,8 @@ 1:10) ## Test nested extensions. + checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), + NULL) test$setExtension(protobuf_unittest.TestNestedExtension.test, "foo") checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), "foo") @@ -54,22 +60,19 @@ test$setExtension(protobuf_unittest.optional_nested_enum_extension, protobuf_unittest.TestAllTypes.NestedEnum$BAR) - # Test that we get an error printed to terminal (not a real stop error) - # not a crash for invalid enum: - # TODO(mstokely): Make this a stop() error. + # This causes an Rcpp exception, but not an R stop error as of my + # version of Rcpp, so we can't checkError unfortunately, but we + # can at least make sure it doesn't crash R. # TODO(edd): Commented out now # test$setExtension(protobuf_unittest.optional_nested_enum_extension, 9) - ## Test nested extensions - checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), - NULL) - test$setExtension(protobuf_unittest.TestNestedExtension.test, "Hello World") - checkEquals(test$getExtension(protobuf_unittest.TestNestedExtension.test), - "Hello World") - ## Test nested message extensions. tmp <- new( protobuf_unittest.TestAllTypes.NestedMessage ) tmp$bb <- 3 test$setExtension(protobuf_unittest.optional_nested_message_extension, tmp) checkEquals(test$getExtension(protobuf_unittest.optional_nested_message_extension)$bb, 3) + + ## 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)) } From noreply at r-forge.r-project.org Thu Aug 22 08:19:12 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 08:19:12 +0200 (CEST) Subject: [Rprotobuf-commits] r512 - pkg/inst/unitTests Message-ID: <20130822061912.444781813EE@r-forge.r-project.org> Author: murray Date: 2013-08-22 08:19:11 +0200 (Thu, 22 Aug 2013) New Revision: 512 Modified: pkg/inst/unitTests/runit.int64.R Log: Fix test to pass file connection to readASCII. It treats characters as the actual input, not as filenames. Modified: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R 2013-08-22 06:13:45 UTC (rev 511) +++ pkg/inst/unitTests/runit.int64.R 2013-08-22 06:19:11 UTC (rev 512) @@ -24,7 +24,8 @@ } a <- protobuf_unittest.TestAllTypes$readASCII( - system.file("unitTests", "data", "int64.ascii", package="RProtoBuf")) + file(system.file("unitTests", "data", "int64.ascii", + package="RProtoBuf"))) # Uncomment when RProtoBuf / Rcpp are unbroken with respect to 64-bit ints. # checkEquals(length(unique(a$repeated_int64)), 2) From noreply at r-forge.r-project.org Thu Aug 22 08:33:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 22 Aug 2013 08:33:48 +0200 (CEST) Subject: [Rprotobuf-commits] r513 - in pkg: . inst/unitTests src Message-ID: <20130822063348.674501813EE@r-forge.r-project.org> Author: murray Date: 2013-08-22 08:33:45 +0200 (Thu, 22 Aug 2013) New Revision: 513 Modified: pkg/ChangeLog pkg/inst/unitTests/runit.addressbook.R pkg/src/wrapper_Descriptor.cpp Log: Add better error handling for readASCII of characters. People frequently forget to call file() around their pathname to invoke the readASCIIFromConnection() method so hopefully the better error message here will make this error clearer. Also add a checkException() test to make sure we alert the user rather than silently returning an empty proto as before. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-22 06:19:11 UTC (rev 512) +++ pkg/ChangeLog 2013-08-22 06:33:45 UTC (rev 513) @@ -1,5 +1,9 @@ 2013-08-21 Murray Stokely + * inst/unitTests/runit.addressbook.R (test.ascii): Add more tests. + * src/wrapper_Descriptor.cpp (rprotobuf): Add better error + handling for readASCII of text strings rather than returning + an empty proto. * R/extensions.R: Add checks to ensure that a valid extension FieldDescriptor is passed to getExtension and setExtension. * inst/unitTests/runit.int64.R (test.int64): Add a test Modified: pkg/inst/unitTests/runit.addressbook.R =================================================================== --- pkg/inst/unitTests/runit.addressbook.R 2013-08-22 06:19:11 UTC (rev 512) +++ pkg/inst/unitTests/runit.addressbook.R 2013-08-22 06:33:45 UTC (rev 513) @@ -62,4 +62,8 @@ out.file2 <- tempfile() writeLines("jibberish", file(out.file2)) book6 <- checkException( readASCII( tutorial.AddressBook, file(out.file2))) + + # Verify that we get an exception if we forget the file() and thus treat the + # path as a protobuf string. + checkException( readASCII( tutorial.AddressBook, out.file2)) } Modified: pkg/src/wrapper_Descriptor.cpp =================================================================== --- pkg/src/wrapper_Descriptor.cpp 2013-08-22 06:19:11 UTC (rev 512) +++ pkg/src/wrapper_Descriptor.cpp 2013-08-22 06:33:45 UTC (rev 513) @@ -166,8 +166,11 @@ RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr desc, std::string input){ GPB::Message* message = PROTOTYPE( desc ) ; - GPB::TextFormat::ParseFromString( input, message ) ; - return( S4_Message( message ) ) ; + if (GPB::TextFormat::ParseFromString( input, message ) ) { + return( S4_Message( message ) ) ; + } else { + throw std::range_error("Could not parse ASCII protocol buffer from text string."); + } } RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr desc, int conn_id){ From noreply at r-forge.r-project.org Wed Aug 28 00:02:05 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 28 Aug 2013 00:02:05 +0200 (CEST) Subject: [Rprotobuf-commits] r514 - in pkg: . src Message-ID: <20130827220205.66C8E185165@r-forge.r-project.org> Author: murray Date: 2013-08-28 00:02:04 +0200 (Wed, 28 Aug 2013) New Revision: 514 Modified: pkg/ChangeLog pkg/src/mutators.cpp Log: Add support for setting int64 fields as R character vectors that are converted to int64 or uint64 C++ types with std::stringstream. This allows the user to get around the lack of 64-bit integer support in R when working interactively with RProtoBufs where a large precision number or identifier needs to be stored. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-22 06:33:45 UTC (rev 513) +++ pkg/ChangeLog 2013-08-27 22:02:04 UTC (rev 514) @@ -1,3 +1,13 @@ +2013-08-27 Murray Stokely + + * src/mutators.cpp (rprotobuf): Add support for setting int64 + fields as R character vectors that are converted to int64 or + uint64 C++ types with std::stringstream. This allows the user + to get around the lack of 64-bit integer support in R when working + interactively with RProtoBufs where a large precision number or + identifier needs to be stored. + + 2013-08-21 Murray Stokely * inst/unitTests/runit.addressbook.R (test.ascii): Add more tests. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-08-22 06:33:45 UTC (rev 513) +++ pkg/src/mutators.cpp 2013-08-27 22:02:04 UTC (rev 514) @@ -110,6 +110,16 @@ return( (int64)LOGICAL(x)[index] ); case RAWSXP: return( (int64)RAW(x)[index] ) ; + case STRSXP: { + const string int64str = CHAR(STRING_ELT(x, index)); + std::stringstream ss(int64str); + int64 ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + throwException("Provided STRSXP cannot be cast to int64", + "CastException"); + } + return ret; + } default: throwException( "cannot cast SEXP to int64", "CastException" ) ; } @@ -136,12 +146,22 @@ switch( TYPEOF(x) ){ case INTSXP: return( (uint64)INTEGER(x)[index] ); - case REALSXP: + case REALSXP: return( (uint64)REAL(x)[index] ); case LGLSXP: return( (uint64)LOGICAL(x)[index] ); case RAWSXP: return( (uint64)RAW(x)[index] ) ; + case STRSXP: { + const string int64str = CHAR(STRING_ELT(x, index)); + std::stringstream ss(int64str); + uint64 ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + throwException(" Provided STRSXP cannot be cast to uint64", + "CastException"); + } + return ret; + } default: throwException( "cannot cast SEXP to uint64", "CastException" ) ; } @@ -596,11 +616,12 @@ case TYPE_SINT64: case TYPE_SFIXED64: { - switch( TYPEOF( value ) ){ - case INTSXP: - case REALSXP: - case LGLSXP: - case RAWSXP: + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + case STRSXP: // For int64, we support chars. { int i = 0; @@ -664,7 +685,8 @@ case INTSXP: case REALSXP: case LGLSXP: - case RAWSXP: + case RAWSXP: + case STRSXP: // For int64, we support chars. { int i = 0; From noreply at r-forge.r-project.org Wed Aug 28 00:33:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 28 Aug 2013 00:33:39 +0200 (CEST) Subject: [Rprotobuf-commits] r515 - in pkg: . inst/unitTests Message-ID: <20130827223339.336BB183D86@r-forge.r-project.org> Author: murray Date: 2013-08-28 00:33:38 +0200 (Wed, 28 Aug 2013) New Revision: 515 Modified: pkg/ChangeLog pkg/inst/unitTests/runit.int64.R Log: Add unit tests for the new int64 as character string support. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-27 22:02:04 UTC (rev 514) +++ pkg/ChangeLog 2013-08-27 22:33:38 UTC (rev 515) @@ -6,8 +6,8 @@ to get around the lack of 64-bit integer support in R when working interactively with RProtoBufs where a large precision number or identifier needs to be stored. + * inst/unitTests/runit.int64.R: Add tests for the above. - 2013-08-21 Murray Stokely * inst/unitTests/runit.addressbook.R (test.ascii): Add more tests. Modified: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R 2013-08-27 22:02:04 UTC (rev 514) +++ pkg/inst/unitTests/runit.int64.R 2013-08-27 22:33:38 UTC (rev 515) @@ -23,10 +23,22 @@ readProtoFiles(file=unittest.proto.file) } + a <- new(protobuf_unittest.TestAllTypes) + a$repeated_int64 <- 1 + # Verify we can set character strings of large 64-bit ints + a$repeated_int64 <- c("9007199254740992", "9007199254740993") + checkEquals(length(a$repeated_int64), 2) + # Verify we can set any garbage string to an int64. + checkException(a$repeated_int64 <-c("invalid", "invalid")) + a <- protobuf_unittest.TestAllTypes$readASCII( file(system.file("unitTests", "data", "int64.ascii", package="RProtoBuf"))) + # And can read them in OK from an ASCII file. + checkEquals(length(a$repeated_int64), 2) + # TODO(mstokely): But the accessors still silently cast to double + # which removes uniqueness. Fix this. # Uncomment when RProtoBuf / Rcpp are unbroken with respect to 64-bit ints. # checkEquals(length(unique(a$repeated_int64)), 2) } From noreply at r-forge.r-project.org Wed Aug 28 03:13:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 28 Aug 2013 03:13:36 +0200 (CEST) Subject: [Rprotobuf-commits] r516 - in pkg: . R inst/unitTests src Message-ID: <20130828011336.446A31855D9@r-forge.r-project.org> Author: murray Date: 2013-08-28 03:13:35 +0200 (Wed, 28 Aug 2013) New Revision: 516 Modified: pkg/ChangeLog pkg/R/zzz.R pkg/inst/unitTests/runit.int64.R pkg/src/Rcppsupport.h pkg/src/extractors.cpp pkg/src/mutators.cpp Log: Add support for a new option("int64AsString") that controls whether extractors for 64-bit integer fields return character strings or use Rcpp's default wrap type which coerces to numeric, possibly losing precision. At any time 64-bit integer fields can now be set with strings, e.g. a$optional_int64 <- "9007199254740993" And now, by default, a$otional_int64 returns a numeric as now : a$optional_int64 [1] 9.007199e+15 But we can get the full-precision string version by setting an option: options("int64AsString"=TRUE) a$optional_int64 [1] "9007199254740993" Code clean up and documentation coming later. Also this should just be done in Rcpp. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/ChangeLog 2013-08-28 01:13:35 UTC (rev 516) @@ -1,5 +1,13 @@ 2013-08-27 Murray Stokely + * src/extractors.cpp (rprotobuf): Add support for a new + option("int64AsString") that controls whether extractors for + 64-bit integer fields return character strings or use Rcpp's + default wrap type which coerces to numeric, possibly losing + precision. + * R/zzz.R (.onLoad): Initialize options("int64AsString" = FALSE). + * src/Rcppsupport.h (rprotobuf): Add RepeatedFieldImporter classes + for int64 and uint64 that return strings instead of int64s. * src/mutators.cpp (rprotobuf): Add support for setting int64 fields as R character vectors that are converted to int64 or uint64 C++ types with std::stringstream. This allows the user Modified: pkg/R/zzz.R =================================================================== --- pkg/R/zzz.R 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/R/zzz.R 2013-08-28 01:13:35 UTC (rev 516) @@ -5,10 +5,9 @@ ##.Call( "check_libprotobuf_version", minversion, PACKAGE = "RProtoBuf" ) readProtoFiles( package=pkgname, lib.loc=libname ) attachDescriptorPool( pos = length(search()) ) - + options("int64AsString" = FALSE) if( exists( ".httpd.handlers.env", asNamespace( "tools" ) ) ){ e <- tools:::.httpd.handlers.env e[["RProtoBuf"]] <- RProtoBuf.http.handler } } - Modified: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/inst/unitTests/runit.int64.R 2013-08-28 01:13:35 UTC (rev 516) @@ -28,17 +28,25 @@ # Verify we can set character strings of large 64-bit ints a$repeated_int64 <- c("9007199254740992", "9007199254740993") checkEquals(length(a$repeated_int64), 2) - # Verify we can set any garbage string to an int64. + # Verify we can't set any garbage string to a repeated int64. checkException(a$repeated_int64 <-c("invalid", "invalid")) + a$optional_int64 <- 1 + a$optional_int64 <- "2" + checkEquals(a$optional_int64, 2) + # Verify we can't set any garbage string to an optional int64. + checkException(a$optional_int64 <- "invalid") + a <- protobuf_unittest.TestAllTypes$readASCII( file(system.file("unitTests", "data", "int64.ascii", package="RProtoBuf"))) # And can read them in OK from an ASCII file. checkEquals(length(a$repeated_int64), 2) - # TODO(mstokely): But the accessors still silently cast to double - # which removes uniqueness. Fix this. - # Uncomment when RProtoBuf / Rcpp are unbroken with respect to 64-bit ints. - # checkEquals(length(unique(a$repeated_int64)), 2) + # By default, when they are read as numerics, only 1 unique value + checkEquals(length(unique(a$repeated_int64)), 1) + + options("int64AsString" = TRUE) + # But we can see they are different if we treat them as strings. + checkEquals(length(unique(a$repeated_int64)), 2) } Modified: pkg/src/Rcppsupport.h =================================================================== --- pkg/src/Rcppsupport.h 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/src/Rcppsupport.h 2013-08-28 01:13:35 UTC (rev 516) @@ -32,6 +32,52 @@ struct enum_field{} ; struct message_field{} ; +class Int64AsStringRepeatedFieldImporter { +public: + // Probably want to convert to strings here. + typedef string r_import_type; + Int64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_ , + const GPB::Message& message_, + const GPB::FieldDescriptor* field_): + ref(ref_), message(message_), field(field_){} + inline int size() const { + return ref->FieldSize( message, field ) ; + } + inline string get(int i) const { + stringstream stream; + int64 val = ref->GetRepeatedInt64(message, field, i) ; + stream << val; + return stream.str(); + } + private: + const GPB::Reflection* ref ; + const GPB::Message& message ; + const GPB::FieldDescriptor* field ; +}; + +class UInt64AsStringRepeatedFieldImporter { +public: + // Probably want to convert to strings here. + typedef string r_import_type; + UInt64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_ , + const GPB::Message& message_, + const GPB::FieldDescriptor* field_): + ref(ref_), message(message_), field(field_){} + inline int size() const { + return ref->FieldSize( message, field ) ; + } + inline string get(int i) const { + stringstream stream; + uint64 val = ref->GetRepeatedUInt64(message, field, i) ; + stream << val; + return stream.str(); + } + private: + const GPB::Reflection* ref ; + const GPB::Message& message ; + const GPB::FieldDescriptor* field ; +}; + template class RepeatedFieldImporter{} ; #undef GENERATE__FIELD__IMPORTER__DECL Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/src/extractors.cpp 2013-08-28 01:13:35 UTC (rev 516) @@ -23,7 +23,50 @@ #include "Rcppsupport.h" namespace rprotobuf{ - + +SEXP kInt64AsStringOptionName = Rf_install("int64AsString"); + +// Rcpp::wrap silently coerces 64-bit integers to numerics +// which drop precision for values between 2^53 - 2^64. +// So, if an option is set, we return as a character string. +// TODO(mstokely): Do more of this in Rcpp. +SEXP PreciseRInt64Type(int64 val) { + if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + std::stringstream ss; + if ((ss << val).fail()) { + // This should not happen, its a bug in the code. + throwException( + "Error converting int64 to STRSXP, unset int64AsString option.", + "ConversionException"); + } + // Rcpp::wrap of the string returns vector of single characters. + // So we must create this vector first to wrap. + std::vector retlist; + retlist.push_back(ss.str()); + return Rcpp::wrap(retlist); + } else { + return Rcpp::wrap(val); + } +} + +SEXP PreciseRUInt64Type(uint64 val) { + if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + std::stringstream ss; + if ((ss << val).fail()) { + // This should not happen, its a bug in the code. + throwException( + "Error converting uint64 to STRSXP, unset int64AsString option.", + "ConversionException"); + } + // Wrap the string version of this int64. + std::vector retlist; + retlist.push_back(ss.str()); + return Rcpp::wrap(retlist); + } else { + return Rcpp::wrap(val); + } +} + /** * extract a field from a message * @@ -71,15 +114,33 @@ HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32) ; HANDLE_REPEATED_FIELD(CPPTYPE_UINT32, GPB::uint32) ; -#ifdef RCPP_HAS_LONG_LONG_TYPES - HANDLE_REPEATED_FIELD(CPPTYPE_INT64, GPB::int64) ; - HANDLE_REPEATED_FIELD(CPPTYPE_UINT64, GPB::uint64) ; -#endif HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double) ; HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float) ; HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool) ; HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field ) ; HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field ) ; +#ifdef RCPP_HAS_LONG_LONG_TYPES + // We can't handle these the same way, because Rcpp::wrap silently + // casts int64s to doubles which may cause us to lose precision. + case CPPTYPE_INT64: + if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + return Rcpp::wrap( + Int64AsStringRepeatedFieldImporter(ref, *message, + fieldDesc)); + } else { + return Rcpp::wrap( + RepeatedFieldImporter(ref, *message, fieldDesc)); + } + case CPPTYPE_UINT64: + if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + return Rcpp::wrap( + UInt64AsStringRepeatedFieldImporter(ref, *message, + fieldDesc)); + } else { + return Rcpp::wrap( + RepeatedFieldImporter(ref, *message, fieldDesc)); + } +#endif #undef HANDLE_REPEATED_FIELD case CPPTYPE_STRING: @@ -112,13 +173,17 @@ HANDLE_SINGLE_FIELD( CPPTYPE_INT32, Int32 ); HANDLE_SINGLE_FIELD( CPPTYPE_UINT32, UInt32 ); -#ifdef RCPP_HAS_LONG_LONG_TYPES - HANDLE_SINGLE_FIELD( CPPTYPE_INT64, Int64 ); - HANDLE_SINGLE_FIELD( CPPTYPE_UINT64, UInt64 ); -#endif HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double ); HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float ); HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool ); +#ifdef RCPP_HAS_LONG_LONG_TYPES + // Handle these types separately since Rcpp::wrap doesn't + // do the right thing. + case CPPTYPE_INT64: + return PreciseRInt64Type(ref->GetInt64(*message, fieldDesc)); + case CPPTYPE_UINT64: + return PreciseRUInt64Type(ref->GetUInt64(*message, fieldDesc)); +#endif #undef HANDLE_SINGLE_FIELD case CPPTYPE_STRING: @@ -146,4 +211,3 @@ } } // namespace rprotobuf - Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-08-27 22:33:38 UTC (rev 515) +++ pkg/src/mutators.cpp 2013-08-28 01:13:35 UTC (rev 516) @@ -1030,13 +1030,56 @@ HANDLE_SINGLE_FIELD( CPPTYPE_INT32, Int32, GPB::int32) ; HANDLE_SINGLE_FIELD( CPPTYPE_UINT32, UInt32, GPB::uint32) ; -#ifdef RCPP_HAS_LONG_LONG_TYPES - HANDLE_SINGLE_FIELD( CPPTYPE_INT64, Int64, GPB::int64) ; - HANDLE_SINGLE_FIELD( CPPTYPE_UINT64, UInt64, GPB::uint64) ; -#endif HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double, double) ; HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float, float) ; HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool, bool) ; +#ifdef RCPP_HAS_LONG_LONG_TYPES + case CPPTYPE_INT64 : + { + // TODO(mstokely) Rcpp::as of a STRSEXP + // should just work for strings representing + // int64s. + if (TYPEOF(value) == STRSXP) { + const string int64str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + std::stringstream ss(int64str); + GPB::int64 ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + throwException( + "Provided STRSXP cannot be cast to int64", + "CastException"); + } + ref->SetInt64(message, field_desc, ret); + break ; + } else { + ref->SetInt64( message, field_desc, Rcpp::as(value)); + break; + } + } + case CPPTYPE_UINT64 : + { + // TODO(mstokely) Rcpp::as of a STRSEXP + // should just work for strings representing + // int64s. + if (TYPEOF(value) == STRSXP) { + const string int64str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + std::stringstream ss(int64str); + GPB::uint64 ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + throwException( + "Provided STRSXP cannot be cast to uint64", + "CastException"); + } + ref->SetUInt64(message, field_desc, ret); + break ; + } else { + ref->SetUInt64(message, field_desc, + Rcpp::as(value)); + break; + } + } +#endif #undef HANDLE_SINGLE_FIELD default: throwException("Unsupported type", "ConversionException"); From noreply at r-forge.r-project.org Fri Aug 30 03:36:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 30 Aug 2013 03:36:35 +0200 (CEST) Subject: [Rprotobuf-commits] r517 - in pkg: . R inst/unitTests src Message-ID: <20130830013635.32BDC18483E@r-forge.r-project.org> Author: murray Date: 2013-08-30 03:36:34 +0200 (Fri, 30 Aug 2013) New Revision: 517 Modified: pkg/ChangeLog pkg/R/zzz.R pkg/inst/unitTests/runit.int64.R pkg/src/extractors.cpp pkg/src/mutators.cpp Log: Make the code more concise by introducing a few templated functions and rename the option name to include a packagename prefix. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-28 01:13:35 UTC (rev 516) +++ pkg/ChangeLog 2013-08-30 01:36:34 UTC (rev 517) @@ -1,3 +1,12 @@ +2013-08-29 Murray Stokely + + * R/zzz.R (.onLoad): Rename option controlling int64 handling with + package name prefix. + * inst/unitTests/runit.int64.R (test.int64): Idem + * src/extractors.cpp (rprotobuf): Add templated function to reduce + code duplication in last changelist. + * src/mutators.cpp (rprotobuf): Idem + 2013-08-27 Murray Stokely * src/extractors.cpp (rprotobuf): Add support for a new Modified: pkg/R/zzz.R =================================================================== --- pkg/R/zzz.R 2013-08-28 01:13:35 UTC (rev 516) +++ pkg/R/zzz.R 2013-08-30 01:36:34 UTC (rev 517) @@ -5,7 +5,7 @@ ##.Call( "check_libprotobuf_version", minversion, PACKAGE = "RProtoBuf" ) readProtoFiles( package=pkgname, lib.loc=libname ) attachDescriptorPool( pos = length(search()) ) - options("int64AsString" = FALSE) + options("RProtoBuf.int64AsString" = FALSE) if( exists( ".httpd.handlers.env", asNamespace( "tools" ) ) ){ e <- tools:::.httpd.handlers.env e[["RProtoBuf"]] <- RProtoBuf.http.handler Modified: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R 2013-08-28 01:13:35 UTC (rev 516) +++ pkg/inst/unitTests/runit.int64.R 2013-08-30 01:36:34 UTC (rev 517) @@ -46,7 +46,7 @@ # By default, when they are read as numerics, only 1 unique value checkEquals(length(unique(a$repeated_int64)), 1) - options("int64AsString" = TRUE) + options("RProtoBuf.int64AsString" = TRUE) # But we can see they are different if we treat them as strings. checkEquals(length(unique(a$repeated_int64)), 2) } Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-08-28 01:13:35 UTC (rev 516) +++ pkg/src/extractors.cpp 2013-08-30 01:36:34 UTC (rev 517) @@ -24,49 +24,31 @@ namespace rprotobuf{ -SEXP kInt64AsStringOptionName = Rf_install("int64AsString"); +const char * kIntStringOptionName = "RProtoBuf.int64AsString"; +bool UseStringsForInt64() { + static const SEXP option_name = Rf_install(kIntStringOptionName); + return (Rf_asLogical(Rf_GetOption1(option_name))); +} // Rcpp::wrap silently coerces 64-bit integers to numerics // which drop precision for values between 2^53 - 2^64. // So, if an option is set, we return as a character string. -// TODO(mstokely): Do more of this in Rcpp. -SEXP PreciseRInt64Type(int64 val) { - if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { - std::stringstream ss; - if ((ss << val).fail()) { - // This should not happen, its a bug in the code. - throwException( - "Error converting int64 to STRSXP, unset int64AsString option.", - "ConversionException"); +template +SEXP Int64AsSEXP(ValueType value) { + if (UseStringsForInt64()) { + std::stringstream ss; + if ((ss << value).fail()) { + // This should not happen, its a bug in the code. + string message = string("Error converting int64 to string, unset ") + + kIntStringOptionName + " option."; + throwException(message.c_str(), "ConversionException"); } - // Rcpp::wrap of the string returns vector of single characters. - // So we must create this vector first to wrap. - std::vector retlist; - retlist.push_back(ss.str()); - return Rcpp::wrap(retlist); - } else { - return Rcpp::wrap(val); - } + return Rcpp::CharacterVector(ss.str()); + } else { + return Rcpp::wrap(value); + } } -SEXP PreciseRUInt64Type(uint64 val) { - if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { - std::stringstream ss; - if ((ss << val).fail()) { - // This should not happen, its a bug in the code. - throwException( - "Error converting uint64 to STRSXP, unset int64AsString option.", - "ConversionException"); - } - // Wrap the string version of this int64. - std::vector retlist; - retlist.push_back(ss.str()); - return Rcpp::wrap(retlist); - } else { - return Rcpp::wrap(val); - } -} - /** * extract a field from a message * @@ -123,7 +105,7 @@ // We can't handle these the same way, because Rcpp::wrap silently // casts int64s to doubles which may cause us to lose precision. case CPPTYPE_INT64: - if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + if (UseStringsForInt64()) { return Rcpp::wrap( Int64AsStringRepeatedFieldImporter(ref, *message, fieldDesc)); @@ -132,7 +114,7 @@ RepeatedFieldImporter(ref, *message, fieldDesc)); } case CPPTYPE_UINT64: - if (Rf_asLogical(Rf_GetOption1(kInt64AsStringOptionName))) { + if (UseStringsForInt64()) { return Rcpp::wrap( UInt64AsStringRepeatedFieldImporter(ref, *message, fieldDesc)); @@ -180,9 +162,9 @@ // Handle these types separately since Rcpp::wrap doesn't // do the right thing. case CPPTYPE_INT64: - return PreciseRInt64Type(ref->GetInt64(*message, fieldDesc)); + return Int64AsSEXP(ref->GetInt64(*message, fieldDesc)); case CPPTYPE_UINT64: - return PreciseRUInt64Type(ref->GetUInt64(*message, fieldDesc)); + return Int64AsSEXP(ref->GetUInt64(*message, fieldDesc)); #endif #undef HANDLE_SINGLE_FIELD Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-08-28 01:13:35 UTC (rev 516) +++ pkg/src/mutators.cpp 2013-08-30 01:36:34 UTC (rev 517) @@ -99,6 +99,17 @@ return (int32)0 ; // -Wall, should not happen since we only call this when we know it works } +template +ValueType Int64FromString(const string value) { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + string message = "Provided character value '" + value + + "' cannot be cast to 64-bit integer."; + throwException(message.c_str(), "CastException"); + } + return ret; +} int64 GET_int64( SEXP x, int index ){ switch( TYPEOF(x) ){ @@ -110,16 +121,8 @@ return( (int64)LOGICAL(x)[index] ); case RAWSXP: return( (int64)RAW(x)[index] ) ; - case STRSXP: { - const string int64str = CHAR(STRING_ELT(x, index)); - std::stringstream ss(int64str); - int64 ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - throwException("Provided STRSXP cannot be cast to int64", - "CastException"); - } - return ret; - } + case STRSXP: + return Int64FromString(CHAR(STRING_ELT(x, index))); default: throwException( "cannot cast SEXP to int64", "CastException" ) ; } @@ -152,16 +155,8 @@ return( (uint64)LOGICAL(x)[index] ); case RAWSXP: return( (uint64)RAW(x)[index] ) ; - case STRSXP: { - const string int64str = CHAR(STRING_ELT(x, index)); - std::stringstream ss(int64str); - uint64 ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - throwException(" Provided STRSXP cannot be cast to uint64", - "CastException"); - } - return ret; - } + case STRSXP: + return Int64FromString(CHAR(STRING_ELT(x, index))); default: throwException( "cannot cast SEXP to uint64", "CastException" ) ; } @@ -1042,14 +1037,8 @@ if (TYPEOF(value) == STRSXP) { const string int64str = COPYSTRING(CHAR( STRING_ELT(value, 0))); - std::stringstream ss(int64str); - GPB::int64 ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - throwException( - "Provided STRSXP cannot be cast to int64", - "CastException"); - } - ref->SetInt64(message, field_desc, ret); + ref->SetInt64(message, field_desc, + Int64FromString(int64str)); break ; } else { ref->SetInt64( message, field_desc, Rcpp::as(value)); @@ -1064,14 +1053,8 @@ if (TYPEOF(value) == STRSXP) { const string int64str = COPYSTRING(CHAR( STRING_ELT(value, 0))); - std::stringstream ss(int64str); - GPB::uint64 ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - throwException( - "Provided STRSXP cannot be cast to uint64", - "CastException"); - } - ref->SetUInt64(message, field_desc, ret); + ref->SetUInt64(message, field_desc, + Int64FromString(int64str)); break ; } else { ref->SetUInt64(message, field_desc, From noreply at r-forge.r-project.org Fri Aug 30 08:30:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 30 Aug 2013 08:30:35 +0200 (CEST) Subject: [Rprotobuf-commits] r518 - pkg Message-ID: <20130830063035.D483B1806EB@r-forge.r-project.org> Author: murray Date: 2013-08-30 08:30:35 +0200 (Fri, 30 Aug 2013) New Revision: 518 Added: pkg/m4-ax_cxx_compile_stdcxx_0x.m4 Modified: pkg/configure pkg/configure.in Log: Add a macro from the autoconf archive that lets us test if we can use C++0x features with the compiler, and if so, add -std=c++0x to CXXFLAGS. This gives us some limited int64 support in Rcpp. Crucially, this change does not cause any sort of error if c++0x is not available. Modified: pkg/configure =================================================================== --- pkg/configure 2013-08-30 01:36:34 UTC (rev 517) +++ pkg/configure 2013-08-30 06:30:35 UTC (rev 518) @@ -1,9 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for RProtoBuf 0.1. +# Generated by GNU Autoconf 2.68 for RProtoBuf 0.1. # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -132,31 +134,6 @@ # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -190,8 +167,7 @@ else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -236,25 +212,21 @@ if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -356,14 +328,6 @@ } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -485,10 +449,6 @@ chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -523,16 +483,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -544,8 +504,28 @@ as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -1148,6 +1128,8 @@ if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1377,9 +1359,9 @@ if $ac_init_version; then cat <<\_ACEOF RProtoBuf configure 0.1 -generated by GNU Autoconf 2.69 +generated by GNU Autoconf 2.68 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1667,7 +1649,7 @@ running configure, to aid debugging if configure makes a mistake. It was created by RProtoBuf $as_me 0.1, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2014,7 +1996,52 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. +#serial 7 + +# This is what autoupdate's m4 run will expand. It fires +# the warning (with _au_warn_XXX), outputs it into the +# updated configure.ac (with AC_DIAGNOSE), and then outputs +# the replacement expansion. + + +# This is an auxiliary macro that is also run when +# autoupdate runs m4. It simply calls m4_warning, but +# we need a wrapper so that each warning is emitted only +# once. We break the quoting in m4_warning's argument in +# order to expand this macro's arguments, not AU_DEFUN's. + + +# Finally, this is the expansion that is picked up by +# autoconf. It tells the user to run autoupdate, and +# then outputs the replacement expansion. We do not care +# about autoupdate's warning because that contains +# information on what to do *after* running autoupdate. + + + + # We are using C++ ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' @@ -2050,7 +2077,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2094,7 +2121,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2687,7 +2714,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2727,7 +2754,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2780,7 +2807,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2821,7 +2848,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2879,7 +2906,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2923,7 +2950,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3119,7 +3146,8 @@ /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3232,7 +3260,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3276,7 +3304,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3462,6 +3490,187 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +# If we can support std=c++0x we should pass flags to do so (this will +# enable better int64 support) but we shouldn't cause the build to +# fail if we can't do this. + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if g++ supports C++0x features without additional flags" >&5 +$as_echo_n "checking if g++ supports C++0x features without additional flags... " >&6; } +if ${ax_cv_cxx_compile_cxx0x_native+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ax_cv_cxx_compile_cxx0x_native=yes +else + ax_cv_cxx_compile_cxx0x_native=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cxx_compile_cxx0x_native" >&5 +$as_echo "$ax_cv_cxx_compile_cxx0x_native" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if g++ supports C++0x features with -std=c++0x" >&5 +$as_echo_n "checking if g++ supports C++0x features with -std=c++0x... " >&6; } +if ${ax_cv_cxx_compile_cxx0x_cxx+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ax_cv_cxx_compile_cxx0x_cxx=yes +else + ax_cv_cxx_compile_cxx0x_cxx=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cxx_compile_cxx0x_cxx" >&5 +$as_echo "$ax_cv_cxx_compile_cxx0x_cxx" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if g++ supports C++0x features with -std=gnu++0x" >&5 +$as_echo_n "checking if g++ supports C++0x features with -std=gnu++0x... " >&6; } +if ${ax_cv_cxx_compile_cxx0x_gxx+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ax_cv_cxx_compile_cxx0x_gxx=yes +else + ax_cv_cxx_compile_cxx0x_gxx=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cxx_compile_cxx0x_gxx" >&5 +$as_echo "$ax_cv_cxx_compile_cxx0x_gxx" >&6; } + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + +$as_echo "#define HAVE_STDCXX_0X /**/" >>confdefs.h + + fi + + ## simpler alternative to test below: AC_PATH_PROG(PROTOC, protoc) @@ -3481,7 +3690,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_PKGCONFIG="yes" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3530,7 +3739,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_PROTOC="yes" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3584,7 +3793,7 @@ for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -3650,7 +3859,7 @@ for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -3912,7 +4121,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_R="yes" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3941,6 +4150,11 @@ fi CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` +# We need this to get some limited int64 support with Rcpp. +if test "x$ax_cv_cxx_compile_cxx0x_cxx" = "xyes" ; then + CXXFLAGS="$CXXFLAGS -std=c++0x" +fi + ## look for Rscript, but use the one found via R_HOME to allow for multiple installations # Extract the first word of "Rscript", so it can be a program name with args. @@ -3959,7 +4173,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RSCRIPT="yes" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3993,7 +4207,7 @@ fi ## now use all these -PKG_CPPFLAGS="${PKG_CPPFLAGS} $protobuf_cxxflags" +PKG_CPPFLAGS="${PKG_CPPFLAGS} ${CXXFLAGS} $protobuf_cxxflags" PKG_LIBS="${PKG_LIBS} $rcpp_ldflags $protobuf_libs" @@ -4442,16 +4656,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -4511,17 +4725,29 @@ as_mkdir_p=false fi +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p - # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4542,7 +4768,7 @@ # values after options handling. ac_log=" This file was extended by RProtoBuf $as_me 0.1, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4595,10 +4821,10 @@ ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ RProtoBuf config.status 0.1 -configured by $0, generated by GNU Autoconf 2.69, +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -4675,7 +4901,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' Modified: pkg/configure.in =================================================================== --- pkg/configure.in 2013-08-30 01:36:34 UTC (rev 517) +++ pkg/configure.in 2013-08-30 06:30:35 UTC (rev 518) @@ -9,6 +9,7 @@ # Process this file with autoconf to produce a configure script. AC_INIT([RProtoBuf],[0.1]) +m4_include([m4-ax_cxx_compile_stdcxx_0x.m4]) # We are using C++ AC_LANG(C++) @@ -16,6 +17,11 @@ AC_PROG_CC AC_PROG_CXX +# If we can support std=c++0x we should pass flags to do so (this will +# enable better int64 support) but we shouldn't cause the build to +# fail if we can't do this. +AC_CXX_COMPILE_STDCXX_0X + ## simpler alternative to test below: AC_PATH_PROG(PROTOC, protoc) AC_DEFUN([AC_PROG_PKGCONFIG], [AC_CHECK_PROG(PKGCONFIG,pkg-config,yes)]) @@ -102,6 +108,11 @@ fi CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` +# We need this to get some limited int64 support with Rcpp. +if test "x$ax_cv_cxx_compile_cxx0x_cxx" = "xyes" ; then + CXXFLAGS="$CXXFLAGS -std=c++0x" +fi + ## look for Rscript, but use the one found via R_HOME to allow for multiple installations AC_DEFUN([AC_PROG_RSCRIPT], [AC_CHECK_PROG(RSCRIPT,Rscript,yes)]) AC_PROG_RSCRIPT @@ -118,7 +129,7 @@ fi ## now use all these -AC_SUBST([PKG_CPPFLAGS],["${PKG_CPPFLAGS} $protobuf_cxxflags"]) +AC_SUBST([PKG_CPPFLAGS],["${PKG_CPPFLAGS} ${CXXFLAGS} $protobuf_cxxflags"]) AC_SUBST([PKG_LIBS],["${PKG_LIBS} $rcpp_ldflags $protobuf_libs"]) AC_CONFIG_FILES([src/Makevars]) AC_OUTPUT Added: pkg/m4-ax_cxx_compile_stdcxx_0x.m4 =================================================================== --- pkg/m4-ax_cxx_compile_stdcxx_0x.m4 (rev 0) +++ pkg/m4-ax_cxx_compile_stdcxx_0x.m4 2013-08-30 06:30:35 UTC (rev 518) @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ + AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, + ax_cv_cxx_compile_cxx0x_native, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, + ax_cv_cxx_compile_cxx0x_cxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, + ax_cv_cxx_compile_cxx0x_gxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) + fi +]) From noreply at r-forge.r-project.org Sat Aug 31 02:22:12 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 02:22:12 +0200 (CEST) Subject: [Rprotobuf-commits] r519 - in pkg: . R Message-ID: <20130831002212.4CEFC185DCB@r-forge.r-project.org> Author: edd Date: 2013-08-31 02:22:11 +0200 (Sat, 31 Aug 2013) New Revision: 519 Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/NAMESPACE pkg/R/internals.R pkg/R/read.R pkg/R/serialize.R pkg/R/wrapper_ZeroCopyInputStream.R pkg/R/zzz.R Log: relatively minor changes to make R CMD check happy when using R-devel Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/ChangeLog 2013-08-31 00:22:11 UTC (rev 519) @@ -1,3 +1,10 @@ +2013-08-30 Dirk Eddelbuettel + + * NAMESPACE: Import 'file_path_as_absolute' from package tools, and + the two functions needed from the RCurl package + * R/*R: Updated several files which no longer need 'tools:::' prefix + * DESCRIPTION: Updated Depends: and Imports accordingly + 2013-08-29 Murray Stokely * R/zzz.R (.onLoad): Rename option controlling int64 handling with Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/DESCRIPTION 2013-08-31 00:22:11 UTC (rev 519) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3 +Version: 0.3.0.1 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel @@ -7,9 +7,10 @@ Description: Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. -Depends: R (>= 2.11.0), RCurl, Rcpp (>= 0.9.6), methods +Depends: R (>= 2.11.0), methods LinkingTo: Rcpp Suggests: RUnit, highlight +Imports: utils, stats, tools, RCurl SystemRequirements: Protocol Buffer compiler (to create C++ header and source files from .proto descriptions) and library (version 2.2.0 or later) License: GPL-2 Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/NAMESPACE 2013-08-31 00:22:11 UTC (rev 519) @@ -2,10 +2,11 @@ ## Package has dynamic library useDynLib(RProtoBuf) -importFrom( methods, new ) -importFrom( utils, str ) -importFrom( "stats", "update") -importFrom( "utils", "packageDescription" ) +importFrom(methods, new) +importFrom(utils, str, packageDescription) +importFrom(stats, update) +importFrom(tools, file_path_as_absolute) +importFrom(RCurl, basicTextGatherer, curlPerform) exportClasses( @@ -16,19 +17,19 @@ "FileDescriptor", "EnumValueDescriptor", # message - "Message", + "Message", # rpc - "RpcHTTP", - + "RpcHTTP", + # virtual streams "ZeroCopyInputStream", "ZeroCopyOutputStream", - + # concrete implementations - "ArrayInputStream", "ArrayOutputStream", - "FileInputStream", "FileOutputStream", + "ArrayInputStream", "ArrayOutputStream", + "FileInputStream", "FileOutputStream", "ConnectionInputStream", "ConnectionOutputStream" - + ) exportMethods( "new", "[[", "[[<-", "$", "$<-", "show", @@ -38,7 +39,7 @@ "clear", "size", "size<-", "swap", "descriptor", "set", "fetch", "toString", "identical", "==", "!=", "all.equal", "add", - "fileDescriptor", "name", "flush", "close", + "fileDescriptor", "name", "flush", "close", "setExtension", "getExtension", "containing_type", @@ -61,19 +62,19 @@ "input_type", "output_type", # rpc - "invoke", - + "invoke", + # streams - "Next", "ByteCount", "BackUp", "Skip", - "ArrayInputStream", "ArrayOutputStream", "FileInputStream", "FileOutputStream", - "GetErrno", "SetCloseOnDelete", - "ConnectionInputStream", "ConnectionOutputStream", - "ReadRaw", "ReadString", "ReadVarint32", - "ReadLittleEndian32", "ReadLittleEndian64", "ReadVarint64", - "WriteRaw", "WriteString", "WriteLittleEndian32", + "Next", "ByteCount", "BackUp", "Skip", + "ArrayInputStream", "ArrayOutputStream", "FileInputStream", "FileOutputStream", + "GetErrno", "SetCloseOnDelete", + "ConnectionInputStream", "ConnectionOutputStream", + "ReadRaw", "ReadString", "ReadVarint32", + "ReadLittleEndian32", "ReadLittleEndian64", "ReadVarint64", + "WriteRaw", "WriteString", "WriteLittleEndian32", "WriteLittleEndian64", "WriteVarint32", "WriteVarint64" - - + + ) export( "P", "readProtoFiles", "asMessage" ) Modified: pkg/R/internals.R =================================================================== --- pkg/R/internals.R 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/R/internals.R 2013-08-31 00:22:11 UTC (rev 519) @@ -41,9 +41,7 @@ # TODO: we need to pass the full path of the file # or create a mapping from the current working directory # in the DiskSourceTree - files <- sapply( files[ex], function(x){ - tools:::file_path_as_absolute(x) - } ) + files <- sapply(files[ex], function(x) file_path_as_absolute(x) ) } directories <- unique( c( getwd(), dirname(files) ) ) .Call( "readProtoFiles", files, directories, PACKAGE = "RProtoBuf" ) Modified: pkg/R/read.R =================================================================== --- pkg/R/read.R 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/R/read.R 2013-08-31 00:22:11 UTC (rev 519) @@ -3,19 +3,19 @@ standardGeneric( "read" ) } ) -setMethod( "read", c( descriptor = "Descriptor" , input = "character" ), +setMethod( "read", c( descriptor = "Descriptor" , input = "character" ), function(descriptor, input ){ - file <- tools:::file_path_as_absolute( input ) - .Call( "Descriptor__readMessageFromFile", descriptor at pointer, file, PACKAGE = "RProtoBuf" ) + file <- file_path_as_absolute( input ) + .Call( "Descriptor__readMessageFromFile", descriptor at pointer, file, PACKAGE = "RProtoBuf" ) } ) setMethod( "read", c( descriptor = "Descriptor", input = "raw" ), function(descriptor, input ){ .Call( "Descriptor__readMessageFromRawVector", descriptor at pointer, input, PACKAGE="RProtoBuf" ) } ) -setMethod( "read", c( descriptor = "Descriptor" ), +setMethod( "read", c( descriptor = "Descriptor" ), function( descriptor, input ){ - if( !inherits( input, "connection" ) ){ + if( !inherits( input, "connection" ) ){ stop( "can only read from connections" ) } wasopen <- identical( summary(input)[["opened"]], "opened" ) @@ -33,14 +33,14 @@ standardGeneric( "readASCII" ) } ) -setMethod( "readASCII", c( descriptor = "Descriptor" , input = "character" ), +setMethod( "readASCII", c( descriptor = "Descriptor" , input = "character" ), function(descriptor, input ){ - .Call( "Descriptor__readASCIIFromString", descriptor at pointer, input, PACKAGE = "RProtoBuf" ) + .Call( "Descriptor__readASCIIFromString", descriptor at pointer, input, PACKAGE = "RProtoBuf" ) } ) -setMethod( "readASCII", c( descriptor = "Descriptor" ), +setMethod( "readASCII", c( descriptor = "Descriptor" ), function( descriptor, input ){ - if( !inherits( input, "connection" ) ){ + if( !inherits( input, "connection" ) ){ stop( "can only read from connections" ) } wasopen <- identical( summary(input)[["opened"]], "opened" ) Modified: pkg/R/serialize.R =================================================================== --- pkg/R/serialize.R 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/R/serialize.R 2013-08-31 00:22:11 UTC (rev 519) @@ -1,44 +1,44 @@ # serialization of protobuf messages -# at the moment, we grab the payload as a raw vector and send this -# to the connection, but in the future, we will directly stream out +# at the moment, we grab the payload as a raw vector and send this +# to the connection, but in the future, we will directly stream out # the payload to the connection setGeneric( "serialize" ) -setMethod( "serialize", c( object = "Message" ) , +setMethod( "serialize", c( object = "Message" ) , function( object, connection, ascii = FALSE, refhook = NULL){ stopifnot(object$isInitialized()) iscon <- inherits(connection, "connection") isnull <- is.null( connection ) - + if( is.character( connection ) ){ # pretend it is a file name if( !file.exists(connection) ){ # FIXME: hack to grab the absolute path name file.create( connection ) - file <- tools:::file_path_as_absolute(connection) + file <- file_path_as_absolute(connection) unlink( file ) } else{ - file <- tools:::file_path_as_absolute(connection) + file <- file_path_as_absolute(connection) } .Call( "Message__serialize_to_file", object at pointer, file, PACKAGE = "RProtoBuf" ) invisible( NULL) } else if( iscon || isnull ) { - - # first grab the payload as a raw vector, + + # first grab the payload as a raw vector, payload <- .Call( "Message__get_payload", object at pointer, PACKAGE = "RProtoBuf" ) if( isnull ){ # just return it if the connection is NULL payload } else{ # otherwise write the payload to the connection - # FIXME: we might want to be more clever about this so that + # FIXME: we might want to be more clever about this so that # we don't have to store the full payload in memory # but for now it will do just fine writeBin( payload, connection ) invisible( NULL ) } - + } } ) Modified: pkg/R/wrapper_ZeroCopyInputStream.R =================================================================== --- pkg/R/wrapper_ZeroCopyInputStream.R 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/R/wrapper_ZeroCopyInputStream.R 2013-08-31 00:22:11 UTC (rev 519) @@ -62,15 +62,15 @@ setGeneric( "ArrayInputStream", function(payload, block_size){ standardGeneric( "ArrayInputStream" ) } ) -setMethod( "ArrayInputStream", c( payload = "raw", block_size = "missing" ) , +setMethod( "ArrayInputStream", c( payload = "raw", block_size = "missing" ) , function(payload, block_size){ .Call( "ArrayInputStream__new", payload, -1L, PACKAGE = "RProtoBuf" ) } ) -setMethod( "ArrayInputStream", c( payload = "raw", block_size = "integer" ) , +setMethod( "ArrayInputStream", c( payload = "raw", block_size = "integer" ) , function(payload, block_size){ .Call( "ArrayInputStream__new", payload, block_size, PACKAGE = "RProtoBuf" ) } ) -setMethod( "ArrayInputStream", c( payload = "raw", block_size = "numeric" ) , +setMethod( "ArrayInputStream", c( payload = "raw", block_size = "numeric" ) , function(payload, block_size){ .Call( "ArrayInputStream__new", payload, as.integer(block_size), PACKAGE = "RProtoBuf" ) } ) @@ -81,22 +81,22 @@ standardGeneric( "ArrayOutputStream" ) } ) setMethod( "ArrayOutputStream", signature( size = "integer", block_size = "missing" ), function(size, block_size){ - .Call( "ArrayOutputStream__new", size, -1L, PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", size, -1L, PACKAGE = "RProtoBuf" ) } ) setMethod( "ArrayOutputStream", signature( size = "integer", block_size = "integer" ), function(size, block_size){ - .Call( "ArrayOutputStream__new", size, block_size, PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", size, block_size, PACKAGE = "RProtoBuf" ) } ) setMethod( "ArrayOutputStream", signature( size = "integer", block_size = "numeric" ), function(size, block_size){ - .Call( "ArrayOutputStream__new", size, as.integer(block_size) , PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", size, as.integer(block_size) , PACKAGE = "RProtoBuf" ) } ) setMethod( "ArrayOutputStream", signature( size = "numeric", block_size = "missing" ), function(size, block_size){ - .Call( "ArrayOutputStream__new", as.integer(size), -1L, PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", as.integer(size), -1L, PACKAGE = "RProtoBuf" ) } ) setMethod( "ArrayOutputStream", signature( size = "numeric", block_size = "integer" ),function(size, block_size){ - .Call( "ArrayOutputStream__new", as.integer(size), block_size, PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", as.integer(size), block_size, PACKAGE = "RProtoBuf" ) } ) setMethod( "ArrayOutputStream", signature( size = "numeric", block_size = "numeric" ), function(size, block_size){ - .Call( "ArrayOutputStream__new", as.integer(size), as.integer(block_size) , PACKAGE = "RProtoBuf" ) + .Call( "ArrayOutputStream__new", as.integer(size), as.integer(block_size) , PACKAGE = "RProtoBuf" ) } ) # }}} @@ -105,7 +105,7 @@ standardGeneric( "FileInputStream" ) } ) setMethod( "FileInputStream", signature( filename = "character", block_size = "integer", close.on.delete = "logical" ), function(filename, block_size = -1L, close.on.delete = FALSE){ - full_filename <- tools:::file_path_as_absolute(filename) + full_filename <- file_path_as_absolute(filename) .Call( "FileInputStream_new", filename, block_size, close.on.delete, PACKAGE = "RProtoBuf" ) } ) setMethod( "close", "FileInputStream", function(con, ...){ @@ -129,12 +129,12 @@ stop( "directory does not exist" ) } file.create( filename ) - filename <- tools:::file_path_as_absolute(filename) + filename <- file_path_as_absolute(filename) unlink( filename ) } else{ - filename <- tools:::file_path_as_absolute(filename) + filename <- file_path_as_absolute(filename) } - + .Call( "FileOutputStream_new", filename, block_size, close.on.delete, PACKAGE = "RProtoBuf" ) } ) setMethod( "flush", "FileOutputStream", function(con){ Modified: pkg/R/zzz.R =================================================================== --- pkg/R/zzz.R 2013-08-30 06:30:35 UTC (rev 518) +++ pkg/R/zzz.R 2013-08-31 00:22:11 UTC (rev 519) @@ -6,8 +6,8 @@ readProtoFiles( package=pkgname, lib.loc=libname ) attachDescriptorPool( pos = length(search()) ) options("RProtoBuf.int64AsString" = FALSE) - if( exists( ".httpd.handlers.env", asNamespace( "tools" ) ) ){ - e <- tools:::.httpd.handlers.env - e[["RProtoBuf"]] <- RProtoBuf.http.handler - } + #if( exists( ".httpd.handlers.env", asNamespace( "tools" ) ) ){ + # e <- tools:::.httpd.handlers.env + # e[["RProtoBuf"]] <- RProtoBuf.http.handler + #} } From noreply at r-forge.r-project.org Sat Aug 31 03:16:16 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 03:16:16 +0200 (CEST) Subject: [Rprotobuf-commits] r520 - in pkg: . m4 Message-ID: <20130831011617.0DC22184500@r-forge.r-project.org> Author: edd Date: 2013-08-31 03:16:16 +0200 (Sat, 31 Aug 2013) New Revision: 520 Added: pkg/m4/ pkg/m4/m4-ax_cxx_compile_stdcxx_0x.m4 Removed: pkg/m4-ax_cxx_compile_stdcxx_0x.m4 Log: ove m4 file to a subdir Copied: pkg/m4/m4-ax_cxx_compile_stdcxx_0x.m4 (from rev 518, pkg/m4-ax_cxx_compile_stdcxx_0x.m4) =================================================================== --- pkg/m4/m4-ax_cxx_compile_stdcxx_0x.m4 (rev 0) +++ pkg/m4/m4-ax_cxx_compile_stdcxx_0x.m4 2013-08-31 01:16:16 UTC (rev 520) @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ + AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, + ax_cv_cxx_compile_cxx0x_native, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, + ax_cv_cxx_compile_cxx0x_cxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, + ax_cv_cxx_compile_cxx0x_gxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) + fi +]) Deleted: pkg/m4-ax_cxx_compile_stdcxx_0x.m4 =================================================================== --- pkg/m4-ax_cxx_compile_stdcxx_0x.m4 2013-08-31 00:22:11 UTC (rev 519) +++ pkg/m4-ax_cxx_compile_stdcxx_0x.m4 2013-08-31 01:16:16 UTC (rev 520) @@ -1,107 +0,0 @@ -# ============================================================================ -# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html -# ============================================================================ -# -# SYNOPSIS -# -# AX_CXX_COMPILE_STDCXX_0X -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the C++0x -# standard. -# -# LICENSE -# -# Copyright (c) 2008 Benjamin Kosnik -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 7 - -AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) -AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ - AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, - ax_cv_cxx_compile_cxx0x_native, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);],, - ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) - AC_LANG_RESTORE - ]) - - AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, - ax_cv_cxx_compile_cxx0x_cxx, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++0x" - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);],, - ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) - CXXFLAGS="$ac_save_CXXFLAGS" - AC_LANG_RESTORE - ]) - - AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, - ax_cv_cxx_compile_cxx0x_gxx, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=gnu++0x" - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);],, - ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) - CXXFLAGS="$ac_save_CXXFLAGS" - AC_LANG_RESTORE - ]) - - if test "$ax_cv_cxx_compile_cxx0x_native" = yes || - test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || - test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then - AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) - fi -]) From noreply at r-forge.r-project.org Sat Aug 31 03:17:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 03:17:54 +0200 (CEST) Subject: [Rprotobuf-commits] r521 - pkg Message-ID: <20130831011754.ED267184500@r-forge.r-project.org> Author: edd Date: 2013-08-31 03:17:54 +0200 (Sat, 31 Aug 2013) New Revision: 521 Modified: pkg/configure.in Log: update m4 include path Modified: pkg/configure.in =================================================================== --- pkg/configure.in 2013-08-31 01:16:16 UTC (rev 520) +++ pkg/configure.in 2013-08-31 01:17:54 UTC (rev 521) @@ -8,8 +8,8 @@ AC_PREREQ(2.61) # Process this file with autoconf to produce a configure script. -AC_INIT([RProtoBuf],[0.1]) -m4_include([m4-ax_cxx_compile_stdcxx_0x.m4]) +AC_INIT([RProtoBuf],[0.3]) +m4_include([,4/m4-ax_cxx_compile_stdcxx_0x.m4]) # We are using C++ AC_LANG(C++) From noreply at r-forge.r-project.org Sat Aug 31 03:20:10 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 03:20:10 +0200 (CEST) Subject: [Rprotobuf-commits] r522 - pkg Message-ID: <20130831012010.45B5D184500@r-forge.r-project.org> Author: edd Date: 2013-08-31 03:20:09 +0200 (Sat, 31 Aug 2013) New Revision: 522 Added: pkg/.Rbuildignore Log: added .Rbuildignore to exclude m4 (and configure.in) file from (CRAN) tarball Added: pkg/.Rbuildignore =================================================================== --- pkg/.Rbuildignore (rev 0) +++ pkg/.Rbuildignore 2013-08-31 01:20:09 UTC (rev 522) @@ -0,0 +1,2 @@ +m4 +configure.in From noreply at r-forge.r-project.org Sat Aug 31 03:23:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 03:23:02 +0200 (CEST) Subject: [Rprotobuf-commits] r523 - patches Message-ID: <20130831012303.00DEF184500@r-forge.r-project.org> Author: edd Date: 2013-08-31 03:23:02 +0200 (Sat, 31 Aug 2013) New Revision: 523 Added: patches/patch_by_Murray_rprotobuf_r475-1.diff patches/patch_by_Murray_rprotobuf_r475-2.diff Log: oops--supposed to have been committed a while back Added: patches/patch_by_Murray_rprotobuf_r475-1.diff =================================================================== --- patches/patch_by_Murray_rprotobuf_r475-1.diff (rev 0) +++ patches/patch_by_Murray_rprotobuf_r475-1.diff 2013-08-31 01:23:02 UTC (rev 523) @@ -0,0 +1,173 @@ +Index: src/RconnectionCopyingInputStream.h +=================================================================== +--- src/RconnectionCopyingInputStream.h (revision 475) ++++ src/RconnectionCopyingInputStream.h (working copy) +@@ -8,9 +8,11 @@ + RconnectionCopyingInputStream( int id ); + + int Read(void * buffer, int size) ; ++ bool Failure() { return(failure); } + + private: + int connection_id ; ++ bool failure; + } ; + + } // namespace rprotobuf +Index: src/RconnectionCopyingInputStream.cpp +=================================================================== +--- src/RconnectionCopyingInputStream.cpp (revision 475) ++++ src/RconnectionCopyingInputStream.cpp (working copy) +@@ -2,9 +2,11 @@ + #include "RconnectionCopyingInputStream.h" + + namespace rprotobuf{ +- ++ /* N.B. connection must be opened in binary mode due to call ++ * to readBin below. */ + RconnectionCopyingInputStream::RconnectionCopyingInputStream(int id) : +- connection_id(id){} ++ connection_id(id), ++ failure(false) {} + + /** + * call readBin to read size bytes from R +@@ -15,18 +17,19 @@ + * @return the number of bytes actually read + */ + int RconnectionCopyingInputStream::Read(void * buffer, int size){ +- + Rcpp::Language call( "readBin", connection_id, Rcpp::RawVector(0), size ) ; + Rcpp::RawVector res ; + try{ +- res = call.eval(); ++ res = call.eval(); + } catch( ... ){ +- return 0 ; ++ /* Failed to read anything from the connection, ++ * could have been permissions, or connection opened ++ * in the wrong type, etc. */ ++ failure = true; ++ return -1 ; + } + int len = res.size() ; + memcpy( buffer, reinterpret_cast(res.begin()), len) ; + return len ; + } +- + } +- +Index: src/wrapper_Descriptor.cpp +=================================================================== +--- src/wrapper_Descriptor.cpp (revision 475) ++++ src/wrapper_Descriptor.cpp (working copy) +@@ -179,8 +179,14 @@ + if( !message ){ + throw std::range_error( "could not call factory->GetPrototype(desc)->New()" ) ; + } +- GPB::TextFormat::Parse( &stream, message ) ; +- return( S4_Message( message ) ) ; ++ if (!GPB::TextFormat::Parse( &stream, message ) ) { ++ throw std::range_error("Could not parse ASCII protocol buffer."); ++ } else { ++ if (wrapper.Failure()) { ++ throw std::range_error("Could not read ASCII protocol buffer."); ++ } ++ return( S4_Message( message ) ); ++ } + } + + #undef METHOD +Index: R/read.R +=================================================================== +--- R/read.R (revision 475) ++++ R/read.R (working copy) +@@ -18,9 +18,9 @@ + if( !inherits( input, "connection" ) ){ + stop( "can only read from connections" ) + } +- sc <- summary( input ) +- wasopen <- identical( sc[["opened"]], "opened" ) +- if( !wasopen ) open( input ) ++ wasopen <- identical( summary(input)[["opened"]], "opened" ) ++ if( !wasopen ) open( input, "rb") ++ stopifnot(summary(input)[["text"]] == "binary") + message <- .Call( "Descriptor__readMessageFromConnection", descriptor at pointer, input, PACKAGE = "RProtoBuf" ) + if( !wasopen ) close( input ) + message +@@ -43,9 +43,9 @@ + if( !inherits( input, "connection" ) ){ + stop( "can only read from connections" ) + } +- sc <- summary( input ) +- wasopen <- identical( sc[["opened"]], "opened" ) +- if( !wasopen ) open( input ) ++ wasopen <- identical( summary(input)[["opened"]], "opened" ) ++ if( !wasopen ) open( input, "rb" ) ++ stopifnot(summary(input)[["text"]] == "binary") + message <- .Call( "Descriptor__readASCIIFromConnection", descriptor at pointer, input, PACKAGE = "RProtoBuf" ) + if( !wasopen ) close( input ) + message +Index: man/readASCII.Rd +=================================================================== +--- man/readASCII.Rd (revision 475) ++++ man/readASCII.Rd (working copy) +@@ -31,9 +31,12 @@ + out.file <- tempfile() + writeLines( as.character(message), file(out.file)) + +-# Verify we can read back in the message from a text file. ++# Verify that we can read back in the message from a text file. + message2 <- readASCII( tutorial.AddressBook, file(out.file, "rb")) + ++# Verify that we can read back in the message from an unopened file. ++message3 <- readASCII( tutorial.AddressBook, file(out.file)) ++ + \dontshow{ + stopifnot( identical( message, message2) ) + } +Index: inst/unitTests/runit.addressbook.R +=================================================================== +--- inst/unitTests/runit.addressbook.R (revision 475) ++++ inst/unitTests/runit.addressbook.R (working copy) +@@ -35,7 +35,27 @@ + out.file <- tempfile() + writeLines( as.character(book), file(out.file)) + +- # Verify we can read back in the message from a text file. ++ # Verify that we can read back in the message from a text file. + book2 <- readASCII( tutorial.AddressBook, file(out.file, "rb")) + checkEquals(as.character(book), as.character(book2) ) ++ ++ # Verify that we can read in messages from unopened connections. ++ book3 <- readASCII( tutorial.AddressBook, file(out.file)) ++ checkEquals(as.character(book), as.character(book3) ) ++ ++ # Verify that we get an exception if we try to read from a text connection. ++ # (better than silently getting an empty proto.) ++ book4 <- checkException( readASCII( tutorial.AddressBook, file(out.file, "rt")) ++ ++ # Verify that we get an exception if the file is not readable. ++ old.mode <- file.info(out.file)[["mode"]]) ++ Sys.chmod(out.file, "0000") ++ book5 <- checkException( readASCII( tutorial.AddressBook, file(out.file, "rb"))) ++ # Set the permissions back to ensure the file is cleaned up properly. ++ Sys.chmod(out.file, old.mode) ++ ++ # Verify that we get an exception if the file is not parseable. ++ out.file2 <- tempfile() ++ writeLines("jibberish", file(out.file2)) ++ book6 <- checkException( readASCII( tutorial.AddressBook, file(out.file2))) + } +Index: inst/unitTests/runit.import.R +=================================================================== +--- inst/unitTests/runit.import.R (revision 475) ++++ inst/unitTests/runit.import.R (working copy) +@@ -15,6 +15,6 @@ + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + test.import <- function() { +- # Verify we get a graceful errorr ather than segfault. ++ # Verify that we get a graceful error rather than a segfault. + checkException(readProtoFiles("/etc/hosts")) + } Added: patches/patch_by_Murray_rprotobuf_r475-2.diff =================================================================== --- patches/patch_by_Murray_rprotobuf_r475-2.diff (rev 0) +++ patches/patch_by_Murray_rprotobuf_r475-2.diff 2013-08-31 01:23:02 UTC (rev 523) @@ -0,0 +1,233 @@ +Index: NAMESPACE +=================================================================== +--- NAMESPACE (revision 475) ++++ NAMESPACE (working copy) +@@ -48,7 +48,7 @@ + "is_extension", "number", "label", + "is_required", "is_repeated", "is_optional", + "has_default_value", "default_value", +- "message_type", "enum_type", ++ "message_type", "enum_type", "type", "cpp_type", + + # EnumDescriptor + "value_count", "value", +@@ -103,4 +103,3 @@ + exportPattern( "^LABEL_" ) + + # export( run_unit_tests ) +- +Index: R/wrapper_FieldDescriptor.R +=================================================================== +--- R/wrapper_FieldDescriptor.R (revision 475) ++++ R/wrapper_FieldDescriptor.R (working copy) +@@ -32,14 +32,17 @@ + TYPE_SINT32 <- 17L + TYPE_SINT64 <- 18L + +-.TYPES <- ls( pattern = "^TYPE_" ) +- + setGeneric( "type", function(object, as.string = FALSE){ + standardGeneric( "type" ) + } ) + setMethod( "type", "FieldDescriptor", function(object, as.string = FALSE){ + type <- .Call( "FieldDescriptor__type", object at pointer, PACKAGE = "RProtoBuf" ) +- if( as.string ) .TYPES[type] else type ++ if( as.string ) { ++ .TYPES <- sapply(ls( "package:RProtoBuf", pattern="^TYPE_" ), get) ++ names(which(.TYPES == type)) ++ } else { ++ type ++ } + } ) + + +@@ -53,27 +56,35 @@ + CPPTYPE_ENUM <- 8L + CPPTYPE_STRING <- 9L + CPPTYPE_MESSAGE <- 10L +-.CPPTYPES <- ls( pattern = "^CPPTYPE_" ) + + setGeneric( "cpp_type", function(object, as.string = FALSE ){ + standardGeneric( "cpp_type" ) + } ) + setMethod( "cpp_type", "FieldDescriptor", function(object, as.string = FALSE){ + cpptype <- .Call( "FieldDescriptor__cpp_type", object at pointer, PACKAGE = "RProtoBuf" ) +- if( as.string ) .CPPTYPES[cpptype] else cpptype ++ if( as.string ) { ++ .CPPTYPES <- sapply(ls( "package:RProtoBuf", pattern="^CPPTYPE_" ), get) ++ names(which(.CPPTYPES == cpptype)) ++ } else { ++ cpptype ++ } + } ) + + LABEL_OPTIONAL <- 1L + LABEL_REQUIRED <- 2L + LABEL_REPEATED <- 3L +-.LABELS <- ls( pattern = "^LABEL_" ) + + setGeneric( "label", function(object, as.string = FALSE ){ + standardGeneric( "label" ) + } ) + setMethod( "label", "FieldDescriptor", function(object, as.string = FALSE){ + lab <- .Call( "FieldDescriptor__label", object at pointer, PACKAGE = "RProtoBuf" ) +- if( as.string ) .LABELS[lab] else lab ++ if( as.string ) { ++ .LABELS <- sapply(ls( "package:RProtoBuf", pattern="^LABEL_" ), get) ++ names(which(.LABELS == lab)) ++ } else { ++ lab ++ } + } ) + + setGeneric( "is_repeated", function(object ){ +Index: man/is_extension.Rd +=================================================================== +--- man/is_extension.Rd (revision 475) ++++ man/is_extension.Rd (working copy) +@@ -9,4 +9,8 @@ + The method is implemented for the \linkS4class{FieldDescriptor} class + } + \keyword{methods} +- ++\examples{ ++proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) ++Person <- P( "tutorial.Person", file = proto.file ) ++is_extension(Person$id) ++} +Index: man/label.Rd +=================================================================== +--- man/label.Rd (revision 475) ++++ man/label.Rd (working copy) +@@ -9,10 +9,26 @@ + + \title{Gets the label of a field} + \description{ +-Gets the label of a field ++Gets the label of a field (optional, required, or repeated). + } ++\arguments{ ++ \item{object}{A \linkS4class{FieldDescriptor} object.} ++ \item{as.string}{If true, print a string representation of the type.} ++} + \seealso{ + The method is implemented for the \linkS4class{FieldDescriptor} class + } + \keyword{methods} +- ++\examples{ ++proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) ++Person <- P( "tutorial.Person", file = proto.file ) ++label(Person$id) ++label(Person$email) ++label(Person$phone) ++label(Person$id, TRUE) ++label(Person$email, TRUE) ++label(Person$phone, TRUE) ++LABEL_OPTIONAL ++LABEL_REQUIRED ++LABEL_REPEATED ++} +Index: man/number.Rd +=================================================================== +--- man/number.Rd (revision 475) ++++ man/number.Rd (working copy) +@@ -9,4 +9,10 @@ + The method is implemented for the \linkS4class{FieldDescriptor} class + } + \keyword{methods} +- ++\examples{ ++proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) ++Person <- P( "tutorial.Person", file = proto.file ) ++number(Person$id) ++number(Person$email) ++as.character(Person) ++} +Index: man/type.Rd +=================================================================== +--- man/type.Rd (revision 475) ++++ man/type.Rd (working copy) +@@ -40,7 +40,19 @@ + \description{ + Gets the type or the C++ type of a field + } ++\arguments{ ++ \item{object}{A \linkS4class{FieldDescriptor} object.} ++ \item{as.string}{If true, print a string representation of the type.} ++} + \seealso{ + The method is implemented for the \linkS4class{FieldDescriptor} class + } + \keyword{methods} ++\examples{ ++proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) ++Person <- P( "tutorial.Person", file = proto.file ) ++type(Person$id) ++type(Person$id, as.string=TRUE) ++cpp_type(Person$email) ++cpp_type(Person$email, TRUE) ++} +Index: inst/unitTests/runit.FieldDescriptor.R +=================================================================== +--- inst/unitTests/runit.FieldDescriptor.R (revision 0) ++++ inst/unitTests/runit.FieldDescriptor.R (revision 0) +@@ -0,0 +1,58 @@ ++# Copyright 2012 Google Inc. ++# Author: Murray Stokely ++# ++# This program is free software; you can redistribute it and/or ++# modify it under the terms of the GNU General Public License ++# as published by the Free Software Foundation; either version 2 ++# of the License, or (at your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program; if not, write to the Free Software ++# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ++ ++test.FieldDescriptor.class <- function() { ++ proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) ++ Person <- P( "tutorial.Person", file = proto.file ) ++ ++ # field descriptor object ++ checkTrue(!is.null(Person$email)) ++ ++ # debug string ++ checkTrue(nchar(as.character( Person$email )) > 1) ++ ++ # default values ++ checkTrue(!has_default_value(Person$id)) ++ checkTrue(has_default_value(Person$PhoneNumber$type)) ++ ++ checkEquals(default_value(Person$PhoneNumber$type), 1) ++ checkEquals(default_value(Person$id), 0) ++ ++ # Get the types of field descriptors ++ checkEquals(type(Person$id), TYPE_INT32) ++ checkEquals(type(Person$id, TRUE), "TYPE_INT32") ++ checkEquals(cpp_type(Person$email), CPPTYPE_STRING) ++ checkEquals(cpp_type(Person$email, TRUE), "CPPTYPE_STRING") ++ ++ # Get the label of a field descriptor ++ checkEquals(label(Person$id), LABEL_REQUIRED) ++ checkEquals(label(Person$id, TRUE), "LABEL_REQUIRED") ++ checkEquals(label(Person$email), LABEL_OPTIONAL) ++ checkEquals(label(Person$email, TRUE), "LABEL_OPTIONAL") ++ ++ # Test if a field is optional ++ checkTrue(is_required(Person$id)) ++ checkTrue(!is_optional(Person$id)) ++ checkTrue(!is_repeated(Person$id)) ++ ++ checkTrue(!is_required(Person$email)) ++ checkTrue(is_optional(Person$email)) ++ checkTrue(!is_repeated(Person$email)) ++ ++ # Return the class of a message field ++ checkTrue(inherits(message_type(Person$phone), "Descriptor")) ++} From noreply at r-forge.r-project.org Sat Aug 31 03:29:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 31 Aug 2013 03:29:28 +0200 (CEST) Subject: [Rprotobuf-commits] r524 - pkg Message-ID: <20130831012928.9B449184500@r-forge.r-project.org> Author: edd Date: 2013-08-31 03:29:28 +0200 (Sat, 31 Aug 2013) New Revision: 524 Modified: pkg/configure.in Log: fff: fat-finger fix [thanks, Murray!] Modified: pkg/configure.in =================================================================== --- pkg/configure.in 2013-08-31 01:23:02 UTC (rev 523) +++ pkg/configure.in 2013-08-31 01:29:28 UTC (rev 524) @@ -9,7 +9,7 @@ # Process this file with autoconf to produce a configure script. AC_INIT([RProtoBuf],[0.3]) -m4_include([,4/m4-ax_cxx_compile_stdcxx_0x.m4]) +m4_include([m4/m4-ax_cxx_compile_stdcxx_0x.m4]) # We are using C++ AC_LANG(C++)