<br><br><div class="gmail_quote">On Tue, Jan 11, 2011 at 1:20 PM, Romain Francois <span dir="ltr">&lt;<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Le 11/01/11 19:12, Davor Cubranic a écrit :<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I think an important point from Doug has been lost in the subsequent 20-odd messages of flamebombing:<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

I do not see this as compatible with the C++ Design principle we use whereby<br>
protection / unprotection occurs relative to the end of scope -- and not<br>
after every single assignment or allocation.<br>
<br>
In other words, gctorture() may well be a fine test for the C API and its<br>
PROTECT and UNPROTECT at every step but possibly not quite as much for Rcpp.<br>
</blockquote>
<br>
I don&#39;t think so.  In the situation that Dominick is describing the C<br>
API is being used (calls to Rf_install, Rf_lang1, Rf_eval, ...) and<br>
you have to play by the rules of the C API.  Essentially every time<br>
that you call a function in the C API that can cause a memory<br>
allocation you are open yourself to the possibility of having the<br>
garbage collector run and getting unprotected SEXPs blown away.  And,<br>
naturally, Rf_eval can cause memory allocation.<br>
<br>
I understood Dominick to be saying that in the code related to Modules<br>
and the evaluator and all that which we have been trying to debug<br>
there are such cases of the use of the C API that are unsafe.<br>
</blockquote>
<br>
Can anyone comment whether this is correct?<br>
<br>
Davor<br>
</blockquote>
<br></div></div>
Yep. Doug&#39;s analysis is right. Rcpp is implemented with the C R API, and apparently there were a few places where we were not careful enough. Most notably in calls to Rf_lcons and Rf_cons. This has been partially dealt with today.<br>
</blockquote><div><br>Just for the record, Doug is summarizing my analysis, based on several examples that I posted to this thread,<br>and that I am pleased to see have inspired some remedial action.<br><br>Dominick<br> <br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
This is not completely over though apparently. The code below still does not support the torture.<br>
<br>
To be continued ...<br>
<br>
Romain<br>
<br>
<br>
<br>
<br>
require(inline)<br>
require(Rcpp)<br>
inc &lt;- &#39;<br>
<br>
class Randomizer {<br>
public:<br>
<br>
    // Randomizer() : min(0), max(1){}<br>
    Randomizer( double min_, double max_) : min(min_), max(max_){}<br>
<br>
    NumericVector get( int n ){<br>
        RNGScope scope ;<br>
        return runif( n, min, max );<br>
    }<br>
<br>
private:<br>
    double min, max ;<br>
} ;<br>
<br>
RCPP_MODULE(mod){<br>
<br>
    class_&lt;Randomizer&gt;( &quot;Randomizer&quot; )<br>
<br>
        // No default: .default_constructor()<br>
        .constructor&lt;double,double&gt;()<br>
<br>
        .method( &quot;get&quot; , &amp;Randomizer::get ) ;<br>
<br>
}<br>
&#39;<br>
    fx &lt;- cxxfunction( , &#39;&#39;, includes = inc, plugin = &quot;Rcpp&quot; )<br>
<br>
mod &lt;- Module( &quot;mod&quot;, getDynLib( fx ) )<br>
gctorture(TRUE)<br>
Rcpp:::.getModulePointer( mod )<br><font color="#888888">
<br>
<br>
-- <br></font><div class="im">
Romain Francois<br>
Professional R Enthusiast<br>
+33(0) 6 28 91 30 30<br>
<a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.free.fr</a><br>
|- <a href="http://bit.ly/fT2rZM" target="_blank">http://bit.ly/fT2rZM</a> : highlight 0.2-5<br>
|- <a href="http://bit.ly/gpCSpH" target="_blank">http://bit.ly/gpCSpH</a> : Evolution of Rcpp code size<br>
`- <a href="http://bit.ly/hovakS" target="_blank">http://bit.ly/hovakS</a> : RcppGSL initial release<br>
<br>
<br>
_______________________________________________<br></div><div><div></div><div class="h5">
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></div></blockquote></div><br>