Skip to content
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

No newlines in SPARC #647

Closed
Enchufa2 opened this issue Feb 11, 2017 · 4 comments
Closed

No newlines in SPARC #647

Enchufa2 opened this issue Feb 11, 2017 · 4 comments

Comments

@Enchufa2
Copy link
Member

I got my hands on a SPARC machine and I've detected that a std::endl issued with Rcpp::Rcout is not printed. I've done the following:

  1. Create a test package with Rcpp::Rcpp.package.skeleton("test").
  2. Modify src/rcpp_hello_world.cpp as follows:
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void rcpp_hello_world() {
  Rcpp::Rcout << "hello world!" << std::endl;
  Rcpp::Rcout << "another hello world!" << std::endl;
}
  1. Build the package with R CMD build test.
  2. And in the SPARC station...
-bash-3.2$ R CMD INSTALL test_1.0.tar.gz 
* installing to library '/export/home/***/R/sparc-sun-solaris2.10-library/3.3'
* installing *source* package 'test' ...
** libs
/opt/csw/bin/g++-5.2 -I/opt/csw/lib/R/include -DNDEBUG  -I/opt/csw/include -I"/export/home/***/R/sparc-sun-solaris2.10-library/3.3/Rcpp/include"   -fPIC  -O2 -pipe -fno-omit-frame-pointer -mcpu=v9 -Wa,-xarch=v8plus  -c RcppExports.cpp -o RcppExports.o
/opt/csw/bin/g++-5.2 -I/opt/csw/lib/R/include -DNDEBUG  -I/opt/csw/include -I"/export/home/***/R/sparc-sun-solaris2.10-library/3.3/Rcpp/include"   -fPIC  -O2 -pipe -fno-omit-frame-pointer -mcpu=v9 -Wa,-xarch=v8plus  -c rcpp_hello_world.cpp -o rcpp_hello_world.o
/opt/csw/bin/g++-5.2 -shared -mcpu=v9 -Wa,-xarch=v8plus -L/opt/csw/lib -o test.so RcppExports.o rcpp_hello_world.o
installing to /export/home/***/R/sparc-sun-solaris2.10-library/3.3/test/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (test)
-bash-3.2$ Rscript -e "test::rcpp_hello_world()"
hello world!another hello world!-bash-3.2$

No newlines! (I've verified that a simple C++ program using std::cout prints the newlines).

@kevinushey
Copy link
Contributor

Here's the bits of Rcpp's stream buffer implementation that are probably relevant here:

template <> inline std::streamsize Rstreambuf<true>::xsputn(const char *s, std::streamsize num ) {
Rprintf( "%.*s", num, s ) ;
return num ;
}
template <> inline std::streamsize Rstreambuf<false>::xsputn(const char *s, std::streamsize num ) {
REprintf( "%.*s", num, s ) ;
return num ;
}

Perhaps something funky is going on with how that stream buffer is receiving input? Do you see the same issue with Rcpp::Rcerr?

@Enchufa2
Copy link
Member Author

Enchufa2 commented Feb 11, 2017

Same issue with Rcpp::Rcerr, yes. However, I've just tried the following and it's working well:

void rcpp_hello_world() {
  std::ostringstream end;
  end << "\n";
  Rcpp::Rcout << "hello world!" << end.str();
  Rcpp::Rcout << "another hello world!" << end.str();
}

And so does this:

void rcpp_hello_world() {
  Rcpp::Rcout << "hello world!\n";
  Rcpp::Rcout << "another hello world!\n";
}

So maybe the bug is upstream in std::endl?

EDIT: But std::endl works well in a standalone program, outside Rcpp!

@Enchufa2
Copy link
Member Author

Another test I made:

void rcpp_hello_world() {
  Rcpp::Rcout << "hello world!" << std::endl << "X";
  Rcpp::Rcout << "another hello world!" << std::endl << "X";
}

prints

-bash-3.2$ Rscript -e "test::rcpp_hello_world()"
hello world!Xanother hello world!X-bash-3.2$

Which means that std::endl is not being inserted at all. Any idea?

@kevinushey
Copy link
Contributor

Unfortunately no -- since none of us have access to a SPARC machine, it's unlikely that we'll be able to help debug further.

My only suggestion would be for you to copy the streambuf implementation we have in:

https://github.com/RcppCore/Rcpp/blob/d38a304dbc4a6c5d7e7cf4012c63ffe3a364090b/inst/include/Rcpp/iostream/Rstreambuf.h

and try playing around with that until you get the expected output.

eddelbuettel added a commit that referenced this issue Feb 14, 2017
close #647: fixed single-character handling in Rstreambuf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants