[Rcpp-devel] NumericVector crashes in dataptr

Dirk Eddelbuettel edd at debian.org
Wed May 7 19:58:07 CEST 2014


Hi Slava,

On 7 May 2014 at 12:07, Slava Mazur wrote:
| I observe a crash in NumericVector constructor with new versions of Rcpp/
| RInside: (0.11.1 and 0.2.11 respectively).

I cannot replicate that. Ubuntu 13.10; everything current.  

A copy and paste session is below.  I just made the size a const to suppress
the warning, and added a stdout report at the end.

I was about to say that the Boost shared_ptr may be playing with fire, but
then I didn't have to as it didn't crash for me ;-)

Dirk


edd at max:~/git/rinside/inst/examples/standard$ cat slava.cpp
////////// dataptr_crash.cpp //////

#include <RInside.h>
#include <Rcpp.h>
#include <boost/shared_ptr.hpp>

static boost::shared_ptr<RInside> Rinst;
 
int main(int argc, char *argv[]) {
    Rinst = boost::shared_ptr<RInside>(new RInside(argc, argv));
    const int N = 173;          // made const for -Wall ....
    double v[N];
    std::fill(v, v+N, 0.0);
    Rcpp::NumericVector x(v, v+N);
    std::cout << "All good\n";
    return 0;
}
edd at max:~/git/rinside/inst/examples/standard$ make slava
ccache g++-4.8 -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/include -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -Wno-unused -pedantic -std=c++11 -Wall    slava.cpp  -Wl,--export-dynamic -fopenmp  -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm  -lblas -llapack  -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o slava
edd at max:~/git/rinside/inst/examples/standard$ ./slava 
All good
edd at max:~/git/rinside/inst/examples/standard$ 
| 
|  
| 
| Here is a test c++ code:
| 
| ////////// dataptr_crash.cpp //////////////////////////////////////////////////
| ////////
| 
| #include <RInside.h>
| 
| #include <Rcpp.h>
| 
| #include <boost/shared_ptr.hpp>
| 
|  
| 
| static boost::shared_ptr<RInside> Rinst;
| 
|  
| 
| int main(int argc, char *argv[]) {
| 
|     Rinst = boost::shared_ptr<RInside>(new RInside(argc, argv));
| 
|     int N = 173;
| 
|     double v[N];
| 
|     std::fill(v, v+N, 0.0);
| 
|     Rcpp::NumericVector x(v, v+N);
| 
|     return 0;
| 
| }
| 
| ///////////////////////////////////////////////////////////////////////////////
| ///////////////////
| 
|  
| 
| to build:
| 
| gcc -g3 -O0 -I$R_HOME/include -I$R_HOME/library/Rcpp/include -I$R_HOME/library/
| RInside/include -L$R_HOME/lib -L$R_HOME/library/Rcpp/lib -L$R_HOME/library/
| RInside/lib -lR -lRcpp -lRInside dataptr_crash.cpp
| 
|  
| 
| environment:
| 
| uname -r
| 
| 2.6.32-279.5.2.el6.x86_64
| 
|  
| 
| gcc --version
| 
| gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)
| 
| Copyright (C) 2010 Free Software Foundation, Inc.
| 
| This is free software; see the source for copying conditions.  There is NO
| 
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| 
|  
| 
| > library(Rcpp)
| 
| > library(RInside)
| 
| > sessionInfo()
| 
| R version 3.0.3 (2014-03-06)
| 
| Platform: x86_64-unknown-linux-gnu (64-bit)
| 
|  
| 
| locale:
| 
| [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
| 
| [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
| 
| [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
| 
| [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
| 
| [9] LC_ADDRESS=C               LC_TELEPHONE=C
| 
| [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
| 
|  
| 
| attached base packages:
| 
| [1] stats     graphics  grDevices utils     datasets  methods   base
| 
|  
| 
| other attached packages:
| 
| [1] RInside_0.2.11 Rcpp_0.11.1
| 
|  
| 
| The test program above crashes in Rcpp::NumericVector ctor and the top of the
| stack looks like the following:
| 
|  
| 
| Program received signal SIGSEGV, Segmentation fault.
| 
| 0x000000000040315e in dataptr (x=Cannot access memory at address 0x7fffff3feff8
| 
| )
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:196
| 
| 196     inline void* dataptr(SEXP x){
| 
| (gdb) bt
| 
| #0  0x000000000040315e in dataptr (x=Cannot access memory at address
| 0x7fffff3feff8
| 
| )
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:196
| 
| #1  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #2  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #3  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #4  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #5  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #6  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #7  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #8  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #9  0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #10 0x00000000004031da in dataptr (x=0x146f290)
| 
|     at /quantpkgs/R/R-3.0.3/lib64/R/library/Rcpp/include/Rcpp/routines.h:199
| 
| #11 0x00000000004031da in dataptr (x=0x146f290)
| 
| ---Type <return> to continue, or q <return> to quit---q
| 
|  
| 
| However, I couldn?t reach the bottom of the stack -- it?s too long.
| 
|  
| 
| In older versions  of R/Rcpp/RInside it works fine. Boost version seems to be
| irrelevant.
| 
|  
| 
| Is this a known issue?
| 
|  
| 
| Thanks,
| 
| SLAVA MAZUR
| PRODUCT MANAGEMENT
| LIQUIDNET
| 498 SEVENTH AVENUE, 15TH FLOOR, NEW YORK, NY 10018
| 
| THINK HFT IS OLD NEWS?
| SO DO WE.
| 
| _______________________________________________
| 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