Skip to content
Prev 12514 / 63461 Next

Segfault: .Call and classes with logical slots

I think you need to PROTECT the vector you're putting in the slot as
well as the overall object.  At any rate, the problem goes away for me
with the revised version of dummy.c below.  (Empirically, PROTECT'ing
the class definition didn't seem to be needed, but experience suggests
that too much protection  is better than too little.)

#include <Rdefines.h>

SEXP foo() {

    SEXP ans, cl, el;

    PROTECT(cl = MAKE_CLASS("test"));
    PROTECT(ans = NEW_OBJECT(cl));
    PROTECT(el = allocVector(LGLSXP, 1));
    SET_SLOT(ans, install("lgl"), el);
    LOGICAL(GET_SLOT(ans, install("lgl")))[0] = TRUE;
    UNPROTECT(3);
    return(ans);
}
Torsten Hothorn wrote: