-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different Rcout object for each translation unit #928
Comments
This issue is stale (365 days without activity) and will be closed in 31 days unless new activity is seen. Please feel free to re-open it is still a concern, possibly with additional data. |
I think this is still worth fixing. |
Sure. Any chance you could take a stab at it in branch? |
Yes, I would like to. I'll try to find some time for this in the coming weeks. My approach would be to follow the design of |
There's a first pass at this here: Enchufa2@d96d806. I would like to ensure that this is the right approach before submitting a PR. Basically I have:
Now the problem is that the initialization of such references must be part of the scaffolding code. For example, in f <- "CharacterVector ptr%s() {
std::ostringstream address;
address << (void const *)(&%s);
return address.str();
}"
Rcpp::cppFunction(sprintf(f, "A", "Rcout"))
Rcpp::cppFunction(sprintf(f, "B", "Rcout"))
ptrA() == ptrB() # should be TRUE So:
|
BTW, a motivating example that could be used for testing: Rcpp::cppFunction('void to_left() { Rcout << std::left; }')
Rcpp::cppFunction('void something() { Rcout << std::setw(20) << "something" << std::endl; }')
something() # right-aligned by default
to_left() # change alignment
something() # should be left-aligned This is the kind of thing that bit me when I opened this, but in the context of two different |
Right. |
By some quick trial and error, I managed to get this pass all the tests except for the use of |
Never mind. That comment was meant for our Twitter DM stream. Redacted here. |
I'm a little worried that re-defining Rcout / Rcerr in this way could be brittle, in that it could be easy to miss places where Rcout / Rcerr should have been initialized, but weren't. What do you think about instead defining
and get the expected result. |
Give #1139 an opportunity, please. :) The advantage is that all the code out there will work just by setting a flag. |
The rev.dep machine has already been turned on :) |
No new issues, as we expected given that an |
I wouldn't expect any issue with the new define set either. |
Right. Which gets us to a next point: could you possibly cook up an example or better still a unit test? |
Address #928: enable global Rcout/Rcerr via RCPP_USE_GLOBAL_ROSTREAM
(The PR had a "tag" for it but no " |
Opening this as per request of @kevinushey. As explained in this thread,
And the same for
Rcerr
. I think that this might be worth fixing on the Rcpp side, but probably it would require to declareRcout
andRcerr
asextern
and generate some code to initialise them inRcppExports.cpp
.The text was updated successfully, but these errors were encountered: