<br><br><div class="gmail_quote">On Sun, Jan 9, 2011 at 8:02 AM, Douglas Bates <span dir="ltr">&lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</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;">
<div class="im">On Sun, Jan 9, 2011 at 12:45 AM, Dominick Samperi &lt;<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>&gt; wrote:<br>
&gt; Doug,<br>
&gt;<br>
&gt; I think the problem is resolved. I wasted a lot of time trying to debug the<br>
&gt; new<br>
&gt; Module code, and didn&#39;t think to try gctorture() with older code that has<br>
&gt; worked<br>
&gt; for a long time. That code failed too!<br>
&gt;<br>
&gt; The attached file tortureFix.cpp shows the kind of fix that is needed in<br>
&gt; some of the Rcpp code, for example, in Reference.cpp, and perhaps in<br>
&gt; other files. The attached script torture.R tests this function with/without<br>
&gt; the suggested fix.<br>
&gt;<br>
&gt; The unsafe code may or may not fail for you. It depends on the<br>
&gt; machine/compiler, but because it can fail it is wrong. It fails consistently<br>
&gt; under Windows using Visual C++, for example, which is a good reason<br>
&gt; why software should be tested using compilers other than GCC, and testing<br>
&gt; with gctorture() is obviously a good idea as well.<br>
<br>
</div>I was filled with hope that it would work to PROTECT all those<br>
instances of creating a call, then UNPROTECTing after evaluation.  I<br>
think I got them all but my modified version still fails at the same<br>
point.<br>
<br>
&gt; library(Uniform)<br>
Loading required package: Rcpp<br>
&gt; gctorture(TRUE)<br>
&gt; Rcpp:::.getModulePointer(unif_module)<br>
Before the evaluation in Evaluator::run, call is<br>
rcpp_tryCatch(evalq(new(&quot;C++Field&quot;), &lt;environment&gt;))<br>
After the evaluation in Evaluator::run<br>
Error in list(c(76904L, 80L),<br>
&quot;/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/R/Rcpp.rdb&quot;,<br>
<div class="im">TRUE, function (n)  :<br>
  unused argument(s)<br>
</div>(&quot;/home/bates/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/R/Rcpp.rdb&quot;,<br>
TRUE, function (n)<br></blockquote><div><br>This is the same error message you get if you do not apply the<br>PROTECTION fixes, so the remaining problem may be of the<br>same nature, but perhaps not as transparent...<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 in Evaluator::run where after the evaluation when the error<br>
code is being retrieved.<br>
<br>
I agree that any SEXP that gets created should be PROTECTed and<br>
appreciate your efforts in helping to debug this.<br>
<br>
I am trying a slightly different approach for the installation of the<br>
error indicator and codes from rcpp_tryCatch.<br>
<div><div></div><div class="h5"><br>
&gt; On Sat, Jan 8, 2011 at 2:06 PM, Douglas Bates &lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Jan 8, 2011 at 12:57 PM, Dominick Samperi &lt;<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Sat, Jan 8, 2011 at 9:48 AM, Douglas Bates &lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Sat, Jan 8, 2011 at 7:49 AM, Douglas Bates &lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt;<br>
&gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt; On Sat, Jan 8, 2011 at 12:45 AM, Dominick Samperi<br>
&gt;&gt; &gt;&gt; &gt; &lt;<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;&gt; I checked things under Linux and Windows (using GCC and VC++ DLL&#39;s)<br>
&gt;&gt; &gt;&gt; &gt;&gt; and<br>
&gt;&gt; &gt;&gt; &gt;&gt; the<br>
&gt;&gt; &gt;&gt; &gt;&gt; same problem occurs at the same place, which is a good sign when it<br>
&gt;&gt; &gt;&gt; &gt;&gt; comes to<br>
&gt;&gt; &gt;&gt; &gt;&gt; memory issues. Basically, the Rcpp::Reference(std::string)<br>
&gt;&gt; &gt;&gt; &gt;&gt; constructor<br>
&gt;&gt; &gt;&gt; &gt;&gt; that<br>
&gt;&gt; &gt;&gt; &gt;&gt; is<br>
&gt;&gt; &gt;&gt; &gt;&gt; part of S4_field, or S4_CppOverloadedMethods constructors fails,<br>
&gt;&gt; &gt;&gt; &gt;&gt; depending<br>
&gt;&gt; &gt;&gt; &gt;&gt; on<br>
&gt;&gt; &gt;&gt; &gt;&gt; which comes first (whether there are fields or not). This only<br>
&gt;&gt; &gt;&gt; &gt;&gt; happens<br>
&gt;&gt; &gt;&gt; &gt;&gt; when<br>
&gt;&gt; &gt;&gt; &gt;&gt; gctorture() is turned on, so R must be clobbering an unprotected<br>
&gt;&gt; &gt;&gt; &gt;&gt; SEXP<br>
&gt;&gt; &gt;&gt; &gt;&gt; somewhere...<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thanks, Dominick. I too have been working on tracking this down and<br>
&gt;&gt; &gt;&gt; &gt; got to that point.  If you follow a little further you will find that<br>
&gt;&gt; &gt;&gt; &gt; it is the evaluation of the R function getCurrentErrorMessage in the<br>
&gt;&gt; &gt;&gt; &gt; Rcpp::Evaluator::run method where things start to go bad, as far as I<br>
&gt;&gt; &gt;&gt; &gt; can see.  I hope to be able to isolate this today as I need a working<br>
&gt;&gt; &gt;&gt; &gt; version of lme4a by tomorrow.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; My current theory is that Rcpp_cache is being blown away by the<br>
&gt;&gt; &gt;&gt; garbage collector.  Because we want this to be persistent I think the<br>
&gt;&gt; &gt;&gt; simplest thing to do is to assign it to a name like .Rcpp_cache in the<br>
&gt;&gt; &gt;&gt; namespace during the .onLoad function.  I&#39;ll try that.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I tested this theory by cutting out the Evaluator code and it appears<br>
&gt;&gt; &gt; that<br>
&gt;&gt; &gt; the cache is not harmed by gctorture(). I suspect that the problem may<br>
&gt;&gt; &gt; be earlier in the chain of construction, either a SEXP that was not<br>
&gt;&gt; &gt; preserved,<br>
&gt;&gt; &gt; or an aliasing problem. It appears that init_Rcpp_cache() is called<br>
&gt;&gt; &gt; twice<br>
&gt;&gt; &gt; at start-up, which does not seem right, but suppressing the second<br>
&gt;&gt; &gt; attempt<br>
&gt;&gt; &gt; does not fix the problem.<br>
&gt;&gt;<br>
&gt;&gt; The second call was eliminated in the SVN archive a couple of days<br>
&gt;&gt; ago.  I have gotten around some of the problems with the garbage<br>
&gt;&gt; collection by redefining how the Rcpp_cache variable is created (not<br>
&gt;&gt; yet checked in) so it progresses further.  I still think that there is<br>
&gt;&gt; a point where a promise in not being evaluated before being used but<br>
&gt;&gt; haven&#39;t found it yet.<br>
&gt;&gt;<br>
&gt;&gt; With lazyLoad enabled the first time that you find a variable in the<br>
&gt;&gt; namespace it will have a PROMSXP typeof field and you need to invoke<br>
&gt;&gt; Rf_eval on it to actually get the value.  There are several variables<br>
&gt;&gt; from the Rcpp namespace being used here, which is why I am suspicious<br>
&gt;&gt; that an unevaluated promise is somehow getting used.<br>
&gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; On Fri, Jan 7, 2011 at 9:47 AM, Romain Francois<br>
&gt;&gt; &gt;&gt; &gt;&gt; &lt;<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Hmm. I commited 2845 and 2846 today.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Anyway, if you see it also with 0.9.0 this means more detective<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; work.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Le 07/01/11 15:05, Douglas Bates a écrit :<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; On Fri, Jan 7, 2011 at 5:34 AM, Romain Francois<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; &lt;<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>&gt;  wrote:<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; Le 05/01/11 18:52, Douglas Bates a écrit :<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; I don&#39;t know whether this is through error on my part or because<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; of<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; an<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; &quot;infelicity&quot; in the Rcpp module code but the lme4a package,<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; which<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; now<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; uses Rcpp modules extensively, ends up with some<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; difficult-to-trace<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; memory corruption issues.  Yesterday i finally bit the bullet<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; and<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; ran<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; a test with gctorture(TRUE) and valgrind enabled.  It takes a<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; very<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; long time and results in a segfault when trying to load the<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; package.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; I enclose the transcript.  I should say that this is using<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; Rcpp_0.9.0<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; from CRAN, not the SVN version of Rcpp.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; I just got these results this morning (it was running overnight)<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; and<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; haven&#39;t looked at the code in Module.cpp and cache.cpp yet.  If<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; it<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; seems likely that the code is beyond me I can try to work out a<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;&gt; simpler example that triggers the problem.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; Hi Doug,<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; Sorry for the delay, I&#39;m not fully operational yet.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; All this might be related to some code I put in during holidays<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; and<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; did<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; not<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; have a chance to fully test.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; Can you try with rev 2845 and let me know if you still see the<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; problem.<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;&gt; Romain<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; Regrettably the problem persists with rev 2845 (which was from<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; 2011-01-04, is that the one you meant?) but it is also present<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; when<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;&gt; using Rcpp_0.9.0<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; --<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Romain Francois<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Professional R Enthusiast<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; +33(0) 6 28 91 30 30<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; <a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.free.fr</a><br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; |- <a href="http://bit.ly/fT2rZM" target="_blank">http://bit.ly/fT2rZM</a> : highlight 0.2-5<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; |- <a href="http://bit.ly/gpCSpH" target="_blank">http://bit.ly/gpCSpH</a> : Evolution of Rcpp code size<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; `- <a href="http://bit.ly/hovakS" target="_blank">http://bit.ly/hovakS</a> : RcppGSL initial release<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; Rcpp-devel mailing list<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;&gt; <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>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>