From maechler at stat.math.ethz.ch  Thu Jul 16 17:56:07 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 16 Jul 2009 17:56:07 +0200
Subject: [Rd] ... gctorture(TRUE) segfault etc
In-Reply-To: <4A5E6F74.30002@fhcrc.org>
References: <20090715013440.v7a1c8r4g0cgksw8@webmail.fhcrc.org>
	<4A5E6F74.30002@fhcrc.org>
Message-ID: <19039.19863.794390.756066@lynne.math.ethz.ch>

>>>>> "HP" == Herv? Pag?s <hpages at fhcrc.org>
>>>>>     on Wed, 15 Jul 2009 17:08:20 -0700 writes:

    HP> Hi,
    >> x <- c(a=10, b=20)
    >> length(x) <- 1
    >> x
    HP> a
    HP> 10

    HP> But with gctorture turned on, I get:

    >> gctorture(TRUE)
    >> x <- c(a=10, b=20)
    >> length(x) <- 1
    >> x
    HP> a
    HP> "a"   <---- ???

    >> x <- c(a=10, b=20)
    >> length(x) <- 3

    HP> *** caught segfault ***
    HP> address (nil), cause 'unknown'

    HP> Possible actions:
    HP> 1: abort (with core dump, if enabled)
    HP> 2: normal R exit
    HP> 3: exit R without saving workspace
    HP> 4: exit R saving workspace

    HP> This seems to have been around for a while (I get this with R 2.10,
    HP> 2.9 and 2.8). Note that I don't get this with an unnamed vector.

    HP> This problem affects the methods package. I found it while
    HP> troubleshooting the "Protection stack overflow" I reported earlier
    HP> (see https://stat.ethz.ch/pipermail/r-devel/2009-July/054030.html)
    HP> but I can't tell yet whether the 2 issues are related or not.

    HP> It would be nice to see some reaction from the R developers
    HP> about these issues. Thanks in advance!

Salut Herv?,
so here comes "some reaction" ..

 {You know we had  "useR! 2009" in Rennes, a big success I think,
  and then a very nice "DSC 2009" in Copenhagen, so many R
  developers were either attending or then were vacationing / too
  busy to attend ==> all reasons for not getting quick replies}

Indeed, you have uncovered quite a nasty bug, and R core will
definitely address it sooner or later.
However, I'm not the one doing that for the time being,
as garbage collection and the protection stack is not my home
ground.

BTW: My subjective probability is pretty high that indeed this
     bug is related to the one you encountered with
     setGeneric() & setMethod() calls, as I also get a	
     "Protection stack overflow" using a variation of the
     example above.

BTW, running under gdb :

> gctorture(TRUE)
> x <- c(a=10, b=20) ; length(x) <- 1
> dput(x)

Program received signal SIGSEGV, Segmentation fault.
0x000000366f823184 in __gconv_transform_utf8_internal () from /lib64/libc.so.6
(gdb) bt
#0  0x000000366f823184 in __gconv_transform_utf8_internal ()
   from /lib64/libc.so.6
#1  0x000000366f88988b in mbrtowc () from /lib64/libc.so.6
#2  0x000000000046e4b1 in Rstrwid (str=0xad76e0 "a", slen=1, 
    ienc=<value optimized out>, quote=34)
    at ../../../R/src/main/printutils.c:304
#3  0x000000000057ed93 in Rf_formatString (x=<value optimized out>, n=1, 
    fieldwidth=0x7fffff3ff1ac, quote=11368166)
    at ../../../R/src/main/format.c:60
#4  0x000000000046f87f in Rf_EncodeElement (x=<value optimized out>, 
    indx=<value optimized out>, quote=34, dec=46 '.')
    at ../../../R/src/main/printutils.c:643
#5  0x0000000000534359 in vector2buff (d=<value optimized out>, 
    vector=<value optimized out>) at ../../../R/src/main/deparse.c:1326
#6  deparse2buff (d=<value optimized out>, vector=<value optimized out>)
    at ../../../R/src/main/deparse.c:1129
#7  0x0000000000537249 in attr2 (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:571
#8  0x000000000053417d in deparse2buff (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:746
#9  0x0000000000537249 in attr2 (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:571
#10 0x000000000053417d in deparse2buff (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:746
#11 0x0000000000537249 in attr2 (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:571
#12 0x000000000053417d in deparse2buff (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:746

..............

#23613 0x0000000000537249 in attr2 (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:571
#23614 0x000000000053417d in deparse2buff (s=0x1913148, d=0x7fffffffb8b0)
    at ../../../R/src/main/deparse.c:746

...............


which very very strongly looks like an infinite loop
( that is not properly caught in the usual way ).

---
Martin



[Rd] ... gctorture(TRUE) segfault etc
Martin Maechler