develooper Front page | perl.perl5.porters | Postings from February 2009

RFC: So, what *shall* we do about st_birthtime, anyway?

Thread Next
From:
Tom Christiansen
Date:
February 27, 2009 02:05
Subject:
RFC: So, what *shall* we do about st_birthtime, anyway?
Message ID:
22723.1235729123@chthon
I’m wondering what’s the cleanest way for Perl to gracefully
acknowledge augmented time stuff in the s̲t̲a̲t̲ structure.
This would seem to mean t̳h̳r̳e̳e̳ things:

  •  adding another −̲X̲ unop
  •  somehow adding another retval to s̲t̲a̲t̲(̲)̲ and l̲s̲t̲a̲t̲(̲)̲
  •  and making allowances for non‐integer times

Traditionally, s̲t̲_̲m̲t̲i̲m̲e̲ and s̲t̲_̲a̲t̲i̲m̲e̲ are in t̲i̲m̲e̲_̲t̲ epoch seconds,
as is s̲t̲_̲c̲t̲i̲m̲e̲.  Perl’s s̲t̲a̲t̲(̲)̲ functions and filetest unops all
agree on this — although −̲C̲ is creation time, not inode change
time in the Land of $Bill.

Well, seems that on BSD systems, i̳n̳c̳l̳u̳d̳i̳n̳g̳ M̳a̳c̳O̳S̳, it’s fancier:

  1.  They’ve all added an s̲t̲_̲b̲i̲r̲t̲h̲t̲i̲m̲e̲, or under OpenBSD,
      mutatis mutandis, _̲_̲s̲t̲_̲b̲i̲r̲t̲h̲t̲i̲m̲e̲.

  2.  Each of the now f̳o̳u̳r̳ s̲t̲_̲ times has t̳w̳o̳ components:
        → a t̲i̲m̲e̲_̲t̲ for epoch seconds
        → a l̲o̲n̲g̲ for nanoseconds

See here:

    /*
     * Structure defined by POSIX.1b to be like a timeval.
     */
    struct timespec {
        time_t  tv_sec;                               /* seconds */
        long    tv_nsec;                      /* and nanoseconds */
    };
    #define TIMEVAL_TO_TIMESPEC(tv, ts) {                         \
        (ts)->tv_sec  = (tv)->tv_sec;                             \
        (ts)->tv_nsec = (tv)->tv_usec * 1000;                     \
    }
    #define TIMESPEC_TO_TIMEVAL(tv, ts) {                         \
        (tv)->tv_sec =  (ts)->tv_sec;                             \
        (tv)->tv_usec = (ts)->tv_nsec / 1000;                     \
    }
    #define st_atime        st_atimespec.tv_sec
    #define st_atimensec    st_atimespec.tv_nsec
    #define st_mtime        st_mtimespec.tv_sec
    #define st_mtimensec    st_mtimespec.tv_nsec
    #define st_ctime        st_ctimespec.tv_sec
    #define st_ctimensec    st_ctimespec.tv_nsec

I’m wondering how those 3 things I mentioned in my initial
paragraph ought best be tackled.  Precedent is mixed and thus
unclear, meaning that multiple models currently inharmoniously
coëxist, with no apparent rhyme nor reason to choose one over
the other:

  ⅰ: We have pragmata like sort.pm and open.pm to change how
     those built‐ins by default operate.

  ⅱ: We have hemipragmata like File::stat, which likewise
     change how their built‐ins act.

  ⅲ: We have vmsish.pm, which can affect several functions.

  ⅳ: We have the File::Glob module, which nonetheless
     affects the g̲l̲o̲b̲(̲)̲ a.k.a. the <̲f̲e̲e̲ f̲o̲o̲ f̲u̲m̲>̲ operator,
     and does so either to C̲O̲R̲E̲:̲:̲g̲l̲o̲b̲(̲)̲ or even superglobally
     to C̲O̲R̲E̲:̲:̲G̲L̲O̲B̲A̲L̲:̲:̲g̲l̲o̲b̲, more after the fashion of some
     non–lexically‐scoped pragma.

  ⅴ: We have Timer::HiRes, which overrides C̲O̲R̲E̲:̲:̲s̲l̲e̲e̲p̲(̲)̲
     with a version accepting a float arg, gives us
     u̲s̲l̲e̲e̲p̲(̲)̲, and, where available, also n̲a̲n̲o̲s̲l̲e̲e̲p̲(̲)̲.

I’ve probably left some out, too, like File::Spec and
File::Basename, not even to mention lovely little bits like

    % perl -MMac::Files -e '$s = FSpGetCatInfo(".");            \
        printf "%12s %s\n", $_, scalar localtime $s->$_         \
            for sort                                            \
                grep { defined *{$CatInfo::{$_}}{CODE} }        \
                grep { /Dat$/ } keys %CatInfo:: '

plus whatever the subfenestrated masses might do.

So I wonder: what route to take on this?  I mildly prefer the
first and last over the middle ones, but in truth haven’t thought
it out very far, and their might be something altogether different
that should be done instead.

One minor road‐pimple is that one can’t from a mere module
easily add a −̲X̲ op.  Or rather, I c̳a̳n̳.  ’Tisn’t the prettiest 
of pictures, though. ☹

    sub X(_) { 0 - (stat($_[0])->st_birthtime) }
                 # sign-extension scares me!

More important, I think, is that considering

    @used = qw{
        e z s u g k
        r w x o R W X O
        f d l p S b c t
        T B M A C
    };
    @unused{ a..z, A..Z } = ();
    delete @unused{ @used };
    print sort keys %unused;

tells me that we have only D̳E̳F̳G̳H̳I̳J̳K̳L̳N̳P̳Q̳U̳V̳Y̳Z̳a̳h̳i̳j̳m̳n̳q̳v̳y̳ left, I
wonder which to choose for true creation time.  I do not enjoy
the unportability of −̲C̲ at all, and wish “we’d” not done that.

Any opinions, notions, ideas?

Any non‐opinions, non‐notions, non‐ideas?

Perhaps −̲N̲ for “natal time”, or −̲G̲ for “genesis time”?

Or am I thinking too small?
 ⬊ 
  ╲
   ⬊ How about a μ̲s̲t̲a̲t̲(̲)̲ ?
    ╲
     ⬊ Should we try for −̲Þ̲ ?
      ╲
       ⬊ Maybe for −̲Γ̲ or −̲γ̲ ⁈
        ╲
         ⬊ Hey, how ’bout using -̲C̲ª̲ or -Ĉ̲̌ or -̲C̲ⁿ̲ ⁉
          ╲
           ╲
            ☠⃝
          ╭ ┬ ╮
          ╰─┼─╯
            ┴̥

Boy, that sure looks like was a slippery slope to me,
and anyway, I̳’̳m̳ j̳u̳s̳t̳ k̳i̳d̳d̳i̳n̳g̳‼ ☻

More seriously, is this a solved problem?

If so, how was it solved?

I also wonder whether this um, “richly diverse” set of disparate
mechanisms we current “enjoy” for internal mut(il)ation might
possibly be something that the numinous Ρϵɾɭ⁶ will oh, like,
just h̳a̳p̳p̳e̳n̳ to clean up, unify, or weed‐out?

Um, puh‐lease? ☺  

——tom


╭────────────────────────────────────────────────────────────────────────╮
│                                                                        │
│   PS: Hey, I c̳o̳u̳l̳d̳ have wrought a missive written in raw tasty t̲r̲o̲f̲f̲!  │
│                                                                        │
├────────────────────────────────────────────────────────────────────────┤
│                                                                        │
│  PPS: Try saying t̳h̳a̳t̳ 3 times really, really fast.  Heh.               │
│                                                                        │
├────────────────────────────────────────────────────────────────────────┤
│                                                                        │
│ PPPS: This has been a test of your terminal emulator’s facility        │
│       and felicity with proper presentation of combined characters,    │
│       inter alios.                                                     │
│                                                                        │
│       I find that x̲t̲e̲r̲m̲(1) passes; anything else?  Gotta love those    │
│       fixed‐width fonts, too.  Heh‐heh.                                │
│                                                                        │
╰────────────────────────────────────────────────────────────────────────╯



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About