I tried it just now. Did not crash on my R. Mmm<div><br></div><div><div>myFun =cppFunction('NumericMatrix myFun(NumericMatrix input, int n){</div><div>+ </div><div>+ NumericMatrix A(n, n);</div><div>+ </div><div>+ for(int Row = 0; Row < n; Row++)</div>

<div>+   for(int Col = 0; Col < n; Col++)</div><div>+   {</div><div>+     A(Row, Col) = input(Row, Col);</div><div>+   }</div><div>+ </div><div>+ return A;</div><div>+ }')</div><div>> n = 10</div><div>> x <- 1:n^2</div>

<div>>  for(ii in 1:10^6)</div><div>+  { </div><div>+    means <- matrix(x, n, n) </div><div>+    res <- myFun(means, n)</div><div>+    a <- res[1, 1]</div><div>+  }</div><div>> </div></div><div><br></div>
<div>
<br><div class="gmail_quote">On Thu, May 16, 2013 at 9:40 AM, Jonathan Olmsted <span dir="ltr"><<a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div class="gmail_default" style="font-size:small">Ditto Kevin's comment. I segfault no matter what.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default">



> sessionInfo()</div><div class="gmail_default">R version 2.15.3 (2013-03-01)</div><div class="gmail_default">Platform: x86_64-apple-darwin12.3.0/x86_64 (64-bit)</div><div class="gmail_default"><br></div><div class="gmail_default">



locale:</div><div class="gmail_default">[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8</div><div class="im"><div class="gmail_default"><br></div><div class="gmail_default">attached base packages:</div>

<div class="gmail_default">

[1] stats     graphics  grDevices utils     datasets  methods   base </div></div></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><br><div><br></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>-------------------------------------------------------------------------<br>



J.P. Olmsted</font></font></font></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font><br></font></font></font></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>029 Corwin (Office)</font></font></font></div>



<div><span style="font-size:small;font-family:arial,helvetica,sans-serif;color:rgb(102,102,102)">130 Corwin Hall (Mail)</span><br></div><div><span style="font-size:small;font-family:arial,helvetica,sans-serif;color:rgb(102,102,102)"><br>



</span></div><div><span style="font-size:small;font-family:arial,helvetica,sans-serif;color:rgb(102,102,102)">Politics Department</span><br></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>Princeton University</font></font></font></div>



<div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>Princeton, NJ 08544</font></font></font></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font><br></font></font></font></div>



<div><font color="#666666"><font face="arial, helvetica, sans-serif"><font><br></font></font></font></div><div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>t: <a href="tel:609.258.6202" value="+16092586202" target="_blank">609.258.6202</a></font></font></font></div>



<div><font color="#666666"><font face="arial, helvetica, sans-serif"><font>f: <a href="tel:609.258.1110" value="+16092581110" target="_blank">609.258.1110</a><br></font></font><font face="arial, helvetica, sans-serif"><a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a></font><br>



</font><div><font face="arial, helvetica, sans-serif"><font color="#666666"><a href="http://about.me/olmjo" target="_blank">http://about.me/olmjo</a><font><br></font><font></font><font>-------------------------------------------------------------------------</font></font><br>



</font></div></div></div></div><div><div class="h5">
<br><br><div class="gmail_quote">On Thu, May 16, 2013 at 12:38 PM, Kevin Ushey <span dir="ltr"><<a href="mailto:kevinushey@gmail.com" target="_blank">kevinushey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div dir="ltr">FWIW, I can reproduce the segfault with this example, whether running R as vanilla or not. <div><br></div><div><div>> sessionInfo()</div><div>R version 3.0.0 (2013-04-03)</div><div>Platform: x86_64-apple-darwin10.8.0 (64-bit)</div>




<div><br></div><div>locale:</div><div>[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8</div><div><br></div><div>attached base packages:</div><div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div>




<div><br></div><div>other attached packages:</div><div>[1] Rcpp_0.10.3</div></div><div><br></div><div>-Kevin</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Thu, May 16, 2013 at 9:01 AM, Matteo Fasiolo <span dir="ltr"><<a href="mailto:matteo.fasiolo@gmail.com" target="_blank">matteo.fasiolo@gmail.com</a>></span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Thanks for your reply Dirk.<div><br></div><div>Maybe I have found something.</div>



<div>Hopefully this is reproducible and simple enough:</div>
<div><br></div><div>/*</div><div>* C++ file "b.cpp" </div>
<div>* Just copying the input matrix into A and returning A.</div><div>*/</div><div><br></div><div><div><div><div>#include <Rcpp.h></div><div><br></div><div>using namespace Rcpp;</div><div><br></div>
<div>// [[Rcpp::export]]</div></div><div>NumericMatrix myFun(NumericMatrix input, int n){</div><div><br></div><div>NumericMatrix A(n, n);</div><div><br></div><div>for(int Row = 0; Row < n; Row++)</div><div>  for(int Col = 0; Col < n; Col++)</div>





<div>  {</div><div>    A(Row, Col) = input(Row, Col);</div><div>  }</div><div><br></div><div>return A;</div><div>}</div></div><div><br></div><div><br></div><div>///////////////////////////////////////////</div><div><br></div>





<div>Then I open a terminal:</div><div><br></div><div><div><div>teo@oracolo:~$ R --vanilla</div><div><br></div><div>R version 3.0.0 (2013-04-03) -- "Masked Marvel"</div><div>Copyright (C) 2013 The R Foundation for Statistical Computing</div>





<div>Platform: x86_64-pc-linux-gnu (64-bit)</div><div>[........]</div><div>Type 'q()' to quit R.</div><div><br></div><div>> library(Rcpp)</div><div>> sourceCpp("~/Desktop/b.cpp")</div><div>> </div>





<div>> #I run it 10 times and everything is fine.</div><div>> n = 10</div><div>> x <- 1:n^2</div><div>> </div><div>> for(ii in 1:10)</div><div>+ { </div><div>+   means <- matrix(x, n, n) </div><div>+   res <- myFun(means, n)</div>





<div>+   a <- res[1, 1]</div><div>+ }</div><div>> res</div><div>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]</div><div> [1,]    1   11   21   31   41   51   61   71   81    91</div><div> [2,]    2   12   22   32   42   52   62   72   82    92</div>





<div> [3,]    3   13   23   33   43   53   63   73   83    93</div><div> [4,]    4   14   24   34   44   54   64   74   84    94</div><div> [5,]    5   15   25   35   45   55   65   75   85    95</div><div> [6,]    6   16   26   36   46   56   66   76   86    96</div>





<div> [7,]    7   17   27   37   47   57   67   77   87    97</div><div> [8,]    8   18   28   38   48   58   68   78   88    98</div><div> [9,]    9   19   29   39   49   59   69   79   89    99</div><div>[10,]   10   20   30   40   50   60   70   80   90   100</div>





<div>> </div><div>> </div><div>> #I run it 10^6 times and everything and I get a segfault.</div><div>> n = 10</div><div>> x <- 1:n^2</div><div>> </div><div>> for(ii in 1:10^6)</div><div>+ { </div>




<div>
+   means <- matrix(x, n, n) </div><div>+   res <- myFun(means, n)</div><div>+   a <- res[1, 1]</div><div>+ }</div><div><br></div><div> *** caught segfault ***</div><div>address (nil), cause 'unknown'</div>





<div><br></div><div>Traceback:</div><div> 1: res[1, 1]</div></div><div><br></div><div><br></div><div>If I run the same code without the --vanilla option it works fine!</div><div>Certainly you know why using --vanilla is a problem here, honestly I've always used that option</div>





<div>because I don't want R to ask me if I want to save the working environment when I quit. </div><div>As you said the problem was coming from R (actually my improper use of R) and hopefully this is it! </div>
<div><br></div></div><div><br></div><div><br></div></div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 16, 2013 at 3:42 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br>





<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Matteo,<br>
<br>
Can you provide a single, self-contained example and calling sequence that<br>
leads to reproducible crashes?<br>
<br>
That would be a bug. And we try to address it in Rcpp.<br>
<br>
As for your "issues" with RNGScope, I'd recommend that you write a C(++)<br>
function called from R __without using Rcpp__ and I very confident that you<br>
would the exact same issue.  Meaning that that all comes form R, which in<br>
itself is a pretty big system with numerous temp. allocations. But generally<br>
no known bug.  So please learn more about R and valgrind -- I suspect that<br>
you are simply getting confused by the copious and somewhat technical output<br>
produced by valgrind when running R.<br>
<div><div><br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</div></div></blockquote></div><br></div></div></div>
<br></div></div><div>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></div></blockquote></div><span><font color="#888888"><br>



<br clear="all"><div>
<br></div>-- <br><div dir="ltr">-Kevin</div>
</font></span></div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div>