From gmbecker at ucdavis.edu  Thu Sep  8 18:50:22 2016
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Thu, 8 Sep 2016 09:50:22 -0700
Subject: [Rd] mget call can trigger C stack usage error
In-Reply-To: <CAERMt4cE8maMs7q9=SB2pDHgV56oikBKphxowjGd8L+gX_V22w@mail.gmail.com>
References: <CAERMt4cE8maMs7q9=SB2pDHgV56oikBKphxowjGd8L+gX_V22w@mail.gmail.com>
Message-ID: <CADwqtCM2g-CfH0cBcS-zNdB4jGZWQrJB-WY5RD5=z8jjyqbXFg@mail.gmail.com>

Alexandre,

AFAICS, this code actually causes infinite recursion, and here's why:


   1. formals grabs returns the formals of the function identified by
   sys.function(sys.parent()) this ends up being print.new, whose first
   argument is x
   2. mget looks for the symbol x in envir = as.environment(-1L) which ends
   up being the evaluation frame for print.new [1]
   3. x in that environment resolves the the object you are trying to print
   4. print() is called on that object, and dispatches to print.new() ...



[1]

> debug(mget)

> foo

*<snip>*

[1] "envir"      "ifnotfound" "inherits"   "mode"       "x"

Browse[2]> *envir*

*<environment: 0x7fa39bf1b278>*

Browse[2]> sys.frames()

[[1]]

<environment: 0x7fa39bf1b550>


*[[2]]*

*<environment: 0x7fa39bf1b278>*


*<snip>*


Browse[2]> sys.calls()

[[1]]

function (x, ...)

UseMethod("print")(x)


*[[2]]*

*print.new(x)*


*<snip>*


Browse[2]> class(envir$x)

[1] *"new"*

Hope that helps.
~G

On Mon, Sep 5, 2016 at 4:48 PM, Alexandre Courtiol <
alexandre.courtiol at gmail.com> wrote:

> Hi all, not sure if you will call this a bug or something else but the
> following silly call trigger a low level error:
>
> foo <- list(x=1)
> class(foo) <- "new"
> print.new <- function(x, ...) print(mget(names(formals())))
> foo
>
> > Error: C stack usage  7969412 is too close to the limit
>
>
>
> --
> Alexandre Courtiol
>
> http://sites.google.com/site/alexandrecourtiol/home
>
> *"Science is the belief in the ignorance of experts"*, R. Feynman
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker, PhD
Associate Scientist (Bioinformatics)
Genentech Research

	[[alternative HTML version deleted]]



[Rd] mget call can trigger C stack usage error
Gabriel Becker