R CMD check: OK in LINUX. Crashes in Windows!

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

R CMD check: OK in LINUX. Crashes in Windows!

rtaylor
Hi,

I have followed the recommended steps for creating a package (rctest). As of
now, my goal is simply to understand how various pieces fit together. The
package includes:
(1) C code with source in sub-directories, compiled to create a static
library.
(a) There is a single C-struct (dns) a simple 'matrix': {int m; int n;
double *d;}
(b) C code to create random matrix of a certain size.
(c) C code to free a dns object.

(2) R-C wrappers.
 (a) There is an S4 class (RDns) with a single slot, an external pointer to
a C-struct (dns).
 (b) C code to create an RDns object from an R matrix. Data from the R
matrix is copied to the C dns object.
 (c) C code to copy data from an RDns object to an R matrix.
 (d)  init.c with registration routines and also a finalizer for the
external pointer.
(3) Makevars, NAMESPACE, Registration etc.
(4) Documentation for all exported functions.

The package passes all tests in R CMD check under Ubuntu. Everything seems
to work fine.

In Windows (using Rtools), R CMD check crashes at the end of the check.  At
various times, the log indicates that all checks were OK and the pdf manual
was created. Yet the console crashes.
At other times "examples" fail to run and console crashes. However, the
actual package loads fine and all of the functions work just fine from
within R. Finalizer also works as expected when invoked by gc().

At this point, I do not have any idea as to where or how I should look for
the source of the problem. I am afraid, there may be something wrong with my
code, but am not sure how to search for the bug.
What other tests should I create to perform extensive tests that all parts
of the code work as expected??

Any help will be appreciated.

Thanks,
bug.

Russ

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R CMD check: OK in LINUX. Crashes in Windows!

Uwe Ligges-3
Hard to say anything if we do not see any details from your package, but
very likely you just had some luck under Ubuntu not to see any crashes...

Uwe Ligges



On 18.02.2010 18:12, rt wrote:

> Hi,
>
> I have followed the recommended steps for creating a package (rctest). As of
> now, my goal is simply to understand how various pieces fit together. The
> package includes:
> (1) C code with source in sub-directories, compiled to create a static
> library.
> (a) There is a single C-struct (dns) a simple 'matrix': {int m; int n;
> double *d;}
> (b) C code to create random matrix of a certain size.
> (c) C code to free a dns object.
>
> (2) R-C wrappers.
>   (a) There is an S4 class (RDns) with a single slot, an external pointer to
> a C-struct (dns).
>   (b) C code to create an RDns object from an R matrix. Data from the R
> matrix is copied to the C dns object.
>   (c) C code to copy data from an RDns object to an R matrix.
>   (d)  init.c with registration routines and also a finalizer for the
> external pointer.
> (3) Makevars, NAMESPACE, Registration etc.
> (4) Documentation for all exported functions.
>
> The package passes all tests in R CMD check under Ubuntu. Everything seems
> to work fine.
>
> In Windows (using Rtools), R CMD check crashes at the end of the check.  At
> various times, the log indicates that all checks were OK and the pdf manual
> was created. Yet the console crashes.
> At other times "examples" fail to run and console crashes. However, the
> actual package loads fine and all of the functions work just fine from
> within R. Finalizer also works as expected when invoked by gc().
>
> At this point, I do not have any idea as to where or how I should look for
> the source of the problem. I am afraid, there may be something wrong with my
> code, but am not sure how to search for the bug.
> What other tests should I create to perform extensive tests that all parts
> of the code work as expected??
>
> Any help will be appreciated.
>
> Thanks,
> bug.
>
> Russ
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R CMD check: OK in LINUX. Crashes in Windows!

rtaylor
In reply to this post by rtaylor
There seem to be some issues with Windows 7 user accounts

(1)

Windows 7 64bit: User Account

Check.log - failed examples

sh.exe: The application was unable to start correctly (0Xc0000142)

Even when CMD.exe and sh.exe are run under admin privilege. This is however
not consistent. Sh.exe executes every once in a while and example file runs.



 (2)

Windows 7 64bit: Admin Account

Check log: All tests OK, BUT the command window closes at the end, even with
option --no-examples/--no-latex.



(3)

Ubuntu:

R CMD check --use-gct --use-valgrind

All tests OK.

==3367== HEAP SUMMARY:

==3367==     in use at exit: 9,651,319 bytes in 4,201 blocks

==3367==   total heap usage: 23,068 allocs, 18,867 frees, 29,072,255 bytes
allocated

==3367==

==3367== LEAK SUMMARY:

==3367==    definitely lost: 80 bytes in 2 blocks

==3367==    indirectly lost: 240 bytes in 20 blocks

==3367==      possibly lost: 7,267,004 bytes in 3,766 blocks

==3367==    still reachable: 2,383,995 bytes in 413 blocks

==3367==         suppressed: 0 bytes in 0 blocks

==3367== Rerun with --leak-check=full to see details of leaked memory

==3367==

==3367== For counts of detected and suppressed errors, rerun with: -v

==3367== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 60 from 13)



 (4)

Ubuntu:

The above examples run from within R with valgrind:

R -d valgrind < rctest-Ex.R



==20540== LEAK SUMMARY:

==20540==    definitely lost: 80 bytes in 2 blocks

==20540==    indirectly lost: 168 bytes in 14 blocks

==20540==      possibly lost: 7,580,784 bytes in 3,936 blocks

==20540==    still reachable: 2,382,065 bytes in 413 blocks

==20540==         suppressed: 0 bytes in 0 blocks

==20540==

==20540== For counts of detected and suppressed errors, rerun with: -v

==20540== ERROR SUMMARY: 1026 errors from 1026 contexts (suppressed: 58 from
11)



On the Windows side, there are clearly issues related to how Rtools function
under different user previleges.

All R related directories have there security setting to allow all user full
access.



On the ubuntu side, I am not sure how to interpret Valgrind results.

R CMD check with valgrind shows no errors

R -d valgrind shows some errors.

Valgrind output file did not include any reference to any of my .c files.



I am not sure how to proceed.



Thanks,


Russ


Hard to say anything if we do not see any details from your package, but
very likely you just had some luck under Ubuntu not to see any crashes...

Uwe Ligges

On 18.02.2010 18:12, rt wrote:
> Hi,
>
> I have followed the recommended steps for creating a package (rctest). As
of

> now, my goal is simply to understand how various pieces fit together. The
> package includes:
> (1) C code with source in sub-directories, compiled to create a static
> library.
> (a) There is a single C-struct (dns) a simple 'matrix': {int m; int n;
> double *d;}
> (b) C code to create random matrix of a certain size.
> (c) C code to free a dns object.
>
> (2) R-C wrappers.
>   (a) There is an S4 class (RDns) with a single slot, an external pointer
to

> a C-struct (dns).
>   (b) C code to create an RDns object from an R matrix. Data from the R
> matrix is copied to the C dns object.
>   (c) C code to copy data from an RDns object to an R matrix.
>   (d)  init.c with registration routines and also a finalizer for the
> external pointer.
> (3) Makevars, NAMESPACE, Registration etc.
> (4) Documentation for all exported functions.
>
> The package passes all tests in R CMD check under Ubuntu. Everything seems
> to work fine.
>
> In Windows (using Rtools), R CMD check crashes at the end of the check.
 At
> various times, the log indicates that all checks were OK and the pdf
manual
> was created. Yet the console crashes.
> At other times "examples" fail to run and console crashes. However, the
> actual package loads fine and all of the functions work just fine from
> within R. Finalizer also works as expected when invoked by gc().
>
> At this point, I do not have any idea as to where or how I should look for
> the source of the problem. I am afraid, there may be something wrong with
my

> code, but am not sure how to search for the bug.
> What other tests should I create to perform extensive tests that all parts
> of the code work as expected??
>
> Any help will be appreciated.
>
> Thanks,
> bug.
>
> Russ

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R CMD check: OK in LINUX. Crashes in Windows!

rtaylor
In reply to this post by rtaylor
Hi,

C code for this problem is embedded. I am not clear about the
R_interface.c.
I would appreciate if someone could point out problems that may lead to
sporadic problems?

Thanks,

Russ

//c_mat.h
 typedef struct cMatrix {
        int m;
        int n;
        double *d;
    } c_mat;
//c_mat.c
void
c_mat_free( c_mat *A ) {
    assert( A != NULL );
    if ( A->d != NULL ) {
        free( A->d );
        A->d = NULL;
    }
    free( A );
    A = NULL;
}
//R_interface.c
// Copies ordinary R matrix (r_matrix)
// and returns an S4 object of type RMat (r_mat)
// RMat has a single slot a pointer (ptr_c_mat)
// to C object of type c_mat (D)
SEXP copy_mat_rtoc(SEXP r_matrix)
{
 SEXP r_mat;
    PROTECT(r_mat = NEW_OBJECT(MAKE_CLASS("RMat")));
 SEXP dims, rptr_c_mat;
 int m,n,i;
 dims = GET_DIM(r_matrix);//needs protecting?
 m = INTEGER(dims)[0];
 n = INTEGER(dims)[1];
 c_mat *D = (c_mat*) malloc(sizeof(c_mat));assert(D);
        D->m = m;
        D->n = n;
        D->d = (double*) calloc(m*n, sizeof(double));assert(D->d);
        for (i = 0; i < m*n; i++){D->d[i] = REAL(r_matrix)[i];}
        PROTECT(rptr_c_mat = R_MakeExternalPtr(D, R_NilValue, R_NilValue));
        R_RegisterCFinalizer(rptr_c_mat, R_mat_free);
  SET_SLOT(r_mat, install("ptr_c_mat"), rptr_c_mat);
        UNPROTECT(2);
 return r_mat;
}
//Finalizer for rptr_c_mat
static void R_mat_free(SEXP rptr_c_mat)
{
    REprintf("Finalizing\n");
 if (TYPEOF(rptr_c_mat) != EXTPTRSXP) error("Argument is not an external
pointer");
 c_mat* m = R_ExternalPtrAddr(rptr_c_mat);
 c_mat_free(m);
    R_ClearExternalPtr(rptr_c_mat);
 REprintf("Finalized\n");
}
// Copies an S4 object of type RMat (r_mat) to an R matrix (r_matrix)
// Data from the C object c_mat pointed to by rptr_c_mat is copied to
// r_matrix
SEXP copy_mat_ctor(SEXP r_mat)
{
 if(!IS_S4_OBJECT(r_mat)) error("'r_mat' must be a RMat object");
 SEXP rptr_c_mat = GET_SLOT(r_mat, install("ptr_c_mat"));//needs protecting?
 c_mat *d = R_ExternalPtrAddr(rptr_c_mat);
 SEXP r_matrix;
 PROTECT( r_matrix  = allocMatrix(REALSXP, d->m , d->n ) ) ;
 int i;
    for (i = 0; i < d->m*d->n; i++){REAL( r_matrix )[i] = d->d[i];}
    UNPROTECT(1);
    return r_matrix;
}
//init.c
SEXP copy_mat_ctor(SEXP);
SEXP copy_mat_rtoc(SEXP);
 static  R_CallMethodDef CallDef[] = {
    {"copy_mat_rtoc", (DL_FUNC)&copy_mat_rtoc, 1},
    {"copy_mat_ctor", (DL_FUNC)&copy_mat_ctor, 1},
 {NULL, NULL, 0},
};
void
R_init_rctest(DllInfo *dll)
{
    R_registerRoutines(dll, NULL, CallDef, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}
/*
Invoked as:
a <- matrix(rnorm(200),40,50)
b <- copyMatrixToRMat(a)
c <- copyRMatToMatrix(b)
rm(a)
rm(b)
rm(c)
gc() ## This prints out the message from the finalizer
*/

Hi,

I have followed the recommended steps for creating a package (rctest). As of
now, my goal is simply to understand how various pieces fit together. The
package includes:

Russ

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel