[Rprotobuf-commits] r547 - in pkg: . R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 15 06:19:42 CET 2013


Author: edd
Date: 2013-12-15 06:19:37 +0100 (Sun, 15 Dec 2013)
New Revision: 547

Modified:
   pkg/ChangeLog
   pkg/R/lookup.R
   pkg/src/lookup.cpp
   pkg/src/rprotobuf.h
Log:
minor update to attaching descriptor pool


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-12-15 00:29:52 UTC (rev 546)
+++ pkg/ChangeLog	2013-12-15 05:19:37 UTC (rev 547)
@@ -1,3 +1,9 @@
+2013-12-14  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/lookup.cpp (rprotobuf): Descrictor pools attached directly
+	* R/lookup.R (attachDescriptorPool): No longer attach them here
+	* src/rprotobuf.h: Updated function declaration
+
 2013-12-14  Murray Stokely  <murray at FreeBSD.org>
 
 	* src/mutators.cpp (rprotobuf): Fix a bug which incorrectly

Modified: pkg/R/lookup.R
===================================================================
--- pkg/R/lookup.R	2013-12-15 00:29:52 UTC (rev 546)
+++ pkg/R/lookup.R	2013-12-15 05:19:37 UTC (rev 547)
@@ -5,17 +5,14 @@
 OTABLE <- NULL
 NAMESPACE <- environment()
 
-attachDescriptorPool <- function( pos = 2){
+attachDescriptorPool <- function(pos = 2) {
+    if (is.null(OTABLE)) {
+        ##unlockBinding( "OTABLE", NAMESPACE )
+        otable <- .Call("newProtocolBufferLookup", pos, PACKAGE = "RProtoBuf")
+        #attach(otable, pos=pos, name="RProtoBuf:DescriptorPool")
+        assign("OTABLE", otable, envir = NAMESPACE, inherits = FALSE)
+        lockBinding("OTABLE", NAMESPACE )
+    }
 
-	if( is.null( OTABLE ) ){
-		#unlockBinding( "OTABLE", NAMESPACE )
-
-		otable <- .Call( "newProtocolBufferLookup" , PACKAGE = "RProtoBuf" )
-		attach( otable, pos = pos, name = "RProtoBuf:DescriptorPool" )
-
-		assign( "OTABLE", otable, envir = NAMESPACE, inherits = FALSE)
-		lockBinding( "OTABLE", NAMESPACE )
-	}
-
 }
 

Modified: pkg/src/lookup.cpp
===================================================================
--- pkg/src/lookup.cpp	2013-12-15 00:29:52 UTC (rev 546)
+++ pkg/src/lookup.cpp	2013-12-15 05:19:37 UTC (rev 547)
@@ -1,3 +1,5 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+
 #include "rprotobuf.h"
 #include "DescriptorPoolLookup.h" 
 
@@ -196,42 +198,47 @@
 	return( objects ); 
 }
 
-SEXP newProtocolBufferLookup(){
+SEXP newProtocolBufferLookup(SEXP possexp){
 #ifdef LOOKUP_DEBUG
- Rprintf( "<newProtocolBufferLookup>\n" ); 
+    Rprintf( "<newProtocolBufferLookup>\n" ); 
 #endif
 
- R_ObjectTable *tb;
- SEXP val, klass;
+    R_ObjectTable *tb;
+    SEXP val, klass;
 
-  tb = (R_ObjectTable *) malloc(sizeof(R_ObjectTable));
-  if(!tb)
-      Rf_error( "cannot allocate space for an internal R object table" );
+    tb = (R_ObjectTable *) malloc(sizeof(R_ObjectTable));
+    if(!tb)
+        Rf_error( "cannot allocate space for an internal R object table" );
+    
+    tb->type = RPROTOBUF_LOOKUP ; /* FIXME: not sure what this should be */
+    tb->cachedNames = NULL;
   
-  tb->type = RPROTOBUF_LOOKUP ; /* FIXME: not sure what this should be */
-  tb->cachedNames = NULL;
-  
-  tb->privateData = (void*)0 ;
+    tb->privateData = (void*)0 ;
 
-  tb->exists = rProtoBufTable_exists;
-  tb->get = rProtoBufTable_get;
-  tb->remove = rProtoBufTable_remove;
-  tb->assign = rProtoBufTable_assign;
-  tb->objects = rProtoBufTable_objects;
-  tb->canCache = rProtoBufTable_canCache;
+    tb->exists = rProtoBufTable_exists;
+    tb->get = rProtoBufTable_get;
+    tb->remove = rProtoBufTable_remove;
+    tb->assign = rProtoBufTable_assign;
+    tb->objects = rProtoBufTable_objects;
+    tb->canCache = rProtoBufTable_canCache;
 
-  tb->onAttach = NULL;
-  tb->onDetach = NULL;
+    tb->onAttach = NULL;
+    tb->onDetach = NULL;
 
-  PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue));
-  PROTECT(klass = Rf_mkString( "UserDefinedDatabase" ) );
-  Rf_setAttrib(val, R_ClassSymbol, klass) ;
-  UNPROTECT(2); /* val, klass */
-
+    PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue));
+    PROTECT(klass = Rf_mkString( "UserDefinedDatabase" ) );
+    Rf_setAttrib(val, R_ClassSymbol, klass) ;
+    UNPROTECT(2); /* val, klass */
+    
 #ifdef LOOKUP_DEBUG
- Rprintf( "</newProtocolBufferLookup>\n" ); 
+    Rprintf( "</newProtocolBufferLookup>\n" ); 
 #endif
-  return(val);
+
+    Rcpp::Function fun("attach");
+    int pos = Rcpp::as<int>(possexp);
+    fun(val, Rcpp::Named("pos")=pos, Rcpp::Named("name")="RProtoBuf:DescriptorPool");
+
+    return(val);
 }
 
 

Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h	2013-12-15 00:29:52 UTC (rev 546)
+++ pkg/src/rprotobuf.h	2013-12-15 05:19:37 UTC (rev 547)
@@ -133,7 +133,7 @@
 RcppExport SEXP throwException( const char*, const char*) ;
 
 /* in lookup.cpp */
-RcppExport SEXP newProtocolBufferLookup() ;
+RcppExport SEXP newProtocolBufferLookup(SEXP) ;
 
 /* in mutators.cpp */
 RcppExport SEXP setMessageField( SEXP, SEXP, SEXP ) ;



More information about the Rprotobuf-commits mailing list