Integrate perlio:
Jarkko Hietaniemi [Sat, 19 Jan 2002 17:55:55 +0000 (17:55 +0000)]
[ 14335]
Split out core of sv_magic() into sv_magicext().
sv_magic provides the extra restictions (no READONLY, only
one of each type, canned set of vtables), and sv_magicext()
does the actual data twiddling.
Also enhances semantics of ->mg_ptr setting via name/namlen
to allow either an uncopied ptr (namlen == 0), or a Newz()ed
scratch area (namlen > 0 && name == NULL).
sv_magicext also returns the MAGIC * it added.
sv_magicext is intended mainly for PERL_MAGIC_ext (~) magic.
To come sv_unmagicext() - which will remove just one magic
of particular type, and additionaly match against ->mg_ptr,
or the MAGIC * (need to experiment as to which is more natural).

p4raw-link: @14335 on //depot/perlio: 92110913508b9944d111285d9488f2f7b604919c

p4raw-id: //depot/perl@14346

14 files changed:
Configure
embed.fnc
ext/Cwd/t/cwd.t
ext/Devel/DProf/DProf.t
ext/File/Glob/t/basic.t
lib/ExtUtils/MM_BeOS.pm
lib/Time/Local.pm
lib/Time/Local.t
perl.h
t/comp/script.t
t/op/stat.t
t/op/utf8decode.t [changed mode: 0755->0644]
t/run/fresh_perl.t
util.c

index fbeaa0b..59ef5eb 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -20,7 +20,7 @@
 
 # $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $
 #
-# Generated on Fri Jan 18 01:06:38 EET 2002 [metaconfig 3.0 PL70]
+# Generated on Sat Jan 19 05:47:21 EET 2002 [metaconfig 3.0 PL70]
 # (with additional metaconfig patches by perlbug@perl.org)
 
 cat >c1$$ <<EOF
@@ -8026,6 +8026,9 @@ if $test "$cont"; then
                fi
        fi
 fi
+case "$myhostname" in
+'') myhostname=noname ;;
+esac
 : you do not want to know about this
 set $myhostname
 myhostname=$1
@@ -8126,7 +8129,7 @@ case "$myhostname" in
                esac
                case "$dflt" in
                .) echo "(Lost all hope -- silly guess then)"
-                       dflt='.uucp'
+                       dflt='.nonet'
                        ;;
                esac
                $rm -f hosts
index f76805e..cb5dcd4 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1011,7 +1011,7 @@ s |void   |apply_attrs    |HV *stash|SV *target|OP *attrs|bool for_my
 s      |void   |apply_attrs_my |HV *stash|OP *target|OP *attrs|OP **imopsp
 #  if defined(PL_OP_SLAB_ALLOC)
 s      |void*  |Slab_Alloc     |int m|size_t sz
-s      |void   |Slab_Free      |void *op
+s      |void   |Slab_Free      |void *op
 #  endif
 #endif
 
index 88a1b94..8fc61b8 100644 (file)
@@ -31,7 +31,7 @@ eval { fastcwd };
 my $pwd_cmd =
     ($^O eq "MSWin32" || $^O eq "NetWare") ?
         "cd" :
-        (grep { -x && -f } map { "$_/pwd" }
+        (grep { -x && -f } map { "$_/pwd$Config{exe_ext}" }
                           split m/$Config{path_sep}/, $ENV{PATH})[0];
 
 $pwd_cmd = 'SHOW DEFAULT' if $IsVMS;
index 5ecba68..de4064d 100644 (file)
@@ -3,6 +3,7 @@
 BEGIN {
     chdir( 't' ) if -d 't';
     @INC = '../lib';
+    require './test.pl';      # for which_perl() etc
     require Config; import Config;
     if ($Config{'extensions'} !~ /\bDevel\/DProf\b/){
       print "1..0 # Skip: Devel::DProf was not built\n";
@@ -27,7 +28,7 @@ getopts('vI:p:');
 
 $path_sep = $Config{path_sep} || ':';
 $perl5lib = $opt_I || join( $path_sep, @INC );
-$perl = $opt_p || $^X;
+$perl = $opt_p || which_perl();
 
 if( $opt_v ){
        print "tests: @tests\n";
index 2eb891b..d7aeea4 100755 (executable)
@@ -92,9 +92,15 @@ else {
     #print "\@a = ", array(@a);
     rmdir $dir;
     if (scalar(@a) != 0 || GLOB_ERROR == 0) {
-       print "not ";
+       if ($^O eq 'vos') {
+           print "not ok 6 -- hit VOS bug posix-956\n";
+       } else {
+           print "not ok 6\n";
+       }
+    }
+    else {
+       print "ok 6\n";
     }
-    print "ok 6\n";
 }
 
 # check for csh style globbing
index 4ea2cf7..298025d 100644 (file)
@@ -39,7 +39,7 @@ least BeOS has one.
 
 sub perl_archive
   {
-  return '$(PERL_INC)' . "/$Config{libperl}":
+  return File::Spec->catdir('$(PERL_INC)',$Config{libperl});
   }
 
 1;
index e99aab1..126c365 100644 (file)
@@ -3,136 +3,117 @@ use 5.006;
 require Exporter;
 use Carp;
 use strict;
+use integer;
 
-our $VERSION    = '1.02';
+our $VERSION    = '1.03';
 our @ISA       = qw( Exporter );
 our @EXPORT    = qw( timegm timelocal );
 our @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck );
 
-# Set up constants
-our $SEC  = 1;
-our $MIN  = 60 * $SEC;
-our $HR   = 60 * $MIN;
-our $DAY  = 24 * $HR;
+my @MonthDays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+
 # Determine breakpoint for rolling century
-    my $ThisYear = (localtime())[5];
-    my $NextCentury = int($ThisYear / 100) * 100;
-    my $Breakpoint = ($ThisYear + 50) % 100;
-       $NextCentury += 100 if $Breakpoint < 50;
+my $ThisYear     = (localtime())[5];
+my $Breakpoint   = ($ThisYear + 50) % 100;
+my $NextCentury  = $ThisYear - $ThisYear % 100;
+   $NextCentury += 100 if $Breakpoint < 50;
+my $Century      = $NextCentury - 100;
+
+my (%Options, %Cheat);
+
+# Determine the EPOC day for this machine
+my $Epoc = 0; $Epoc = _daygm(gmtime(0));
+%Cheat=(); # clear the cache as epoc has changed
+
+my $MaxDay = do {
+  no integer;
+  int((~0>>1-43200)/86400)-1;
+};
+
+
+sub _daygm {
+    $_[3] + ($Cheat{pack("ss",@_[4,5])} ||= do {
+       my $month = ($_[4] + 10) % 12;
+       my $year = $_[5] + 1900 - $month/10;
+       365*$year + $year/4 - $year/100 + $year/400 + ($month*306 + 5)/10 - $Epoc
+    });
+}
+
+
+sub _timegm {
+    $_[0]  +  60 * $_[1]  +  3600 * $_[2]  +  86400 * &_daygm;
+}
 
-our(%Options, %Cheat);
 
 sub timegm {
-    my (@date) = @_;
-    if ($date[5] > 999) {
-        $date[5] -= 1900;
+    my ($sec,$min,$hour,$mday,$month,$year) = @_;
+
+    if ($year >= 1000) {
+       $year -= 1900;
+    }
+    elsif ($year < 100 and $year >= 0) {
+       $year += ($year > $Breakpoint) ? $Century : $NextCentury;
+    }
+
+    unless ($Options{no_range_check}) {
+       if (abs($year) >= 0x7fff) {
+           $year += 1900;
+           croak "Cannot handle date ($sec, $min, $hour, $mday, $month, $year)";
+       }
+
+       croak "Month '$month' out of range 0..11" if $month > 11 or $month < 0;
+
+       my $md = $MonthDays[$month];
+       ++$md unless $month != 1 or $year % 4 or !($year % 400);
+
+       croak "Day '$mday' out of range 1..$md"   if $mday  > $md  or $mday  < 1;
+       croak "Hour '$hour' out of range 0..23"   if $hour  > 23   or $hour  < 0;
+       croak "Minute '$min' out of range 0..59"  if $min   > 59   or $min   < 0;
+       croak "Second '$sec' out of range 0..59"  if $sec   > 59   or $sec   < 0;
     }
-    elsif ($date[5] >= 0 && $date[5] < 100) {
-        $date[5] -= 100 if $date[5] > $Breakpoint;
-        $date[5] += $NextCentury;
+
+    my $days = _daygm(undef, undef, undef, $mday, $month, $year);
+
+    unless ($Options{no_range_check} or abs($days) < $MaxDay) {
+       $year += 1900;
+       croak "Cannot handle date ($sec, $min, $hour, $mday, $month, $year)";
     }
-    my $ym = pack('C2', @date[5,4]);
-    my $cheat = $Cheat{$ym} || &cheat($ym, @date);
-    $cheat
-    + $date[0] * $SEC
-    + $date[1] * $MIN
-    + $date[2] * $HR
-    + ($date[3]-1) * $DAY;
+
+    $sec + 60*$min + 3600*$hour + 86400*$days;
 }
 
+
 sub timegm_nocheck {
     local $Options{no_range_check} = 1;
     &timegm;
 }
 
+
 sub timelocal {
-    my $t = &timegm;
-    my $tt = $t;
-
-    my (@lt) = localtime($t);
-    my (@gt) = gmtime($t);
-    if ($t < $DAY and ($lt[5] >= 70 or $gt[5] >= 70 )) {
-       # Wrap error, too early a date
-       # Try a safer date
-       $tt += $DAY;
-       @lt = localtime($tt);
-       @gt = gmtime($tt);
-    }
+    my $ref_t = &timegm;
+    my $loc_t = _timegm(localtime($ref_t));
 
-    my $tzsec = ($gt[1] - $lt[1]) * $MIN + ($gt[2] - $lt[2]) * $HR;
+    # Is there a timezone offset from GMT or are we done
+    my $zone_off = $ref_t - $loc_t
+       or return $loc_t;
 
-    if($lt[5] > $gt[5]) {
-       $tzsec -= $DAY;
-    }
-    elsif($gt[5] > $lt[5]) {
-       $tzsec += $DAY;
-    }
-    else {
-       $tzsec += ($gt[7] - $lt[7]) * $DAY;
-    }
+    # Adjust for timezone
+    $loc_t = $ref_t + $zone_off;
 
-    $tzsec += $HR if($lt[8]);
-    
-    my $time = $t + $tzsec;
-    my @test = localtime($time + ($tt - $t));
-    $time -= $HR if $test[2] != $_[2];
-    $time;
+    # Are we close to a DST change or are we done
+    my $dst_off = $ref_t - _timegm(localtime($loc_t))
+       or return $loc_t;
+
+    # Adjust for DST change
+    $loc_t + $dst_off;
 }
 
+
 sub timelocal_nocheck {
     local $Options{no_range_check} = 1;
     &timelocal;
 }
 
-sub cheat {
-    my($ym, @date) = @_;
-    my($sec, $min, $hour, $day, $month, $year) = @date;
-    unless ($Options{no_range_check}) {
- croak "Month '$month' out of range 0..11" if $month > 11   || $month < 0;
-        my $md = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$month];
-       $md++ if $month == 1 &&
-           $year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 100);  # leap
- croak "Day '$day' out of range 1..$md"    if $day   > $md  || $day   < 1;
- croak "Hour '$hour' out of range 0..23"   if $hour  > 23   || $hour  < 0;
- croak "Minute '$min' out of range 0..59"  if $min   > 59   || $min   < 0;
- croak "Second '$sec' out of range 0..59"  if $sec   > 59   || $sec   < 0;
-    }
-    my $guess = $^T;
-    my @g = gmtime($guess);
-    my $lastguess = "";
-    my $counter = 0;
-    while (my $diff = $year - $g[5]) {
-        my $thisguess;
-       croak "Can't handle date (".join(", ",@date).")" if ++$counter > 255;
-       $guess += $diff * (363 * $DAY);
-       @g = gmtime($guess);
-       if (($thisguess = "@g") eq $lastguess){
-           croak "Can't handle date (".join(", ",@date).")";
-           #date beyond this machine's integer limit
-       }
-       $lastguess = $thisguess;
-    }
-    while (my $diff = $month - $g[4]) {
-        my $thisguess;
-       croak "Can't handle date (".join(", ",@date).")" if ++$counter > 255;
-       $guess += $diff * (27 * $DAY);
-       @g = gmtime($guess);
-       if (($thisguess = "@g") eq $lastguess){
-           croak "Can't handle date (".join(", ",@date).")";
-           #date beyond this machine's integer limit
-       }
-       $lastguess = $thisguess;
-    }
-    my @gfake = gmtime($guess-1); #still being sceptic
-    if ("@gfake" eq $lastguess){
-        croak "Can't handle date (".join(", ",@date).")";
-        #date beyond this machine's integer limit
-    }
-    $g[3]--;
-    $guess -= $g[0] * $SEC + $g[1] * $MIN + $g[2] * $HR + $g[3] * $DAY;
-    $Cheat{$ym} = $guess;
-}
-
 1;
 
 __END__
@@ -227,27 +208,21 @@ These routines are quite efficient and yet are always guaranteed to agree
 with localtime() and gmtime().  We manage this by caching the start times
 of any months we've seen before.  If we know the start time of the month,
 we can always calculate any time within the month.  The start times
-themselves are guessed by successive approximation starting at the
-current time, since most dates seen in practice are close to the
-current date.  Unlike algorithms that do a binary search (calling gmtime
-once for each bit of the time value, resulting in 32 calls), this algorithm
-calls it at most 6 times, and usually only once or twice.  If you hit
-the month cache, of course, it doesn't call it at all.
+are calculated using a mathematical formula. Unlike other algorithms
+that do multiple calls to gmtime().
 
 timelocal() is implemented using the same cache.  We just assume that we're
 translating a GMT time, and then fudge it when we're done for the timezone
 and daylight savings arguments.  Note that the timezone is evaluated for
 each date because countries occasionally change their official timezones.
 Assuming that localtime() corrects for these changes, this routine will
-also be correct.  The daylight savings offset is currently assumed 
-to be one hour.
+also be correct.
 
 =head1 BUGS
 
 The whole scheme for interpreting two-digit years can be considered a bug.
 
-Note that the cache currently handles only years from 1900 through 2155.
-
 The proclivity to croak() is probably a bug.
 
 =cut
+
index d70383a..a384b17 100755 (executable)
@@ -19,7 +19,10 @@ use Time::Local;
    [2010, 10, 12, 14, 13, 12],
    [2020,  2, 29, 12, 59, 59],
    [2030,  7,  4, 17, 07, 06],
-   [2038,  1, 17, 23, 59, 59],     # last full day in any tz
+# The following test fails on a surprising number of systems
+# so it is commented out. The end of the Epoch for a 32-bit signed
+# implementation of time_t should be Jan 19, 2038  03:14:07 UTC.
+#  [2038,  1, 17, 23, 59, 59],     # last full day in any tz
   );
 
 # use vmsish 'time' makes for oddness around the Unix epoch
diff --git a/perl.h b/perl.h
index 11cac10..c6a3dcd 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -434,7 +434,7 @@ int usleep(unsigned int);
 #  define MYSWAP
 #endif
 
-/* Cannot include embed.h here on Win32 as win32.h has not
+/* Cannot include embed.h here on Win32 as win32.h has not 
    yet been included and defines some config variables e.g. HAVE_INTERP_INTERN
  */
 #if !defined(PERL_FOR_X2P) && !(defined(WIN32)||defined(VMS))
index 2dbdaf2..6efffdf 100755 (executable)
@@ -3,10 +3,10 @@
 BEGIN {
     chdir 't';
     @INC = '../lib';
-    require './test.pl';
+    require './test.pl';       # for which_perl() etc
 }
 
-my $Perl = which_perl;
+my $Perl = which_perl();
 
 print "1..3\n";
 
index 4857836..1c0d4b2 100755 (executable)
@@ -3,7 +3,7 @@
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
-    require './test.pl';
+    require './test.pl';       # for which_perl() etc
 }
 
 use Config;
@@ -11,7 +11,7 @@ use File::Spec;
 
 plan tests => 69;
 
-my $Perl = which_perl;
+my $Perl = which_perl();
 
 $Is_Amiga   = $^O eq 'amigaos';
 $Is_Cygwin  = $^O eq 'cygwin';
old mode 100755 (executable)
new mode 100644 (file)
index 73680eb..d59d0da 100644 (file)
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
-    require './test.pl';
+    require './test.pl';       # for which_perl() etc
 }
 
 use strict;
 
-my $Perl = which_perl;
+my $Perl = which_perl();
 
 $|=1;
 
diff --git a/util.c b/util.c
index a816cb9..6cc7a77 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4032,7 +4032,11 @@ Perl_new_vstring(pTHX_ char *s, SV *sv)
     return s;
 }
 
-#if !defined(HAS_SOCKETPAIR) && defined(HAS_SOCKET)
+#if !defined(HAS_SOCKETPAIR) && defined(HAS_SOCKET) && defined(AF_INET) && defined(PF_INET) && defined(SOCK_DGRAM)
+#   define EMULATE_SOCKETPAIR_UDP
+#endif
+
+#ifdef EMULATE_SOCKETPAIR_UDP
 static int
 S_socketpair_udp (int fd[2]) {
     dTHX;
@@ -4198,8 +4202,10 @@ Perl_my_socketpair (int family, int type, int protocol, int fd[2]) {
         return -1;
     }
 
+#ifdef EMULATE_SOCKETPAIR_UDP
     if (type == SOCK_DGRAM)
         return S_socketpair_udp (fd);
+#endif
 
     listener = PerlSock_socket (AF_INET, type, 0);
     if (listener == -1)