[Rcpp-devel] R CMD BATCH - segfault (was: Create and access several instances of a C++ class from R)
Douglas Bates
bates at stat.wisc.edu
Fri May 20 17:26:35 CEST 2011
On Fri, May 20, 2011 at 5:01 AM, <soeren.vogel at uzh.ch> wrote:
> On 18.05.2011, at 15:17, Douglas Bates wrote:
>
>> On May 18, 2011 2:53 AM, <soeren.vogel at uzh.ch> wrote:
>>
>>> [...]
>>>
>>> When librarying the class, assigning an object, do some calculations,
>>> whatever -- everything goes fine. Yet, when using R CMD BATCH on a file
>>> listing the same commands as by hand, R produces some nice information at
>>> the end, however, here it produces an segmentation fault, which does --
>>> according to my small knowledge -- say something bad:
>>>
>>> proc.time()
>>> user system elapsed
>>> 0.702 0.017 0.714
>>> R(72992) malloc: *** error for object 0x2c9b604: incorrect checksum for
>>> freed object - object was probably modified after being freed.
>>> *** set a breakpoint in malloc_error_break to debug
>>>
>>> *** caught segfault ***
>>> address 0x4909d58, cause 'memory not mapped'
>>>
>>> Traceback:
>>> 1: save(list = ls(envir = .GlobalEnv, all.names = TRUE), file = outfile,
>>> version = version, ascii = ascii, compress = compress, envir =
>>> .GlobalEnv, precheck = FALSE)
>>> 2: save.image(name)
>>> 3: sys.save.image(".RData")
>>> aborting ...
>>>
>>> Any idea what goes wrong there?
>>
>> As you can see, the problem occurs when R is saving the worksheet. At
>> present an instance of a Rcpp module class cannot be saved. It is likely
>> that this will need to be addressed by the person designing each C++ class
>> that will be expressed in a module. R can't serialize the contents of
>> memory that it doesn't "own".
>>
>> The current fix is "don't do that". Add the --no-save or --vanilla in your
>> call to R CMD BATCH to suppress saving the worksheet.
>
> Hello Douglas
>
> Ah, I see. Thanks for this tip.
>
> However, I am wondering why removing objects and detaching the package (where the Rcpp module resides) do not resolve the issue in the same way:
>
> x <- new(FOO)
> do_something_with_x()
> rm(x)
> detach("package:GUTS")
You are counting on being able to clean out everything that the
modules have created in the .GlobalEnv and it is entirely possible
that there are still a few pieces left in various corners. It is
simplest to avoid trying to save the worksheet.
More information about the Rcpp-devel
mailing list