<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">That makes sense. No real reason not to use attributes anyway :) <div><br></div><div><div><div>Le 21 août 2014 à 15:54, JJ Allaire <<a href="mailto:jj@rstudio.com">jj@rstudio.com</a>> a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite">Yes, the link posted by Matteo is what provoked us to make the change in Rcpp Attributes to dance around the constructor/destructor issues. <div><br></div><div>Net: If you are using attributes then this isn't a concern, if you are not then you need the return value SEXP on the stack prior to RNGScope.<br>
<br>On Thursday, August 21, 2014, Romain Francois <<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Ah interesting. PutRNGstate does indeed allocate so might trigger GC. <div><a href="https://github.com/wch/r-source/blob/fbf5cdf29d923395b537a9893f46af1aa75e38f3/src/main/RNG.c#L437" target="_blank">https://github.com/wch/r-source/blob/fbf5cdf29d923395b537a9893f46af1aa75e38f3/src/main/RNG.c#L437</a></div>
<div><br></div><div>That's a whole new Pandora's box right there. </div><div><br></div><div><div><div>Le 21 août 2014 à 12:10, Matteo Fasiolo <<a href="javascript:_e(%7B%7D,'cvml','matteo.fasiolo@gmail.com');" target="_blank">matteo.fasiolo@gmail.com</a>> a écrit :</div>
<br><blockquote type="cite"><div dir="ltr">Hi Romain and Gregor,<div><br></div><div>maybe I am misunderstanding everything, but hasn't this problem been explained and solved here:<br><br><a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-May/005838.html" target="_blank">http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-May/005838.html</a></div>


<div><br></div><div>Best,</div><div><br></div><div>Matteo<br><div><br></div><div> </div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 21, 2014 at 10:58 AM, Romain Francois <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','romain@r-enthusiasts.com');" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Le 21 août 2014 à 11:47, Gregor Kastner <<a href="javascript:_e(%7B%7D,'cvml','gregor.kastner@wu.ac.at');" target="_blank">gregor.kastner@wu.ac.at</a>> a écrit :<br>
<br>
> On Thu, 21 Aug 2014 11:34:23 +0200<br>
> Romain Francois <<a href="javascript:_e(%7B%7D,'cvml','romain@r-enthusiasts.com');" target="_blank">romain@r-enthusiasts.com</a>> wrote:<br>
><br>
> GK> Yep, sorry for the misuse of language. And I do understand going back to<br>
> GK> GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely<br>
> GK> confirm that it seems to be safer than resorting do the<br>
> GK> constructor/destuctor magic.<br>
>><br>
>> Compiler/Destructor is not magic. It is determinism.<br>
>><br>
>> That's like feature #1 of C++.<br>
><br>
> agreed: s/magic/automagic/g<br>
><br>
>> And BTW it is definitely safer than any manual handling.<br>
><br>
> I cannot say that in the current case, as relying on the destructor does seem<br>
> to create problems (in rare cases, making it even worse!) if objects which<br>
> are to be returned are instantiated after the RNGScope object. Conditional on<br>
> the fact the I understood JJ correctly, that is.<br>
<br>
Then it's a bug in how constructor or destructor is implemented in this class, probably with the counter.<br>
<br>
Or something invalidates the very assumptions of C++ here. Perhaps raw R api is called and the destructor is not called because of some long jump or something.<br>
<br>
Without a repex anyway, it is hard to diagnose what's happening.<br>
<br>
You're probably onto somthing, but going directly to the "destructor are not safe, I'll just use C function calls" is a dangerous route, soon you'll start using SEXP as you won't trust ctors/dtors of Rcpp objects do the right thing.<br>



<br>
> Manual handling works perfectly.<br>
><br>
> Best,<br>
> /g<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','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>
</blockquote></div><br></div></div></blockquote></div>
</blockquote></div><br></div></body></html>