[Rd] C function is wrong under Windows 7
Thomas Lumley
tlumley at uw.edu
Mon Oct 24 18:36:53 CEST 2011
On Mon, Oct 24, 2011 at 6:04 AM, Evarist Planet
<evarist.planet at irbbarcelona.org> wrote:
> Dear mailing list,
>
> I have a C function that gives me a wrong result when I run it under Windows
> 7.
The fact that you extract pointers to the contents of fchr and sign
before coercing them to REALSXP is deeply suspicious to me, though I
admit I don't see how it causes the problem, since you don't use the
new versions, you don't overwrite them, and the old versions should
still be protected as arguments to the function.
> SEXP getEs(SEXP fchr, SEXP sign)
> {
> int i, nfchr, nsign;
> double *rfchr = REAL(fchr), *res;
> int *rsign = INTEGER(sign);
>
> PROTECT(fchr = coerceVector(fchr, REALSXP));
> PROTECT(sign = coerceVector(sign, REALSXP));
>
> nfchr = length(fchr);
> nsign = length(sign);
>
> SEXP es;
> PROTECT(es = allocVector(REALSXP, nfchr));
> res = REAL(es);
>
> double nr = getNr(rfchr, rsign, nsign);
>
> SEXP phit;
> PROTECT(phit = allocVector(REALSXP, nfchr));
> double *rphit;
> rphit = REAL(phit);
> for(i = 0; i < nfchr; i++) rphit[i] = 0.0;
> getPhit(rfchr, rsign, nsign, nr, rphit);
> cumsum(rphit, nfchr);
>
> SEXP pmiss;
> PROTECT(pmiss = allocVector(REALSXP, nfchr));
> double *rpmiss;
> rpmiss = REAL(pmiss);
> for(i = 0; i < nfchr; i++) rpmiss[i] = 0.0;
> getPmiss(rsign, nfchr, nsign, rpmiss);
> cumsum(rpmiss, nfchr);
>
> for (i = 0; i < nfchr; ++i) {
> res[i] = rphit[i] - rpmiss[i];
> }
>
> UNPROTECT(5);
> return es;
> }
>
> Could you please help me to find out what I am doing wrong?
>
> Many thanks in advance,
>
> --
> Evarist Planet
> Research officer, Bioinformatics and Biostatistics unit
> IRB Barcelona
> Tel (+34) 93 402 0553
> Fax (+34) 93 402 0257
>
> evarist.planet at irbbarcelona.org
> http://www.irbbarcelona.org/bioinformatics
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Thomas Lumley
Professor of Biostatistics
University of Auckland
More information about the R-devel
mailing list