[Rcpp-devel] tracking volatile bug

Sokol Serguei serguei.sokol at gmail.com
Sun Nov 23 20:07:31 CET 2014


Gabor Grothendieck has written at  Sat, 22 Nov 2014 19:17:27 -0500
> On Sat, Nov 22, 2014 at 1:43 PM, Sokol Serguei<serguei.sokol at gmail.com>  wrote:
>> Let try to stick with regular rcpp code
>> (file: matrix_norm.cpp):
>>
>> //[[Rcpp::depends(RcppArmadillo)]]
>> #include <RcppArmadillo.h>
>> using namespace Rcpp;
>> using namespace arma;
>>
>> // [[Rcpp::export]]
>> double nmat(mat A) {
>>     Function Matrix_norm_r_=Environment("package:Matrix")["norm"];
>>     double res=as<double>(Matrix_norm_r_(A, "1"));
>>     return res;
>> }
>>
>> When called in R as:
>>
>> library(Rcpp)
>> library(Matrix)
>> sourceCpp("matrix_norm.cpp")
>> gctorture(TRUE)
>> nmat(as.matrix(pi))
>>
>> it gives an error:
>> Erreur : 'getCharCE' doit être appelé sur un CHARSXP
>> (my English translation: Error: 'getCharCE' must be called on CHARSXP)
>>
>> Something was irregular on my side here?
>> Serguei.
> Try replacing the line that sets res with:
>
>     double res=as<double>(Matrix_norm_r_(NumericMatrix(wrap(A)),
> CharacterVector::create("1")));
>
> Be sure to try it on a fresh session since errors from prior runs
> could have messed up R.
Yes, this version works too.
The least change that leads to a working code that I have found (thanks 
to Martin) is

double res=as<double>(Matrix_norm_r_(A, CharacterVector("1")));

but it is still unclear what is wrong with passing a plain string.
In quickref, all examples pass just numbers without any prior conversion
to NumericVector or IntegerVector. Strings are exception to this?
I have an impression that they are supposed to work too without
any explicit conversion. If you set gctorture(FALSE), it works and
there is no warning or error message that plain strings are not supported
in this place.
So, gctorture() reveals that somewhere there is an un-protected pointer
which is getting corrupted. If it is needed to be said, I don't pretend
that this unprotected pointer is in Rcpp code. May be it is in R, may be
in Matrix, it is still unclear.



More information about the Rcpp-devel mailing list