[Rcpp-devel] Irregular crash with rcpp and inline

Dirk Eddelbuettel edd at debian.org
Sun Apr 15 22:33:58 CEST 2012


Hi David,

On 15 April 2012 at 11:20, Silkworth,David J. wrote:
| While I really appreciated this exchange as informative in tutorial
| sense,
| I am still trying to figure out the cause of Marie's seg-fault.
| 
| Holding Dirk's first fix up to the light with Marie's code all I really
| see is removal of the 
| 
|        #include <cmath>
| 
| directive (which I assume, without looking, is in either inline or
| CircStats libraries).

I believe it is already loaded by Rcpp et al as removing it created no new
errors or warnings.

But you missed the actual indexing mishap I also corrected in my first reply
to Marie. 

Quoting from my email (and indenting for clarity)

   |        for(int j = 1; j < nc+1; j++){
   |          ata[j] = fmod(ata[j-1] + rtac[j],2*PI);
   |        }
   
   Here ata is length nc, yet you let j reach length nc --> one past the boundary.
   
   If I change this, all is good as shown below.

   [...]

     ata[0] = fmod(rtac[0],2*PI);
     for(int j = 1; j < nc; j++){
       ata[j] = fmod(ata[j-1] + rtac[j],2*PI);
     }

So the error was the extra '+ 1' after nc.

 
| However, with the armadillo run it seems that the seg-fault error is
| detected.

Correct, as Armadillo __when compiled without -NDEBUG which is now imposed by
R so that you need to correct for it__ uses bounds checking in the ()
operator and hence catches it.

| (I am also quite amazed that the original signature worked at all.)

Because the interface is RcppArmadillo which uses the same interface from R
as Rcpp.
 
| Is there still some protective error test that is required to avoid
| Marie's seg-fault?

See above. I hope it is clear now.

Cheers, Dirk
 
| _______________________________________________
| 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

-- 
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com


More information about the Rcpp-devel mailing list