[Rcpp-devel] RInside destructor not working properly?
Dirk Eddelbuettel
edd at debian.org
Mon Aug 27 13:51:00 CEST 2012
Christian,
On 27 August 2012 at 13:28, Christian Sigg wrote:
| The following program
|
| #include <RInside.h>
|
| void foo() {
| RInside R;
| }
|
| void bar() {
| RInside R;
| }
|
| int main(int argc, const char * argv[]) {
| foo();
| bar();
| return 0;
| }
|
| produces a great number of the following two lines
|
| Error: bad target context--should NEVER happen;
| please bug.report() [R_run_onexits]
|
| as output.
|
| Question: Is the RInside destructor not working properly? I would have expected that both in foo() and bar(), an instance of R is created and then destroyed| immediately, without producing any kind of output.
No, wrong setup. R is single-threaded, and you can have only
precisely __ONE__ instance of R in your program. You have two.
Create one in main() and pass references around.
| Context: I'm developing code that calls the OpenCV library from R, with the help of Rcpp. For rapid development and unit testing, I use RInside to set up the environment before calling my C++ function that calls into the OpenCV library. The above mentioned error appears when the second unit test again calls the RInside constructor to set up its test environment.
|
| This is on OS X 10.7 with Xcode 4.4.1 (Apple LLVM Compiler 4.0) and the latest version of the command line tools. I use R 2.15.1 and RInside 0.2.7.
|
| If I avoid calling RInside() twice in the same program, my code is running smoothly.
That's the point. Use one, as R can only be called once per process.
There is a bit of a singleton-alike pattern in RInside::initialize() which
should have caught this. I am a bit surprised you got this far. If anybody
has ideas of how to prevent your design error from even passing the compile
stage I'd be all ears.
Dirk
|
| Thanks for any assistance,
| Christian
|
|
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list