Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.84k stars 524 forks source link

perlport: localtime/gmtime with negative numbers on MSWin32 #4846

Closed p5pRT closed 21 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#8253 (status was 'resolved')

Searchable as RT8253$

p5pRT commented 22 years ago

From @eserte

This is a bug report for perl from eserte@​mom.intra.onlineoffice.de\, generated with the help of perlbug 1.33 running under perl v5.6.0.


localtime and gmtime behave differently on Linux/FreeBSD/cygwin and MSWin32 if used with a negative parameter. The first is an output on the Unix-like systems\, the second is the output with ActivePerl build 622.

perl -e "warn scalar gmtime -3600" Wed Dec 31 23​:00​:00 1969 at -e line 1.

D​:\>perl -e "warn scalar gmtime -3600" Warning​: something's wrong at -e line 1.

I think this could be worth a sentence in the perlport documentation. Or maybe the ActivePerl guys can find a workaround.



Flags​:   category=docs   severity=low


This perlbug was built using Perl v5.6.1 - Wed Jun 20 19​:43​:16 CEST 2001 It is being executed now by Perl v5.6.0 - Wed May 3 12​:16​:28 CEST 2000.

Site configuration information for perl v5.6.0​:

Configured by eserte at Wed May 3 12​:16​:28 CEST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration​:   Platform​:   osname=linux\, osvers=2.2.14\, archname=i686-linux   uname='linux mom 2.2.14 #1 mon mar 13 10​:51​:48 gmt 2000 i686 unknown '   config_args='-der'   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef   useperlio=undef d_sfio=undef uselargefiles=define   use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef   Compiler​:   cc='cc'\, optimize='-O2'\, gccversion=2.95.2 19991024 (release)   cppflags='-fno-strict-aliasing -I/usr/local/include'   ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'   stdchar='char'\, d_stdstdio=define\, usevfork=false   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8   d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12   ivtype='long'\, ivsize=4\, nvtype='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8   alignbytes=4\, usemymalloc=n\, prototype=define   Linker and Libraries​:   ld='cc'\, ldflags =' -L/usr/local/lib'   libpth=/usr/local/lib /lib /usr/lib   libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt   libc=\, so=so\, useshrplib=false\, libperl=libperl.a   Dynamic Linking​:   dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-rdynamic'   cccdlflags='-fpic'\, lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:  


@​INC for perl v5.6.0​:   /home/e/eserte/work/WE_Framework/lib   /home/e/eserte/work/WE_Tk_Framework/lib   /home/e/eserte/work/Tk-OO/lib   /usr/local/lib/perl5/5.6.0/i686-linux   /usr/local/lib/perl5/5.6.0   /usr/local/lib/perl5/site_perl/5.6.0/i686-linux   /usr/local/lib/perl5/site_perl/5.6.0   /usr/local/lib/perl5/site_perl   .


Environment for perl v5.6.0​:   HOME=/home/e/eserte   LANG=de_DE   LANGUAGE (unset)   LC_COLLATE=POSIX   LD_LIBRARY_PATH (unset)   LOGDIR (unset)   PATH=/usr/X11R6/bin​:/usr/X11/bin​:/usr/local/bin​:/usr/ucb​:/usr/bin​:/bin​:/usr/gnu/bin​:/usr/TeX/bin​:/usr/etc​:/usr/local/lib​:/usr/local/etc​:/usr/local/sbin​:/usr/sbin​:/sbin​:/home/e/eserte/bin/linux​:/home/e/eserte/bin/sh​:/home/e/eserte/bin​:/usr/www/bin​:/usr/sepia/bin​:/usr/informix/online/bin​:/usr/local/Hughes/bin​:/usr/motif/bin​:/usr/cctb/bin​:/usr/sas​:/usr/ocs/bin​:/home/autos/bin​:/usr/games​:/home/pub/bin/linux​:/home/pub/bin​:/home/pub/bin/pbmplus​:/home/e/eserte/devel/fahrinfo​:/home/e/eserte/devel​:/opt/kde2/bin​:/opt/kde/bin​:/opt/gnome/bin​:/hobbes/opt/kde/bin​:/hobbes/opt/gnome/bin​:/hobbes/usr/X11R6/bin​:/hobbes/usr/local/bin​:/hobbes/usr/bin​:/home/hwsyst55/bin/LINUX_LIBC6​:/home/e/eserte/work/nse-homepage/scripts​:/home/hwsyst55/bin/LINUX_LIBC6​:/home/e/eserte/work/medlive/scripts​:/home/e/eserte/work/WE_Framework/scripts​:/home/e/eserte/work/WE_Tk_Framework/scripts   PERL5LIB=​:/home/e/eserte/work/WE_Framework/lib​:/home/e/eserte/work/WE_Tk_Framework/lib​:/home/e/eserte/work/Tk-OO/lib   PERL_BADLANG (unset)   SHELL=/bin/tcsh

p5pRT commented 21 years ago

From @cwest

http​://rt.perl.org/rt2/Ticket/Display.html?id=8253

Ok. With the help of Sean Burke I've managed to come up with some sort of reasonable text for perlport as the requestor ... requested. The patch is below\, but this is another one of those odd areas for me. I can't decide if we should document that it's broken\, or if it should be fixed. You decide. :-)

Having said that\, I would like to admit that I can't begin to fathom the problem here. Also\, I'm not sure if my assumption on drive usage is correct or if it should really say 'and you are running perl from any drive but C​:'. Please advise.

  Casey West

-- Shooting yourself in the foot with C You shoot yourself in the foot.

Inline Patch ```diff --- perl-current.orig/pod/perlport.pod Thu Apr 10 01:48:00 2003 +++ perl-current/pod/perlport.pod Fri May 9 06:30:04 2003 @@ -600,6 +600,11 @@ some large number. C<$offset> can then be added to a Unix time value to get what should be the proper value on any system. +On Windows, if you pass a negative value to C or C +and you are running perl from a drive other than the one it was +installed on, these functions will return C in scalar context +and an empty list in list context. + =head2 Character sets and character encoding Assume very little about character sets. ```
p5pRT commented 21 years ago

From abe@ztreet.demon.nl

Op een zonnige lentedag (Friday 09 May 2003 12​:55)\, schreef Casey West​:

http​://rt.perl.org/rt2/Ticket/Display.html?id=8253

Ok. With the help of Sean Burke I've managed to come up with some sort of reasonable text for perlport as the requestor ... requested. The patch is below\, but this is another one of those odd areas for me. I can't decide if we should document that it's broken\, or if it should be fixed. You decide. :-)

Having said that\, I would like to admit that I can't begin to fathom the problem here. Also\, I'm not sure if my assumption on drive usage is correct or if it should really say 'and you are running perl from any drive but C​:'. Please advise.

For ActivePerl 5.8.0 (806) this hasn't got anything to do with drives (volumes). It's just that on Windows (at least on my 2k box) localtime() doesn't take a negative argument.

This is from MinGW/include/time.h (GCC for Windows)​:

* NOTE​: localtime\, and perhaps the others of the four functions grouped * below may return NULL if their argument is not 'acceptable'. Also note * that calling asctime with a NULL pointer will produce an Invalid Page * Fault and crap out your program. Guess how I know. Hint​: stat called on * a directory gives 'invalid' times in st_atime etc...

apparently a negative argument is not 'acceptable'

Good luck\,

Abe -- (*) Before the testing posse is on my case :-) let me preempt them by saying that fake networks don't really help here. You'll be testing a fake network. That proves that the module worked on a fake network. That's great. Like drinking decaffeinated.   -- Jarkko Hietaniemi on p5p @​ 2001-11-22

p5pRT commented 21 years ago

From @cwest

It was Friday\, May 09\, 2003 when Abe Timmerman took the soap box\, saying​: : Op een zonnige lentedag (Friday 09 May 2003 12​:55)\, schreef Casey West​: : : > http​://rt.perl.org/rt2/Ticket/Display.html?id=8253 : > : > Ok. With the help of Sean Burke I've managed to come up with some : > sort of reasonable text for perlport as the requestor ... requested. : > The patch is below\, but this is another one of those odd areas for : > me. I can't decide if we should document that it's broken\, or if it : > should be fixed. You decide. :-) : > : > Having said that\, I would like to admit that I can't begin to fathom : > the problem here. Also\, I'm not sure if my assumption on drive usage : > is correct or if it should really say 'and you are running perl from : > any drive but C​:'. Please advise. : : For ActivePerl 5.8.0 (806) this hasn't got anything to do with drives : (volumes). It's just that on Windows (at least on my 2k box) localtime() : doesn't take a negative argument.

That's interesting. In testing\, when called with a negative argument it returns epoch when run from the C​: drive (or the drive where Perl is installed)\, and nothing on the D​: drive. I know you say that drives don't have anything to do with it but this behaviour seems odd. Is it just an inconsistency that shouldn't be relied upon?

: This is from MinGW/include/time.h (GCC for Windows)​: : : * NOTE​: localtime\, and perhaps the others of the four functions grouped : * below may return NULL if their argument is not 'acceptable'. Also note : * that calling asctime with a NULL pointer will produce an Invalid Page : * Fault and crap out your program. Guess how I know. Hint​: stat called on : * a directory gives 'invalid' times in st_atime etc... : : apparently a negative argument is not 'acceptable'

Good note\, that.

  Casey West

-- Shooting yourself in the foot with Smalltalk You spend so much time playing with the graphics and windowing system that your boss shoots you in the foot\, takes away your workstation and makes you develop in COBOL on a character terminal.

p5pRT commented 21 years ago

From @rgs

Casey West wrote​: ...

: For ActivePerl 5.8.0 (806) this hasn't got anything to do with drives : (volumes). It's just that on Windows (at least on my 2k box) localtime() : doesn't take a negative argument.

That's interesting. In testing\, when called with a negative argument it returns epoch when run from the C​: drive (or the drive where Perl is installed)\, and nothing on the D​: drive. I know you say that drives don't have anything to do with it but this behaviour seems odd. Is it just an inconsistency that shouldn't be relied upon?

So\, has the following (intentionally terse) patch your approval :

--- pod/perlport.pod (revision 1200) +++ pod/perlport.pod (working copy) @​@​ -600\,6 +600\,8 @​@​ some large number. C\<$offset> can then be added to a Unix time value to get what should be the proper value on any system.

+On Windows\, you shouldn't pass a negative value to C\ or C\. + =head2 Character sets and character encoding

Assume very little about character sets.

: This is from MinGW/include/time.h (GCC for Windows)​: : : * NOTE​: localtime\, and perhaps the others of the four functions grouped : * below may return NULL if their argument is not 'acceptable'. Also note : * that calling asctime with a NULL pointer will produce an Invalid Page : * Fault and crap out your program. Guess how I know. Hint​: stat called on : * a directory gives 'invalid' times in st_atime etc... : : apparently a negative argument is not 'acceptable'

Good note\, that.

p5pRT commented 21 years ago

From abe@ztreet.demon.nl

Op een zonnige lentedag (Sunday 11 May 2003 16​:36)\, schreef Rafael Garcia-Suarez​:

Casey West wrote​: ...

: For ActivePerl 5.8.0 (806) this hasn't got anything to do with drives : (volumes). It's just that on Windows (at least on my 2k box) : localtime() doesn't take a negative argument.

That's interesting. In testing\, when called with a negative argument it returns epoch when run from the C​: drive (or the drive where Perl is installed)\, and nothing on the D​: drive. I know you say that drives don't have anything to do with it but this behaviour seems odd. Is it just an inconsistency that shouldn't be relied upon?

So\, has the following (intentionally terse) patch your approval :

--- pod/perlport.pod (revision 1200) +++ pod/perlport.pod (working copy) @​@​ -600\,6 +600\,8 @​@​ some large number. C\<$offset> can then be added to a Unix time value to get what should be the proper value on any system.

+On Windows\, you shouldn't pass a negative value to C\ or C\. + =head2 Character sets and character encoding

That looks fine to me\, thanks!

Good luck\,

Abe -- Yitzchak> Or did the "Thanks\, applied" autoresponder miss it :)

Autoresponder busy studying Bulgarian EBCDIC locales. No\, I'm not making this up. I wish.   -- Jarkko Hietaniemi on p5p @​ 2002-01-30

p5pRT commented 21 years ago

From @eserte

Rafael Garcia-Suarez \rgarciasuarez@&#8203;free\.fr writes​:

Casey West wrote​: ..

: For ActivePerl 5.8.0 (806) this hasn't got anything to do with drives : (volumes). It's just that on Windows (at least on my 2k box) localtime() : doesn't take a negative argument.

That's interesting. In testing\, when called with a negative argument it returns epoch when run from the C​: drive (or the drive where Perl is installed)\, and nothing on the D​: drive. I know you say that drives don't have anything to do with it but this behaviour seems odd. Is it just an inconsistency that shouldn't be relied upon?

So\, has the following (intentionally terse) patch your approval :

--- pod/perlport.pod (revision 1200) +++ pod/perlport.pod (working copy) @​@​ -600\,6 +600\,8 @​@​ some large number. C\<$offset> can then be added to a Unix time value to get what should be the proper value on any system.

+On Windows\, you shouldn't pass a negative value to C\ or C\. + =head2 Character sets and character encoding

Assume very little about character sets.

I think somebody said that even on POSIX systems a negative value does not have be interpreted "correctly".

Regards\,   Slaven

: This is from MinGW/include/time.h (GCC for Windows)​: : : * NOTE​: localtime\, and perhaps the others of the four functions grouped : * below may return NULL if their argument is not 'acceptable'. Also note : * that calling asctime with a NULL pointer will produce an Invalid Page : * Fault and crap out your program. Guess how I know. Hint​: stat called on : * a directory gives 'invalid' times in st_atime etc... : : apparently a negative argument is not 'acceptable'

Good note\, that.

-- Slaven Rezic - slaven@​rezic.de

  Berlin Perl Mongers - http​://berliner.pm.org

p5pRT commented 21 years ago

From @rgs

Slaven Rezic wrote​:

I think somebody said that even on POSIX systems a negative value does not have be interpreted "correctly".

I applied this : ==== //depot/perl/pod/perlport.pod#133 (text) ====

@​@​ -600\,6 +600\,9 @​@​ some large number. C\<$offset> can then be added to a Unix time value to get what should be the proper value on any system.

+On Windows (at least)\, you shouldn't pass a negative value to C\ or +C\. +

p5pRT commented 21 years ago

@rgs - Status changed from 'open' to 'resolved'