[Rinside-commits] r270 - in pkg: . inst inst/examples inst/examples/qt inst/examples/standard inst/examples/threads inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 5 21:12:58 CET 2012


Author: edd
Date: 2012-12-05 21:12:58 +0100 (Wed, 05 Dec 2012)
New Revision: 270

Added:
   pkg/inst/examples/threads/
   pkg/inst/examples/threads/Makefile
   pkg/inst/examples/threads/boostEx.cpp
Modified:
   pkg/ChangeLog
   pkg/DESCRIPTION
   pkg/cleanup
   pkg/doxyfile
   pkg/inst/NEWS.Rd
   pkg/inst/examples/qt/qtdensity.pro
   pkg/inst/examples/standard/rinside_module_sample0.cpp
   pkg/inst/examples/standard/rinside_sample9.cpp
   pkg/inst/include/RInside.h
   pkg/inst/include/RInsideCommon.h
   pkg/src/RInside.cpp
Log:
release 0.2.10


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/ChangeLog	2012-12-05 20:12:58 UTC (rev 270)
@@ -1,3 +1,23 @@
+2012-12-05  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/RInside.cpp: Set R_CStackLimit to -1 to block stack checking,
+	place assignment after initialization of embedded R instance (on all
+	platforms but Windows which does not have R_CStackLimit)
+	* inst/include/RInsideCommon.h: Updated to ensure R_CStackLimit is
+	defined, added a few more #include statements here
+
+	* inst/examples/threads/boostEx.cpp: New example directory for simple
+	multi-threaded use demo building on a simple Boost mutex example
+	* cleanup: Also clean new example directory threads/
+	* doxyfile: Added new example directory threads/
+
+	* inst/examples/qt/qtdensity.pro: Corrected link order statement
+	permitting use of example on Windows as well as Linux / OS X
+
+	* inst/examples/standard/rinside_sample9.cpp: Disabled as passing
+	external C/C++ function through simplified interface currently borked
+	* inst/examples/standard/rinside_module_sample0.cpp: Idem
+	
 2012-11-08  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/standard/rinside_sample11.cpp: added include for

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/DESCRIPTION	2012-12-05 20:12:58 UTC (rev 270)
@@ -1,6 +1,6 @@
 Package: RInside
 Title: C++ classes to embed R in C++ applications
-Version: 0.2.9
+Version: 0.2.10
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois
 Maintainer: Dirk Eddelbuettel <edd at debian.org>

Modified: pkg/cleanup
===================================================================
--- pkg/cleanup	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/cleanup	2012-12-05 20:12:58 UTC (rev 270)
@@ -4,10 +4,10 @@
 	inst/lib/lib*.so inst/lib/lib*.a \
 	Librinside.a
 
-for d in standard mpi qt wt armadillo eigen
+for d in standard mpi qt wt armadillo eigen threads
 do
     cd inst/examples/${d} 
-    test -f Makefile && make clean 
+    test -f Makefile && make clean && rm -f *~
     cd ../../..
 done
 

Modified: pkg/doxyfile
===================================================================
--- pkg/doxyfile	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/doxyfile	2012-12-05 20:12:58 UTC (rev 270)
@@ -702,7 +702,8 @@
 			 src/examples/qt \
 			 src/examples/wt \
 			 src/examples/armadillo \
-			 src/examples/eigen
+			 src/examples/eigen \
+			 src/examples/threads
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the 
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 

Modified: pkg/inst/NEWS.Rd
===================================================================
--- pkg/inst/NEWS.Rd	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/NEWS.Rd	2012-12-05 20:12:58 UTC (rev 270)
@@ -2,6 +2,19 @@
 \title{News for Package 'RInside'}
 \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
 
+\section{Changes in RInside version 0.2.10 (2012-12-05)}{
+  \itemize{
+    \item Adjusted to change in R which requires turning checking of the
+    stack limit off in order to allow for access from multiple threads
+    as in the Wt examples. As there are have been no side-effects, this
+    is enabled by default on all platforms (with the exception of Windows).
+    \item Added new \sQuote{threads} example directory with a simple
+    example based on a Boost mutex use example.
+    \item Disabled two examples (passing an external function down)
+    which do not currently work; external pointer use should still work.
+  }
+}
+   
 \section{Changes in RInside version 0.2.9 (2012-11-04)}{
   \itemize{
     \item Applied (modified) patch by Theodore Lytras which lets RInside

Modified: pkg/inst/examples/qt/qtdensity.pro
===================================================================
--- pkg/inst/examples/qt/qtdensity.pro	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/examples/qt/qtdensity.pro	2012-12-05 20:12:58 UTC (rev 270)
@@ -3,7 +3,12 @@
 ## Qt usage example for RInside, inspired by the standard 'density
 ## sliders' example for other GUI toolkits
 ##
-## Copyright (C) 2011  Dirk Eddelbuettel and Romain Francois
+## This file can be used across operating systems as qmake selects appropriate 
+## values as needed, as do the R and R-related calls below. See the thread at
+##     http://thread.gmane.org/gmane.comp.lang.r.rcpp/4376/focus=4402
+## for discussion specific to Windows.
+##
+## Copyright (C) 2012  Dirk Eddelbuettel and Romain Francois
 
 ## build an app based on the one headers and two source files
 TEMPLATE = 		app
@@ -28,8 +33,8 @@
 RRPATH =		-Wl,-rpath,$$R_HOME/lib
 
 ## include headers and libraries for Rcpp interface classes
-RCPPINCL = 		$$system($$R_HOME/bin/Rscript -e \'Rcpp:::CxxFlags\(\)\')
-RCPPLIBS = 		$$system($$R_HOME/bin/Rscript -e \'Rcpp:::LdFlags\(\)\')
+RCPPINCL = 		$$system($$R_HOME/bin/Rscript -e \"Rcpp:::CxxFlags\(\)\")
+RCPPLIBS = 		$$system($$R_HOME/bin/Rscript -e \"Rcpp:::LdFlags\(\)\")
 
 ## for some reason when building with Qt we get this each time
 ##   /usr/local/lib/R/site-library/Rcpp/include/Rcpp/module/Module_generated_ctor_signature.h:25: warning: unused parameter ‘classname
@@ -38,12 +43,12 @@
 #RCPPWARNING =		-Wno-unused-parameter 
 
 ## include headers and libraries for RInside embedding classes
-RINSIDEINCL = 		$$system($$R_HOME/bin/Rscript -e \'RInside:::CxxFlags\(\)\')
-RINSIDELIBS = 		$$system($$R_HOME/bin/Rscript -e \'RInside:::LdFlags\(\)\')
+RINSIDEINCL = 		$$system($$R_HOME/bin/Rscript -e \"RInside:::CxxFlags\(\)\")
+RINSIDELIBS = 		$$system($$R_HOME/bin/Rscript -e \"RInside:::LdFlags\(\)\")
 
 ## compiler etc settings used in default make rules
 QMAKE_CXXFLAGS +=	$$RCPPWARNING $$RCPPFLAGS $$RCPPINCL $$RINSIDEINCL
-QMAKE_LIBS +=           $$RLDFLAGS $$RBLAS $$RLAPACK $$RCPPLIBS $$RINSIDELIBS
+QMAKE_LIBS +=           $$RLDFLAGS $$RBLAS $$RLAPACK $$RINSIDELIBS $$RCPPLIBS
 
 ## addition clean targets
 QMAKE_CLEAN +=		qtdensity Makefile

Modified: pkg/inst/examples/standard/rinside_module_sample0.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_module_sample0.cpp	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/examples/standard/rinside_module_sample0.cpp	2012-12-05 20:12:58 UTC (rev 270)
@@ -2,7 +2,7 @@
 //
 // Simple example showing how expose a C++ function
 //
-// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012  Dirk Eddelbuettel and Romain Francois
 
 #include <RInside.h>                    // for the embedded R via RInside
 
@@ -27,8 +27,11 @@
     R["bling"] = LOAD_RCPP_MODULE(bling) ;
     
     // call it and display the result
-    std::string result = R.parseEval("bling$hello('world')") ;
-    std::cout << "bling$hello( 'world') =  '" << result << "'" << std::endl ; 
+    Rcpp::Rcout << "** rinside_module_sample0 is currently disabled.\n";
+    if (FALSE) {
+		std::string result = R.parseEval("bling$hello('world')") ;
+		std::cout << "bling$hello( 'world') =  '" << result << "'" << std::endl ; 
+	}
     exit(0);
 }
 

Modified: pkg/inst/examples/standard/rinside_sample9.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample9.cpp	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/examples/standard/rinside_sample9.cpp	2012-12-05 20:12:58 UTC (rev 270)
@@ -8,9 +8,9 @@
 
 // a c++ function we wish to expose to R
 const char* hello( std::string who ){
-        std::string result( "hello " ) ;
-        result += who ;
-        return result.c_str() ;
+    std::string result( "hello " ) ;
+    result += who ;
+    return result.c_str() ;
 } 
 
 int main(int argc, char *argv[]) {
@@ -22,8 +22,11 @@
     R["hello"] = Rcpp::InternalFunction( &hello ) ;
    
     // call it and display the result
-    std::string result = R.parseEval("hello('world')") ;
-    std::cout << "hello( 'world') =  " << result << std::endl ; 
+    Rcpp::Rcout << "** rinside_sample9 is currently disabled.\n";
+    if (FALSE) {
+	std::string result = R.parseEvalNT("hello(\"world\")") ;
+	std::cout << "hello( 'world') =  " << result << std::endl ; 
+    }
 
     exit(0);
 }

Added: pkg/inst/examples/threads/Makefile
===================================================================
--- pkg/inst/examples/threads/Makefile	                        (rev 0)
+++ pkg/inst/examples/threads/Makefile	2012-12-05 20:12:58 UTC (rev 270)
@@ -0,0 +1,48 @@
+
+## This Makefile is __very__ barebones
+##
+## It works on Debian/Ubuntu. On other systems, add -I and -L flags as needed. 
+
+
+## comment this out if you need a different version of R, 
+## and set set R_HOME accordingly as an environment variable
+R_HOME := 		$(shell R RHOME)
+
+## include headers and libraries for R 
+RCPPFLAGS := 		$(shell $(R_HOME)/bin/R CMD config --cppflags)
+RLDFLAGS := 		$(shell $(R_HOME)/bin/R CMD config --ldflags)
+RBLAS := 		$(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
+RLAPACK := 		$(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
+
+## if you need to set an rpath to R itself, also uncomment
+#RRPATH :=		-Wl,-rpath,$(R_HOME)/lib
+
+## include headers and libraries for Rcpp interface classes
+RCPPINCL := 		$(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RCPPLIBS := 		$(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)
+
+## include headers and libraries for RInside embedding classes
+RINSIDEINCL := 		$(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RINSIDELIBS := 		$(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)
+
+
+## minimal Boost libs -- works for me on Ubuntu, may need -L switches elsewhere...
+BOOSTLIBS :=		-lboost_thread
+
+
+## compiler etc settings used in default make rules
+CXX := 			$(shell $(R_HOME)/bin/R CMD config CXX)
+CPPFLAGS := 		-Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
+CXXFLAGS := 		$(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
+LDLIBS := 		$(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS) $(BOOSTLIBS)
+
+
+
+all:			boostEx
+
+boostEx:		boostEx.cpp
+			$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDLIBS) 
+			strip $@
+
+clean:
+			rm -f boostEx

Added: pkg/inst/examples/threads/boostEx.cpp
===================================================================
--- pkg/inst/examples/threads/boostEx.cpp	                        (rev 0)
+++ pkg/inst/examples/threads/boostEx.cpp	2012-12-05 20:12:58 UTC (rev 270)
@@ -0,0 +1,43 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; -*-
+
+#include <boost/thread.hpp>
+#include <boost/bind.hpp>
+
+#include <RInside.h>
+
+class Resource {
+public:
+    Resource(): i(0), RR(RInside::instance()) { }
+
+    void use() {
+	boost::mutex::scoped_lock lock(guard);
+	RR.parseEvalQ("cat(\"Hello, world from use()\\n\")");
+	++i;
+    }
+    int getValue() { return i; }
+
+private:
+    int i;
+    RInside & RR;		// reference to embedded R instance
+    boost::mutex guard;
+};
+
+void thread_func(Resource& resource) {
+    resource.use();
+}
+
+extern uintptr_t R_CStackLimit;
+
+int main(int argc, char *argv[]) {
+
+    RInside R(argc, argv);
+    R.parseEvalQ("cat(\"Hello, world from main()\\n\")");
+
+    Resource resource;
+    boost::thread_group thread_group;
+    thread_group.create_thread(boost::bind(thread_func, boost::ref(resource)));
+    thread_group.create_thread(boost::bind(thread_func, boost::ref(resource)));
+    thread_group.join_all();
+    std::cout << "At end value is " << resource.getValue() << std::endl;
+    return 0;
+}

Modified: pkg/inst/include/RInside.h
===================================================================
--- pkg/inst/include/RInside.h	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/include/RInside.h	2012-12-05 20:12:58 UTC (rev 270)
@@ -42,7 +42,7 @@
 					const bool loadRcpp, const bool verbose, const bool interactive);
 
     static RInside* instance_m ;
-    
+
 #ifdef RINSIDE_CALLBACKS
     Callbacks* callbacks ;
     friend void RInside_ShowMessage( const char* message);
@@ -85,11 +85,12 @@
     ~RInside();
 
 	void setVerbose(const bool verbose) 	{ verbose_m = verbose; }
+
+    Rcpp::Environment::Binding operator[]( const std::string& name );
     
-    Rcpp::Environment::Binding operator[]( const std::string& name ) ;
+    static RInside& instance();
+    static RInside* instancePtr();
     
-    static RInside& instance() ;
-    
 #ifdef RINSIDE_CALLBACKS
     void set_callbacks(Callbacks* callbacks_) ;
 	void repl() ;

Modified: pkg/inst/include/RInsideCommon.h
===================================================================
--- pkg/inst/include/RInsideCommon.h	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/inst/include/RInsideCommon.h	2012-12-05 20:12:58 UTC (rev 270)
@@ -24,6 +24,13 @@
 
 #include <RInsideConfig.h>
 
+#include <sys/time.h>           // gettimeofday()
+#include <sys/types.h>		// pid_t
+#include <unistd.h>		// getpid()
+
+#include <inttypes.h>		// intptr_t (one day we use cinttypes from C++11)
+#include <stdint.h>		// uint64_t (one day we use cstdint from C++11)
+
 #include <string>
 #include <vector>
 #include <iostream>
@@ -37,10 +44,16 @@
   #endif
 #endif
 
+#ifndef WIN32
+  // needed to turn-off stack checking, and we already have uintptr_t
+  #define CSTACK_DEFNS
+  #define HAVE_UINTPTR_T
+#endif
+
 #include <Rembedded.h>
 #ifndef WIN32
-#define R_INTERFACE_PTRS
-#include <Rinterface.h>
+  #define R_INTERFACE_PTRS
+  #include <Rinterface.h>
 #endif
 #include <R_ext/RStartup.h>
 

Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp	2012-11-08 20:44:14 UTC (rev 269)
+++ pkg/src/RInside.cpp	2012-12-05 20:12:58 UTC (rev 270)
@@ -25,11 +25,6 @@
 
 RInside* RInside::instance_m = 0 ;
 
-#include <sys/time.h>           // gettimeofday()
-#include <stdint.h>		// uint64_t
-#include <sys/types.h>		// pid_t
-#include <unistd.h>		// getpid()
-
 const char *programName = "RInside";
 
 #ifdef WIN32
@@ -143,10 +138,6 @@
     R_SignalHandlers = 0;               // Don't let R set up its own signal handlers
     #endif
 
-    #ifdef CSTACK_DEFNS
-    R_CStackLimit = (uintptr_t)-1;      // Don't do any stack checking, see R Exts, '8.1.5 Threading issues'
-    #endif
-
     init_tempdir();
 
     const char *R_argv[] = {(char*)programName, "--gui=none", "--no-save", "--no-readline", "--silent", "", ""};
@@ -154,6 +145,10 @@
     int R_argc = (sizeof(R_argv) - sizeof(R_argv_opt) ) / sizeof(R_argv[0]);
     Rf_initEmbeddedR(R_argc, (char**)R_argv);
 
+    #ifndef WIN32
+    R_CStackLimit = -1;      		// Don't do any stack checking, see R Exts, '8.1.5 Threading issues'
+    #endif
+
     R_ReplDLLinit();                    // this is to populate the repl console buffers
 
     structRstart Rst;
@@ -403,6 +398,10 @@
     return *instance_m;
 }
 
+RInside* RInside::instancePtr(){
+    return instance_m;
+}
+
 /* callbacks */
 
 #ifdef RINSIDE_CALLBACKS



More information about the Rinside-commits mailing list