[Rd] (PR#7826) Re: ... print.POSIXct .. infinite recursion

maechler at stat.math.ethz.ch maechler at stat.math.ethz.ch
Sat Apr 30 15:37:32 CEST 2005


Thank you, Jskud.

I can reproduce your problem, though not the
seg.fault, see below

>>>>> "Jskud" == Jskud  <Jskud at Jskud.com>
>>>>>     on Sat, 30 Apr 2005 09:04:03 +0200 (CEST) writes:

    Jskud> In attempting to build R using rpmbuild --rebuild
    Jskud> R-2.1.0-0.fdr.2.fc3.src.rpm

    Jskud> on a fairly up-to-date RedHat 9 system (that is, with
    Jskud> patches installed through May 1 2004), it failed at
    Jskud> the make check-all step.

    Jskud> The problem was reproducible by going into the tests
    Jskud> directory and

    Jskud> 	make test-Segfault

<....>

    Jskud> I was able to reproduce the problem (a segfault) as the following simple
    Jskud> transcript demonstrates: 

    Jskud> LC_ALL=C SRCDIR=. R_DEFAULT_PACKAGES= ../bin/R --vanilla

    Jskud> R : Copyright 2005, The R Foundation for Statistical Computing
    Jskud> Version 2.1.0  (2005-04-18), ISBN 3-900051-07-0

<....>

    >> unusual_but_ok <- c.POSIXlt(character(0))
    >> unusual_but_ok
    Jskud> character(0)
    >> unusual_and_faults <- c.POSIXct(character(0))
    >> unusual_and_faults
    Jskud> Segmentation fault

    Jskud> Running this test program under gdb, we find that we're running off the
    Jskud> end of the stack, with 4222 stack frames showing -- apparently in an
    Jskud> infinite recursion -- "as.character" shows up every 69 function calls:
<........>

    Jskud> So it would seem that *printing* the unusual POSIXct
    Jskud> value is suspect.  

that's correct.

    Jskud> value is suspect.  Looking at a R-1.8.1 install, we
    Jskud> find these definitions in base/R/base:

    Jskud>     print.POSIXct <- function(x, ...)  {
    Jskud> print(format(x, usetz=TRUE), ...)  invisible(x) }

    Jskud>     print.POSIXlt <- function(x, ...)  {
    Jskud> print(format(x, usetz=TRUE), ...)  invisible(x) }

    Jskud> However, looking at the 2.1.0 src file
    Jskud> R-2.1.0/src/library/base/R/datetime.R, we find

    Jskud>     print.POSIXct <- function(x, ...)  {
    Jskud> print(format(x, usetz=TRUE, ...), ...)  invisible(x)
    Jskud> }

    Jskud>     print.POSIXlt <- function(x, ...)  {
    Jskud> print(format(x, usetz=TRUE), ...)  invisible(x) }

    Jskud> Note the suspicious definition of print.POSIXct using
    Jskud> *two* sets of ellipses, and that the print.POSIXct
    Jskud> and print.POSIXlt definitions no longer match.

well, passing the "..." to both format() and print()
is probably on purpose -- and I assume even fixes another bug.  
You are right however in wondering, why this is done only in
print.*ct() and not in print.*lt().

The infinite recursion, BTW, happens with format(), not print()...:
Here is the end of the stack you get from 
traceback(), after e.g. options(expressions = 50)

13: structure(format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...), 
        names = names(x))
12: format.POSIXct(x, ...)
11: format(x, ...)
10: as.character.POSIXt(x)
9: as.character(x)
8: strptime(x, f)
7: fromchar(x)
6: as.POSIXlt(x, tz)
5: inherits(x, "POSIXlt")
4: format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...)
3: structure(format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...), 
       names = names(x))
2: format.POSIXct(unusual_and_faults, usetz = TRUE)
1: format(unusual_and_faults, usetz = TRUE)

- - - 
Unfortunately, I must do less fun things at the moment than
fixing such a bug...  but of course it *will* be fixed rather
sooner than later.

Martin Maechler, ETH Zurich



More information about the R-devel mailing list