From hpages at fhcrc.org  Tue Jul  7 02:25:04 2009
From: hpages at fhcrc.org (=?ISO-8859-1?Q?Herv=E9_Pag=E8s?=)
Date: Mon, 06 Jul 2009 17:25:04 -0700
Subject: [Rd] Protection stack overflow when calling
 setGeneric()/setMethod() from within .onLoad()
Message-ID: <4A5295E0.30000@fhcrc.org>

Hi list,

Calling setGeneric()/setMethod() from within the .onLoad() hook
of MyPkg package produces the following error:

   > gctorture(TRUE)
   > library(MyPkg)
   .onLoad(): ok1
   .onLoad(): ok2
   Error : protect(): protection stack overflow
   Error : .onLoad failed in 'loadNamespace' for 'MyPkg'
   Error: package/namespace load failed for 'MyPkg'

This is with the following code in the .onLoad() hook:

   .onLoad <- function(libname, pkgname) {
     cat(".onLoad(): ok1\n")
     setGeneric("foo", function(x, y) standardGeneric("foo"))
     cat(".onLoad(): ok2\n")
     setMethod("foo", c("ANY", "ANY"),
         function(x, y) cat("calling foo,ANY,ANY method\n")
     )
     cat(".onLoad(): ok3\n")
   }

and with R-2.9.0/R-2.9.1 or recent R-devel.

Note that without the call to gctorture(TRUE), everything *seems* to work
fine:

   > library(MyPkg)
   .onLoad(): ok1
   .onLoad(): ok2
   .onLoad(): ok3

but it could be that my session is now corrupted because some users have
reported the nasty and now famous:

   Error in get(name, envir = table) :
     formal argument "envir" matched by multiple actual arguments
   Calls: assign ... .getGeneric -> .cacheGeneric -> .cacheGenericTable -> get

after they've loaded MyPkg and started to run some other code that is not
necessarily calling foo(). Those users are running R-2.9.1 or a very recent
R-devel (less than 1 week old) so they are not triggering the reg.finalizer()
problem reported here (and fixed) a few weeks ago:

   https://stat.ethz.ch/pipermail/r-devel/2009-June/053607.html

Also note that if I make foo() a function of one argument only, I don't
get the protection stack overflow anymore.

Cheers,
H.


-- 
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



[Rd] Protection stack overflow when calling setGeneric()/setMethod() from within .onLoad()
=?ISO-8859-1?Q?Herv=E9_Pag=E8s?=