Dear Peter,

Thank you very much for your kind and helpful reply.

As I mentioned in a followup email to r-bugs, indeed, one aspect of this
issue is a (user specified) shorter stack than that expected by R -- I
had only allowed 1 MB of stack space a long long time ago, and forgotten
about it.

Due to a glitch with [EMAIL PROTECTED], I ended up submitting this
bug twice, and your original response was attached to (PR#7827), which
Prof Brian Ripley moved to the trashcan, as was appropriate.  

I've taken the liberty of responding to PR#7826 (including your reply,
below) to have your helpful response (specifically, the unclass
suggestion) associated with the representative bug number.

/Jskud

>------ Begin Included Message ------
> To: [EMAIL PROTECTED]
> Cc: r-devel@stat.math.ethz.ch, [EMAIL PROTECTED]
> Subject: Re: [Rd] segfault during build of 2.1.0 on RH9; print.POSIXct 
> implicated (PR#7827)
> From: Peter Dalgaard <[EMAIL PROTECTED]>
> Date: 30 Apr 2005 12:18:56 +0200
> Lines: 73
> 
> [EMAIL PROTECTED] writes:
> >     > unusual_but_ok <- c.POSIXlt(character(0))
> >     > unusual_but_ok
> >     character(0)
> >     > unusual_and_faults <- c.POSIXct(character(0))
> >     > unusual_and_faults
> >     Segmentation fault
> > 
> > Running this test program under gdb, we find that we're running off the
> > end of the stack, with 4222 stack frames showing -- apparently in an
> > infinite recursion -- "as.character" shows up every 69 function calls:
> 
> This gives a protection stack overflow on FC3 and RH8. Is the stack
> particularly small on RH9? I have 8MB on RH8 and 10MB on FC3. (The R
> limits for expression depth and pointer protection were increased in
> 2.1.0). I can force a segfault, but only after "ulimit -s 1024" or so.
> 
> > #64 0x080ea1ef in Rf_usemethod (generic=0x81c8b12 "as.character", obj=0x0, 
> > call=0x85a04f4, 
> ...
> > So it would seem that *printing* the unusual POSIXct value is suspect.
> 
> Pretty obviously, yes.
> 
> > Looking at a R-1.8.1 install, we find these definitions in base/R/base:
> > 
> >     print.POSIXct <- function(x, ...)
> >     {
> >     print(format(x, usetz=TRUE), ...)
> >     invisible(x)
> >     }
> > 
> >     print.POSIXlt <- function(x, ...)
> >     {
> >     print(format(x, usetz=TRUE), ...)
> >     invisible(x)
> >     }
> > 
> > However, looking at the 2.1.0 src file
> > R-2.1.0/src/library/base/R/datetime.R, we find
> > 
> >     print.POSIXct <- function(x, ...)
> >     {
> >     print(format(x, usetz=TRUE, ...), ...)
> >     invisible(x)
> >     }
> > 
> >     print.POSIXlt <- function(x, ...)
> >     {
> >     print(format(x, usetz=TRUE), ...)
> >     invisible(x)
> >     }
> > 
> > Note the suspicious definition of print.POSIXct using *two* sets of
> > ellipses, and that the print.POSIXct and print.POSIXlt definitions no
> > longer match.
> 
> Probably both should use the double ellipses, but "..." will be empty
> on automatic printing, so that's not it. 
> 
> The issue is an infinite recursion inside as.POSIXlt(). Specifically,
> strptime() internally calls as.character(x) inside the fromchar()
> function in as.POSIXlt(), and as.character.POSIXt() invokes format()
> which calls as.POSIXlt() again.
> 
> I think the fix is to unclass(x) inside fromchar(), but perhaps others
> know better?
> 
> 
> -- 
>    O__  ---- Peter Dalgaard             Blegdamsvej 3  
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907
> 
>------  End Included Message  ------

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to