[Rcpp-devel] Segfault when attributes are not used

Matteo Fasiolo matteo.fasiolo at gmail.com
Sun Aug 10 16:36:26 CEST 2014


Dear Rcpp developer,

 I have experienced intermittent crashes of some of my
Rcpp function and I managed to reduce it to the following.

I build a package using Rcpp.package.skeleton(), I delete
all the files in the R and src folder, and I include in the src
folder 2 files:

####### exper.cpp

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericMatrix exper( )
{
     RNGScope scope;

      NumericMatrix out(10, 10);

      return out;

}

######### exper2.cpp

#include <Rcpp.h>
using namespace Rcpp;

RcppExport SEXP exper2( )
{
      RNGScope scope;

      NumericMatrix out(10, 10);

      return out;

}

The first version uses // [[Rcpp::export]] the second RcppExport.
I then call compileAttributes(".") inside the package folder.

Then I run:

#### test.R

library(anRpackage)
set.seed(4341)
for(ii in 1:500000){

  a <- .Call( "anRpackage_exper",  PACKAGE = "anRpackage" )

  matrix(a, 1, 100)
}

set.seed(4341)
for(ii in 1:500000){

  a <- .Call( "exper2",  PACKAGE = "anRpackage" )

  matrix(a, 1, 100)
}

exper2 crashes with:

 *** caught segfault ***
address (nil), cause 'unknown'

Am I doing something wrong?

Removing the line "RNGScope scope;" solves the problem.

Maybe there is a relation with the problem found in this old discussion
<http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-May/005815.html>
?

Many thanks for you help.

Matteo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140810/f3f715aa/attachment.html>


More information about the Rcpp-devel mailing list