[Rcpp-devel] Loading a package using Rcpp Modules results in memory corruption

Douglas Bates bates at stat.wisc.edu
Fri Jan 7 15:05:33 CET 2011


On Fri, Jan 7, 2011 at 5:34 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
> Le 05/01/11 18:52, Douglas Bates a écrit :
>>
>> I don't know whether this is through error on my part or because of an
>> "infelicity" in the Rcpp module code but the lme4a package, which now
>> uses Rcpp modules extensively, ends up with some difficult-to-trace
>> memory corruption issues.  Yesterday i finally bit the bullet and ran
>> a test with gctorture(TRUE) and valgrind enabled.  It takes a very
>> long time and results in a segfault when trying to load the package.
>> I enclose the transcript.  I should say that this is using Rcpp_0.9.0
>> from CRAN, not the SVN version of Rcpp.
>>
>> I just got these results this morning (it was running overnight) and
>> haven't looked at the code in Module.cpp and cache.cpp yet.  If it
>> seems likely that the code is beyond me I can try to work out a
>> simpler example that triggers the problem.
>
> Hi Doug,
>
> Sorry for the delay, I'm not fully operational yet.
>
> All this might be related to some code I put in during holidays and did not
> have a chance to fully test.
>
> Can you try with rev 2845 and let me know if you still see the problem.
>
> Romain

Regrettably the problem persists with rev 2845 (which was from
2011-01-04, is that the one you meant?) but it is also present when
using Rcpp_0.9.0
-------------- next part --------------

R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(inline)
> library(Rcpp)
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=C             LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=en_US.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_0.9.0.2 inline_0.3.8
> str(packageDescription("Rcpp"))
List of 15
 $ Package    : chr "Rcpp"
 $ Title      : chr "Seamless R and C++ Integration"
 $ Version    : chr "0.9.0.2"
 $ Date       : chr "$Date: 2011-01-04 13:14:52 -0600 (Tue, 04 Jan 2011) $"
 $ Author     : chr "Dirk Eddelbuettel and Romain Francois,\nwith contributions by Douglas Bates and John Chambers"
 $ Maintainer : chr "Dirk Eddelbuettel and Romain Francois <RomainAndDirk at r-enthusiasts.com>"
 $ Description: chr "The Rcpp package provides a C++ library which facilitates the\nintegration of R and C++.\n\nR data types (SEXP) are matched to "| __truncated__
 $ Depends    : chr "R (>= 2.12.0), methods"
 $ Suggests   : chr "RUnit, inline, rbenchmark"
 $ URL        : chr "http://dirk.eddelbuettel.com/code/rcpp.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp"
 $ License    : chr "GPL (>= 2)"
 $ BugReports : chr "http://r-forge.r-project.org/tracker/?atid=637&group_id=155&func=browse"
 $ MailingList: chr "Please send questions and comments regarding Rcpp to rcpp-devel at lists.r-forge.r-project.org"
 $ Packaged   : chr "2011-01-07 13:35:12 UTC; bates"
 $ Built      : chr "R 2.12.1; x86_64-pc-linux-gnu; 2011-01-07 13:38:32 UTC; unix"
 - attr(*, "class")= chr "packageDescription"
 - attr(*, "file")= chr "/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/Meta/package.rds"
> fx_unif <- cxxfunction( , "", includes = '
+ using namespace Rcpp;
+ class Uniform {
+ public:
+     Uniform(double min_, double max_) : min(min_), max(max_) {}
+ 
+     NumericVector draw(int n) const {
+         RNGScope scope;
+         return runif( n, min, max );
+     }
+ 
+     double min, max;
+ };
+ 
+ double range( Uniform* w) {
+     return w->max - w->min;
+ }
+ 
+ RCPP_MODULE(unif_module) {
+ 
+     class_<Uniform>( "Uniform" )
+ 
+     .constructor<double,double>()
+ 
+     .field( "min", &Uniform::min )
+     .field( "max", &Uniform::max )
+ 
+     .method( "draw", &Uniform::draw )
+     .method( "range", &range )
+     ;
+ 
+ }
+ ', plugin = "Rcpp" )
> unif_module <- Module( "unif_module", getDynLib(fx_unif ) )
> gctorture(TRUE)
> Rcpp:::.getModulePointer(unif_module)
Error in list(`$<-` = `$<-`) : 
  0 arguments passed to '$<-' which requires 3
Calls: <Anonymous> -> Module -> .Call
Execution halted
-------------- next part --------------

R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(inline)
> library(Rcpp)
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=C             LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=en_US.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_0.9.0   inline_0.3.8
> str(packageDescription("Rcpp"))
List of 17
 $ Package         : chr "Rcpp"
 $ Title           : chr "Seamless R and C++ Integration"
 $ Version         : chr "0.9.0"
 $ Date            : chr "$Date: 2010-12-19 18:36:29 -0600 (Sun, 19 Dec 2010) $"
 $ Author          : chr "Dirk Eddelbuettel and Romain Francois, with contributions by\nDouglas Bates and John Chambers"
 $ Maintainer      : chr "Dirk Eddelbuettel and Romain Francois\n<RomainAndDirk at r-enthusiasts.com>"
 $ Description     : chr "The Rcpp package provides a C++ library which facilitates\nthe integration of R and C++.\n\nR data types (SEXP) are matched to "| __truncated__
 $ Depends         : chr "R (>= 2.12.0), methods"
 $ Suggests        : chr "RUnit, inline, rbenchmark"
 $ URL             : chr "http://dirk.eddelbuettel.com/code/rcpp.html,\nhttp://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp"
 $ License         : chr "GPL (>= 2)"
 $ BugReports      : chr "\nhttp://r-forge.r-project.org/tracker/?atid=637&group_id=155&func=browse"
 $ MailingList     : chr "Please send questions and comments regarding Rcpp to\nrcpp-devel at lists.r-forge.r-project.org"
 $ Packaged        : chr "2010-12-20 16:10:12.05155 UTC; edd"
 $ Repository      : chr "CRAN"
 $ Date/Publication: chr "2010-12-22 11:18:19"
 $ Built           : chr "R 2.12.1; x86_64-pc-linux-gnu; 2011-01-07 13:58:01 UTC; unix"
 - attr(*, "class")= chr "packageDescription"
 - attr(*, "file")= chr "/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/Meta/package.rds"
> fx_unif <- cxxfunction( , "", includes = '
+ using namespace Rcpp;
+ class Uniform {
+ public:
+     Uniform(double min_, double max_) : min(min_), max(max_) {}
+ 
+     NumericVector draw(int n) const {
+         RNGScope scope;
+         return runif( n, min, max );
+     }
+ 
+     double min, max;
+ };
+ 
+ double range( Uniform* w) {
+     return w->max - w->min;
+ }
+ 
+ RCPP_MODULE(unif_module) {
+ 
+     class_<Uniform>( "Uniform" )
+ 
+     .constructor<double,double>()
+ 
+     .field( "min", &Uniform::min )
+     .field( "max", &Uniform::max )
+ 
+     .method( "draw", &Uniform::draw )
+     .method( "range", &range )
+     ;
+ 
+ }
+ ', plugin = "Rcpp" )
> unif_module <- Module( "unif_module", getDynLib(fx_unif ) )
> gctorture(TRUE)
> Rcpp:::.getModulePointer(unif_module)
Error in list(c(76662L, 78L), "/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/R/Rcpp.rdb", TRUE, function (n)  : 
  unused argument(s) ("/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/R/Rcpp.rdb", TRUE, function (n) 
Calls: <Anonymous> -> Module -> .Call -> <Anonymous>
Execution halted


More information about the Rcpp-devel mailing list