[Rprotobuf-commits] r338 - pkg/inst/examples/HighFrequencyFinance

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 17 23:20:38 CEST 2010


Author: edd
Date: 2010-07-17 23:20:38 +0200 (Sat, 17 Jul 2010)
New Revision: 338

Removed:
   pkg/inst/examples/HighFrequencyFinance/protoLoadForR.cpp
Modified:
   pkg/inst/examples/HighFrequencyFinance/Makefile
   pkg/inst/examples/HighFrequencyFinance/loadInR.r
   pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
Log:
module code is not re-entrant -- segfaults


Modified: pkg/inst/examples/HighFrequencyFinance/Makefile
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/Makefile	2010-07-17 20:20:36 UTC (rev 337)
+++ pkg/inst/examples/HighFrequencyFinance/Makefile	2010-07-17 21:20:38 UTC (rev 338)
@@ -8,7 +8,7 @@
 RCPPINC=		$(shell Rscript -e 'Rcpp:::CxxFlags()')
 RCPPLIB=		$(shell Rscript -e 'Rcpp:::LdFlags()')
 
-TARGETS=		protoCreate protoDump protoLoadForR.so protoModule.so TradeData.pb.cc
+TARGETS=		protoCreate protoDump protoModule.so TradeData.pb.cc
 
 all:			$(TARGETS)
 
@@ -18,9 +18,9 @@
 protoDump:		protoDump.cpp TradeData.pb.cc
 			$(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)
 
-protoLoadForR.so:	protoLoadForR.cpp TradeData.pb.cc
-			PKG_CXXFLAGS="$(CXXFLAGS) $(RCPPINC)" PKG_LIBS="$(LDLIBS) $(RCPPLIB)" \
-				R CMD SHLIB $^
+#protoLoadForR.so:	protoLoadForR.cpp TradeData.pb.cc
+#			PKG_CXXFLAGS="$(CXXFLAGS) $(RCPPINC)" PKG_LIBS="$(LDLIBS) $(RCPPLIB)" \
+#				R CMD SHLIB $^
 
 protoModule.so:		protoModule.cpp TradeData.pb.cc
 			PKG_CXXFLAGS="$(CXXFLAGS) $(RCPPINC)" PKG_LIBS="$(LDLIBS) $(RCPPLIB)" \

Modified: pkg/inst/examples/HighFrequencyFinance/loadInR.r
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/loadInR.r	2010-07-17 20:20:36 UTC (rev 337)
+++ pkg/inst/examples/HighFrequencyFinance/loadInR.r	2010-07-17 21:20:38 UTC (rev 338)
@@ -81,12 +81,11 @@
 
     stopifnot(file.exists(file))
 
-    dll <- dyn.load("protoModule.so")
     trds <- Module("trades", dll)
     td <- new( trds$Trades )
     td$init(file)
-    #n <- td$numberOfFills()
-    df <- NULL #td$getData()
+    print(n <- td$numberOfFills())
+    df <- td$getData()
 
     if (verbose) print(summary(df))
 
@@ -99,11 +98,15 @@
 suppressMessages(library(Rcpp))
 suppressMessages(library(rbenchmark))
 
-dyn.load("protoLoadForR.so")
+dll <- dyn.load("protoModule.so")
 
-#print(summary(moduled())); q()
+print(summary(moduled()));
+print(summary(moduled()));
+q()
 
 
+
+
 print(benchmark(compiled  = compiled(FALSE),
                 #moduled   = moduled(FALSE),
                 basicUse  = basicUse(FALSE),

Deleted: pkg/inst/examples/HighFrequencyFinance/protoLoadForR.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoLoadForR.cpp	2010-07-17 20:20:36 UTC (rev 337)
+++ pkg/inst/examples/HighFrequencyFinance/protoLoadForR.cpp	2010-07-17 21:20:38 UTC (rev 338)
@@ -1,45 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-
-#include "TradeData.pb.h"
-
-#include <Rcpp.h>
-#include <iostream>
-#include <fstream>
-
-extern "C" SEXP pbload(SEXP b) {
-
-	std::string pbfile = Rcpp::as<std::string>(b);
-
-	// Verify that the version of the library that we linked against is
-	// compatible with the version of the headers we compiled against.
-	GOOGLE_PROTOBUF_VERIFY_VERSION;
-
-	TradeData::Trades tr;
-	
-	std::fstream fs(pbfile.c_str(), std::ios::in | std::ios::binary);
-
-	if (!tr.ParseFromIstream(&fs)) {
-		std::cerr << "Trouble parsing..." << std::cout;
-		return R_NilValue;
-	}
-
-	int n = tr.fill_size();
-	Rcpp::DatetimeVector timestamp(n);
-	Rcpp::CharacterVector tsym(n);
-	Rcpp::NumericVector tprice(n);
-	Rcpp::IntegerVector tsize(n);
-
-	for (int i=0; i<n; i++) {
-		const TradeData::Fill &fill = tr.fill(i);
-		timestamp[i] = fill.timestamp();
-		tsym[i]      = fill.symbol();
-		tprice[i]    = fill.price();
-		tsize[i]     = fill.size();
-	}
-
-    //google::protobuf::ShutdownProtobufLibrary();
-    return Rcpp::DataFrame::create(Rcpp::Named("times")  = timestamp,
-                                   Rcpp::Named("symbol") = tsym,
-                                   Rcpp::Named("price")  = tprice,
-                                   Rcpp::Named("size")   = tsize);
-}

Modified: pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoModule.cpp	2010-07-17 20:20:36 UTC (rev 337)
+++ pkg/inst/examples/HighFrequencyFinance/protoModule.cpp	2010-07-17 21:20:38 UTC (rev 338)
@@ -4,7 +4,48 @@
 
 #include <Rcpp.h>
 #include <fstream>
+#include <iostream>
 
+
+extern "C" SEXP pbload(SEXP b) {
+
+	std::string pbfile = Rcpp::as<std::string>(b);
+
+	// Verify that the version of the library that we linked against is
+	// compatible with the version of the headers we compiled against.
+	GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+	TradeData::Trades tr;
+	
+	std::fstream fs(pbfile.c_str(), std::ios::in | std::ios::binary);
+
+	if (!tr.ParseFromIstream(&fs)) {
+		std::cerr << "Trouble parsing..." << std::cout;
+		return R_NilValue;
+	}
+
+	int n = tr.fill_size();
+	Rcpp::DatetimeVector timestamp(n);
+	Rcpp::CharacterVector tsym(n);
+	Rcpp::NumericVector tprice(n);
+	Rcpp::IntegerVector tsize(n);
+
+	for (int i=0; i<n; i++) {
+		const TradeData::Fill &fill = tr.fill(i);
+		timestamp[i] = fill.timestamp();
+		tsym[i]      = fill.symbol();
+		tprice[i]    = fill.price();
+		tsize[i]     = fill.size();
+	}
+
+    //google::protobuf::ShutdownProtobufLibrary();
+    return Rcpp::DataFrame::create(Rcpp::Named("times")  = timestamp,
+                                   Rcpp::Named("symbol") = tsym,
+                                   Rcpp::Named("price")  = tprice,
+                                   Rcpp::Named("size")   = tsize);
+}
+
+
 class TradeModule 
 {
 private:



More information about the Rprotobuf-commits mailing list