[Rprotobuf-commits] r444 - in pkg: inst inst/unitTests inst/unitTests/data src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon May 14 04:56:27 CEST 2012
Author: edd
Date: 2012-05-14 04:56:27 +0200 (Mon, 14 May 2012)
New Revision: 444
Removed:
pkg/inst/unitTests/data/int64.proto
pkg/inst/unitTests/runit.int64.support.R
Modified:
pkg/inst/NEWS
pkg/src/mutators.cpp
pkg/src/rprotobuf.h
pkg/src/streams.cpp
pkg/src/wrapper_Message.cpp
Log:
1) new reversion attempt: running
svn merge -r 434:426 svn+ssh://edd@svn.r-forge.r-project.org/svnroot/rprotobuf/pkg/
to undo Romain's set of patches with int64 support
and manual edits for conflicts in mutators.cpp and wrapper_Message.cpp
2) rprotobuf.h has added header file for g++-4.7
Modified: pkg/inst/NEWS
===================================================================
--- pkg/inst/NEWS 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/inst/NEWS 2012-05-14 02:56:27 UTC (rev 444)
@@ -1,12 +1,10 @@
-0.2.4 future
+0.2.4 2012-05-xx
- o changes to handle int64, etc ... fields better. Based on the new
- int64 package and related changes in Rcpp. This work has been
- sponsored by the Google Open Source Programs Office
+ o Suppport g++-4.7 and stricter #include file checking by adding unistd
0.2.3 2011-04-12
- o Protect UINT64 and INT64 with '#ifdef RCPP_HAS_LONG_LONG' which
+ o Protect UINT64 and INT64 with '#ifdef RCPP_HAS_LONG_LONG' which
itself is valid with either g++ <= 4.4, or newer versions if the
-std=c++0x is used
Deleted: pkg/inst/unitTests/data/int64.proto
===================================================================
--- pkg/inst/unitTests/data/int64.proto 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/inst/unitTests/data/int64.proto 2012-05-14 02:56:27 UTC (rev 444)
@@ -1,7 +0,0 @@
-
-message TestInt64 {
- required int64 a = 1;
- required uint64 b = 2;
- repeated int64 c = 3 ;
- repeated uint64 d = 4 ;
-}
Deleted: pkg/inst/unitTests/runit.int64.support.R
===================================================================
--- pkg/inst/unitTests/runit.int64.support.R 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/inst/unitTests/runit.int64.support.R 2012-05-14 02:56:27 UTC (rev 444)
@@ -1,68 +0,0 @@
-# Copyright 2011 Google Inc.
-# Copyright 2011 Dirk Eddelbuettel and Romain Francois
-#
-# 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.
-
-.setUp <- function(){
- if( ! exists( "TestInt64", "RProtoBuf:DescriptorPool" ) ){
- unitest.proto.file <- system.file( "unitTests", "data", "int64.proto", package = "RProtoBuf" )
- readProtoFiles(file = unitest.proto.file)
- }
-}
-
-test.int64 <- function() {
- msg <- new( TestInt64, a = 1, b = 2, c = seq(1,4,by=1), d = seq(1,4,by=1) )
- checkEquals( msg$a, as.int64(1) )
- checkEquals( msg$b, as.uint64(2) )
- checkEquals( msg$c, as.int64(1:4) )
- checkEquals( msg$d, as.uint64(1:4) )
- msg$a <- 11
- msg$b <- 12
- msg$c <- seq(1,15, by = 1 )
- msg$d <- seq(1,15, by = 1 )
- checkEquals( msg$a, as.int64(11) )
- checkEquals( msg$b, as.uint64(12) )
- checkEquals( msg$c, as.int64(1:15) )
- checkEquals( msg$d, as.uint64(1:15) )
-
- msg <- new( TestInt64, a = 1L, b = 2L, c = 1:4, d = 1:4 )
- checkEquals( msg$a, as.int64(1) )
- checkEquals( msg$b, as.uint64(2) )
- checkEquals( msg$c, as.int64(1:4) )
- checkEquals( msg$d, as.uint64(1:4) )
- msg$a <- 11L
- msg$b <- 12L
- msg$c <- 1:15
- msg$d <- 1:15
- checkEquals( msg$a, as.int64(11) )
- checkEquals( msg$b, as.uint64(12) )
- checkEquals( msg$c, as.int64(1:15) )
- checkEquals( msg$d, as.uint64(1:15) )
-
- msg <- new( TestInt64, a = as.int64(1), b = as.int64(2), c = as.int64(1:4), d = as.int64(1:4) )
- checkEquals( msg$a, as.int64(1) )
- checkEquals( msg$b, as.uint64(2) )
- checkEquals( msg$c, as.int64(1:4) )
- checkEquals( msg$d, as.uint64(1:4) )
- msg$a <- as.int64(11)
- msg$b <- as.uint64(12)
- msg$c <- as.int64( 1:15 )
- msg$d <- as.uint64( 1:15 )
- checkEquals( msg$a, as.int64(11) )
- checkEquals( msg$b, as.uint64(12) )
- checkEquals( msg$c, as.int64(1:15) )
- checkEquals( msg$d, as.uint64(1:15) )
-
-}
Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/src/mutators.cpp 2012-05-14 02:56:27 UTC (rev 444)
@@ -20,7 +20,6 @@
#include "rprotobuf.h"
#include "fieldtypes.h"
-/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
namespace rprotobuf{
@@ -100,6 +99,23 @@
return (int32)0 ; // -Wall, should not happen since we only call this when we know it works
}
+
+int64 GET_int64( SEXP x, int index ){
+ switch( TYPEOF(x) ){
+ case INTSXP:
+ return( (int64)INTEGER(x)[index] );
+ case REALSXP:
+ return( (int64)REAL(x)[index] );
+ case LGLSXP:
+ return( (int64)LOGICAL(x)[index] );
+ case RAWSXP:
+ return( (int64)RAW(x)[index] ) ;
+ default:
+ throwException( "cannot cast SEXP to int64", "CastException" ) ;
+ }
+ return (int64)0 ; // -Wall, should not happen since we only call this when we know it works
+}
+
uint32 GET_uint32( SEXP x, int index ){
switch( TYPEOF(x) ){
case INTSXP:
@@ -116,7 +132,6 @@
return (uint32)0 ; // -Wall, should not happen since we only call this when we know it works
}
-
int64 GET_int64( SEXP x, int index ){
#ifdef RCPP_HAS_INT64
if( Rf_inherits(x, "int64" ) ){
@@ -142,7 +157,6 @@
}
-
uint64 GET_uint64( SEXP x, int index ){
#ifdef RCPP_HAS_INT64
if( Rf_inherits( x, "uint64" ) ){
@@ -633,19 +647,12 @@
for( ; i<field_size; i++){
ref->SetRepeatedInt64( message, field_desc, i, GET_int64(value,i) ) ;
}
-
- /* then add some if needed */
- if( value_size > field_size ){
- for( ; i<value_size; i++){
- ref->AddInt64( message, field_desc, GET_int64(value,i) ) ;
- }
- }
- break ;
- }
-
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
- }
+ }
+ break ;
+ }
+
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
#ifdef RCPP_HAS_INT64
}
#endif
@@ -719,18 +726,11 @@
for( ; i<field_size; i++){
ref->SetRepeatedUInt64( message, field_desc, i, GET_uint64(value,i) ) ;
}
-
- /* then add some if needed */
- if( value_size > field_size ){
- for( ; i<value_size; i++){
- ref->AddUInt64( message, field_desc, GET_uint64(value,i) ) ;
- }
- }
- break ;
- }
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
- }
+ }
+ break ;
+ }
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
#ifdef RCPP_HAS_INT64
}
#endif
Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/src/rprotobuf.h 2012-05-14 02:56:27 UTC (rev 444)
@@ -50,6 +50,9 @@
RCPP_ENUM_TRAITS(GPB::FieldDescriptor::CppType)
RCPP_ENUM_TRAITS(GPB::FieldDescriptor::Type)
+//RCPP_TRAITS(GPB::int64,REALSXP)
+//RCPP_TRAITS(GPB::uint64,REALSXP)
+
#include <Rcpp.h>
#include <Rdefines.h>
Modified: pkg/src/streams.cpp
===================================================================
--- pkg/src/streams.cpp 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/src/streams.cpp 2012-05-14 02:56:27 UTC (rev 444)
@@ -193,15 +193,15 @@
SEXP ZeroCopyInputStream_ReadLittleEndian64( SEXP xp){
GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ;
uint64 res = 0 ;
- if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading little endian int64" ) ;
- return Rcpp::int64::LongVector<uint64_t>( res ) ;
+ if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading little endian int32" ) ;
+ return Rf_ScalarReal( (double)res ) ;
}
SEXP ZeroCopyInputStream_ReadVarint64( SEXP xp){
GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ;
uint64 res = 0 ;
if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading varint64" ) ;
- return Rcpp::int64::LongVector<uint64_t>( res ) ;
+ return Rf_ScalarReal( (double)res ) ;
}
#endif
// }}}
Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp 2012-05-14 01:46:37 UTC (rev 443)
+++ pkg/src/wrapper_Message.cpp 2012-05-14 02:56:27 UTC (rev 444)
@@ -7,6 +7,33 @@
/* helpers */
+ /* this is only to be called for repeated fields */
+ int MESSAGE_GET_REPEATED_INT( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){
+
+ const GPB::Reflection* ref = message->GetReflection() ;
+
+ switch( field_desc->type() ){
+ case TYPE_INT32:
+ case TYPE_SINT32:
+ case TYPE_SFIXED32:
+ return (int) ref->GetRepeatedInt32( *message, field_desc, index ) ;
+ case TYPE_INT64:
+ case TYPE_SINT64:
+ case TYPE_SFIXED64:
+ return (int) ref->GetRepeatedInt64( *message, field_desc, index ) ;
+ case TYPE_UINT32:
+ case TYPE_FIXED32:
+ return (int) ref->GetRepeatedUInt32( *message, field_desc, index ) ;
+ case TYPE_UINT64:
+ case TYPE_FIXED64:
+ return (int) ref->GetRepeatedUInt64( *message, field_desc, index ) ;
+ case TYPE_ENUM:
+ return ref->GetRepeatedEnum( *message, field_desc, index )->number() ;
+ default:
+ throwException( "cannot cast to int", "CastException" ) ;
+ }
+ return 0 ; // -Wall
+ }
/* this is only to be called for repeated fields */
double MESSAGE_GET_REPEATED_DOUBLE( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){
@@ -954,26 +981,24 @@
}
int n = index.size() ;
- const GPB::Reflection* ref = message->GetReflection() ;
-
switch( field_desc->type() ){
case TYPE_INT32:
case TYPE_SINT32:
case TYPE_SFIXED32:
- {
- Rcpp::IntegerVector res(n) ;
- for( int i=0; i<n; i++){
- res[i] = ref->GetRepeatedInt32( *message, field_desc, index[i] ) ;
- }
- return res ;
- }
+ case TYPE_INT64:
+ case TYPE_SINT64:
+ case TYPE_SFIXED64:
case TYPE_UINT32:
case TYPE_FIXED32:
+ case TYPE_UINT64:
+ case TYPE_FIXED64:
+ case TYPE_ENUM:
{
Rcpp::IntegerVector res(n) ;
for( int i=0; i<n; i++){
- res[i] = (int)ref->GetRepeatedUInt32( *message, field_desc, index[i] ) ;
+ res[i] = MESSAGE_GET_REPEATED_INT(
+ message, field_desc, index[i] ) ;
}
return res;
}
@@ -1098,19 +1123,10 @@
case TYPE_SINT64:
case TYPE_SFIXED64:
{
- if( Rf_inherits(values, "int64" ) ){
- Rcpp::int64::LongVector<int64_t> data(values) ;
- for( int i=0; i<n; i++){
- ref->SetRepeatedInt64( message, field_desc,
- index[i],
- data.get(i) ) ;
- }
- } else {
- for( int i=0; i<n; i++){
- ref->SetRepeatedInt64( message, field_desc,
- index[i],
- GET_int64( values, i ) ) ;
- }
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedInt64( message, field_desc,
+ index[i],
+ GET_int64( values, i ) ) ;
}
break ;
}
@@ -1129,19 +1145,10 @@
case TYPE_UINT64:
case TYPE_FIXED64:
{
- if( Rf_inherits( values, "uint64" ) ){
- Rcpp::int64::LongVector<uint64_t> data( values) ;
- for( int i=0; i<n; i++){
- ref->SetRepeatedUInt64( message, field_desc,
- index[i],
- data.get(i) ) ;
- }
- } else {
- for( int i=0; i<n; i++){
- ref->SetRepeatedUInt64( message, field_desc,
- index[i],
- GET_uint64( values, i ) ) ;
- }
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedUInt64( message, field_desc,
+ index[i],
+ GET_uint64( values, i ) ) ;
}
break ;
}
More information about the Rprotobuf-commits
mailing list