[Rcpp-devel] Segfaults

Romain François romain at r-enthusiasts.com
Wed Jan 4 16:01:38 CET 2012


Le 04/01/12 15:55, Steve Lianoglou a écrit :
> Woops -- seems I misdiagnosed the cause of error, please ignore :-)
>
> Still, I'm surprised the attempted logical (NA) to Numeric conversion
> isn't a source of some potential woes, too?
That is because the NumericVector constructor coerces the logical to a 
numeric.
> On Wed, Jan 4, 2012 at 9:50 AM, Steve Lianoglou
> <mailinglist.honeypot at gmail.com>  wrote:
>> Hi,
>>
>> On Wed, Jan 4, 2012 at 9:33 AM, Hadley Wickham<hadley at rice.edu>  wrote:
>>> Hi all,
>>>
>>> Is it a bug to cause a segfault with Rcpp? Or are am I doing something
>>> so dumb that an automatic check could never protect?  See minimal
>>> reproducible example below.
>>>
>>> Hadley
>>>
>>> library(inline)
>>> f<- cxxfunction(signature(x = "numeric", i = "numeric"), plugin = "Rcpp", '
>>>   Rcpp::NumericVector x_(x);
>>>   Rcpp::NumericVector i_(i);
>>>
>>>   x_[(int) (i_[0]) - 1] = 1000;
>>>
>>>   return(x_);
>>> ')
>>> f(1:10, 1) # works
>>> f(1:10, 1.5) # also works
>>> f(1:10, NA) # segfaults
>> I reckon that's because `NA` is actually of `logical` type, where your
>> first to examples are of the correct (real/double) type.
>>
>> When I use inline for anything semi-permanent (the last step before
>> turning it into a package, let's say), I typically have a thin R
>> wrapper function that calls down to my inline function and I never
>> call the inline function directly anywhere else. The job of the thin R
>> wrapper function is to sanity check and/or coerce the vars to the
>> correct type before they are past to the inline'd function to avoid
>> the segfault.
>>
>> -steve
>>
>>> --
>>> Assistant Professor / Dobelman Family Junior Chair
>>> Department of Statistics / Rice University
>>> http://had.co.nz/
>>> _______________________________________________
>>> Rcpp-devel mailing list
>>> Rcpp-devel at lists.r-forge.r-project.org
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>>
>> --
>> Steve Lianoglou
>> Graduate Student: Computational Systems Biology
>>   | Memorial Sloan-Kettering Cancer Center
>>   | Weill Medical College of Cornell University
>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>
>


-- 
Romain Francois
Professional R Enthusiast
http://romainfrancois.blog.free.fr



More information about the Rcpp-devel mailing list