[Rcpp-devel] NumericVector crashes in dataptr

Slava Mazur smazur at liquidnet.com
Wed May 7 21:06:32 CEST 2014


Hi Dirk,

Thanks for the prompt attention to this issue. It does not have anything to do with boost: the following behaves the same way:

#include <RInside.h>
#include <Rcpp.h>

int main(int argc, char *argv[]) {
    RInside Rinst(argc, argv);
    const int N = 173;
    double v[N];
    std::fill(v, v+N, 0.0);
    Rcpp::NumericVector x(v, v+N);
    std::cout << "All good\n";
    return 0;
}

I tried to dig into it a little bit further and observed things that look strange to me. Execution eventually gets to the following code in Rcpp/routines.h[196:200]

inline void* dataptr(SEXP x){
    typedef void* (*Fun)(SEXP) ;
    static Fun fun = GET_CALLABLE("dataptr") ;
    return fun(x) ; 
} 

It seems that the "fun" pointer above points to the dataptr function itself and thus its call starts an unlimited recursion, which is confirmed by stepping through "return fun(x)" code in gdb.

It is interesting that if I recompile the same code with -DCOMPILING_RCPP the issue goes away. Is it an intended behavior? Please advise.

Thanks again,

SLAVA MAZUR
PRODUCT MANAGEMENT
LIQUIDNET
498 SEVENTH AVENUE, 15TH FLOOR, NEW YORK, NY, 10018



More information about the Rcpp-devel mailing list