Re: [Rd] formal argument "envir" matched by multiple actual arguments

From: Hervé Pagès <hpages_at_fhcrc.org>
Date: Fri, 12 Jun 2009 18:06:57 -0700

That's great news Luke! Thanks for finding and fixing that one! I will do some testing and update the BioC build system with the latest R.

H.

luke_at_stat.uiowa.edu wrote:

> On Tue, 2 Jun 2009, luke_at_stat.uiowa.edu wrote:
> 

>> On Tue, 2 Jun 2009, Henrik Bengtsson wrote:
>>
>>> Nice case - I think you're onto something. /Henrik
>>>
>>> 2009/6/2 <hpages_at_fhcrc.org>:
>>>> In fact reg.finalizer() looks like a dangerous feature.
>>>>
>>>> If the finalizer itself triggers (implicitely or
>>>> explicitely) garbage collection, then bad things happen.
>>>> In the following example, garbage collection is triggered
>>>> explicitely (using R-2.9.0):
>>>>
>>>> setClass("B", representation(bb="environment"))
>>>>
>>>> newB <- function()
>>>> {
>>>> ans <- new("B", bb=new.env())
>>>> reg.finalizer(ans_at_bb,
>>>> function(e)
>>>> {
>>>> gc()
>>>> cat("cleaning", class(ans), "object...\n")
>>>> }
>>>> )
>>>> return(ans)
>>>> }
>>>>
>>>> > for (i in 1:500) {cat(i, "\n"); b1 <- newB()}
>>>> 1
>>>> 2
>>>> 3
>>>> 4
>>>> 5
>>>> 6
>>>> ...
>>>> 13
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> 14
>>>> ...
>>>> 169
>>>> 170
>>>> 171
>>>> Error: not a weak reference
>>>> Error: not a weak reference
>>>> [repeat the above line thousands of times]
>>>> ...
>>>> Error: not a weak reference
>>>> Error: not a weak reference
>>>> cleaning B object...
>>>> Error: SET_VECTOR_ELT() can only be applied to a 'list', not a
>>>> 'integer'
>>>> Error: SET_VECTOR_ELT() can only be applied to a 'list', not a
>>>> 'integer'
>>>> [repeat the above line thousands of times]
>>>> ...
>>>> Error: SET_VECTOR_ELT() can only be applied to a 'list', not a
>>>> 'integer'
>>>> Error: SET_VECTOR_ELT() can only be applied to a 'list', not a
>>>> 'integer'
>>>> 172
>>>> ...
>>>> 246
>>>> 247
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>> cleaning B object...
>>>>
>>>> *** caught segfault ***
>>>> address 0x41, cause 'memory not mapped'
>>>>
>>>> Traceback:
>>>> 1: gc()
>>>> 2: function (e) { gc() cat("cleaning", class(ans),
>>>> "object...\n")}(<environment>)
>>>>
>>>> Possible actions:
>>>> 1: abort (with core dump, if enabled)
>>>> 2: normal R exit
>>>> 3: exit R without saving workspace
>>>> 4: exit R saving workspace
>>>> Selection: 2
>>>> Save workspace image? [y/n/c]: n
>>>> Segmentation fault
>>>>
>>>> So apparently, if the finalizer triggers garbage collection,
>>>> then we can end up with a corrupted session. Then anything can
>>>> happen, from the strange 'formal argument "envir" matched by
>>>> multiple actual arguments' error I reported in the previous post,
>>>> to a segfault. In the worse case, nothing apparently happens but
>>>> the output produced by the code is wrong.
>>>>
>>>> Maybe garbage collection requests should be ignored during the
>>>> execution of the finalizer? (and more generally during garbbage
>>>> collection itself)
>>
>> Thanks for the report. The gc proper does not (or should not) do
>> anything that could cause allocation or trigger another gc. The gc
>> proper only identifies objects ready for finalization; running the
>> finalizers happens outside the gc proper where allocation and gc calls
>> should be safe. This looks like either a missing PROTECT call in the
>> code for running finalizers or possibly a more subltle bug in managing
>> the lists of objects in different states of finalization. I will look
>> more carefully when I get a chance.
> 
> This is now fixed in R-devel and the R-patched (it was essentially a
> missing PROTECT call).
> 
> luke
> 

>>
>> luke
>>
>>
>>>>
>>>> Cheers,
>>>> H.
>>>>
>>>> ______________________________________________
>>>> R-devel_at_r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> ______________________________________________
>>> R-devel_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>>
>
-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages_at_fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 13 Jun 2009 - 01:11:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 13 Jun 2009 - 12:35:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive