[Rcpp-devel] (Very) rare segfault

Romain Francois romain at r-enthusiasts.com
Thu Aug 21 11:58:24 CEST 2014


Le 21 août 2014 à 11:47, Gregor Kastner <gregor.kastner at wu.ac.at> a écrit :

> On Thu, 21 Aug 2014 11:34:23 +0200
> Romain Francois <romain at r-enthusiasts.com> wrote:
> 
> GK> Yep, sorry for the misuse of language. And I do understand going back to
> GK> GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely
> GK> confirm that it seems to be safer than resorting do the
> GK> constructor/destuctor magic.
>> 
>> Compiler/Destructor is not magic. It is determinism. 
>> 
>> That's like feature #1 of C++. 
> 
> agreed: s/magic/automagic/g
> 
>> And BTW it is definitely safer than any manual handling.  
> 
> I cannot say that in the current case, as relying on the destructor does seem
> to create problems (in rare cases, making it even worse!) if objects which
> are to be returned are instantiated after the RNGScope object. Conditional on
> the fact the I understood JJ correctly, that is.

Then it's a bug in how constructor or destructor is implemented in this class, probably with the counter. 

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. 

Without a repex anyway, it is hard to diagnose what's happening. 

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.

> Manual handling works perfectly.
> 
> Best,
> /g



More information about the Rcpp-devel mailing list