Skip to content
Prev 12518 / 63461 Next

Segfault: .Call and classes with logical slots

torsten@hothorn.de writes:
Perhaps this example is an indication that gctorture is too
aggressive.  I use constructions like

   PROTECT(ans = ...);

   SET_SLOT(ans, install("lgl"), allocVector(LGLSXP,1));
   LOGICAL(GET_SLOT(ans, install("lgl")))[0] = TRUE;

in many places in my code, having been assured by a usually reliable
source (Luke) that SET_SLOT applied to a freshly allocated vector
would be atomic with respect to garbage collection.  That is, under
the usual conditions there would be no chance of a garbage
collection being triggered between the allocVector and SET_SLOT
operations.  It may be that gctorture is causing a garbage collection
at a place where it otherwise could not occur and the additional
(UN)PROTECT are redundant except when gctorture is active.

In trying to avoid (UN)PROTECT calls I'm not as concerned about
efficiency as I am about clarity of the code.  I would prefer not to
clutter the code with (UN)PROTECT calls if they are known to be
redundant.

At the time we discussed this Luke suggested that we document a set of
C calls that are atomic with respect to garbage collection.  I think
this would be a good idea but I suspect that no one has the time to do
it right now.